LINUX.ORG.RU

Расширение PHP - segfault

 , ,


0

1

Привет всем! Пишу^W быдлокодю php расширение:

#include "php_text_preprocessor.h"

static zend_function_entry preprocessor_methods[] = {
	PHP_ME(Preprocessor, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
	{NULL, NULL, NULL}
}; 

static zend_function_entry functions[] = { }; 

zend_module_entry text_preprocessor_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
	STANDARD_MODULE_HEADER, 
#endif
	PHP_TEXT_PREPROCESSOR_EXTNAME, 
	functions, 
	PHP_MINIT(text_preprocessor), 
	NULL, 
	NULL, 
	NULL, 
	NULL, 
#if ZEND_MODULE_API_NO >= 20010901
	PHP_TEXT_PREPROCESSOR_VERSION, 
#endif
	STANDARD_MODULE_PROPERTIES
}; 

extern "C" {
#ifdef COMPILE_DL_TEXT_PREPROCESSOR
	ZEND_GET_MODULE(text_preprocessor)
#endif
}

void preprocessor_free_storage(void *object TSRMLS_DC) {
	preprocessor_object *obj = (preprocessor_object *)object; 
	if (obj -> tp) {
		delete obj -> tp; 
		obj -> tp = 0; 
	}
	zend_hash_destroy(obj -> std.properties); 
	FREE_HASHTABLE(obj -> std.properties); 
	efree(obj); 
}

zend_object_value preprocessor_create_handler(zend_class_entry *type TSRMLS_DC) {
	zval *tmp; 
	zend_object_value retval; 
	
	preprocessor_object *obj = (preprocessor_object *)emalloc(sizeof(preprocessor_object)); 
	memset(obj, 0, sizeof(preprocessor_object)); 
	obj -> std.ce = type; 
	
	ALLOC_HASHTABLE(obj -> std.properties); 
	zend_hash_init(obj -> std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); 
	
	#if PHP_VERSION_ID < 50399
		zend_hash_copy(obj -> std.properties, &type -> default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); 
	#else
		object_properties_init(&(obj -> std), preprocessor_ce); 
	#endif
	
	retval.handle   = zend_objects_store_put(obj, NULL, preprocessor_free_storage, NULL TSRMLS_CC); 
	retval.handlers = &preprocessor_object_handlers; 
	return retval; 
}

PHP_MINIT_FUNCTION(text_preprocessor) {
	zend_class_entry ce; 
	INIT_CLASS_ENTRY(ce, PHP_TEXT_PREPROCESSOR_NS "\\Preprocessor", preprocessor_methods); 
	preprocessor_ce = zend_register_internal_class(&ce TSRMLS_CC); 
	preprocessor_ce -> create_object = preprocessor_create_handler;
	memcpy(&preprocessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 
	preprocessor_object_handlers.clone_obj = NULL; 
	preprocessor_ce -> ce_flags |= ZEND_ACC_FINAL_CLASS; 
	return SUCCESS; 
}

PHP_METHOD(Preprocessor, __construct) {
    //char *text; 
	//int text_len = 0; 
	//if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &text, &text_len) != SUCCESS)
	//	return; 
	zval *object = getThis(); 
	preprocessor_object *obj = (preprocessor_object *)zend_object_store_get_object(object TSRMLS_CC); 
	// obj -> tp = new TextPreprocessor(); 
}

Вот здесь при конструировании класса почему-то возникает segmentation fault. Если убрать

PHP_ME(Preprocessor, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)

Естественно всё ок. ЧЯДНТ?



Последнее исправление: Azq2 (всего исправлений: 1)
Ответ на: комментарий от ziemin
php.h:
#define PHP_ME          ZEND_ME

Zend_API.h:

#define ZEND_FENTRY(zend_name, name, arg_info, flags)	{ #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
.....
#define ZEND_ME(classname, name, arg_info, flags)	ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)

Azq2
() автор топика
Ответ на: комментарий от ziemin
- static zend_function_entry functions[] = { }; 
+ static zend_function_entry functions[] = {
+ 	{NULL, NULL, NULL}
+ }; 

Исправил )))

Azq2
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.