On Wed, 12 Feb 2003 13:40:09 -0800, Eric Lambart wrote:

UPDATE...
If you ask me, this is stranger still.  If you recall from my original
post--

> I am trying to return a "serverId" object member which contains a value
> such as "N^VESoDMN(107)".  Again, right before my PHP_FUNCTION returns
> control to the script, this value is perfect.  When I DON'T use
> --enable-debug, and the serverId is NOT getting completely clobbered,
> the value that is returned by $table->serverId is not "N^VESoDMN(107)".
> It is "N^VESoDMN'107)"
>
> This is not a random thing.  It is very consistent--I have several
> PHP_FUNCTIONs that return serverIds, either with RETVAL_STRING or as a
> member of a more complex object, and server IDs are always in a similar
> format, a string ending with a parenthesized integer.  Yet EVERY time,
> the "(" is replaced by a single quote.

OK, here's an update.  I was not entirely correct about the ( becoming '
being some sort of simple character substitution.

First of all, I have recompiled my extension under PHP 4.3.0 and the
problem persists; exactly the same thing happens.  It is therefore not an 
issue with 4.2.3.

I am no longer using --enable-debug since it was not revealing any memory 
leaks anyway, and the problem with the single-character substitution seemed a
little less abstract than the strings getting completely clobbered, as
with debug enabled.

Second of all, I have narrowed the problem down a bit.  It has nothing to
do with parentheses or single-quotes (surprise!).  Seriously... I just
observed it mangling another string, but what seemed stranger yet, it
changed "\037N^VESOBJ(4)" to "\037N^VESOBJ(3)" (this is output from gdb,
so that's ASCII octal 37, which isn't a printable character and
didn't show up in my previous console output).

So what does this have in common with changing "\037N^VESoDMN(107)" to
"\037N^VESoDMN'107)"?  Simple: it is the 11th character of the string that
is getting changed.  Moreover, it is getting decremented by one.  Just as 3
precedes 4 in the ASCII table, ' precedes ).  These strings that are
getting mangled are not the same variables... not the same zvals or memory
locations or anything.

And in the case of 4 becoming 3, the circumstances are completely
different. It has nothing (at least directly) to do with my extension 
functions.  The only thing they have in common is the location: 
((my zval*)->value->str.val) + 11

Check out this code from my test script:

  $arrayClass = eo_invoke_method($conn, $objPtr, $method, 0, $params);
  echo "arrayClass='$arrayClass'\n";
  $method = "Interface";
  echo "arrayClass='$arrayClass'\n";
  $params = array();
  echo "arrayClass='$arrayClass'\n";

Which produces this console output:

arrayClass='N^VESOBJ(4)'
arrayClass='N^VESOBJ(4)'
arrayClass='N^VESOBJ(3)'

Now to me, this is really baffling.  Right before my variable changes, I am 
initializing the variable $params to be a new array() object (fwiw, $params 
already _was_ an array() containing one value; I am just re-using the variable).
So, in the process of initializing a standard PHP array(), something in the 
Zend engine is mangling my seemingly unrelated variable, $arrayClass... and I 
swear I'm not telling it to!  $arrayClass, coincidentally, refers to an object 
stored on a remote database server, and never contains, nor is ever contained 
IN, a PHP array.  It is just a simple PHP string.

Running trusty (?) old gdb, I set read and write watches on 
$arrayClass->value->str.val, but can't seem to catch where it's changing.  
The read watch is only triggered by PHP processing each echo statement which 
displays $arrayClass's value, the write watchpoint is never caught.

But what could be doing this?  Does the number 11 hold any special significance?
And why is the 11th character being decremented?  Could Zend be trying to 
decrement the refcount for something and pointing to the wrong part of memory?  
I suppose it could be decrementing just about anything, but why the 11th 
character of several different string-containing zvals?  This is obviously 
not completely random.

Please help me before I lose what's left of my mind!

TIA
Eric

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

Reply via email to