zend_parse_parameters question

php.internals

unkno me

22 years ago
Hi, I am using the zend_parse_parameter function to retrieve a string passed to my function like: char* s, int sl; zend_parse_parameter(ZEND_NUM_ARGS() TSRMLS_CC,"s", &s,&sl); and then later I am using the memcmp function to test 2 strings like: memcmp(key,s,sl); but for some reason, the memcmp never return 0 indicates key and s is the same even I KNOW key and s is indeed the same. key and s is always of the same length. In fact, even doing a: fprintf(stderr,"[%s %i]\n",s,sl); yields different result for s and sl than what's really passed to my function. Why is that? Is there a bug in the zend_parse_paramter function that I am not aware of? I should mention that: 1. The string is always ASCII 2. Sometimes, I do see the expected result but not all the time. That's what makes me so confuse. Thanks! __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/

Derick Rethans

22 years ago
On Tue, 27 Jan 2004, unkno me wrote:
> I am using the zend_parse_parameter function to > retrieve a string passed to my function like: > > char* s, int sl;
You need to use a long for sl here.
> > zend_parse_parameter(ZEND_NUM_ARGS() TSRMLS_CC,"s", &s,&sl);
Shouldn't it be zend_parse_parameters (with an extra s?)
> > and then later I am using the memcmp function to test > 2 strings like: > > memcmp(key,s,sl); > > but for some reason, the memcmp never return 0 > indicates key and s is the same even I KNOW key and s > is indeed the same. key and s is always of the same > length. In fact, even doing a: > > fprintf(stderr,"[%s %i]\n",s,sl); > > yields different result for s and sl than what's > really passed to my function. Why is that? Is there a > bug in the zend_parse_paramter function that I am not > aware of? I should mention that: > > 1. The string is always ASCII > 2. Sometimes, I do see the expected result but not all > the time. That's what makes me so confuse.
Might be memory curruption somewhere else, try to run with valgrind to see if that's the case. regards, Derick

unkno me

22 years ago
--- Derick Rethans <derick@php.net> wrote:
> On Tue, 27 Jan 2004, unkno me wrote: > > > I am using the zend_parse_parameter function to > > retrieve a string passed to my function like: > > > > char* s, int sl; > > You need to use a long for sl here.
I changed it. Thanks!
> > > > > zend_parse_parameter(ZEND_NUM_ARGS() > TSRMLS_CC,"s", &s,&sl); > > Shouldn't it be zend_parse_parameters (with an extra > s?) >
Sorry. A typo.
> > Might be memory curruption somewhere else, try to > run with valgrind to > see if that's the case. >
Here is what I got when I passed '100% free stuff' to the function and use fprintf(stderr,"[%s %ld]\n",s,sl) to print them out: [100 free 8] [100 free stuff 14] [free 4] [stuff 5] As you can see, each time the result is different and NONE of them match what really passed it! And the result is not consistent either! I am very confuse about it and don't know how to solve that. Is there a manual way of extracting the paramters from the function instead of using the zend_* API? I have never used valgrind. I know it's a debugger of some sort. Where can I download it? And how can I start it to debug my extension? Thanks! __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/

unkno me

22 years ago
--- Derick Rethans <derick@php.net> wrote: [snip]
> > Might be memory curruption somewhere else, try to > run with valgrind to > see if that's the case. >
I just find out that this behavior only happens when the function is called from a web interface. For example, if I do: dl("myextension.so"); call_the_function("100% free stuff"); from the command line, everything works as expected. But if the function is called from a web request, it doesn't work. Is there something special about using the zend_* API from the web interface? __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/