V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Nicksxs
V2EX  ›  PHP

求助关于 PHP -leveldb

  •  
  •   Nicksxs · 2017-01-20 16:34:46 +08:00 · 2135 次点击
    这是一个创建于 2866 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近想把 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中,有点不明白,求指点

    2 条回复    2017-01-21 09:44:29 +08:00
    gouchaoer
        1
    gouchaoer  
       2017-01-20 19:42:39 +08:00 via Android
    他有个 php7 分支不知道你看到没, issue 里已经有人能编译出来了,当然只是能 work 估计还要很多工作要做
    Nicksxs
        2
    Nicksxs  
    OP
       2017-01-21 09:44:29 +08:00
    @gouchaoer 嗯嗯,谢谢,昨天没发现,二了,昨天自己改了一整天,还是有很多错误没编译通过, PHP7 底层变化实在是有点大
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1070 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:12 · PVG 03:12 · LAX 11:12 · JFK 14:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.