Professional Web Applications Themes

[PHP-DEV] help request: passing return value - PHP Development

Hi internals. [background] I'm newbie here and with php extensions. Working on php extension. It should give access to librep. I have very little experience with C. [problem] zval f1(some_args) { zval r; ... return r; } /* f1 can return many different types */ ZEND_FUNCTION(f2) { /* working on some_args here */ ... ... /* here i need to return what f1(some_args) returns */ } What's the best way to pass the result ? Any macro that would ? [tried] To look at another modules. Make f1 be (zval *) and "*return_value=*rep_data_converter(result);" in f2. Since zval is not very ...

  1. #1

    Default [PHP-DEV] help request: passing return value

    Hi internals.

    [background]
    I'm newbie here and with php extensions.
    Working on php extension.
    It should give access to librep.
    I have very little experience with C.

    [problem]

    zval f1(some_args) {
    zval r;
    ...
    return r;
    }

    /* f1 can return many different types */

    ZEND_FUNCTION(f2) {
    /* working on some_args here */
    ...
    ...
    /* here i need to return what
    f1(some_args) returns */
    }

    What's the best way to pass the result ?
    Any macro that would ?
    [tried]

    To look at another modules.

    Make f1 be (zval *) and
    "*return_value=*rep_data_converter(result);"
    in f2.
    Since zval is not very simple structure - it doesn't work.


    P.S.
    Posting this message to php.internals seems to fail.

    --
    NetCat


    ---------------------------------------------------
    FREE 10MB Email + AntiSpam + POP3 + more.
    Get it at [url]http://www.doal.co.il:81/free/?c=antispam[/url]

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    netcat Guest

  2. #2

    Default Re: [PHP-DEV] help request: passing return value

    PHP_FUNCTION (or ZEND_FUNCTION - they are the same)
    includes the function paramters; one of those is:

    zval *return_value;

    which already contains an allocated zval (set to NULL).

    If you want to change this in one of your own functions, you could
    do something like this:

    int f1(zval *return_value, ...)
    {
    ... change the return_value here ...
    return SUCCESS;
    }

    PHP_FUNCTION(my_func)
    {
    if (f1(return_value) == SUCCESS) {
    /* it worked */
    return;
    } else {
    /* it didn't work */
    php_error(....)
    }
    }

    Also take a look in Zend/zend.h at the definitions for
    INTERNAL_FUNCTION_PARAMETERS and
    INTERNAL_FUNCTION_PARAM_PASSTHRU
    which can be used in you own function declarations to handle
    the php function paramters.

    Hope that helps,

    --Wez.

    PS: You're welcome to join the PHP Extension Community Library,
    or PECL, on [email]pecl-devlists.php.net[/email]

    ----- Original Message -----
    From: "netcat" <netcatabox.co.il>
    To: "PHP Development" <internalslists.php.net>
    Sent: Tuesday, October 07, 2003 9:43 AM
    Subject: [PHP-DEV] help request: passing return value

    > Hi internals.
    >
    > [background]
    > I'm newbie here and with php extensions.
    > Working on php extension.
    > It should give access to librep.
    > I have very little experience with C.
    >
    > [problem]
    >
    > zval f1(some_args) {
    > zval r;
    > ...
    > return r;
    > }
    >
    > /* f1 can return many different types */
    >
    > ZEND_FUNCTION(f2) {
    > /* working on some_args here */
    > ...
    > ...
    > /* here i need to return what
    > f1(some_args) returns */
    > }
    >
    > What's the best way to pass the result ?
    > Any macro that would ?
    > [tried]
    >
    > To look at another modules.
    >
    > Make f1 be (zval *) and
    > "*return_value=*rep_data_converter(result);"
    > in f2.
    > Since zval is not very simple structure - it doesn't work.
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php

    Wez Furlong Guest

  3. #3

    Default Re: [PHP-DEV] help request: passing return value

    Wez Furlong wrote:
    >PHP_FUNCTION (or ZEND_FUNCTION - they are the same)
    >includes the function paramters; one of those is:
    >
    >zval *return_value;
    >
    >which already contains an allocated zval (set to NULL).
    >
    >If you want to change this in one of your own functions, you could
    >do something like this:
    >
    >int f1(zval *return_value, ...)
    >{
    > ... change the return_value here ...
    > return SUCCESS;
    >}
    >
    >PHP_FUNCTION(my_func)
    >{
    > if (f1(return_value) == SUCCESS) {
    > /* it worked */
    > return;
    > } else {
    > /* it didn't work */
    > php_error(....)
    > }
    >}
    >
    >
    >
    Thanks a lot, it seems to work.
    >Also take a look in Zend/zend.h at the definitions for
    >INTERNAL_FUNCTION_PARAMETERS and
    >INTERNAL_FUNCTION_PARAM_PASSTHRU
    >
    >
    I will. Thanks again.
    >which can be used in you own function declarations to handle
    >the php function paramters.
    >
    >Hope that helps,
    >
    >--Wez.
    >
    >PS: You're welcome to join the PHP Extension Community Library,
    >or PECL, on [email]pecl-devlists.php.net[/email]
    >
    >----- Original Message -----
    >From: "netcat" <netcatabox.co.il>
    >To: "PHP Development" <internalslists.php.net>
    >Sent: Tuesday, October 07, 2003 9:43 AM
    >Subject: [PHP-DEV] help request: passing return value
    >
    >
    >
    >
    >>Hi internals.
    >>
    >>[background]
    >>I'm newbie here and with php extensions.
    >>Working on php extension.
    >>It should give access to librep.
    >>I have very little experience with C.
    >>
    >>[problem]
    >>
    >>zval f1(some_args) {
    >> zval r;
    >> ...
    >> return r;
    >>}
    >>
    >>/* f1 can return many different types */
    >>
    >>ZEND_FUNCTION(f2) {
    >> /* working on some_args here */
    >> ...
    >> ...
    >> /* here i need to return what
    >> f1(some_args) returns */
    >>}
    >>
    >>What's the best way to pass the result ?
    >>Any macro that would ?
    >>[tried]
    >>
    >>To look at another modules.
    >>
    >>Make f1 be (zval *) and
    >>"*return_value=*rep_data_converter(result);"
    >>in f2.
    >>Since zval is not very simple structure - it doesn't work.
    >>
    >>
    >
    >
    >

    --
    NetCat




    ------------------------------------------------------
    SPAM-Free 10mb Free email + Antivirus + POP3 + more...
    Get it at http://www.doal.co.il:81/free/?c=all-spam

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php

    netcat Guest

Similar Threads

  1. Passing datagrid data with check cellrenderer by request
    By cesarrodriguez in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: April 14th, 01:10 PM
  2. Passing request to service
    By Dino Chiesa [Microsoft] in forum ASP.NET Web Services
    Replies: 0
    Last Post: June 30th, 04:40 AM
  3. Passing request.form contents to a class
    By Stu in forum ASP.NET General
    Replies: 1
    Last Post: August 11th, 01:25 PM
  4. Replies: 1
    Last Post: July 29th, 05:27 AM
  5. Replies: 2
    Last Post: July 4th, 12:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139