# strange php_stream_from_zval requires return_value

- Thread: https://externals.io/message/26508
- Original archive: https://news-web.php.net/php.internals/26508
- Started by Arnold Daniels on 2006-11-11T01:13:40+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26508 — Arnold Daniels — 2006-11-11T01:13:40+00:00

URL: https://externals.io/message/26508#26508

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

---

## #26509 — Antony Dovgal — 2006-11-11T01:30:59+00:00

URL: https://externals.io/message/26508#26509 · In reply to: #26508

> 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

---

## #26517 — Wez Furlong — 2006-11-11T15:59:43+00:00

URL: https://externals.io/message/26508#26517 · In reply to: #26509

You probably want php_stream_from_zval_no_verify which doesn't
auto-return if there is an invalid stream passed in.

--Wez.


> 
> > […]
>
> 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
