php-c-parser icon indicating copy to clipboard operation
php-c-parser copied to clipboard

Can´t parse rdkafka.h

Open dirx opened this issue 6 years ago • 1 comments

Parsing rdkafka.h gives PHP Warning: Only arrays and Traversables can be unpacked in /app/vendor/ircmaxell/php-c-parser/lib/Context.php on line 140:

https://github.com/ircmaxell/php-c-parser/blob/8dbb1e48655f10d3a996e4a330135c2f294ddce4/lib/Context.php#L140

You may replay this with:

--TEST--
Test  bug
--FILE--

#ifndef TEST
#define TEST 1
#endif

#if TEST
int bar;
#endif

--EXPECT--
int bar;

dirx avatar May 07 '19 19:05 dirx

Back playing around with rdkafka.h & FFIMe....

See: https://github.com/dirx/php-ffi-librdkafka/blob/master/examples/generate-binding.php

I am running into the following issues:

Include features.h (already mentioned in #6)

Currently working around not including includes and defining needed types manually

Unsupported compiler extension __attribute__

Maybe a workaround could be something like https://github.com/eliben/pycparser/wiki/FAQ#what-do-i-do-about-attribute

FFIMe related ParenType exception & missing callback/callable type support

See https://github.com/ircmaxell/FFIMe/pull/9

Unsupported __inline

static RD_INLINE const char *
RD_UNUSED 
rd_kafka_message_errstr(const rd_kafka_message_t *rkmessage) {
	if (!rkmessage->err)
		return NULL;

	if (rkmessage->payload)
		return (const char *)rkmessage->payload;

	return rd_kafka_err2str(rkmessage->err);
}

Leads to Fatal error: Uncaught PHPCParser\Error: ->identifier Not implemented on line 295 in /app/vendor/ircmaxell/php-c-parser/lib/Parser.php on line 841

Missing support for Function type?

When parsing rdkafka.h> dumping C > parsing again...

typedef rd_kafka_resp_err_t
(rd_kafka_interceptor_f_on_commit_t) (
        rd_kafka_t *rk,
        const rd_kafka_topic_partition_list_t *offsets,
        rd_kafka_resp_err_t err, void *ic_opaque);

dumps to

typedef (rd_kafka_resp_err_t(rd_kafka_t *rk, rd_kafka_topic_partition_list_t *offsets, rd_kafka_resp_err_t err, void *ic_opaque)) rd_kafka_interceptor_f_on_commit_t;

and after parsing again - leads to Fatal error: Uncaught PHPCParser\Error: Syntax error, unexpected TYPEDEF_NAME(rd_kafka_resp_err_t), expecting IDENTIFIER or '(' or '*' on line 447 in /app/vendor/ircmaxell/php-c-parser/lib/ParserAbstract.php on line 235

dirx avatar Oct 04 '19 15:10 dirx