最近想把 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
中,有点不明白,求指点
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.