php 扩展源码 我无力了吐槽

好为 发布于 2018/08/03 16:41
阅读 229
收藏 0
static zend_class_entry *class_ce;

PHP_METHOD(class_ce, __construct)
{
    zval list;
    array_init(&list);
    add_assoc_long(&list, "age", 5);
    zend_update_property(NULL, getThis(), "list", sizeof("list") - 1, &list TSRMLS_CC);
}

PHP_METHOD(class_ce, put)
{
    zend_string *key;
    zval *value;

    if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &key, &value) == FAILURE) {
        php_error_docref(NULL, E_ERROR, "few arguments");
        RETURN_FALSE;
    }

    zval *list = zend_read_property(NULL, getThis(), "list", sizeof("list") - 1, 0, NULL);
    php_printf("%d\n", zend_hash_num_elements(Z_ARRVAL_P(list)));
    zend_hash_update(Z_ARRVAL_P(list), key, value);
    zend_update_property(class_ce, getThis(), "list", sizeof("list") - 1, list TSRMLS_CC);
    RETURN_TRUE;
}

PHP_METHOD(class_ce, get)
{
    char *key;
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key) == FAILURE) {
        php_error_docref(NULL, E_ERROR, "few arguments");
        RETURN_FALSE;
    }

}

static zend_function_entry class_method[] = {
    PHP_ME(class_ce, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
    PHP_ME(class_ce, put, NULL, ZEND_ACC_PUBLIC)
    PHP_ME(class_ce, get, NULL, ZEND_ACC_PUBLIC)
    PHP_FE_END
};

PHP_MINIT_FUNCTION(test)
{
    zend_class_entry ce;
    INIT_CLASS_ENTRY(ce, "test", class_method);
    zend_register_internal_class(&ce TSRMLS_CC);
    return SUCCESS;
}

 

报错:/Zend/zend_hash.c:658: _zend_hash_add_or_update_i: Assertion `(zend_gc_refcount(&(ht)->gc) == 1) || ((ht)->u.flags & (1<<6))' failed.
Aborted (core dumped)

 

C 代码 主要是实现以下 PHP 代码 功能, 求高人指导一下

<?php

class test
{
    public $list = array();

    public function put($key, $value)
    {
        $this->list[$key] = $value;
        return true;
    }
}

 

 

 

 

已解决:

引用  zend_class_entry 上下文错误

 

 

 

 

加载中
0
开源中国首席C菜鸟
开源中国首席C菜鸟
你这代码非常乱,zend-read-property参数都传,最后的两个参数 1 NULL zend
当前问题已关闭评论
返回顶部
顶部