Help: call_user_function() core dumps
| From: | Dhiru Pandey | Date: | Wed, 30 Apr 2008 16:52:13 +0000 |
| Subject: | Help: call_user_function() core dumps | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-37364@lists.php.net to get a copy of this message | ||
I am new to PHP extension writing and embedding. Following the book from
Sara Goleman - Extending and Embedding PHP (Developer's Library)
I wrote the following program based on her example in Chap. 20
===================================================================
#include <stdio.h>
#include <stdlib.h>
#include <sapi/embed/php_embed.h>
int main(int argc, char** argv) {
PHP_EMBED_START_BLOCK(argc, argv);zval* args[2]; zval funcname; zval input_str; zval count; zval retval; char* ans;
ZVAL_STRING(&funcname, "str_repeat", 0);args[0] = &input_str; args[1] = &count; ZVAL_STRINGL(args[0], "DHIRU ", 6, 0); ZVAL_LONG(args[1], 5L);
call_user_function(EG(function_table), NULL, &funcname, &retval, 2, args TSRMLS_CC);
ans = Z_STRVAL(retval);
printf("%s\n", ans);
PHP_EMBED_END_BLOCK();
return 0;
}
========================================================================
When I run this program it core dumps with the following message:
/export/home/dhiru/work/php/php-5.2.5/Zend/zend_variables.h(35) : Block 0x08049188 status:
/export/home/dhiru/work/php/php-5.2.5/Zend/zend_variables.c(36) : Actual location (location was relayed)
Invalid pointer: ((thread_id=0x4C45535F) != (expected=0xB78D26B0))
Segmentation fault (core dumped)
When I step thru the debugger it appears that the function str_repeat call is successful
via zend_call_function(), but after the call to the str_repeat function it tries to execute
zend_ptr_stack_clear_multiple(TSRMLS_C), which in turn calls zend_mm_check_ptr() and something
seems to go wrong here :
#ifdef ZTS
if (ZEND_MM_BAD_THREAD_ID(p)) {
if (!silent) {
zend_debug_alloc_output("Invalid pointer: ((thread_id=0x%0.8X) != (expected=0x%0.8X))\n", (long)p->thread_id, (long)tsrm_thread_id());
had_problems = 1;
} else {
return zend_mm_check_ptr(heap, ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
}
#endif
Any help will be greatly appreciated
Thanks,
-Dhiru
P.S.: I am using Ubuntu and PHP 5.2.5