PHP_METHOD(Test_NativeArray, testArray22) { zval *a; ZEPHIR_MM_GROW(); ZEPHIR_INIT_VAR(a); array_init_size(a, 5); add_index_long(a, 0, 4); add_index_long(a, 1, 5); add_index_long(a, 2, 6); RETURN_CCTOR(a); }
/* {{{ php_foreach_all */ static int php_foreach_all (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata) { int is_stop = 0; zval *args; zval *retval; TSRMLS_FETCH(); MAKE_STD_ZVAL(args); array_init(args); add_index_long(args, 0, instatus); add_index_stringl(args, 1, inkey, inkeylen, 1); add_index_stringl(args, 2, inval, invallen, 1); php_yp_all_callback *cb = (php_yp_all_callback *) indata; zend_fcall_info_args(&cb->fci, args TSRMLS_CC); zend_fcall_info_call(&cb->fci, &cb->fcc, &retval, args TSRMLS_CC); zend_fcall_info_args_clear(&cb->fci, 1); if (retval) { is_stop = zval_is_true(retval); zval_ptr_dtor(&retval); } return is_stop; }
/* {{{ property result_lengths_read */ static zval *result_lengths_read(mysqli_object *obj, zval *retval) { MYSQL_RES *p; #if defined(MYSQLI_USE_MYSQLND) const size_t *ret; #else const zend_ulong *ret; #endif uint32_t field_count; CHECK_STATUS(MYSQLI_STATUS_VALID); p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; field_count = mysql_num_fields(p); if (!p || !field_count || !(ret = mysql_fetch_lengths(p))) { ZVAL_NULL(retval); } else { zend_ulong i; array_init(retval); for (i = 0; i < field_count; i++) { add_index_long(retval, i, ret[i]); } } return retval; }
/* {{{ 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)); } }
/* {{{ proto array WriteResult::getUpsertedIds() Returns the identifiers generated by the server for upsert operations. */ PHP_METHOD(WriteResult, getUpsertedIds) { bson_iter_t iter, child; php_phongo_writeresult_t *intern; SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) intern = Z_WRITERESULT_OBJ_P(getThis()); if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); if (bson_iter_init_find(&iter, intern->reply, "upserted") && BSON_ITER_HOLDS_ARRAY(&iter) && bson_iter_recurse(&iter, &child)) { while (bson_iter_next(&child)) { int32_t index; bson_iter_t outer; if (!BSON_ITER_HOLDS_DOCUMENT(&child) || !bson_iter_recurse(&child, &outer)) { continue; } if (!bson_iter_find(&outer, "index") || !BSON_ITER_HOLDS_INT32(&outer)) { continue; } index = bson_iter_int32(&outer); if (!bson_iter_find(&outer, "_id")) { continue; } if (BSON_ITER_HOLDS_OID(&outer)) { #if PHP_VERSION_ID >= 70000 zval zid; php_phongo_objectid_new_from_oid(&zid, bson_iter_oid(&outer) TSRMLS_CC); add_index_zval(return_value, index, &zid); #else zval *zid = NULL; MAKE_STD_ZVAL(zid); php_phongo_objectid_new_from_oid(zid, bson_iter_oid(&outer) TSRMLS_CC); add_index_zval(return_value, index, zid); #endif } else if (BSON_ITER_HOLDS_INT32(&outer)) { int32_t val = bson_iter_int32(&outer); add_index_long(return_value, index, val); } else if (BSON_ITER_HOLDS_INT64(&outer)) { int64_t val = bson_iter_int64(&outer); ADD_INDEX_INT64(return_value, index, val); } } } }
PHP_METHOD(Test_NativeArray, testArray22) { zval a; zval *this_ptr = getThis(); ZVAL_UNDEF(&a); ZEPHIR_MM_GROW(); ZEPHIR_INIT_VAR(&a); zephir_create_array(&a, 3, 0 TSRMLS_CC); add_index_long(&a, 0, 4); add_index_long(&a, 1, 5); add_index_long(&a, 2, 6); RETURN_CCTOR(&a); }
void zephir_init_static_properties_Ansi_Color(TSRMLS_D) { zval *_1; zval *_0; ZEPHIR_MM_GROW(); ZEPHIR_INIT_VAR(_0); array_init(_0); zephir_update_static_property_ce(ansi_color_ce, SL("_fg_arr"), &_0 TSRMLS_CC); ZEPHIR_INIT_VAR(_1); zephir_create_array(_1, 1, 0 TSRMLS_CC); add_index_long(_1, 1, 1); zephir_update_static_property_ce(ansi_color_ce, SL("_bg_arr"), &_1 TSRMLS_CC); ZEPHIR_MM_RESTORE(); }
PHPAPI int php_sscanf_internal( char *string, char *format, int argCount, zval *args, int varStart, zval *return_value) { int numVars, nconversions, totalVars = -1; int i, result; zend_long value; int objIndex; char *end, *baseString; zval *current; char op = 0; int base = 0; int underflow = 0; size_t width; zend_long (*fn)() = NULL; char *ch, sch; int flags; char buf[64]; /* Temporary buffer to hold scanned number * strings before they are passed to strtoul() */ /* do some sanity checking */ if ((varStart > argCount) || (varStart < 0)){ varStart = SCAN_MAX_ARGS + 1; } numVars = argCount - varStart; if (numVars < 0) { numVars = 0; } #if 0 zend_printf("<br>in sscanf_internal : <br> string is \"%s\", format = \"%s\"<br> NumVars = %d. VarStart = %d<br>-------------------------<br>", string, format, numVars, varStart); #endif /* * Check for errors in the format string. */ if (ValidateFormat(format, numVars, &totalVars) != SCAN_SUCCESS) { scan_set_error_return( numVars, return_value ); return SCAN_ERROR_INVALID_FORMAT; } objIndex = numVars ? varStart : 0; /* * If any variables are passed, make sure they are all passed by reference */ if (numVars) { for (i = varStart;i < argCount;i++){ if ( ! Z_ISREF(args[ i ] ) ) { php_error_docref(NULL, E_WARNING, "Parameter %d must be passed by reference", i); scan_set_error_return(numVars, return_value); return SCAN_ERROR_VAR_PASSED_BYVAL; } } } /* * Allocate space for the result objects. Only happens when no variables * are specified */ if (!numVars) { zval tmp; /* allocate an array for return */ array_init(return_value); for (i = 0; i < totalVars; i++) { ZVAL_NULL(&tmp); if (add_next_index_zval(return_value, &tmp) == FAILURE) { scan_set_error_return(0, return_value); return FAILURE; } } varStart = 0; /* Array index starts from 0 */ } baseString = string; /* * Iterate over the format string filling in the result objects until * we reach the end of input, the end of the format string, or there * is a mismatch. */ nconversions = 0; /* note ! - we need to limit the loop for objIndex to keep it in bounds */ while (*format != '\0') { ch = format++; flags = 0; /* * If we see whitespace in the format, skip whitespace in the string. */ if ( isspace( (int)*ch ) ) { sch = *string; while ( isspace( (int)sch ) ) { if (*string == '\0') { goto done; } string++; sch = *string; } continue; } if (*ch != '%') { literal: if (*string == '\0') { underflow = 1; goto done; } sch = *string; string++; if (*ch != sch) { goto done; } continue; } ch = format++; if (*ch == '%') { goto literal; } /* * Check for assignment suppression ('*') or an XPG3-style * assignment ('%n$'). */ if (*ch == '*') { flags |= SCAN_SUPPRESS; ch = format++; } else if ( isdigit(UCHAR(*ch))) { value = ZEND_STRTOUL(format-1, &end, 10); if (*end == '$') { format = end+1; ch = format++; objIndex = varStart + value - 1; } } /* * Parse any width specifier. */ if ( isdigit(UCHAR(*ch))) { width = ZEND_STRTOUL(format-1, &format, 10); ch = format++; } else { width = 0; } /* * Ignore size specifier. */ if ((*ch == 'l') || (*ch == 'L') || (*ch == 'h')) { ch = format++; } /* * Handle the various field types. */ switch (*ch) { case 'n': if (!(flags & SCAN_SUPPRESS)) { if (numVars && objIndex >= argCount) { break; } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_LONG(current, (zend_long)(string - baseString) ); } else { add_index_long(return_value, objIndex++, string - baseString); } } nconversions++; continue; case 'd': case 'D': op = 'i'; base = 10; fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'i': op = 'i'; base = 0; fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'o': op = 'i'; base = 8; fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'x': case 'X': op = 'i'; base = 16; fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'u': op = 'i'; base = 10; flags |= SCAN_UNSIGNED; fn = (zend_long (*)())ZEND_STRTOUL_PTR; break; case 'f': case 'e': case 'E': case 'g': op = 'f'; break; case 's': op = 's'; break; case 'c': op = 's'; flags |= SCAN_NOSKIP; /*-cc-*/ if (0 == width) { width = 1; } /*-cc-*/ break; case '[': op = '['; flags |= SCAN_NOSKIP; break; } /* switch */ /* * At this point, we will need additional characters from the * string to proceed. */ if (*string == '\0') { underflow = 1; goto done; } /* * Skip any leading whitespace at the beginning of a field unless * the format suppresses this behavior. */ if (!(flags & SCAN_NOSKIP)) { while (*string != '\0') { sch = *string; if (! isspace((int)sch) ) { break; } string++; } if (*string == '\0') { underflow = 1; goto done; } } /* * Perform the requested scanning operation. */ switch (op) { case 'c': case 's': /* * Scan a string up to width characters or whitespace. */ if (width == 0) { width = (size_t) ~0; } end = string; while (*end != '\0') { sch = *end; if ( isspace( (int)sch ) ) { break; } end++; if (--width == 0) { break; } } if (!(flags & SCAN_SUPPRESS)) { if (numVars && objIndex >= argCount) { break; } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_STRINGL(current, string, end-string); } else { add_index_stringl(return_value, objIndex++, string, end-string); } } string = end; break; case '[': { CharSet cset; if (width == 0) { width = (size_t) ~0; } end = string; format = BuildCharSet(&cset, format); while (*end != '\0') { sch = *end; if (!CharInSet(&cset, (int)sch)) { break; } end++; if (--width == 0) { break; } } ReleaseCharSet(&cset); if (string == end) { /* * Nothing matched the range, stop processing */ goto done; } if (!(flags & SCAN_SUPPRESS)) { if (numVars && objIndex >= argCount) { break; } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_STRINGL(current, string, end-string); } else { add_index_stringl(return_value, objIndex++, string, end-string); } } string = end; break; } /* case 'c': / Scan a single character./ sch = *string; string++; if (!(flags & SCAN_SUPPRESS)) { if (numVars) { char __buf[2]; __buf[0] = sch; __buf[1] = '\0';; current = args[objIndex++]; zval_dtor(*current); ZVAL_STRINGL( *current, __buf, 1); } else { add_index_stringl(return_value, objIndex++, &sch, 1); } } break; */ case 'i': /* * Scan an unsigned or signed integer. */ /*-cc-*/ buf[0] = '\0'; /*-cc-*/ if ((width == 0) || (width > sizeof(buf) - 1)) { width = sizeof(buf) - 1; } flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO; for (end = buf; width > 0; width--) { switch (*string) { /* * The 0 digit has special meaning at the beginning of * a number. If we are unsure of the base, it * indicates that we are in base 8 or base 16 (if it is * followed by an 'x'). */ case '0': /*-cc-*/ if (base == 16) { flags |= SCAN_XOK; } /*-cc-*/ if (base == 0) { base = 8; flags |= SCAN_XOK; } if (flags & SCAN_NOZERO) { flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO); } else { flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); } goto addToInt; case '1': case '2': case '3': case '4': case '5': case '6': case '7': if (base == 0) { base = 10; } flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); goto addToInt; case '8': case '9': if (base == 0) { base = 10; } if (base <= 8) { break; } flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); goto addToInt; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': if (base <= 10) { break; } flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); goto addToInt; case '+': case '-': if (flags & SCAN_SIGNOK) { flags &= ~SCAN_SIGNOK; goto addToInt; } break; case 'x': case 'X': if ((flags & SCAN_XOK) && (end == buf+1)) { base = 16; flags &= ~SCAN_XOK; goto addToInt; } break; } /* * We got an illegal character so we are done accumulating. */ break; addToInt: /* * Add the character to the temporary buffer. */ *end++ = *string++; if (*string == '\0') { break; } } /* * Check to see if we need to back up because we only got a * sign or a trailing x after a 0. */ if (flags & SCAN_NODIGITS) { if (*string == '\0') { underflow = 1; } goto done; } else if (end[-1] == 'x' || end[-1] == 'X') { end--; string--; } /* * Scan the value from the temporary buffer. If we are * returning a large unsigned value, we have to convert it back * to a string since PHP only supports signed values. */ if (!(flags & SCAN_SUPPRESS)) { *end = '\0'; value = (zend_long) (*fn)(buf, NULL, base); if ((flags & SCAN_UNSIGNED) && (value < 0)) { snprintf(buf, sizeof(buf), ZEND_ULONG_FMT, value); /* INTL: ISO digit */ if (numVars && objIndex >= argCount) { break; } else if (numVars) { /* change passed value type to string */ current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_STRING(current, buf); } else { add_index_string(return_value, objIndex++, buf); } } else { if (numVars && objIndex >= argCount) { break; } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_LONG(current, value); } else { add_index_long(return_value, objIndex++, value); } } } break; case 'f': /* * Scan a floating point number */ buf[0] = '\0'; /* call me pedantic */ if ((width == 0) || (width > sizeof(buf) - 1)) { width = sizeof(buf) - 1; } flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_PTOK | SCAN_EXPOK; for (end = buf; width > 0; width--) { switch (*string) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS); goto addToFloat; case '+': case '-': if (flags & SCAN_SIGNOK) { flags &= ~SCAN_SIGNOK; goto addToFloat; } break; case '.': if (flags & SCAN_PTOK) { flags &= ~(SCAN_SIGNOK | SCAN_PTOK); goto addToFloat; } break; case 'e': case 'E': /* * An exponent is not allowed until there has * been at least one digit. */ if ((flags & (SCAN_NODIGITS | SCAN_EXPOK)) == SCAN_EXPOK) { flags = (flags & ~(SCAN_EXPOK|SCAN_PTOK)) | SCAN_SIGNOK | SCAN_NODIGITS; goto addToFloat; } break; } /* * We got an illegal character so we are done accumulating. */ break; addToFloat: /* * Add the character to the temporary buffer. */ *end++ = *string++; if (*string == '\0') { break; } } /* * Check to see if we need to back up because we saw a * trailing 'e' or sign. */ if (flags & SCAN_NODIGITS) { if (flags & SCAN_EXPOK) { /* * There were no digits at all so scanning has * failed and we are done. */ if (*string == '\0') { underflow = 1; } goto done; } /* * We got a bad exponent ('e' and maybe a sign). */ end--; string--; if (*end != 'e' && *end != 'E') { end--; string--; } } /* * Scan the value from the temporary buffer. */ if (!(flags & SCAN_SUPPRESS)) { double dvalue; *end = '\0'; dvalue = zend_strtod(buf, NULL); if (numVars && objIndex >= argCount) { break; } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); ZVAL_DOUBLE(current, dvalue); } else { add_index_double(return_value, objIndex++, dvalue ); } } break; } /* switch (op) */ nconversions++; } /* while (*format != '\0') */ done: result = SCAN_SUCCESS; if (underflow && (0==nconversions)) { scan_set_error_return( numVars, return_value ); result = SCAN_ERROR_EOF; } else if (numVars) { convert_to_long(return_value ); Z_LVAL_P(return_value) = nconversions; } else if (nconversions < totalVars) { /* TODO: not all elements converted. we need to prune the list - cc */ } return result; }
PHP_METHOD(PhalconPlus_Db_Mysql, __construct) { zval *_2, *_4; int ZEPHIR_LAST_CALL_STATUS; zval *confName = NULL; zval *di, *confName_param = NULL, *_0, *config = NULL, *dbConfig, *_1, *_3 = NULL, *_5, *_6; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &di, &confName_param); if (unlikely(Z_TYPE_P(confName_param) != IS_STRING && Z_TYPE_P(confName_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'confName' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(confName_param) == IS_STRING)) { zephir_get_strval(confName, confName_param); } else { ZEPHIR_INIT_VAR(confName); ZVAL_EMPTY_STRING(confName); } ZEPHIR_INIT_VAR(_0); array_init(_0); zephir_update_property_this(this_ptr, SL("descriptor"), _0 TSRMLS_CC); ZEPHIR_INIT_VAR(_1); ZVAL_STRING(_1, "config", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&config, di, "get", NULL, _1); zephir_check_temp_parameter(_1); zephir_check_call_status(); ZEPHIR_OBS_VAR(dbConfig); zephir_read_property_zval(&dbConfig, config, confName, PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("di"), di TSRMLS_CC); ZEPHIR_INIT_VAR(_2); zephir_create_array(_2, 6, 0 TSRMLS_CC); ZEPHIR_OBS_VAR(_3); zephir_read_property(&_3, dbConfig, SL("host"), PH_NOISY_CC); zephir_array_update_string(&_2, SL("host"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(_3); zephir_read_property(&_3, dbConfig, SL("port"), PH_NOISY_CC); zephir_array_update_string(&_2, SL("port"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(_3); zephir_read_property(&_3, dbConfig, SL("username"), PH_NOISY_CC); zephir_array_update_string(&_2, SL("username"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(_3); zephir_read_property(&_3, dbConfig, SL("password"), PH_NOISY_CC); zephir_array_update_string(&_2, SL("password"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(_3); zephir_read_property(&_3, dbConfig, SL("dbname"), PH_NOISY_CC); zephir_array_update_string(&_2, SL("dbname"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_VAR(_4); zephir_create_array(_4, 3, 0 TSRMLS_CC); ZEPHIR_OBS_NVAR(_3); zephir_read_property(&_3, dbConfig, SL("charset"), PH_NOISY_CC); ZEPHIR_INIT_VAR(_5); ZEPHIR_CONCAT_SV(_5, "SET NAMES ", _3); zephir_array_update_long(&_4, 1002, &_5, PH_COPY, "phalconplus/Db/Mysql.zep", 29); ZEPHIR_OBS_VAR(_6); zephir_read_property(&_6, dbConfig, SL("timeout"), PH_NOISY_CC); zephir_array_update_long(&_4, 2, &_6, PH_COPY, "phalconplus/Db/Mysql.zep", 29); add_index_long(_4, 3, 2); zephir_array_update_string(&_2, SL("options"), &_4, PH_COPY | PH_SEPARATE); zephir_update_property_this(this_ptr, SL("descriptor"), _2 TSRMLS_CC); ZEPHIR_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts = NULL; zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dot_comma = NULL, *dsn_attributes = NULL; zval *pdo_type = NULL, *dsn = NULL, *options = NULL, *persistent = NULL, *pdo = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!descriptor) { PHALCON_ALLOC_ZVAL_MM(descriptor); ZVAL_NULL(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (Z_TYPE_P(descriptor) == IS_NULL) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } eval_int = phalcon_array_isset_string(descriptor, SS("username")); if (eval_int) { PHALCON_INIT_VAR(username); phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("username")); } else { PHALCON_INIT_VAR(username); ZVAL_NULL(username); } eval_int = phalcon_array_isset_string(descriptor, SS("password")); if (eval_int) { PHALCON_INIT_VAR(password); phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("password")); } else { PHALCON_INIT_VAR(password); ZVAL_NULL(password); } eval_int = phalcon_array_isset_string(descriptor, SS("dsn")); if (!eval_int) { PHALCON_INIT_VAR(dsn_parts); array_init(dsn_parts); if (!phalcon_valid_foreach(descriptor TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(descriptor); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); PHALCON_INIT_VAR(dsn_attribute); PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(dot_comma); ZVAL_STRING(dot_comma, ";", 1); PHALCON_INIT_VAR(dsn_attributes); phalcon_fast_join(dsn_attributes, dot_comma, dsn_parts TSRMLS_CC); } else { PHALCON_INIT_VAR(dsn_attributes); phalcon_array_fetch_string(&dsn_attributes, descriptor, SL("dsn"), PH_NOISY_CC); } PHALCON_INIT_VAR(pdo_type); phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC); PHALCON_INIT_VAR(dsn); PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); PHALCON_INIT_VAR(options); array_init(options); add_index_long(options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); add_index_long(options, PDO_ATTR_CASE, PDO_CASE_LOWER); add_index_long(options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL); eval_int = phalcon_array_isset_string(descriptor, SS("persistent")); if (eval_int) { PHALCON_INIT_VAR(persistent); phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY_CC); if (zend_is_true(persistent)) { phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_SEPARATE TSRMLS_CC); } } ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(pdo); object_init_ex(pdo, ce0); PHALCON_CALL_METHOD_PARAMS_4_NORETURN(pdo, "__construct", dsn, username, password, options, PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); PHALCON_MM_RESTORE();}
/* {{{ apc_cache_info */ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited) { zval info; zval list; zval gc; zval slots; apc_cache_slot_t* p; zend_ulong i, j; if (!cache) { ZVAL_NULL(&info); return info; } /* read lock header */ APC_RLOCK(cache->header); array_init(&info); add_assoc_long(&info, "num_slots", cache->nslots); add_assoc_long(&info, "ttl", cache->ttl); add_assoc_double(&info, "num_hits", (double)cache->header->nhits); add_assoc_double(&info, "num_misses", (double)cache->header->nmisses); add_assoc_double(&info, "num_inserts", (double)cache->header->ninserts); add_assoc_long(&info, "num_entries", cache->header->nentries); add_assoc_double(&info, "expunges", (double)cache->header->nexpunges); add_assoc_long(&info, "start_time", cache->header->stime); add_assoc_double(&info, "mem_size", (double)cache->header->mem_size); #if APC_MMAP add_assoc_stringl(&info, "memory_type", "mmap", sizeof("mmap")-1); #else add_assoc_stringl(&info, "memory_type", "IPC shared", sizeof("IPC shared")-1); #endif if (!limited) { /* For each hashtable slot */ array_init(&list); array_init(&slots); for (i = 0; i < cache->nslots; i++) { p = cache->slots[i]; j = 0; for (; p != NULL; p = p->next) { zval link = apc_cache_link_info(cache, p); add_next_index_zval(&list, &link); j++; } if(j != 0) { add_index_long(&slots, (ulong)i, j); } } /* For each slot pending deletion */ array_init(&gc); for (p = cache->header->gc; p != NULL; p = p->next) { zval link = apc_cache_link_info(cache, p); add_next_index_zval(&gc, &link); } add_assoc_zval(&info, "cache_list", &list); add_assoc_zval(&info, "deleted_list", &gc); add_assoc_zval(&info, "slot_distribution", &slots); } /* unlock header */ APC_RUNLOCK(cache->header); return info; }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts = NULL; zval *value = NULL, *key = NULL, *dsn = NULL, *options = NULL, *persistent = NULL; zval *r0 = NULL, *r1 = NULL; zval *t0 = NULL; zval *c0 = NULL; zval *i0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!descriptor) { PHALCON_ALLOC_ZVAL_MM(descriptor); ZVAL_NULL(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } eval_int = phalcon_array_isset_string(descriptor, SL("username")+1); if (eval_int) { PHALCON_INIT_VAR(username); phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SL("username")+1); } else { PHALCON_INIT_VAR(username); ZVAL_NULL(username); } eval_int = phalcon_array_isset_string(descriptor, SL("password")+1); if (eval_int) { PHALCON_INIT_VAR(password); phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SL("password")+1); } else { PHALCON_INIT_VAR(password); ZVAL_NULL(password); } PHALCON_INIT_VAR(dsn_parts); array_init(dsn_parts); if (!phalcon_valid_foreach(descriptor TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(descriptor); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_7f5d_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_7f5d_0; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(r0); PHALCON_CONCAT_VSV(r0, key, "=", value); phalcon_array_append(&dsn_parts, r0, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_7f5d_0; fee_7f5d_0: if(0){} PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_type"), PH_NOISY_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ";", 1); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_join(r1, c0, dsn_parts TSRMLS_CC); PHALCON_INIT_VAR(dsn); PHALCON_CONCAT_VSV(dsn, t0, ":", r1); PHALCON_INIT_VAR(options); array_init(options); add_index_long(options, 3, 0); add_index_long(options, 8, 2); add_index_long(options, 10, 1); eval_int = phalcon_array_isset_string(descriptor, SL("persistent")+1); if (eval_int) { PHALCON_INIT_VAR(persistent); phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY_CC); if (zend_is_true(persistent)) { phalcon_array_update_long_bool(&options, 12, 1, PH_SEPARATE TSRMLS_CC); } } ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, ce0); PHALCON_CALL_METHOD_PARAMS_4_NORETURN(i0, "__construct", dsn, username, password, options, PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_pdo"), i0 TSRMLS_CC); PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo", "__construct", descriptor); PHALCON_MM_RESTORE(); }
PHP_METHOD(PhalconPlus_Db_Mysql, __construct) { zval _9; zend_long ZEPHIR_LAST_CALL_STATUS; zval name; zval *di, di_sub, *name_param = NULL, config, dbConfig, _0, options, _3, _4, _5, _1$$3, _2$$4, _6$$5, _7$$5, _8$$5; zval *this_ptr = getThis(); ZVAL_UNDEF(&di_sub); ZVAL_UNDEF(&config); ZVAL_UNDEF(&dbConfig); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&options); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$4); ZVAL_UNDEF(&_6$$5); ZVAL_UNDEF(&_7$$5); ZVAL_UNDEF(&_8$$5); ZVAL_UNDEF(&name); ZVAL_UNDEF(&_9); ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &di, &name_param); if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string") TSRMLS_CC); RETURN_MM_NULL(); } if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) { zephir_get_strval(&name, name_param); } else { ZEPHIR_INIT_VAR(&name); ZVAL_EMPTY_STRING(&name); } ZEPHIR_INIT_VAR(&_0); ZVAL_STRING(&_0, "config"); ZEPHIR_CALL_METHOD(&config, di, "get", NULL, 0, &_0); zephir_check_call_status(); ZEPHIR_OBS_VAR(&dbConfig); zephir_read_property_zval(&dbConfig, &config, &name, PH_NOISY_CC); zephir_update_property_zval(this_ptr, SL("di"), di); zephir_update_property_zval(this_ptr, SL("name"), &name); if (zephir_isset_property(&dbConfig, SL("retryTimes"))) { zephir_read_property(&_1$$3, &dbConfig, SL("retryTimes"), PH_NOISY_CC | PH_READONLY); zephir_update_property_zval(this_ptr, SL("retryTimes"), &_1$$3); } if (zephir_isset_property(&dbConfig, SL("retryInterval"))) { zephir_read_property(&_2$$4, &dbConfig, SL("retryInterval"), PH_NOISY_CC | PH_READONLY); zephir_update_property_zval(this_ptr, SL("retryInterval"), &_2$$4); } ZEPHIR_INIT_VAR(&options); zephir_create_array(&options, 3, 0 TSRMLS_CC); zephir_read_property(&_3, &dbConfig, SL("charset"), PH_NOISY_CC | PH_READONLY); ZEPHIR_INIT_VAR(&_4); ZEPHIR_CONCAT_SV(&_4, "SET NAMES ", &_3); zephir_array_update_long(&options, 1002, &_4, PH_COPY ZEPHIR_DEBUG_PARAMS_DUMMY); ZEPHIR_OBS_VAR(&_5); zephir_read_property(&_5, &dbConfig, SL("timeout"), PH_NOISY_CC); zephir_array_update_long(&options, 2, &_5, PH_COPY ZEPHIR_DEBUG_PARAMS_DUMMY); add_index_long(&options, 3, 2); if (zephir_isset_property(&dbConfig, SL("options"))) { zephir_read_property(&_6$$5, &dbConfig, SL("options"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_7$$5, &_6$$5, "toarray", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_8$$5); zephir_add_function(&_8$$5, &_7$$5, &options); zephir_update_property_zval(this_ptr, SL("options"), &_8$$5); } else { zephir_update_property_zval(this_ptr, SL("options"), &options); } ZEPHIR_INIT_VAR(&_9); zephir_create_array(&_9, 6, 0 TSRMLS_CC); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, &dbConfig, SL("host"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("host"), &_5, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, &dbConfig, SL("port"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("port"), &_5, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, &dbConfig, SL("username"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("username"), &_5, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, &dbConfig, SL("password"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("password"), &_5, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, &dbConfig, SL("dbname"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("dbname"), &_5, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_NVAR(&_5); zephir_read_property(&_5, this_ptr, SL("options"), PH_NOISY_CC); zephir_array_update_string(&_9, SL("options"), &_5, PH_COPY | PH_SEPARATE); zephir_update_property_zval(this_ptr, SL("descriptor"), &_9); ZEPHIR_MM_RESTORE(); }