/* {{{ apc_cache_make_context_ex */ PHP_APCU_API zend_bool apc_cache_make_context_ex(apc_context_t* context, apc_serializer_t* serializer, apc_malloc_t _malloc, apc_free_t _free, apc_protect_t _protect, apc_unprotect_t _unprotect, apc_pool_type pool_type, apc_copy_type copy_type, uint force_update) { /* attempt to create the pool */ context->pool = apc_pool_create( pool_type, _malloc, _free, _protect, _unprotect ); if (!context->pool) { apc_warning("Unable to allocate memory for pool."); return 0; } /* set context information */ context->serializer = serializer; context->copy = copy_type; context->force_update = force_update; /* set this to avoid memory errors */ memset(&context->copied, 0, sizeof(HashTable)); return 1; } /* }}} */
/* {{{ apc_lookup_class_hook */ int apc_lookup_class_hook(char *name, int len, ulong hash, zend_class_entry ***ce) { apc_class_t *cl; apc_context_t ctxt = {0,}; TSRMLS_FETCH(); if(zend_is_compiling(TSRMLS_C)) { return FAILURE; } if(zend_hash_quick_find(APCG(lazy_class_table), name, len, hash, (void**)&cl) == FAILURE) { return FAILURE; } ctxt.pool = apc_pool_create(APC_UNPOOL, apc_php_malloc, apc_php_free, apc_sma_protect, apc_sma_unprotect TSRMLS_CC); ctxt.copy = APC_COPY_OUT_OPCODE; if(install_class(*cl, &ctxt, 0 TSRMLS_CC) == FAILURE) { apc_warning("apc_lookup_class_hook: could not install %s" TSRMLS_CC, name); return FAILURE; } if(zend_hash_quick_find(EG(class_table), name, len, hash, (void**)ce) == FAILURE) { apc_warning("apc_lookup_class_hook: known error trying to fetch class %s" TSRMLS_CC, name); return FAILURE; } return SUCCESS; }
/* {{{ apc_lookup_function_hook */ int apc_lookup_function_hook(char *name, int len, ulong hash, zend_function **fe) { apc_function_t *fn; int status = FAILURE; apc_context_t ctxt = {0,}; TSRMLS_FETCH(); ctxt.pool = apc_pool_create(APC_UNPOOL, apc_php_malloc, apc_php_free, apc_sma_protect, apc_sma_unprotect TSRMLS_CC); ctxt.copy = APC_COPY_OUT_OPCODE; if(zend_hash_quick_find(APCG(lazy_function_table), name, len, hash, (void**)&fn) == SUCCESS) { *fe = apc_copy_function_for_execution(fn->function, &ctxt TSRMLS_CC); if (fe == NULL) return FAILURE; status = zend_hash_add(EG(function_table), fn->name, fn->name_len+1, *fe, sizeof(zend_function), NULL); } return status; }
/* {{{ apc_iterator_item */ static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, slot_t **slot_pp) { zval *zvalue; char md5str[33]; slot_t *slot = *slot_pp; apc_context_t ctxt = {0, }; apc_iterator_item_t *item = ecalloc(1, sizeof(apc_iterator_item_t)); if (slot->key.type == APC_CACHE_KEY_FILE) { /* keys should be unique and with stat=1 we could have multiple files with the same name, so use '<device> <inode>' instead */ #ifdef PHP_WIN32 item->key_len = spprintf(&item->key, 0, "%I64d %I64d", slot->key.data.file.device, slot->key.data.file.inode); #else item->key_len = spprintf(&item->key, 0, "%ld %ld", (ulong)slot->key.data.file.device, (ulong)slot->key.data.file.inode); #endif item->filename_key = estrdup(slot->value->data.file.filename); } else if (slot->key.type == APC_CACHE_KEY_USER) { item->key = estrndup((char*)slot->key.data.user.identifier, slot->key.data.user.identifier_len); item->key_len = slot->key.data.user.identifier_len; item->filename_key = item->key; } else if (slot->key.type == APC_CACHE_KEY_FPFILE) { item->key = estrndup((char*)slot->key.data.fpfile.fullpath, slot->key.data.fpfile.fullpath_len); item->key_len = slot->key.data.fpfile.fullpath_len; } else { apc_eprint("Internal error, invalid entry type."); } ALLOC_INIT_ZVAL(item->value); array_init(item->value); if (APC_ITER_TYPE & iterator->format) { if(slot->value->type == APC_CACHE_ENTRY_FILE) { add_assoc_string(item->value, "type", "file", 1); } else if(slot->value->type == APC_CACHE_ENTRY_USER) { add_assoc_string(item->value, "type", "user", 1); } } if (APC_ITER_FILENAME & iterator->format) { if(slot->value->type == APC_CACHE_ENTRY_FILE) { if (slot->key.type == APC_CACHE_KEY_FILE) { add_assoc_string(item->value, "filename", slot->value->data.file.filename, 1); } else { /* APC_CACHE_FPFILE */ add_assoc_string(item->value, "filename", (char*)slot->key.data.fpfile.fullpath, 1); } } } if (APC_ITER_DEVICE & iterator->format) { if(slot->key.type == APC_CACHE_KEY_FILE) { #ifdef PHP_WIN32 char buf[20]; sprintf(buf, "%I64d", slot->key.data.file.device); add_assoc_string(item->value, "device", buf, 1); #else add_assoc_long(item->value, "device", slot->key.data.file.device); #endif } } if (APC_ITER_INODE & iterator->format) { if(slot->key.type == APC_CACHE_KEY_FILE) { #ifdef PHP_WIN32 char buf[20]; sprintf(buf, "%I64d", slot->key.data.file.device); add_assoc_string(item->value, "device", buf, 1); #else add_assoc_long(item->value, "inode", slot->key.data.file.inode); #endif } } if (APC_ITER_KEY & iterator->format) { add_assoc_stringl(item->value, "key", item->key, item->key_len, 1); } if (APC_ITER_VALUE & iterator->format) { if(slot->value->type == APC_CACHE_ENTRY_USER) { ctxt.pool = apc_pool_create(APC_UNPOOL, apc_php_malloc, apc_php_free, NULL, NULL); ctxt.copy = APC_COPY_OUT_USER; MAKE_STD_ZVAL(zvalue); apc_cache_fetch_zval(zvalue, slot->value->data.user.val, &ctxt); apc_pool_destroy(ctxt.pool); add_assoc_zval(item->value, "value", zvalue); } } if (APC_ITER_MD5 & iterator->format) { if(slot->value->type == APC_CACHE_ENTRY_FILE) { if(slot->key.md5) { make_digest(md5str, slot->key.md5); add_assoc_string(item->value, "md5", md5str, 1); } } } if (APC_ITER_NUM_HITS & iterator->format) { add_assoc_long(item->value, "num_hits", slot->num_hits); } if (APC_ITER_MTIME & iterator->format) { add_assoc_long(item->value, "mtime", slot->key.mtime); } if (APC_ITER_CTIME & iterator->format) { add_assoc_long(item->value, "creation_time", slot->creation_time); } if (APC_ITER_DTIME & iterator->format) { add_assoc_long(item->value, "deletion_time", slot->deletion_time); } if (APC_ITER_ATIME & iterator->format) { add_assoc_long(item->value, "access_time", slot->access_time); } if (APC_ITER_REFCOUNT & iterator->format) { add_assoc_long(item->value, "ref_count", slot->value->ref_count); } if (APC_ITER_MEM_SIZE & iterator->format) { add_assoc_long(item->value, "mem_size", slot->value->mem_size); } if (APC_ITER_TTL & iterator->format) { if(slot->value->type == APC_CACHE_ENTRY_USER) { add_assoc_long(item->value, "ttl", slot->value->data.user.ttl); } } return item; }