Re: Function names in private strings...

From: Date: Fri, 17 Nov 2000 22:35:31 +0000
Subject: Re: Function names in private strings...
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-38455@lists.php.net to get a copy of this message
On Fri, 17 Nov 2000, David Muse wrote: > I hope this is the right list to post this to... > > I have a software project called SQL Relay with a C++ API. It has a C API > which wraps the C++ API and a PHP API which wraps the C API. > > The PHP API has always worked for me in the past, but a few people have > complained over the last few months of random, strange bugs that I could not > reproduce. I originally dismissed them, then finally looked into my own code > but could never find anything. > > At length, I randomly ran across one of the reported bugs while adding a new > function to the PHP API. > > It appears that in some circumstances, character pointers are getting > reassigned to point to PHP function names. > > For example: > > My C++ API has a private variable: > char *querystring; > > It also has methods: > void sqlrclient::prepareQuery(char *query) { > ... > querystring=query; > ... > } > ... > void sqlrclient::defineOutputBindVariable(char *variable, int length) { > ... > } > ... > void sqlrclient::executeQuery() { > ... > } > > Then, there is a C wrapper API for the C++ API with functions like: > void sqlrc_prepareQuery(sqlrc s,char *query); > void sqlrc_defineOutputBindVariable(sqlrc s,char *variable, int length); > void sqlrc_executeQuery(sqlrc s); > > and at last, a PHP wrapper with functions named the same as the C wrapper. > > When I put some debug code into the C++ API and run the following PHP code: > ... > sqlrc_prepareQuery($s,"begin :output:=100; end;"); > sqlrc_defineOutputBindVariable($s,"output",5); > sqlrc_executeQuery($s) > ... > I find that when the C++ method prepareQuery() exits > querystring=="begin :output:=100; end;" > but at the start of defineOutputBindVariable(), > querystring=="sqlr_defineoutputbindvariable" > > The private variable querystring now points to the name of that function. > It happens every time, and if I leave out the call to > sqlrc_defineOutputBindVariable(), queryclient stays set to the query. > > If I place calls to other functions between those functions, > querystring still gets set to "sqlr_defineoutputbindvariable". Like there's > magic associated with that function. > > Other people have reported the same bug to me, but with different functions > and different private variables. In some cases, a variable in the C++ API's > base class gets reset. > > I've been over all of my code with a fine-toothed comb and can't find anything > that could cause something like that to happen. My Perl and Python wrappers > work just fine. > > I suspect a bug in PHP (or some component of it) though there may be > some too-obvious-to-notice bug in my PHP wrapper code. > > At any rate, is this a known issue? Is there some glaring error that I've > made? Is there anything I can do to debug it further on my end? > > Thanks, > > David Muse > david.muse@zapmedia.com > Quick question: Is your C++ API using C linkage? -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.dev (#38455) next »