php-5.6.26源代码 - hash存储结构 - 初始化

 

 

初始化
    有指定析构函数,在销毁hash的时候会调用,如:“类似extension=test.so扩展”也是存放在HashTable中的,“类似extension=test.so扩展”的module_shutdown_func函数就是靠hash的析构函数来调用的
zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); 
{
    // zend_hash_init_ex 定义在文件“php-5.6.26\Zend\zend_hash.h”
    #define zend_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection)        _zend_hash_init_ex((ht), (nSize), (pDestructor), (persistent), (bApplyProtection) ZEND_FILE_LINE_CC)
    {
        
        // _zend_hash_init_ex 实现在文件“php-5.6.26\Zend\zend_hash.c”
        ZEND_API int _zend_hash_init_ex(HashTable *ht, uint nSize, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC)
        {
            int retval = _zend_hash_init(ht, nSize, pDestructor, persistent ZEND_FILE_LINE_CC);
            {
                uint i = 3;

                SET_INCONSISTENT(HT_OK);
            
                if (nSize >= 0x80000000) {
                    /* prevent overflow */
                    ht->nTableSize = 0x80000000;
                } else {
                    while ((1U << i) < nSize) {
                        i++;
                    }
                    ht->nTableSize = 1 << i;
                }
            
                ht->nTableMask = 0;    /* 0 means that ht->arBuckets is uninitialized */
                ht->pDestructor = pDestructor; // !!! 析构函数
                ht->arBuckets = (Bucket**)&uninitialized_bucket;
                ht->pListHead = NULL;
                ht->pListTail = NULL;
                ht->nNumOfElements = 0;
                ht->nNextFreeElement = 0;
                ht->pInternalPointer = NULL;
                ht->persistent = persistent;
                ht->nApplyCount = 0;
                ht->bApplyProtection = 1;
                return SUCCESS;
            }
        
            ht->bApplyProtection = bApplyProtection;
            return retval;
        }
    }
}

 

posted on 2018-03-23 18:09  周~~  阅读(138)  评论(0)    收藏  举报

导航