最近想把 php-leveldb 的扩展升级到 PHP7 (作者很久没维护更新了),渣渣第一次改扩展,碰到很多问题, 比如:
https://github.com/reeze/php-leveldb/blob/master/leveldb.c 这个文件 82 行的 php_leveldb_obj_new
#define php_leveldb_obj_new(obj, class_type) \
zend_object_value retval; \
obj *intern; \
\
intern = (obj *)emalloc(sizeof(obj)); \
memset(intern, 0, sizeof(obj)); \
\
zend_object_std_init(&intern->std, class_type TSRMLS_CC); \
init_properties(intern); \
\
retval.handle = zend_objects_store_put(intern, \
(zend_objects_store_dtor_t) zend_objects_destroy_object, \
php_##obj##_free, NULL TSRMLS_CC); \
retval.handlers = &leveldb_default_handlers; \
\
return retval;
中调用 zend_objects_store_put
函数,在 PHP5 中我看了下第三个参数的类型是 zend_objects_free_object_storage_t
,
ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_store_dtor_t dtor, zend_objects_free_object_storage_t free_storage, zend_objects_store_clone_t clone TSRMLS_DC)
{
zend_object_handle handle;
struct _store_object *obj;
if (EG(objects_store).free_list_head != -1) {
handle = EG(objects_store).free_list_head;
EG(objects_store).free_list_head = EG(objects_store).object_buckets[handle].bucket.free_list.next;
} else {
if (EG(objects_store).top == EG(objects_store).size) {
EG(objects_store).size <<= 1;
EG(objects_store).object_buckets = (zend_object_store_bucket *) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object_store_bucket));
}
handle = EG(objects_store).top++;
}
obj = &EG(objects_store).object_buckets[handle].bucket.obj;
EG(objects_store).object_buckets[handle].destructor_called = 0;
EG(objects_store).object_buckets[handle].valid = 1;
EG(objects_store).object_buckets[handle].apply_count = 0;
obj->refcount = 1;
GC_OBJ_INIT(obj);
obj->object = object;
obj->dtor = dtor?dtor:(zend_objects_store_dtor_t)zend_objects_destroy_object;
obj->free_storage = free_storage;
obj->clone = clone;
obj->handlers = NULL;
#if ZEND_DEBUG_OBJECTS
fprintf(stderr, "Allocated object id #%d\n", handle);
#endif
return handle;
}
但是这边是 php_##obj##_free
,这个有点理解不能了
在 PHP7 里这个好像要放在custom_object_handlers.free_obj
中,有点不明白,求指点
1
gouchaoer 2017-01-20 19:42:39 +08:00 via Android
他有个 php7 分支不知道你看到没, issue 里已经有人能编译出来了,当然只是能 work 估计还要很多工作要做
|