Hi,
I've noticed that building an extension will fail when using macro
php_stream_from_zval and there is not return_value variable within the
scope.
/root/php-5.1.6/ext/hello/hello.c: In function streamit': /root/php-5.1.6/ext/hello/hello.c:58: error:
return_value' undeclared
(first use in this function)
/root/php-5.1.6/ext/hello/hello.c:58: error: (Each undeclared identifier
is reported only once
/root/php-5.1.6/ext/hello/hello.c:58: error: for each function it
appears in.)
when building
void streamit(zval * zstream TSRMLS_DC)
{
//zval return_value; / Will work if I uncomment this line */
php_stream *stream;
php_stream_from_zval(stream, &zstream);
php_stream_write(stream, "hello\n", 6);
}
PHP_FUNCTION(hello_stream)
{
zval *zstream;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
&zstream))
return;
streamit(zstream TSRMLS_CC);
RETURN_TRUE;
}
When return_value is added, the function will work without a problem.
I'm not sure whether this is bug or expected behavior and if I should
use the bug reporting site or just post it here on the list. Anyhow it
looks strange to me.
Best regards,
Arnold
Hi,
I've noticed that building an extension will fail when using macro
php_stream_from_zval and there is not return_value variable within the
scope.
Well, looks like it's time to install cscope or ctags and use it to see which code actually stands behind a particular macro.
#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
#define ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2)
rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2);
ZEND_VERIFY_RESOURCE(rsrc);
#define ZEND_VERIFY_RESOURCE(rsrc)
if (!rsrc) {
RETURN_FALSE; \ <------------ nb
}
Obviously this macro is not what you need.
I guess you need zend_fetch_resource(), which is the function actually used in ZEND_FETCH_RESOURCE2().
--
Wbr,
Antony Dovgal
You probably want php_stream_from_zval_no_verify which doesn't
auto-return if there is an invalid stream passed in.
--Wez.
Hi,
I've noticed that building an extension will fail when using macro
php_stream_from_zval and there is not return_value variable within the
scope.Well, looks like it's time to install cscope or ctags and use it to see which code actually stands behind a particular macro.
#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
#define ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2)
rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2);
ZEND_VERIFY_RESOURCE(rsrc);#define ZEND_VERIFY_RESOURCE(rsrc)
if (!rsrc) {
RETURN_FALSE; \ <------------ nb
}Obviously this macro is not what you need.
I guess you need zend_fetch_resource(), which is the function actually used in ZEND_FETCH_RESOURCE2().--
Wbr,
Antony Dovgal