CodeGen_PECL int pass-by-reference
| From: | Matt Williamson | Date: | Thu, 13 Sep 2007 16:56:46 +0000 |
| Subject: | CodeGen_PECL int pass-by-reference | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-4875@lists.php.net to get a copy of this message | ||
Hello list,
It was suggested I ask my question here, hope this is appropriate.
I'm trying to write a wrapper extension for the netCDF C library (or the
C++ library would be better, but sounds much harder). So far, I'm trying
to do this with CodeGen_PECL (I've also briefly tried SWIG, but had no
luck).
The problem I'm having is that the netCDF C library has this nasty habit
of returning values using pass-by-reference (it uses the actual return
value for an error code). So far, mostly "int" values. For example, the
nc_open function has the following C prototype:
int nc_open (const char *path, int omode, int *ncidp);
Where the return value is an error code, and the ncidp parameter is
overwritten with the filehandle number of the opened file. But I can't
figure out how to construct a <proto> and <code> block that will make
this work. E.g.:
<function name="nc_open">
<proto>
int nc_open(string path, int omode, resource nc_filehandle &ncidp)
</proto>
<code>
<?data
int intncidp, retval;
retval = nc_open((char*)path, omode, &intncidp);
ncidp = (long)intncidp;
RETURN_LONG(retval);
?>
</code
</function>
Seems like this should work, but the new value for the third parameter
doesn't get passed back to PHP. E.g.:
<?php
$intHandle = 42;
nc_open('/path/to/file.nc', NC_NOWRITE, $intHandle);
//or nc_open('/path/to/file.nc', NC_NOWRITE, &$intHandle); neither works
echo $intHandle;
?>
Outputs "42". And looking at the C function generated by CodeGen_PECL, I
don't see any mechanism there for the value to get passed back, so I
must not be giving the right input to make it happen.
Help?!?
Thanks!
> Le 13 sept. 07 à 14:56, Matthew Williamson a écrit :
>
> > So, to ask again, I want to know what the <function> tag,
> > specifically the <proto> and <code> tags would look like if you
> > wanted to do pass-by-reference (and get a modified value back) in
> > one of the parameters. That's the question. Perhaps I've
> > overcomplicated it with a real-world example, but that is what I
> > want to know.
>
> You should ask on the PECL list, I think Harmut, the CodeGen_PECL
> author, hangs around there more often.
>
>
>
> --
> Bertrand Mansion
> Mamasam
> Work : http://www.mamasam.com
> Blog : http://golgote.freeflux.net
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>