I originally posted this about 20 hours ago, and it has still not
appeared on the newsgroup.  I assume something went wrong, and apologize
if it appears twice.

In my original message, I neglected to mention that I am compiling code
this with PHP 4.2.3, though I have had similar problems with an earlier
version of this extension (on another dev server) with 4.3.0.

---

Hello all,
I have scoured the php.dev group, reading most of the messages I could
find regarding extensions and modules, but could not find any other
reports of this problem anywhere.  I have a feeling there is an obvious
answer.

I have a PHP_FUNCTION() defined within my extension, which is in turn 
calling a standard C function (called "getDataReply()") which is passed 
the standard return_value zval*.  My getDataReply() function initializes 
a Zend object (which I have defined) using object_init_ex(), then calls 
the object's constructor, and then assigns some values to the members of 
the object.

That is all well and good.  Everything works great.  I can use a
php_var_dump() and everything looks as it should.  I even do another
php_var_dump(&return_value, 1 TSRMLS_CC) within my PHP_FUNCTION(), and
sure enough... return_value still contains the proper data structure (see
below).

The problem occurs as soon as control returns to the script.  In my test
script, I do a var_dump() and the data is corrupted!  I have looked at
the Zend internals but forgive me, I don't have the time or patience to 
to step line-by-line through code (using gdb) that has few comments and 
which I don't understand very well.

Can anyone please give me some ideas as to what I could be doing wrong
here?  NOTE that I have discovered that if I perform a deep copy using 
zend_copy_ctor(return_value) before returning to the script, my data is
undamaged... but then I have a big memory leak.  I also anticipate having
very large data sets within my objects, and deep-copying all of that 
every time would be very expensive.

Here is a how I am calling my C function from within my PHP function:

  PHP_FUNCTION(eo_create_object)
  {
    ..
    .. do stuff
    ..

    /* let's see what the server has to say */
    temp = getDataReply(conn, return_value);

    if ( temp )
    {
      .. in this case return_value is set based on the value of temp, a
      .. fairly simple data structure (but this code is NOT being reached;
      .. see below.  return_value is only being modified by the above 
      .. function.
    }
    else
    {
      printf("temp is NULL\n");
    }

    printf("done with getDataReply()\n");

    /* this php_var_dump() returns uncorrupted data */

    php_var_dump(&return_value, 1 TSRMLS_CC);

  } // end eo_create_object()

I don't see why it should make any difference, but in another source file,
getDataReply() is declared like this:

  variant *getDataReply(eo_connection *conn, zval *return_value)
  {
    .. do stuff, init return_value as eo_table class, init it, and fill w/data
  }

The following are the exact results of the php_var_dump() from within 
zif_eo_create_object(), _immediately_ before returning control to the 
script.
-----------------------
  temp is NULL
  done with getDataReply()
  object(eo_table)(10) {
    ["serverId"]=>
    string(14) "N^VESoDMN(94)"
    ["rows"]=>
    int(0)
    ["cols"]=>
    int(0)
    ["namedCols"]=>
    bool(false)
    ["errorText"]=>
    string(0) ""
    ["errorItem"]=>
    string(0) ""
    ["errorId"]=>
    int(0)
    ["flags"]=>
    int(0)
    ["colNames"]=>
    NULL
    ["table"]=>
    NULL
  }

Those data are correct, everything looks PERFECT.

---------

Here is what I am doing in the test script (PHP code):
    
  <?php

  /* $conn is a resource, $o is an associative array */
  $table = eo_create_object($conn, '...table', 0, $o, NULL, NULL, NULL);
  var_dump($table);

  ?>

And here are the results of the last var_dump():
  object(eo_table)(10) {
    ["serverId"]=>
    &UNKNOWN:0
    ["rows"]=>
    &UNKNOWN:0
    ["cols"]=>
    int(0)
    ["namedCols"]=>
    bool(false)
    ["errorText"]=>
    string(0) ""
    ["errorItem"]=>
    string(0) ""
    ["errorId"]=>
    int(0)
    ["flags"]=>
    int(0)
    ["colNames"]=>
    NULL
    ["table"]=>
    NULL
  }

...as you can see, some of the values have been corrupted.  As soon as I try 
to access $table->serverId, PHP segfaults in erealloc().  I will not include 
the backtrace here as it seems irrelevant; serverId no longer has a legitimate 
value, so of course it cannot be accessed.

This is a simple example.  The member variable "table", when it has a value, 
contains an associative array.  Sometimes those values are OK, sometimes they
are corrupted.  I have had other strange corruptions in returned values, and 
I do not understand why.

Thanks for any help you can offer,
Eric

-- 
This message was created in a marvelously Microsoft-free computing environment.

To email me, ADD "spam" before the "bo"

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

Reply via email to