static void php_phpdbg_destroy_bp_condition(void *data) /* {{{ */ { phpdbg_breakcond_t *brake = (phpdbg_breakcond_t*) data; if (brake) { if (brake->ops) { TSRMLS_FETCH(); destroy_op_array( brake->ops TSRMLS_CC); efree(brake->ops); } efree((char*)brake->code); } } /* }}} */
static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) { TSRMLS_FETCH(); if (PG(display_errors)) { msgpack_globals->error_display = 1; } else { msgpack_globals->error_display = 0; } msgpack_globals->php_only = 1; }
static int himote_info_write_wrapper(const char *str, uint str_length) { int new_len, written; char *elem_esc; TSRMLS_FETCH(); elem_esc = himote_escape_html_entities((unsigned char *)str, str_length, &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC); written = himote_body_write(elem_esc, new_len TSRMLS_CC); efree(elem_esc); return written; }
// Create a PHP object given a typename and call the ctor, optionally passing up to 2 arguments void createObject(char* obj_typename, zval* return_value, int nargs = 0, zval* arg1 = NULL, zval* arg2 = NULL) { TSRMLS_FETCH(); size_t obj_typename_len = strlen(obj_typename); zend_class_entry* ce = zend_fetch_class(obj_typename, obj_typename_len, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); if (! ce) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", obj_typename); RETURN_NULL(); } object_and_properties_init(return_value, ce, NULL); zend_function* constructor = zend_std_get_constructor(return_value TSRMLS_CC); zval* ctor_rv = NULL; zend_call_method(&return_value, ce, &constructor, NULL, 0, &ctor_rv, nargs, arg1, arg2 TSRMLS_CC); zval_ptr_dtor(&ctor_rv); }
static void php_rl_callback_handler(char *the_line) { zval *params[1]; zval dummy; TSRMLS_FETCH(); ZVAL_NULL(&dummy); params[0] = _readline_string_zval(the_line); call_user_function(CG(function_table), NULL, _prepped_callback, &dummy, 1, params TSRMLS_CC); zval_ptr_dtor(¶ms[0]); zval_dtor(&dummy); }
void ZendObjectStore::freeObject(zend_object_handle handle) { zend_object_store_bucket & bucket = m_store.at(handle); assert(bucket.valid); auto & obj = bucket.bucket.obj; if (obj.free_storage) { TSRMLS_FETCH(); HPHP::JIT::VMRegAnchor _; obj.free_storage(obj.object TSRMLS_CC); } bucket.bucket.free_list.next = m_free_list_head; m_free_list_head = handle; bucket.valid = 0; }
/** * Constructor * * The constructor receives a filename as parameter. It uses the normal * PHP include path resolve algorithms to find the location of the file. * * @param name the filename * @param size length of the filename */ File::File(const char *name, size_t size) { // we need the tsrm_ls variable TSRMLS_FETCH(); // resolve the path _path = zend_resolve_path(name, size TSRMLS_CC); // the resolve-path function sometimes returns the original pointer, we // do not want that because we may have to store the pathname in this object if (_path != name) return; // make a full copy of the pathname _path = estrndup(name, size); }
/*VARARGS*/ protected void file_magwarn(struct magic_set *ms, const char *f, ...) { va_list va; char *expanded_format; TSRMLS_FETCH(); va_start(va, f); vasprintf(&expanded_format, f, va); va_end(va); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format); free(expanded_format); }
static void zend_accel_destroy_zend_function(zval *zv) { zend_function *function = Z_PTR_P(zv); TSRMLS_FETCH(); if (function->type == ZEND_USER_FUNCTION) { if (function->op_array.static_variables) { FREE_HASHTABLE(function->op_array.static_variables); function->op_array.static_variables = NULL; } } destroy_zend_function(function TSRMLS_CC); }
static int php_info_printf(const char *fmt, ...) /* {{{ */ { char *buf; int len, written; va_list argv; TSRMLS_FETCH(); va_start(argv, fmt); len = vspprintf(&buf, 0, fmt, argv); va_end(argv); written = php_output_write(buf, len TSRMLS_CC); efree(buf); return written; }
ZEND_API int zend_list_insert(void *ptr, int type) { int index; zend_rsrc_list_entry le; TSRMLS_FETCH(); le.ptr=ptr; le.type=type; le.refcount=1; index = zend_hash_next_free_element(&EG(regular_list)); zend_hash_index_update(&EG(regular_list), index, (void *) &le, sizeof(zend_rsrc_list_entry), NULL); return index; }
void construct_with_zval(zval* _p, size_t _buffer_size) { buffer = reinterpret_cast<char*>(emalloc(_buffer_size)); buffer_ptr = buffer; buffer_used = 0; buffer_size = _buffer_size; p = _p; // Get the transport for the passed protocol zval gettransport; ZVAL_STRING(&gettransport, "getTransport", 0); MAKE_STD_ZVAL(t); ZVAL_NULL(t); TSRMLS_FETCH(); call_user_function(EG(function_table), &p, &gettransport, t, 0, NULL TSRMLS_CC); }
DIR *opendir(const char *dir) { DIR *dp; char *filespec; HANDLE handle; int index; char resolved_path_buff[MAXPATHLEN]; TSRMLS_FETCH(); if (!VCWD_REALPATH(dir, resolved_path_buff)) { return NULL; } filespec = (char *)malloc(strlen(resolved_path_buff) + 2 + 1); if (filespec == NULL) { return NULL; } strcpy(filespec, resolved_path_buff); index = (int)strlen(filespec) - 1; if (index >= 0 && (filespec[index] == '/' || (filespec[index] == '\\' && (index == 0 || !IsDBCSLeadByte(filespec[index-1]))))) filespec[index] = '\0'; strcat(filespec, "\\*"); dp = (DIR *) malloc(sizeof(DIR)); if (dp == NULL) { free(filespec); return NULL; } dp->offset = 0; dp->finished = 0; if ((handle = FindFirstFile(filespec, &(dp->fileinfo))) == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); if (err == ERROR_NO_MORE_FILES || err == ERROR_FILE_NOT_FOUND) { dp->finished = 1; } else { free(dp); free(filespec); return NULL; } } dp->dir = strdup(resolved_path_buff); dp->handle = handle; free(filespec); return dp; }
static luasandbox_timer * luasandbox_timer_alloc() { int status; size_t old_hash_size; off_t i; luasandbox_timer *lt; luasandbox_timer **old_hash; status = pthread_rwlock_wrlock(&timer_hash_rwlock); if (status != SUCCESS) { // Some other error TSRMLS_FETCH(); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to acquire timer rwlock for writing: %s", strerror(errno)); return NULL; } // Allocate the timer and set its id lt = (luasandbox_timer*)pecalloc(1, sizeof(*lt), 1); lt->id = timer_next_id; if (++timer_next_id < 0) { timer_next_id = 1; } // Is it time to increase the hash table size? timer_hash_entries++; if (timer_hash_entries >= timer_hash_size * TIMER_HASH_LOAD_FACTOR) { old_hash = timer_hash; old_hash_size = timer_hash_size; if (timer_hash_size == 0) { timer_hash_size = 10; } else { timer_hash_size = timer_hash_size * 2; } timer_hash = (luasandbox_timer**)pecalloc(timer_hash_size, sizeof(*timer_hash), 1); for (i = 0; i < old_hash_size; i++) { if (old_hash[i]) { timer_hash_insert(old_hash[i]); } } } // Insert the new timer into the hash table timer_hash_insert(lt); pthread_rwlock_unlock(&timer_hash_rwlock); return lt; }
void dcc_php(struct network *net, struct trigger *trig, struct irc_data *data, struct dcc_session *dcc, const char *dccbuf) { zval *ret; TSRMLS_FETCH(); ALLOC_INIT_ZVAL(ret); zend_try { if(zend_eval_string_ex(troll_makearg(dccbuf,trig->mask),&ret,"DCC Code",1 TSRMLS_CC) != SUCCESS) { } } }
/* {{{ apc_reload_cache */ static void apc_clear_cache(int signo, siginfo_t *siginfo, void *context) { TSRMLS_FETCH(); if (apc_user_cache) { apc_cache_clear( apc_user_cache TSRMLS_CC); } apc_rehandle_signal(signo, siginfo, context); #if !defined(WIN32) && !defined(NETWARE) kill(getpid(), signo); #else raise(signo); #endif } /* }}} */
static void suhosin_op_array_ctor(zend_op_array *op_array) { TSRMLS_FETCH(); if (suhosin_zend_extension_entry.resource_number != -1) { unsigned long suhosin_flags = 0; if (SUHOSIN_G(in_code_type) == SUHOSIN_EVAL) { suhosin_flags |= SUHOSIN_FLAG_CREATED_BY_EVAL; } op_array->reserved[suhosin_zend_extension_entry.resource_number] = (void *)suhosin_flags; } }
void directWrite(const char* data, size_t len) { zval writefn; ZVAL_STRING(&writefn, "write", 0); char* newbuf = (char*)emalloc(buffer_used + 1); memcpy(newbuf, buffer, buffer_used); newbuf[buffer_used] = '\0'; zval *args[1]; MAKE_STD_ZVAL(args[0]); ZVAL_STRINGL(args[0], newbuf, buffer_used, 0); TSRMLS_FETCH(); zval ret; ZVAL_NULL(&ret); call_user_function(EG(function_table), &t, &writefn, &ret, 1, args TSRMLS_CC); zval_ptr_dtor(args); zval_dtor(&ret); }
void segv_handler(int sig_num, siginfo_t * info, void * ucontext) { TSRMLS_FETCH(); fflush(stderr); fprintf(stderr, "CRASH(%d): signal %d (%s), address is %p\n", getpid(), sig_num, strsignal(sig_num), info->si_addr); if(CATCH_G(on_crash) & CATCH_STACK) { print_trace(); } if(CATCH_G(on_crash) & CATCH_PHP_STACK) { print_php_trace(); } fflush(stderr); if(CATCH_G(on_crash) & CATCH_STOP) { pause(); } }
int diff_printf(const char *format, ...) { va_list args; int ret; char *buffer; int size; TSRMLS_FETCH(); va_start(args, format); size = vspprintf(&buffer, 0, format, args); ret = PHPWRITE(buffer, size); efree(buffer); va_end(args); return ret; }
/* ------------------------------------------------------------------ */ decContext * decContextSetStatus(decContext *context, uInt status) { #if defined(HAVE_DECIMAL) /* modified for php Decimal Extension */ TSRMLS_FETCH(); extern zend_class_entry *decimal_ce_DecimalException; #endif context->status|=status; #if defined(HAVE_DECIMAL) /* modified for php Decimal Extension */ if (status & context->traps) { zend_throw_exception_ex(decimal_ce_DecimalException, 0 TSRMLS_CC, "DecimalException[status=0x%x, traps=0x%x]", context->status, context->traps); } #else if (status & context->traps) raise(SIGFPE); #endif return context;} // decContextSetStatus
static int suhosin_module_startup(zend_extension *extension) { zend_module_entry *module_entry_ptr; int resid; TSRMLS_FETCH(); /* zend_register_module(&suhosin_module_entry TSRMLS_CC); */ if (zend_hash_find(&module_registry, "suhosin", sizeof("suhosin"), (void **)&module_entry_ptr)==SUCCESS) { if (extension) { extension->handle = module_entry_ptr->handle; } else { zend_extension ext; ext = suhosin_zend_extension_entry; ext.handle = module_entry_ptr->handle; /* zend_llist_add_element(&zend_extensions, &ext); extension = zend_llist_get_last(&zend_extensions); */ extension = &suhosin_zend_extension_entry; } module_entry_ptr->handle = NULL; } else { return FAILURE; } if (SUHOSIN_G(apc_bug_workaround)) { resid = zend_get_resource_handle(extension); } resid = zend_get_resource_handle(extension); suhosin_zend_extension_entry.resource_number = resid; suhosin_hook_treat_data(); suhosin_hook_post_handlers(TSRMLS_C); suhosin_aes_gentables(); suhosin_hook_register_server_variables(); suhosin_hook_header_handler(); suhosin_hook_execute(TSRMLS_C); suhosin_hook_session(TSRMLS_C); return SUCCESS; }
int _record_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line, const char *sql_state, int error_code, const char *error_message) { pdo_nuodb_db_handle *H = (pdo_nuodb_db_handle *)dbh->driver_data; pdo_error_type *pdo_err; pdo_nuodb_error_info *einfo; pdo_nuodb_stmt *S = NULL; PDO_DBG_ENTER("_record_error"); PDO_DBG_INF_FMT("file=%s line=%d", file, line); PDO_DBG_INF_FMT("sql_state=%s error_code=%d error_message=%s", sql_state, error_code, error_message); if (stmt) { S = (pdo_nuodb_stmt*)stmt->driver_data; PDO_DBG_INF_FMT("sql=%s", S->sql); pdo_err = &stmt->error_code; einfo = &S->einfo; } else { pdo_err = &dbh->error_code; einfo = &H->einfo; } einfo->errcode = error_code; einfo->file = file; einfo->line = line; if (einfo->errmsg) { pefree(einfo->errmsg, dbh->is_persistent); einfo->errmsg = NULL; } if (!einfo->errcode) { /* no error */ strcpy(*pdo_err, PDO_ERR_NONE); PDO_DBG_RETURN(0); } einfo->errmsg = pestrdup(error_message, dbh->is_persistent); strncpy(*pdo_err, sql_state, 6); if (!dbh->methods) { TSRMLS_FETCH(); PDO_DBG_INF("Throwing exception"); zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } PDO_DBG_RETURN(einfo->errcode); }
void apd_summary_output_footer(void) { apd_fcall_t *fcall; apd_function_entry_t *function_entry; apd_file_entry_t *file_entry; apd_coverage_t coverage; char *ret; size_t ret_len; TSRMLS_FETCH(); memset(&coverage, 0, sizeof(apd_coverage_t)); php_printf("<table border=\"1\" width=\"100%%\">\n"); php_printf("<tr>\n"); php_printf("<th>Function</th>\n"); php_printf("<th>File</th>\n"); php_printf("<th>Line</th>\n"); php_printf("<th># of calls</th>\n"); php_printf("<th>User</th>\n"); php_printf("<th>System</th>\n"); php_printf("<th>Real</th>\n"); php_printf("</tr>\n"); find_expensive(&coverage, 20 TSRMLS_CC); fcall = coverage.head; while (fcall) { function_entry = fcall->entry; file_entry = apd_array_get(&APD_GLOBALS(summary).files, fcall->file); php_basename(file_entry->filename, strlen(file_entry->filename), NULL, 0, &ret, &ret_len TSRMLS_CC); php_printf("<tr>\n"); php_printf("<td>%s</td>\n", function_entry->name); php_printf("<td><abbr title=\"%s\">%s</abbr></td>\n", file_entry->filename, ret); php_printf("<td>%d</td>\n", fcall->line); php_printf("<td>%d</td>\n", fcall->calls); php_printf("<td>%4.2f</td>\n", (double) fcall->usertime / 1000000); php_printf("<td>%4.2f</td>\n", (double) fcall->systemtime / 1000000); php_printf("<td>%4.2f</td>\n", (double) fcall->realtime / 1000000); php_printf("</tr>\n"); fcall = fcall->next; /* efree(ret); */ } php_printf("</table>\n"); zend_llist_clean(&APD_GLOBALS(summary).call_list); }
zval * util_array_map_deep(zval* arr, zend_fcall_info* fci, zend_fcall_info_cache* fci_cache, zend_bool on_nonscalar) { zval *result, **zvalue; char *key; uint keylen; ulong idx; int type, value_type; HashTable* arr_hash; HashPosition pointer; zval **args[1]; zval **arr_value; MAKE_STD_ZVAL(result); array_init(result); TSRMLS_FETCH(); // Copy a temp array zval temp; temp = *arr; zval_copy_ctor(&temp); arr_hash = Z_ARRVAL_P(&temp); zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); while (zend_hash_get_current_data_ex(arr_hash, (void**) &zvalue, &pointer) == SUCCESS) { type = zend_hash_get_current_key_ex(arr_hash, &key, &keylen, &idx, 0, &pointer); value_type = Z_TYPE_P(*zvalue); if (value_type == IS_ARRAY) { if (type == HASH_KEY_IS_LONG) { add_index_zval(result, idx, util_array_map_deep(*zvalue, fci, fci_cache, on_nonscalar)); } else { add_assoc_zval(result, key, util_array_map_deep(*zvalue, fci, fci_cache, on_nonscalar)); } } else if (value_type == IS_BOOL || value_type == IS_LONG || value_type == IS_DOUBLE || value_type == IS_STRING || on_nonscalar) { zval *retval_ptr = NULL; args[0] = zvalue; (*fci).retval_ptr_ptr = &retval_ptr; (*fci).params = args; if (zend_call_function(fci, fci_cache TSRMLS_CC) == SUCCESS && retval_ptr) { if (type == HASH_KEY_IS_LONG) { add_index_zval(result, idx, retval_ptr); } else { add_assoc_zval(result, key, retval_ptr); } } } zend_hash_move_forward_ex(arr_hash, &pointer); } return result; }
static IPYNotation *get_pinyin_notation(zval *cls) { zval *pylink; IPYNotation *pynotation; TSRMLS_FETCH(); pylink = zend_read_property(Z_OBJCE_P(cls), cls, ZEND_STRL("_pynotation"), 0 TSRMLS_CC); pynotation = (IPYNotation *)zend_fetch_resource(&pylink TSRMLS_CC, -1, PINYIN_NOTATION_LINK_DESC, NULL, 1, le_pinyin_notation_link); if (!pynotation) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong resource handler for IPYNotation."); } return pynotation; }
int php_mongo_io_stream_send(mongo_connection *con, mongo_server_options *options, void *data, int size, char **error_message) { int retval; ERROR_HANDLER_DECLARATION(error_handler) TSRMLS_FETCH(); php_mongo_stream_notify_io(options, MONGO_STREAM_NOTIFY_IO_WRITE, 0, size TSRMLS_CC); ERROR_HANDLER_REPLACE(error_handler, mongo_ce_ConnectionException); retval = php_stream_write(con->socket, (char *) data, size); ERROR_HANDLER_RESTORE(error_handler); if (retval >= size) { php_mongo_stream_notify_io(options, MONGO_STREAM_NOTIFY_IO_COMPLETED, size, size TSRMLS_CC); } return retval; }
void throw_tprotocolexception(char* what, long errorcode) { TSRMLS_FETCH(); zval *zwhat, *zerrorcode; MAKE_STD_ZVAL(zwhat); MAKE_STD_ZVAL(zerrorcode); ZVAL_STRING(zwhat, what, 1); ZVAL_LONG(zerrorcode, errorcode); zval* ex; MAKE_STD_ZVAL(ex); createObject("TProtocolException", ex, 2, zwhat, zerrorcode); zval_ptr_dtor(&zwhat); zval_ptr_dtor(&zerrorcode); throw PHPExceptionWrapper(ex); }
void pvt_fprintf(const char* fmt, ...) { va_list args; char* new_str; TSRMLS_FETCH(); va_start(args, fmt); new_str = pvt_sprintf_real(fmt, args); va_end(args); if (PVT_G(trace_file_f)) { fprintf(PVT_G(trace_file_f), "%s", new_str); } efree(new_str); }
/** * Execute the file * @return Value */ Value File::execute() { // do we already have the opcodes? if (_opcodes) return _opcodes->execute(); // try compiling the file if (!compile()) return nullptr; // we need the tsrm_ls variable (@todo would it be better if this was a member?) TSRMLS_FETCH(); // add the entry to the list of included files zend_hash_add_empty_element(&EG(included_files), _path, ::strlen(_path) + 1); // execute the opcodes return _opcodes->execute(); }