Re: CodeGen_PECL int pass-by-reference

From: Date: Thu, 13 Sep 2007 03:12:47 +0000
Subject: Re: CodeGen_PECL int pass-by-reference
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-27916@lists.php.net to get a copy of this message
On Sep 12, 2007, at 7:15 PM, Justin Patrin wrote:
Are you trying to get back an int or a pointer to an int? In C passing an int by reference means passing a pointer to an int (int * var). If the function is allocating an int and returning the pointer to it for you to use then it would be an int ** var.
No, pretty sure what I need back is a value--I'm not sure what I'd do with the pointer if it got returned to PHP anyway. nc_open, for example, takes three parameters. The last parameter is an int, which the nc_open function modifies, and sets to be what is basically a filehandle number, which is the handle that is used to refer to the file in later function calls. The function's /return value/ is an error code (or zero for no error), so it uses that third parameter to pass back the filehandle number. I did figure out part of my problem: the compiler warnings were there because when CodeGen_PECL generates the C code for the extension, any "int" types from the prototype are actually represented as "long"s, so I just had to do some type coercion in the <code> block to get the warning to go away. But I still have the fundamental problem that the variable I pass in the third parameter to nc_open doesn't get modified. E.g.: <?php $intHandle = 42; nc_open('/path/to/file.nc', NC_NOWRITE, $intHandle); // or &$intHandle ... neither works echo $intHandle; ?> outputs "42". I put a printf statement in the <code> block to output the value that the C code sees (after the wrapped C call to nc_open), and it was "3", for example. But the changed variable doesn't get sent back in the third parameter. Help?!?

« previous php.pear.general (#27916) next »