/* {{{ gmp_zval_binary_ui_op2_ex Execute GMP binary operation which returns 2 values. May return GMP resources or longs if operation allows this. */ static inline void gmp_zval_binary_ui_op2_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op2_t gmp_op, gmp_binary_ui_op2_t gmp_ui_op, int allow_ui_return, int check_b_zero TSRMLS_DC) { mpz_t *gmpnum_a, *gmpnum_b, *gmpnum_result1, *gmpnum_result2; zval r; int use_ui = 0; unsigned long long_result = 0; int arga_tmp = 0, argb_tmp = 0; FETCH_GMP_ZVAL(gmpnum_a, a_arg, arga_tmp); if (gmp_ui_op && Z_TYPE_PP(b_arg) == IS_LONG && Z_LVAL_PP(b_arg) >= 0) { /* use _ui function */ use_ui = 1; } else { FETCH_GMP_ZVAL(gmpnum_b, b_arg, argb_tmp); } if(check_b_zero) { int b_is_zero = 0; if(use_ui) { b_is_zero = (Z_LVAL_PP(b_arg) == 0); } else { b_is_zero = !mpz_cmp_ui(*gmpnum_b, 0); } if(b_is_zero) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero operand not allowed"); FREE_GMP_TEMP(arga_tmp); FREE_GMP_TEMP(argb_tmp); RETURN_FALSE; } } INIT_GMP_NUM(gmpnum_result1); INIT_GMP_NUM(gmpnum_result2); if (use_ui && gmp_ui_op) { if (allow_ui_return) { long_result = gmp_ui_op(*gmpnum_result1, *gmpnum_result2, *gmpnum_a, (unsigned long)Z_LVAL_PP(b_arg)); } else { gmp_ui_op(*gmpnum_result1, *gmpnum_result2, *gmpnum_a, (unsigned long)Z_LVAL_PP(b_arg)); } } else { gmp_op(*gmpnum_result1, *gmpnum_result2, *gmpnum_a, *gmpnum_b); } FREE_GMP_TEMP(arga_tmp); FREE_GMP_TEMP(argb_tmp); array_init(return_value); ZEND_REGISTER_RESOURCE(&r, gmpnum_result1, le_gmp); add_index_resource(return_value, 0, Z_LVAL(r)); if (use_ui && allow_ui_return) { mpz_clear(*gmpnum_result2); add_index_long(return_value, 1, long_result); } else { ZEND_REGISTER_RESOURCE(&r, gmpnum_result2, le_gmp); add_index_resource(return_value, 1, Z_LVAL(r)); } }
PHP_METHOD(WinGdiPath, invertRectangle) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval *coords_zval, **tmp; RECT rect_coords; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &coords_zval) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); // Is this the best way to do this? zend_hash_index_find(Z_ARRVAL_P(coords_zval), 0, (void **)&tmp); rect_coords.top = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 1, (void **)&tmp); rect_coords.left = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 2, (void **)&tmp); rect_coords.bottom = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 3, (void **)&tmp); rect_coords.right = Z_LVAL_PP(tmp); RETURN_BOOL(InvertRect(dc_obj->hdc, &rect_coords)); }
PHP_METHOD(WinGdiPath, beizerTo) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y; POINT *points = NULL; DWORD points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 2 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 2 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); points_total++; } } } RETVAL_BOOL(PolyBezierTo(dc_obj->hdc, points, points_total)); CLEANUP: efree(points); }
/* {{{ gmp_zval_binary_ui_op_ex Execute GMP binary operation. May return GMP resource or long if operation allows this */ static inline void gmp_zval_binary_ui_op_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int allow_ui_return, int check_b_zero, int use_sign TSRMLS_DC) { mpz_t *gmpnum_a, *gmpnum_b, *gmpnum_result; unsigned long long_result = 0; int use_ui = 0; int arga_tmp = 0, argb_tmp = 0; FETCH_GMP_ZVAL(gmpnum_a, a_arg, arga_tmp); if (gmp_ui_op && Z_TYPE_PP(b_arg) == IS_LONG && Z_LVAL_PP(b_arg) >= 0) { use_ui = 1; } else { FETCH_GMP_ZVAL(gmpnum_b, b_arg, argb_tmp); } if(check_b_zero) { int b_is_zero = 0; if(use_ui) { b_is_zero = (Z_LVAL_PP(b_arg) == 0); } else { b_is_zero = !mpz_cmp_ui(*gmpnum_b, 0); } if(b_is_zero) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero operand not allowed"); FREE_GMP_TEMP(arga_tmp); FREE_GMP_TEMP(argb_tmp); RETURN_FALSE; } } INIT_GMP_NUM(gmpnum_result); if (use_ui && gmp_ui_op) { if (allow_ui_return) { long_result = gmp_ui_op(*gmpnum_result, *gmpnum_a, (unsigned long)Z_LVAL_PP(b_arg)); if (use_sign && mpz_sgn(*gmpnum_a) == -1) { long_result = -long_result; } } else { gmp_ui_op(*gmpnum_result, *gmpnum_a, (unsigned long)Z_LVAL_PP(b_arg)); } } else { gmp_op(*gmpnum_result, *gmpnum_a, *gmpnum_b); } FREE_GMP_TEMP(arga_tmp); FREE_GMP_TEMP(argb_tmp); if (use_ui && allow_ui_return) { FREE_GMP_NUM(gmpnum_result); RETURN_LONG((long)long_result); } else { ZEND_REGISTER_RESOURCE(return_value, gmpnum_result, le_gmp); } }
/* Extract uint32_t values from the given zval** and write them into the given protobuf message pointer. handle optional/required/repeated */ int uint32_proto (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field, zval** val) { uint32_t* member = (uint32_t*)get_member(message, field); unsigned int* quantifier = get_quantifier(message, field); if (field->label == PROTOBUF_C_LABEL_REQUIRED || field->label == PROTOBUF_C_LABEL_OPTIONAL) { if (Z_TYPE_PP(val) == IS_LONG) *member = (uint32_t)Z_LVAL_PP(val); else if (Z_TYPE_PP(val) == IS_DOUBLE) *member = (uint32_t)Z_DVAL_PP(val); else return 1; if (field->label == PROTOBUF_C_LABEL_OPTIONAL) *quantifier = 1; } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { if (Z_TYPE_PP(val) != IS_ARRAY) return 1; HashPosition pos; HashTable* hash_table = Z_ARRVAL_PP(val); size_t num_elements = (size_t)zend_hash_num_elements(hash_table); zval** data; char* key; int i, key_len, curr = 0; long index; uint32_t* values = emalloc(sizeof(uint32_t) * num_elements); zend_hash_internal_pointer_reset_ex(hash_table, &pos); for (;; zend_hash_move_forward_ex(hash_table, &pos)) { zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos); i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTANT) break; if (Z_TYPE_PP(data) == IS_LONG) values[curr++] = (uint32_t)(Z_LVAL_PP(data)); else if (Z_TYPE_PP(data) == IS_DOUBLE) values[curr++] = (uint32_t)(Z_DVAL_PP(data)); } *quantifier = num_elements; memcpy((void*)member, (void*)&values, sizeof(void*)); } return 0; }
/** * Checks a plain text password and its hash version to check if the password matches * * @param string $password * @param string $passwordHash * @param int $maxPasswordLength * @return boolean */ PHP_METHOD(Phalcon_Security, checkHash){ zval **password, **password_hash, **max_pass_length = NULL, *hash; zval* params[2]; int check = 0; phalcon_fetch_params_ex(2, 1, &password, &password_hash, &max_pass_length); PHALCON_ENSURE_IS_STRING(password); if (max_pass_length) { PHALCON_ENSURE_IS_LONG(max_pass_length); if (Z_LVAL_PP(max_pass_length) > 0 && Z_STRLEN_PP(password) > Z_LVAL_PP(max_pass_length)) { RETURN_FALSE; } } params[0] = *password; params[1] = *password_hash; ALLOC_INIT_ZVAL(hash); phalcon_call_func_params_w(hash, SL("crypt"), 2, params TSRMLS_CC); if (UNEXPECTED(EG(exception) != NULL)) { zval_ptr_dtor(&hash); RETURN_NULL(); } if (UNEXPECTED(Z_TYPE_P(hash) != IS_STRING)) { convert_to_string(hash); } if (Z_STRLEN_P(hash) == Z_STRLEN_PP(password_hash)) { int n = Z_STRLEN_P(hash); char *h1 = Z_STRVAL_P(hash); char *h2 = Z_STRVAL_PP(password_hash); while (n) { check |= ((unsigned int)*h1) ^ ((unsigned int)*h2); ++h1; ++h2; --n; } zval_ptr_dtor(&hash); RETURN_BOOL(check == 0); } zval_ptr_dtor(&hash); RETURN_FALSE; }
static void cpManagerReload(int sig) { zval *group_conf = NULL; group_conf = cpGetConfig(CPGC.ini_file); if (!Z_BVAL_P(group_conf)) { cpLog("parse ini file[%s] error,%s reload error!", CPGC.ini_file, CPGC.title); } else { zval **v, **conf; if (zend_hash_find(Z_ARRVAL_P(group_conf), CPGC.title, strlen(CPGC.title) + 1, (void **) &conf) == SUCCESS) { if (pthread_mutex_lock(CPGS->mutex_lock) == 0) { if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_max"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGS->worker_max = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("pool_min"), (void **) &v) == SUCCESS) { convert_to_long(*v); int new_min = (int) Z_LVAL_PP(v); if (new_min > CPGC.worker_min) {//增加最小 while (CPGS->worker_num < new_min) { cpCreate_worker_mem(CPGS->worker_num); CPGS->workers_status[CPGS->worker_num] = CP_WORKER_IDLE; CPGS->worker_num++; //先加 线程安全 int new_pid = cpFork_one_worker(CPGS->worker_num - 1); if (new_pid < 0) { cpLog("Fork worker process failed. Error: %s [%d]", strerror(errno), errno); } else { CPGS->workers[CPGS->worker_num - 1].pid = new_pid; } } } CPGC.worker_min = new_min; } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.recycle_num = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_PP(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.idel_time = (int) Z_LVAL_PP(v); } if (pthread_mutex_unlock(CPGS->mutex_lock) != 0) { cpLog("pthread_mutex_unlock. Error: %s [%d]", strerror(errno), errno); } } } else { cpLog("find %s failed,The reload can only modify 'pool_min','pool_max','recycle_num' and 'idel_time',if you want modify other options please restart pool", CPGC.title); } zval_ptr_dtor(&group_conf); } }
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type) { zval **arg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) { RETURN_FALSE; } if (Z_TYPE_PP(arg) == type) { if (type == IS_OBJECT) { zend_class_entry *ce; if(Z_OBJ_HT_PP(arg)->get_class_entry == NULL) { /* if there's no get_class_entry it's not a PHP object, so it can't be INCOMPLETE_CLASS */ RETURN_TRUE; } ce = Z_OBJCE_PP(arg); if (!strcmp(ce->name, INCOMPLETE_CLASS)) { RETURN_FALSE; } } if (type == IS_RESOURCE) { const char *type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC); if (!type_name) { RETURN_FALSE; } } RETURN_TRUE; } else { RETURN_FALSE; } }
static char * rlib_php_resolve_memory_variable(char *name) { void *temp; zval ** data; if (zend_hash_find(&EG(symbol_table),name,strlen(name)+1, (void *)&temp)==FAILURE) { return NULL; } else { char *data_result, dstr[1024]; memset(dstr, 1024, 0); data = temp; if( Z_TYPE_PP(data) == IS_STRING ) data_result = Z_STRVAL_PP(data); else if( Z_TYPE_PP(data) == IS_LONG ) { sprintf(dstr,"%ld",Z_LVAL_PP(data)); data_result = estrdup(dstr); } else if( Z_TYPE_PP(data) == IS_DOUBLE ) { sprintf(dstr,"%f",Z_DVAL_PP(data)); data_result = estrdup(dstr); } else if( Z_TYPE_PP(data) == IS_NULL ) { data_result = estrdup(""); } else { sprintf(dstr,"ZEND Z_TYPE %d NOT SUPPORTED",Z_TYPE_PP(data)); data_result = estrdup(dstr); } return data_result; } }
/** * Rotate the image by a given amount. * * @param int $degrees degrees to rotate: -360-360 * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, rotate) { zval **degrees, *d; long tmp_degrees; phalcon_fetch_params_ex(1, 0, °rees); PHALCON_ENSURE_IS_LONG(degrees); PHALCON_MM_GROW(); tmp_degrees = Z_LVAL_PP(degrees); if (tmp_degrees > 180) { tmp_degrees %= 360; if (tmp_degrees > 180) { tmp_degrees -= 360; }; } else if (tmp_degrees < -180) { do { tmp_degrees += 360; } while (tmp_degrees < -180); } PHALCON_ALLOC_GHOST_ZVAL(d); ZVAL_LONG(d, tmp_degrees); PHALCON_CALL_METHOD(NULL, this_ptr, "_rotate", d); RETURN_THIS(); }
// CHash method setTargets(array(<target> => <weight> [, ...])) -> long PHP_METHOD(CHash, setTargets) { HashPosition position; chash_object *instance = (chash_object *)zend_object_store_get_object(getThis() TSRMLS_CC); zval *targets, **weight; char *target; ulong unused; uint length; int status; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &targets) != SUCCESS) { RETURN_LONG(chash_return(instance, CHASH_ERROR_INVALID_PARAMETER)) } if ((status = chash_clear_targets(&(instance->context))) < 0) { RETURN_LONG(chash_return(instance, status)) } for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(targets), &position); zend_hash_get_current_key_ex(Z_ARRVAL_P(targets), &target, &length, &unused, 0, &position) == HASH_KEY_IS_STRING && zend_hash_get_current_data_ex(Z_ARRVAL_P(targets), (void **)&weight, &position) == SUCCESS && Z_TYPE_PP(weight) == IS_LONG; zend_hash_move_forward_ex(Z_ARRVAL_P(targets), &position)) { if ((status = chash_add_target(&(instance->context), target, Z_LVAL_PP(weight))) < 0) { RETURN_LONG(chash_return(instance, status)) } } RETURN_LONG(chash_return(instance, chash_targets_count(&(instance->context)))) }
void binary_serialize_spec(zval* zthis, PHPOutputTransport& transport, HashTable* spec) { HashPosition key_ptr; zval** val_ptr; TSRMLS_FETCH(); zend_class_entry* ce = zend_get_class_entry(zthis TSRMLS_CC); for (zend_hash_internal_pointer_reset_ex(spec, &key_ptr); zend_hash_get_current_data_ex(spec, (void**)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex(spec, &key_ptr)) { ulong fieldno; if (zend_hash_get_current_key_ex(spec, NULL, NULL, &fieldno, 0, &key_ptr) != HASH_KEY_IS_LONG) { throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA); return; } HashTable* fieldspec = Z_ARRVAL_PP(val_ptr); // field name zend_hash_find(fieldspec, "var", 4, (void**)&val_ptr); char* varname = Z_STRVAL_PP(val_ptr); // thrift type zend_hash_find(fieldspec, "type", 5, (void**)&val_ptr); if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr); int8_t ttype = Z_LVAL_PP(val_ptr); zval* prop = zend_read_property(ce, zthis, varname, strlen(varname), false TSRMLS_CC); if (Z_TYPE_P(prop) != IS_NULL) { transport.writeI8(ttype); transport.writeI16(fieldno); binary_serialize(ttype, transport, &prop, fieldspec); } } transport.writeI8(T_STOP); // struct end }
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type) { pval **arg; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only one argument expected"); RETURN_FALSE; } if (Z_TYPE_PP(arg) == type) { if (type == IS_OBJECT) { zend_class_entry *ce; ce = Z_OBJCE_PP(arg); if (!strcmp(ce->name, INCOMPLETE_CLASS)) { RETURN_FALSE; } } if (type == IS_RESOURCE) { char *type_name; type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC); if (!type_name) { RETURN_FALSE; } } RETURN_TRUE; } else { RETURN_FALSE; } }
/** * Add a reflection to an image. The most opaque part of the reflection * will be equal to the opacity setting and fade out to full transparent. * Alpha transparency is preserved. * * @param int $height reflection height * @param int $opacity reflection opacity: 0-100 * @param boolean $fade_in TRUE to fade in, FALSE to fade out * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, reflection) { zval **h = NULL, **op = NULL, **fade_in = NULL; zval *image_height, *height = NULL, *opacity = NULL; long tmp_image_height; phalcon_fetch_params_ex(0, 3, &h, &op, &fade_in); PHALCON_MM_GROW(); image_height = phalcon_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY TSRMLS_CC); tmp_image_height = phalcon_get_intval(image_height); if (!h || Z_TYPE_PP(h) != IS_LONG || Z_LVAL_PP(h) > tmp_image_height) { PHALCON_INIT_VAR(height); ZVAL_LONG(height, tmp_image_height); } else { PHALCON_CPY_WRT_CTOR(height, *h); } if (!op) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 100); } else { PHALCON_ENSURE_IS_LONG(op); if (Z_LVAL_PP(op) > 100) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 100); } else if (Z_LVAL_PP(op) < 0) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 0); } else { PHALCON_CPY_WRT_CTOR(opacity, *op); } } if (!fade_in) { fade_in = &PHALCON_GLOBAL(z_false); } PHALCON_CALL_METHOD(NULL, this_ptr, "_reflection", height, opacity, *fade_in); RETURN_THIS(); }
inline int validate_request_method(zval **z_route_options_pp, int current_request_method TSRMLS_DC) { zval **z_route_method = NULL; if ( zend_hash_find( Z_ARRVAL_PP(z_route_options_pp) , "method", sizeof("method"), (void**) &z_route_method ) == SUCCESS ) { if ( Z_TYPE_PP(z_route_method) == IS_LONG && Z_LVAL_PP(z_route_method) != current_request_method ) { return 0; } } return 1; }
ZEND_METHOD(YConsistent,consistent_end){ zval *object = getThis(); zval **conhash_prop; if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){ RETURN_NULL(); } if(zend_list_delete(Z_LVAL_PP(conhash_prop)) == FAILURE){ RETURN_FALSE; } RETURN_TRUE; }
/* {{{ gmp_zval_unary_ui_op */ static inline void gmp_zval_unary_ui_op(zval *return_value, zval **a_arg, gmp_unary_ui_op_t gmp_op TSRMLS_DC) { mpz_t *gmpnum_result; convert_to_long_ex(a_arg); INIT_GMP_NUM(gmpnum_result); gmp_op(*gmpnum_result, Z_LVAL_PP(a_arg)); ZEND_REGISTER_RESOURCE(return_value, gmpnum_result, le_gmp); }
/* {{{ MongoDate::__set_state() */ PHP_METHOD(MongoDate, __set_state) { zval *state, **sec, **usec; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &state) == FAILURE) { return; } if (zend_hash_find(HASH_P(state), "sec", strlen("sec") + 1, (void**) &sec) == FAILURE) { return; } if (zend_hash_find(HASH_P(state), "usec", strlen("usec") + 1, (void**) &usec) == FAILURE) { return; } convert_to_long(*sec); convert_to_long(*usec); object_init_ex(return_value, mongo_ce_Date); php_mongo_mongodate_populate(return_value, Z_LVAL_PP(sec), Z_LVAL_PP(usec) TSRMLS_CC); }
/* {{{ php_pack */ static void php_pack(zval **val, int size, int *map, char *output) { int i; char *v; convert_to_long_ex(val); v = (char *) &Z_LVAL_PP(val); for (i = 0; i < size; i++) { *output++ = v[map[i]]; } }
PHP_METHOD(WinGdiPath, frameRectangle) { wingdi_devicecontext_object *dc_obj; wingdi_brush_object *br_obj; wingdi_path_object *path_obj; zval *coords_zval, *br_zval, **tmp; RECT rect_coords; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &br_zval, &coords_zval) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); if (Z_TYPE_P(br_zval) == IS_OBJECT) br_obj = zend_object_store_get_object(br_zval TSRMLS_CC); else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected an object for parameter 2, got %s", zend_zval_type_name(br_zval)); return; } // Is this the best way to do this? zend_hash_index_find(Z_ARRVAL_P(coords_zval), 0, (void **)&tmp); rect_coords.top = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 1, (void **)&tmp); rect_coords.left = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 2, (void **)&tmp); rect_coords.bottom = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 3, (void **)&tmp); rect_coords.right = Z_LVAL_PP(tmp); RETURN_BOOL(FrameRect(dc_obj->hdc, &rect_coords, br_obj->brush_handle)); }
/* {{{ pip_zval_to_pyobject(zval **val) Converts the given zval into an equivalent PyObject */ PyObject * pip_zval_to_pyobject(zval **val) { PyObject *ret; if (val == NULL) { return NULL; } switch (Z_TYPE_PP(val)) { case IS_BOOL: ret = Py_BuildValue("i", Z_LVAL_PP(val) ? 1 : 0); break; case IS_LONG: ret = Py_BuildValue("l", Z_LVAL_PP(val)); break; case IS_DOUBLE: ret = Py_BuildValue("d", Z_DVAL_PP(val)); break; case IS_STRING: ret = Py_BuildValue("s", Z_STRVAL_PP(val)); break; case IS_ARRAY: ret = pip_hash_to_dict(val); break; case IS_OBJECT: ret = pip_zobject_to_pyobject(val); break; case IS_NULL: Py_INCREF(Py_None); ret = Py_None; break; default: ret = NULL; break; } return ret; }
void php_functional_prepare_array_key(int hash_key_type, zval **key, zval ***value, char *string_key, uint string_key_len, int int_key) { switch (hash_key_type) { case HASH_KEY_IS_LONG: Z_TYPE_PP(key) = IS_LONG; Z_LVAL_PP(key) = int_key; break; case HASH_KEY_IS_STRING: ZVAL_STRINGL(*key, string_key, string_key_len - 1, 0); break; } }
static void *clock_loop(void* _clock_array) { int x, y, i; char *key; uint key_len; int array_count; HashTable *arr_hash; HashPosition pointer; zval **data; ulong index; static struct clocks_struct clock_args; zval* clock_array = (zval*) _clock_array; arr_hash = Z_ARRVAL_P(clock_array); array_count = zend_hash_num_elements(arr_hash); clock_args.clock = ecalloc(array_count, sizeof(struct clock_struct)); clock_args.anz_clocks = array_count; i = 0; for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { zend_hash_get_current_key_ex(arr_hash, &key, &key_len, &index, 0, &pointer); clock_args.clock[i].start_time = Z_LVAL_PP(data); clock_args.clock[i].x = 62; clock_args.clock[i].y = index + 4; i++; } while (stop == 0) { time_t now; time(&now); long dauer; int stunden, minuten, sekunden; for (i = 0; i < clock_args.anz_clocks; i++) { dauer = difftime(now, clock_args.clock[i].start_time); x = clock_args.clock[i].x; y = clock_args.clock[i].y; stunden = dauer / 3600; minuten = (dauer % 3600) / 60; sekunden = (dauer % 3600) % 60; php_printf("\x1B[%d;%dH%02d:%02d:%02d\n", y, x, stunden, minuten, sekunden); } php_printf("\x1B[%d;%dH", line + 4, 3); fflush(stdout); sleep(1); } efree(clock_args.clock); return NULL; }
ZEND_METHOD(YConsistent,add_server){ char *host; int host_len,port,weight; zval *object = getThis(); zval **conhash_prop; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sll",&host,&host_len,&port,&weight) == FAILURE){ return; } if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){ RETURN_NULL(); } conhash *con = zend_list_find(Z_LVAL_PP(conhash_prop),&le_conhash); conhash_add_server(host,port,weight,con); }
/** * Sharpen the image by a given amount. * * @param int $amount amount to sharpen: 1-100 * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, sharpen) { zval **amount; phalcon_fetch_params_ex(1, 0, &amount); PHALCON_MM_GROW(); SEPARATE_ZVAL_IF_NOT_REF(amount); if (Z_TYPE_PP(amount) != IS_LONG) { convert_to_long(*amount); } if (Z_LVAL_PP(amount) > 100) { ZVAL_LONG(*amount, 100); } else if (Z_LVAL_PP(amount) < 1) { ZVAL_LONG(*amount, 1); } PHALCON_CALL_METHOD(NULL, this_ptr, "_sharpen", *amount); RETURN_THIS(); }
/** * Pixelate image * * @param int $amount amount to pixelate * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, pixelate) { zval **amount = NULL, *amt; phalcon_fetch_params_ex(0, 1, &amount); PHALCON_MM_GROW(); PHALCON_ALLOC_GHOST_ZVAL(amt); if (!amount || Z_TYPE_PP(amount) != IS_LONG) { ZVAL_LONG(amt, 10); } else { PHALCON_ENSURE_IS_LONG(amount); if (Z_LVAL_PP(amount) < 2) { ZVAL_LONG(amt, 2); } else { ZVAL_LONG(amt, Z_LVAL_PP(amount)); } } PHALCON_CALL_METHOD(NULL, this_ptr, "_pixelate", amt); RETURN_THIS(); }
/** * Flip the image along the horizontal or vertical axis. * * @param $int $direction direction: Image::HORIZONTAL, Image::VERTICAL * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, flip) { zval **direction, *dir; phalcon_fetch_params_ex(1, 0, &direction); PHALCON_ENSURE_IS_LONG(direction); PHALCON_MM_GROW(); PHALCON_ALLOC_GHOST_ZVAL(dir); ZVAL_LONG(dir, (Z_LVAL_PP(direction) != 11) ? 12 : 11); PHALCON_CALL_METHOD(NULL, this_ptr, "_flip", dir); RETURN_THIS(); }
/* {{{ proto string ProtocolBuffersEnum::getName(long $value) */ PHP_METHOD(protocolbuffers_enum, getName) { #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3) zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getName can't work under PHP 5.3. please consider upgrading your PHP"); return; #else long value; zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &value) == FAILURE) { return; } if (zend_call_method_with_0_params(NULL, EG(called_scope), NULL, "getenumdescriptor", &result)) { zval *values, **entry; HashPosition pos; if (!instanceof_function_ex(Z_OBJCE_P(result), php_protocol_buffers_enum_descriptor_class_entry, 0 TSRMLS_CC)) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getEnumDescriptor returns unexpected value."); zval_ptr_dtor(&result); return; } php_protocolbuffers_read_protected_property(result, ZEND_STRS("values"), &values TSRMLS_CC); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry, &pos) == SUCCESS) { if (Z_LVAL_PP(entry) == value) { char *key; uint key_len; ulong index; zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &key, &key_len, &index, 0, &pos); RETURN_STRINGL(key, key_len, 1); break; } zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos); } zval_ptr_dtor(&result); RETVAL_FALSE; } else { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "cannot call ProtocolBuffersEnum::getEnumDescriptor."); return; } #endif }
/* {{{ convert_to_gmp * Convert zval to be gmp number */ static int convert_to_gmp(mpz_t * *gmpnumber, zval **val, int base TSRMLS_DC) { int ret = 0; int skip_lead = 0; *gmpnumber = emalloc(sizeof(mpz_t)); switch (Z_TYPE_PP(val)) { case IS_LONG: case IS_BOOL: case IS_CONSTANT: { convert_to_long_ex(val); mpz_init_set_si(**gmpnumber, Z_LVAL_PP(val)); } break; case IS_STRING: { char *numstr = Z_STRVAL_PP(val); if (Z_STRLEN_PP(val) > 2) { if (numstr[0] == '0') { if (numstr[1] == 'x' || numstr[1] == 'X') { base = 16; skip_lead = 1; } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) { base = 2; skip_lead = 1; } } } ret = mpz_init_set_str(**gmpnumber, (skip_lead ? &numstr[2] : numstr), base); } break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING,"Unable to convert variable to GMP - wrong type"); efree(*gmpnumber); return FAILURE; } if (ret) { FREE_GMP_NUM(*gmpnumber); return FAILURE; } return SUCCESS; }
void cpServer_init_common(zval *conf) { zval **v; //daemonize,守护进程化 if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("daemonize"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.daemonize = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.recycle_num = (int) Z_LVAL_PP(v); } //error_file if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("log_file"), (void **) &v) == SUCCESS) { memcpy(CPGC.log_file, Z_STRVAL_PP(v), Z_STRLEN_PP(v)); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_read_len"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.max_read_len = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("port"), (void **) &v) == SUCCESS) {//todo check null convert_to_long(*v); CPGC.port = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.idel_time = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("ser_fail_hits"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.ser_fail_hits = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_fail_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.max_fail_num = (int) Z_LVAL_PP(v); } }