PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int persistent, int codepage) { char *C_str; uint length = 0; //request needed buffersize uint reqSize = WideCharToMultiByte(codepage, WC_COMPOSITECHECK, unicode_str, -1, NULL, 0, NULL, NULL); if(reqSize) { C_str = (char *) pemalloc(sizeof(char) * reqSize, persistent); //convert string length = WideCharToMultiByte(codepage, WC_COMPOSITECHECK, unicode_str, -1, C_str, reqSize, NULL, NULL) - 1; } else { C_str = (char *) pemalloc(sizeof(char), persistent); *C_str = 0; php_error(E_WARNING,"Error in php_OLECHAR_to_char()"); } if(out_length) *out_length = length; return C_str; }
static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */ { zend_file_handle fh; browscap_parser_ctx ctx = {0}; if (filename == NULL || filename[0] == '\0') { return FAILURE; } fh.handle.fp = VCWD_FOPEN(filename, "r"); fh.opened_path = NULL; fh.free_filename = 0; if (!fh.handle.fp) { zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename); return FAILURE; } fh.filename = filename; fh.type = ZEND_HANDLE_FP; browdata->htab = pemalloc(sizeof *browdata->htab, persistent); if (browdata->htab == NULL) { return FAILURE; } zend_hash_init_ex(browdata->htab, 0, NULL, persistent ? browscap_entry_dtor_persistent : browscap_entry_dtor, persistent, 0); browdata->kv_size = 16 * 1024; browdata->kv_used = 0; browdata->kv = pemalloc(sizeof(browscap_kv) * browdata->kv_size, persistent); /* Create parser context */ ctx.bdata = browdata; ctx.current_entry = NULL; ctx.current_section_name = NULL; ctx.str_empty = zend_string_init("", sizeof("")-1, persistent); ctx.str_one = zend_string_init("1", sizeof("1")-1, persistent); zend_hash_init(&ctx.str_interned, 8, NULL, NULL, persistent); zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW, (zend_ini_parser_cb_t) php_browscap_parser_cb, &ctx); /* Destroy parser context */ if (ctx.current_section_name) { zend_string_release(ctx.current_section_name); } zend_string_release(ctx.str_one); zend_string_release(ctx.str_empty); zend_hash_destroy(&ctx.str_interned); return SUCCESS; }
/* {{{ proto bool SolrInputDocument::addField(string field_name, field_value [, float field_boost]) Adds a field to the document. Can be called multiple times. */ PHP_METHOD(SolrInputDocument, addField) { solr_char_t *field_name = NULL, *field_value = NULL; COMPAT_ARG_SIZE_T field_name_length = 0, field_value_length = 0; solr_document_t *doc_entry = NULL; double field_boost = 0.0; /* Process the parameters passed to the method */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|d", &field_name, &field_name_length, &field_value, &field_value_length, &field_boost) == FAILURE) { RETURN_FALSE; } if (!field_name_length) { RETURN_FALSE; } /* Retrieve the document entry for the SolrDocument instance */ if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) { solr_field_list_t *field_values = NULL; /* If the field already exists in the SolrDocument instance append the value to the field list queue */ if ((field_values = (solr_field_list_t *)zend_hash_str_find_ptr(doc_entry->fields, field_name, field_name_length)) != NULL) { if (solr_document_insert_field_value(field_values, (solr_char_t *)field_value, field_boost) == FAILURE) { RETURN_FALSE; } } else { /* Otherwise, create a new one and add it to the hash table */ field_values = (solr_field_list_t *) pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT); memset(field_values, 0, sizeof(solr_field_list_t)); field_values->count = 0L; field_values->field_boost = 0.0; field_values->field_name = (solr_char_t *) pestrdup((char *)field_name, SOLR_DOCUMENT_FIELD_PERSISTENT); field_values->head = NULL; field_values->last = NULL; if (solr_document_insert_field_value(field_values, field_value, field_boost) == FAILURE) { solr_destroy_field_list(field_values); RETURN_FALSE; } if (zend_hash_str_add_ptr(doc_entry->fields, field_name, field_name_length,(void *) field_values) == NULL) { solr_destroy_field_list(field_values); RETURN_FALSE; } /* Increment field count only when HEAD is added */ doc_entry->field_count++; } RETURN_TRUE; } RETURN_FALSE; }
/** * Gets the contents of the BLOB b and offers it to Zend for parsing/execution */ void exec_php(BLOBCALLBACK b, PARAMDSC *res, ISC_SHORT *init) { int result, remaining = b->blob_total_length, i = 0; char *code = pemalloc(remaining+1, 1); ISC_USHORT read; for (code[remaining] = '\0'; remaining > 0; remaining -= read) b->blob_get_segment(b->blob_handle, &code[i++<<16],min(0x10000,remaining), &read); LOCK(); switch (init && *init) { default: #ifdef PHP_EMBED php_request_shutdown(NULL); if (FAILURE == (result = php_request_startup(TSRMLS_C))) { break; } case 0: #endif /* feed it to the parser */ zend_first_try { result = zend_eval_stringl(code, b->blob_total_length, NULL, "Firebird Embedded PHP engine" TSRMLS_CC); } zend_end_try(); } UNLOCK(); free(code); res->dsc_dtype = dtype_long; *(ISC_LONG*)res->dsc_address = (result == SUCCESS); }
/** * Helpers for sticking items into the Gir namespace */ char* gir_enum_constant_name(const char *ns_name, const char *constant, const char *name, zend_bool persistent) { char *phpname = pemalloc(4 + strlen(ns_name) + strlen(constant) + strlen(name) + 2, persistent); sprintf(phpname, "Gir\\%s\\%s\\%s", ns_name, name, constant); return phpname; }
/* get the curl item of the key */ static CURL* find(char *key, uint key_len) { uint i; curl_item *item; for (i=0; i<ITEM_MAX; i++) { item = items[i]; if (item == NULL) { item = pemalloc(sizeof(curl_item), 1); item->key = key; item->key_len = key_len; item->curl = curl_easy_init(); if (item->curl != NULL) { curl_easy_setopt(item->curl, CURLOPT_HEADER, 0); curl_easy_setopt(item->curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); items[i] = item; return item->curl; } return NULL; } if (item->key_len == key_len && (strcmp(item->key, key) == 0)) { return item->curl; } } return replace(key, key_len); }
/** * This function allocates a persistent zval and copy the string with pestrndup (persistent). */ void MAKE_PZVAL_STR(zval** zdata, zval * zstr) { *zdata = pemalloc(sizeof(zval), 1); Z_TYPE_PP(zdata) = Z_TYPE_P(zstr); Z_STRVAL_PP(zdata) = pestrndup(Z_STRVAL_P(zstr), Z_STRLEN_P(zstr), 1); Z_STRLEN_PP(zdata) = Z_STRLEN_P(zstr); }
ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent) /* {{{ */ { stack->top_element = stack->elements = (void **) pemalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE, persistent); stack->max = PTR_STACK_BLOCK_SIZE; stack->top = 0; stack->persistent = persistent; }
/* {{{ _mysqlnd_pemalloc */ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold); #endif DBG_ENTER(mysqlnd_pemalloc_name); DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno); #if PHP_DEBUG /* -1 is also "true" */ if (*threshold) { #endif ret = pemalloc(REAL_SIZE(size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { ret = NULL; } #endif DBG_INF_FMT("size=%lu ptr=%p persistent=%u", size, ret, persistent); if (ret && collect_memory_statistics) { enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_MALLOC_COUNT:STAT_MEM_EMALLOC_COUNT; enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_MALLOC_AMOUNT:STAT_MEM_EMALLOC_AMOUNT; *(size_t *) ret = size; MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size); } DBG_RETURN(FAKE_PTR(ret)); }
ZEND_API void zend_interned_strings_init(void) { char s[2]; int i; zend_string *str; zend_init_interned_strings_ht(&interned_strings_permanent, 1); zend_new_interned_string = zend_new_interned_string_permanent; zend_string_init_interned = zend_string_init_interned_permanent; /* interned empty string */ str = zend_string_alloc(sizeof("")-1, 1); ZSTR_VAL(str)[0] = '\000'; zend_empty_string = zend_new_interned_string_permanent(str); s[1] = 0; for (i = 0; i < 256; i++) { s[0] = i; zend_one_char_string[i] = zend_new_interned_string_permanent(zend_string_init(s, 1, 1)); } /* known strings */ zend_known_strings = pemalloc(sizeof(zend_string*) * ((sizeof(known_strings) / sizeof(known_strings[0]) - 1)), 1); for (i = 0; i < (sizeof(known_strings) / sizeof(known_strings[0])) - 1; i++) { str = zend_string_init(known_strings[i], strlen(known_strings[i]), 1); zend_known_strings[i] = zend_new_interned_string_permanent(str); } }
/* {{{ void field_copy_constructor(solr_field_list_t **original_field_queue) */ PHP_SOLR_API void field_copy_constructor(solr_field_list_t **original_field_queue) { solr_field_list_t *new_field_queue = NULL; solr_field_value_t *ptr = (*original_field_queue)->head; if (ptr == NULL) { return; } new_field_queue = (solr_field_list_t *) pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT); new_field_queue->count = 0L; new_field_queue->field_name = (solr_char_t *) pestrdup((char *) (*original_field_queue)->field_name, SOLR_DOCUMENT_FIELD_PERSISTENT); new_field_queue->head = NULL; new_field_queue->last = NULL; new_field_queue->field_boost = (*original_field_queue)->field_boost; while(ptr != NULL) { solr_document_insert_field_value(new_field_queue, ptr->field_value, 0); ptr = ptr->next; } *original_field_queue = new_field_queue; }
static int lsapi_activate_user_ini_mk_user_config(_lsapi_activate_user_ini_ctx *ctx, void* next) { fn_activate_user_ini_chain_t *fn_next = next; /* Find cached config entry: If not found, create one */ ctx->entry = zend_hash_str_find_ptr(&user_config_cache, ctx->path, ctx->path_len); if (ctx->entry) { DEBUG_MESSAGE("found entry for %s", ctx->path); } else { DEBUG_MESSAGE("entry for %s not found, creating new entry", ctx->path); ctx->entry = pemalloc(sizeof(user_config_cache_entry), 1); ctx->entry->expires = 0; zend_hash_init(&ctx->entry->user_config, 0, NULL, config_zval_dtor, 1); zend_hash_str_update_ptr(&user_config_cache, ctx->path, ctx->path_len, ctx->entry); } if (*fn_next) { return (*fn_next)(ctx, fn_next + 1); } else { return SUCCESS; } }
int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC) { zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS); INIT_PZVAL(property); ZVAL_BOOL(property, value); return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC); }
static void function_copy_ctor(zval *zv) /* {{{ */ { zend_function *old_func = Z_FUNC_P(zv); Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1); memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function)); function_add_ref(Z_FUNC_P(zv)); }
static PHP_INI_MH(OnChangeCallback) /* {{{ */ { if (EG(in_execution)) { if (ASSERTG(callback)) { zval_ptr_dtor(&ASSERTG(callback)); ASSERTG(callback) = NULL; } if (new_value && (ASSERTG(callback) || new_value_length)) { MAKE_STD_ZVAL(ASSERTG(callback)); ZVAL_STRINGL(ASSERTG(callback), new_value, new_value_length, 1); } } else { if (ASSERTG(cb)) { pefree(ASSERTG(cb), 1); } if (new_value && new_value_length) { ASSERTG(cb) = pemalloc(new_value_length + 1, 1); memcpy(ASSERTG(cb), new_value, new_value_length); ASSERTG(cb)[new_value_length] = '\0'; } else { ASSERTG(cb) = NULL; } } return SUCCESS; }
void *riack_php_persistent_alloc(void *ptr, size_t size)/* {{{ */ { if (size == 0) { return 0; } return pemalloc(size, 1); }
void *riack_php_alloc(void* ptr, size_t size)/* {{{ */ { if (size == 0) { return 0; } return pemalloc(size, 0); }
static void *s_pemalloc_fn(const memcached_st *memc, size_t size, void *context) { zend_bool *is_persistent = memcached_get_user_data(memc); return pemalloc(size, *is_persistent); }
/* {{{ proto bool SolrInputDocument::updateField(string fieldName, int modifier, string value) */ PHP_METHOD(SolrInputDocument, updateField) { solr_char_t *field_name = NULL, *field_value = NULL; COMPAT_ARG_SIZE_T field_name_length = 0, field_value_len = 0; solr_document_t *doc_entry; solr_field_list_t *field; uint field_exists = 0; long modifier = 0L; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &field_name, &field_name_length, &modifier, &field_value, &field_value_len) == FAILURE) { return; } if (!field_name_length || !field_value_len) { RETURN_FALSE; } if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == FAILURE) { return; } switch (modifier) { case SOLR_FIELD_VALUE_MOD_ADD: case SOLR_FIELD_VALUE_MOD_REMOVE: case SOLR_FIELD_VALUE_MOD_REMOVEREGEX: case SOLR_FIELD_VALUE_MOD_SET: case SOLR_FIELD_VALUE_MOD_INC: break; default: solr_throw_exception_ex(solr_ce_SolrIllegalArgumentException, SOLR_ERROR_4003 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_4003_MSG); return; } if ((field = zend_hash_str_find_ptr(doc_entry->fields, field_name, field_name_length)) == NULL){ field = (solr_field_list_t *)pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT); memset(field, 0, sizeof(solr_field_list_t)); field->field_name = pestrdup(field_name, SOLR_DOCUMENT_FIELD_PERSISTENT); field->count = 1; field->head = NULL; field->last = NULL; if (modifier > 0) { field->modified = 1; } doc_entry->field_count++; if (zend_hash_str_add_ptr(doc_entry->fields, field_name, field_name_length, field) == NULL) { RETURN_FALSE; } } else if (field->modified == 0) { solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_4004 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_4004_MSG); RETURN_FALSE; } solr_document_insert_field_value(field, field_value, 0.0, modifier); }
/* {{{ PHP_SOLR_API int solr_document_insert_field_value(solr_field_list_t *queue, const solr_char_t *field_value, double field_boost) */ PHP_SOLR_API int solr_document_insert_field_value(solr_field_list_t *queue, const solr_char_t *field_value, double field_boost) { solr_field_value_t *new_entry = (solr_field_value_t *) pemalloc(sizeof(solr_field_value_t), SOLR_DOCUMENT_FIELD_PERSISTENT); if (new_entry == NULL) { return FAILURE; } new_entry->field_value = (solr_char_t *) pestrdup((char *) field_value, SOLR_DOCUMENT_FIELD_PERSISTENT); if (new_entry->field_value == NULL) { return FAILURE; } new_entry->next = NULL; if (queue->head == NULL) { /* This is the first and only item in the field list */ queue->head = new_entry; queue->last = new_entry; /* Update the field boost value */ if (field_boost > 0.0) { queue->field_boost = field_boost; } } else { /* There are already entries in the list. */ /* Append to the end of the queue */ queue->last->next = new_entry; /* Set the last item in the queue to the latest entry */ queue->last = new_entry; /* Update the field boost value */ if (field_boost > 0.0) { if (queue->field_boost > 0.0) { queue->field_boost *= field_boost; } else { queue->field_boost = field_boost; } } } queue->count++; return SUCCESS; }
/* {{{ php_mb_regex_globals_alloc */ zend_mb_regex_globals *php_mb_regex_globals_alloc(void) { zend_mb_regex_globals *pglobals = pemalloc( sizeof(zend_mb_regex_globals), 1); if (SUCCESS != _php_mb_regex_globals_ctor(pglobals)) { pefree(pglobals, 1); return NULL; } return pglobals; }
php_driver_ref* php_driver_new_peref(void *data, php_driver_free_function destructor, int persistent) { php_driver_ref *ref = (php_driver_ref*) pemalloc(sizeof(php_driver_ref), persistent); ref->data = data; ref->destruct = destructor; ref->count = 1; return ref; }
static void auto_global_copy_ctor(zval *zv) /* {{{ */ { zend_auto_global *old_ag = (zend_auto_global *) Z_PTR_P(zv); zend_auto_global *new_ag = pemalloc(sizeof(zend_auto_global), 1); new_ag->name = old_ag->name; new_ag->auto_global_callback = old_ag->auto_global_callback; new_ag->jit = old_ag->jit; Z_PTR_P(zv) = new_ag; }
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c) { void *ret; zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT); memcpy(copy, c, sizeof(zend_constant)); ret = zend_hash_add_ptr(ht, key, copy); if (!ret) { pefree(copy, c->flags & CONST_PERSISTENT); } return ret; }
int sapi_stack_init_ex(sapi_stack *stack, int persistent) { stack->top = 0; stack->persistent = persistent; stack->elements = (void **) pemalloc(sizeof(void **) * STACK_BLOCK_SIZE, persistent); if (!stack->elements) { return FAILURE; } else { stack->max = STACK_BLOCK_SIZE; return SUCCESS; } }
PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length) { *left = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); *right = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); if (*left == NULL || *right == NULL) { goto exit_fail; } (*left)->buf = pemalloc(length, in->is_persistent); (*left)->buflen = length; memcpy((*left)->buf, in->buf, length); (*left)->refcount = 1; (*left)->own_buf = 1; (*left)->is_persistent = in->is_persistent; (*right)->buflen = in->buflen - length; (*right)->buf = pemalloc((*right)->buflen, in->is_persistent); memcpy((*right)->buf, in->buf + length, (*right)->buflen); (*right)->refcount = 1; (*right)->own_buf = 1; (*right)->is_persistent = in->is_persistent; return SUCCESS; exit_fail: if (*right) { if ((*right)->buf) { pefree((*right)->buf, in->is_persistent); } pefree(*right, in->is_persistent); } if (*left) { if ((*left)->buf) { pefree((*left)->buf, in->is_persistent); } pefree(*left, in->is_persistent); } return FAILURE; }
ZEND_API zend_bool gc_enable(zend_bool enable) { zend_bool old_enabled = GC_G(gc_enabled); GC_G(gc_enabled) = enable; if (enable && !old_enabled && GC_G(buf) == NULL) { GC_G(buf) = (gc_root_buffer*) pemalloc(sizeof(gc_root_buffer) * GC_DEFAULT_BUF_SIZE, 1); GC_G(buf)[0].ref = NULL; GC_G(buf_size) = GC_DEFAULT_BUF_SIZE; GC_G(gc_threshold) = GC_THRESHOLD_DEFAULT + GC_FIRST_ROOT; gc_reset(); } return old_enabled; }
static int compact_hash_table(HashTable *ht) { uint i = 3; uint j; uint nSize; Bucket *d; Bucket *p; if (!ht->nNumOfElements || (ht->u.flags & HASH_FLAG_PACKED)) { /* Empty tables don't allocate space for Buckets */ return 1; } if (ht->nNumOfElements >= 0x80000000) { /* prevent overflow */ nSize = 0x80000000; } else { while ((1U << i) < ht->nNumOfElements) { i++; } nSize = 1 << i; } if (nSize >= ht->nTableSize) { /* Keep the size */ return 1; } d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(zend_uint)), ht->u.flags & HASH_FLAG_PERSISTENT); if (!d) { return 0; } for (i = 0, j = 0; i < ht->nNumUsed; i++) { p = ht->arData + i; if (Z_TYPE(p->val) != IS_UNDEF) { d[j++] = *p; } } ht->nNumUsed = j; pefree(ht->arData, ht->u.flags & HASH_FLAG_PERSISTENT); ht->arData = d; ht->arHash = (zend_uint *)(d + nSize); ht->nTableSize = nSize; ht->nTableMask = ht->nTableSize - 1; zend_hash_rehash(ht); return 1; }
/* Given a bucket, returns a version of that bucket with a writeable buffer. * If the original bucket has a refcount of 1 and owns its buffer, then it * is returned unchanged. * Otherwise, a copy of the buffer is made. * In both cases, the original bucket is unlinked from its brigade. * If a copy is made, the original bucket is delref'd. * */ PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket) { php_stream_bucket *retval; php_stream_bucket_unlink(bucket); if (bucket->refcount == 1 && bucket->own_buf) { return bucket; } retval = (php_stream_bucket*)pemalloc(sizeof(php_stream_bucket), bucket->is_persistent); memcpy(retval, bucket, sizeof(*retval)); retval->buf = pemalloc(retval->buflen, retval->is_persistent); memcpy(retval->buf, bucket->buf, retval->buflen); retval->refcount = 1; retval->own_buf = 1; php_stream_bucket_delref(bucket); return retval; }
static void copy_zend_constant(zval *zv) { zend_constant *c = Z_PTR_P(zv); ZEND_ASSERT(c->flags & CONST_PERSISTENT); Z_PTR_P(zv) = pemalloc(sizeof(zend_constant), 1); memcpy(Z_PTR_P(zv), c, sizeof(zend_constant)); c = Z_PTR_P(zv); c->name = zend_string_copy(c->name); if (Z_TYPE(c->value) == IS_STRING) { Z_STR(c->value) = zend_string_dup(Z_STR(c->value), 1); } }