A question about php_streams

php.internals

Mikey

21 years ago
Hi NG! This is my first post to this NG and would like to prefix my question with the following: - I have read the manual, thoroughly. There is absolutely nothing in there apart from how to call the funtion. - I have searched the mailing list archives, to no avail. - I have grep'ed the source, and have found one use of this function in opendir(), this has had limited usefulness. - I have googled, and this had provided a great big list of manual mirrors for my future reference ;-) Although I did find a page with a CVS commit on it that had modified my example code. I am trying to write a function that will recurse a directory, now the logic of that is my bat and I am not seeking help with that. But I have tried using the php_streams API to open the base directory with the following code: php_stream *base_dir = NULL; php_stream_context *context = NULL; TSRMLS_FETCH(); base_dir = php_stream_opendir (TMPL_G(template_dir), ENFORCE_SAFE_MODE|REPORT_ERRORS, context); However, everytime I try to run the module with this last line, I get a segfault in apache. Now I am not very capable when it comes to Linux C development and am only vaguely familiar with what gdb does, so I can't really provide you with any other info than this. Any help, pointers, etc would be greatly appreciated... Mikey

Sara Golemon

21 years ago
> php_stream *base_dir = NULL; > > php_stream_context *context = NULL; > > TSRMLS_FETCH(); > > base_dir = php_stream_opendir (TMPL_G(template_dir), > ENFORCE_SAFE_MODE|REPORT_ERRORS, context); >
That code is (on the surface at least) fine.
> However, everytime I try to run the module with this last line, I get a > segfault in apache. Now I am not very capable when it comes to Linux C > development and am only vaguely familiar with what gdb does, so I can't > really provide you with any other info than this. >
Here's some instructions on generating a backtrace: http://bugs.php.net/bugs-generating-backtrace.php Also, check to make sure that TMPL_G(template_dir) is (A) defined, and (B) points to a NULL terminated string in a memory segmet accessable to the process. Of course, the backtrace will reveal that anyway. -Sara

Mikey

21 years ago
> Here's some instructions on generating a backtrace: > http://bugs.php.net/bugs-generating-backtrace.php
OK, well this is the only output I get from gdb that isn't (no debugging symbols found): Program received signal SIGSEGV, Segmentation fault. 0x4045853b in zend_hash_index_update_or_next_insert (ht=0x40538dc8, h=0, pData=0xbffff3e0, nDataSize=12, pDest=0x0, flag=1) at /usr/local/src/php-4.3.10/Zend/zend_hash.c:390 390 p = ht->arBuckets[nIndex]; Does this help?
> Also, check to make sure that TMPL_G(template_dir) is (A) > defined, and (B) points to a NULL terminated string in a > memory segmet accessable to the process. Of course, the > backtrace will reveal that anyway.
A) Has to be defined as it is the macro for accessing global variables: #define TMPL_G(v) (tmpl_globals.v) B) I read in the header file that the TSRMLS_FETCH(); call was all I needed to make for access to the global vars in a helper function. Is this correct? Thanks for your help, Mikey

Sara Golemon

21 years ago
>> Here's some instructions on generating a backtrace: >> http://bugs.php.net/bugs-generating-backtrace.php > > OK, well this is the only output I get from gdb that isn't (no debugging > symbols found): > > Program received signal SIGSEGV, Segmentation fault. > 0x4045853b in zend_hash_index_update_or_next_insert (ht=0x40538dc8, h=0, > pData=0xbffff3e0, > nDataSize=12, pDest=0x0, flag=1) at > /usr/local/src/php-4.3.10/Zend/zend_hash.c:390 > 390 p = ht->arBuckets[nIndex]; > > Does this help? >
Not really...can you include the entire backtrace? Did you compile with --enable-debug?
>> Also, check to make sure that TMPL_G(template_dir) is (A) >> defined, and (B) points to a NULL terminated string in a >> memory segmet accessable to the process. Of course, the >> backtrace will reveal that anyway. > > A) Has to be defined as it is the macro for accessing global variables: > #define TMPL_G(v) (tmpl_globals.v) > B) I read in the header file that the TSRMLS_FETCH(); call was all I > needed > to make for access to the global vars in a helper function. Is this > correct? >
You misunderstood. I mean make sure that TMPL_G(template_dir) != NULL, and that whatever TMPL_G(template_dir) points to (as in the address referred to by the char* datatype) has meaningful data in it. -Sara