/* {{{ proto ProtocolBuffers_DescriptorBuilder ProtocolBuffers_DescriptorBuilder::__construct() */ PHP_METHOD(berg_buffers, __construct) { zval *instance = getThis(); zval fields,options,extension_ranges,*tmp; array_init(&fields); add_next_index_double(&fields,42.00); add_next_index_long(&fields,42); php_var_dump(&fields,1); zend_update_property(Z_OBJCE_P(instance),instance,ZEND_STRL("fields"),&fields); zval_ptr_dtor(&fields); // array_init(&options); // zend_update_property(berg_buffers_class_entry,instance,ZEND_STRL("options"),&options); // zval_ptr_dtor(&options); // // array_init(&extension_ranges); // zend_update_property(berg_buffers_class_entry,instance,ZEND_STRL("extension_ranges"),&extension_ranges); // zval_ptr_dtor(&extension_ranges); zend_string *key = zend_string_init(ZEND_STRL("fields"),0); if((tmp=zend_hash_find(Z_OBJPROP_P(instance), key))!=NULL){ php_var_dump(tmp,1); } zend_string_release(key); //>gdb //(gdb) p fields1->u2 //$1 = {var_flags = 4294967295, next = 4294967295, cache_slot = 4294967295, lineno = 4294967295, num_args = 4294967295, fe_pos = 4294967295, fe_iter_idx = 4294967295} //(gdb) p fields1->value->arr->nNumUsed //$4 = 1 //(gdb) p fields1->value->arr->nTableSize //$5 = 4294956704 //(gdb) p fields1->value->arr->nNumOfElements //$6 = 0 }
static void php_r_to_zval(SEXP value, zval *result) /* {{{ */ { int value_len, i; zval_dtor(result); array_init(result); value_len = GET_LENGTH(value); if (value_len == 0) { return; } for (i = 0; i < value_len; i++) { switch (TYPEOF(value)) { case INTSXP: add_next_index_long(result, INTEGER_DATA(value)[i]); break; case REALSXP: add_next_index_double(result, NUMERIC_DATA(value)[i]); break; case LGLSXP: add_next_index_bool(result, LOGICAL_DATA(value)[i]); break; case STRSXP: add_next_index_string(result, CHAR(STRING_ELT(value, 0)), 1); break; } } return; }
/* {{{ Helpers */ void retval_point_from_coordinates(zval *return_value, double lon, double lat) { zval *coordinates; array_init(return_value); GEOSPAT_MAKE_STD_ZVAL(coordinates); array_init(coordinates); ADD_STRING(return_value, "type", "Point"); add_next_index_double(coordinates, lon); add_next_index_double(coordinates, lat); #if PHP_VERSION_ID >= 70000 add_assoc_zval_ex(return_value, "coordinates", sizeof("coordinates") - 1, coordinates); efree(coordinates); #else add_assoc_zval_ex(return_value, "coordinates", sizeof("coordinates"), coordinates); #endif }
void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray) { if (value->IsNull() || value->IsUndefined()) { add_next_index_null(phpArray); } else if (value->IsBool()) { if (value->ToBool()) add_next_index_bool(phpArray, 1); else add_next_index_bool(phpArray, 0); } else if (value->IsNumber()) { /* No way to check whether the number is an integer or a double here. All Kroll numbers are doubles, so return a double. This could cause some PHP to function incorrectly if it's doing strict type checking. */ add_next_index_double(phpArray, value->ToNumber()); } else if (value->IsString()) { add_next_index_stringl(phpArray, (char *) value->ToString(), strlen(value->ToString()), 1); } else if (value->IsObject()) { /*TODO: Implement*/ } else if (value->IsMethod()) { /*TODO: Implement*/ } else if (value->IsList()) { zval *phpValue; AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>(); if (!pl.isNull()) phpValue = pl->ToPHP(); else phpValue = PHPUtils::ToPHPValue(value); add_next_index_zval(phpArray, phpValue); } }
void php_array_add_sum_double(zval *row, zval *data1, zval *data2) { double x1, x2; zval temp; temp = *data1; zval_copy_ctor(&temp); convert_to_double(&temp); x1 = Z_DVAL(temp); zval_dtor(&temp); temp = *data2; zval_copy_ctor(&temp); convert_to_double(&temp); x2 = Z_DVAL(temp); zval_dtor(&temp); add_next_index_double(row, x1 + x2); }
/* {{{ proto array GmagickDraw::getStrokeDashArray() Returns an array representing the pattern of dashes and gaps used to stroke paths (see DrawSetStrokeDashArray). The array must be freed once it is no longer required by the user. */ PHP_METHOD(gmagickdraw, getstrokedasharray) { php_gmagickdraw_object *internd; double *stroke_array; unsigned long num_elements, i; if (zend_parse_parameters_none() == FAILURE) { return; } internd = (php_gmagickdraw_object *)zend_object_store_get_object(getThis() TSRMLS_CC); stroke_array = DrawGetStrokeDashArray(internd->drawing_wand, &num_elements); array_init(return_value); for (i = 0; i < num_elements ; i++) { add_next_index_double(return_value, stroke_array[i]); } GMAGICK_FREE_MEMORY(double *, stroke_array); return; }
/* {{{ proto mixed R::__call(string function_name, array arguments) */ static PHP_METHOD(R, __call) { char *func; int func_len, error_occurred = 0, num_args; zval *args; SEXP e, fun, val, arg, next; HashPosition pos; zval **element; SEXPTYPE type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &func, &func_len, &args) == FAILURE) { return; } fun = Rf_install(func); if (!fun) { RETURN_FALSE; } num_args = zend_hash_num_elements(Z_ARRVAL_P(args)); PROTECT(fun); PROTECT(e = allocVector(LANGSXP, num_args + 1)); SETCAR(e, fun); next = CDR(e); for(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **)&element, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos) ) { arg = php_zval_to_r(element); SETCAR(next, arg); next = CDR(next); } val = R_tryEval(e, R_GlobalEnv, &error_occurred); if (error_occurred) { UNPROTECT(2); RETURN_FALSE; } /* okay, the call succeeded */ PROTECT(val); if (val == NULL_USER_OBJECT || GET_LENGTH(val) == 0) { /* ignore the return value */ } else if (php_is_r_primitive(val, &type)) { int i; array_init(return_value); for (i = 0; i < GET_LENGTH(val); i++) { switch (type) { case STRSXP: add_next_index_string(return_value, CHAR(STRING_ELT(val, 0)), 1); break; case LGLSXP: add_next_index_bool(return_value, LOGICAL_DATA(val)[0] ? 1 : 0); break; case INTSXP: add_next_index_long(return_value, INTEGER_DATA(val)[0]); break; case REALSXP: add_next_index_double(return_value, NUMERIC_DATA(val)[0]); break; default: add_next_index_null(return_value); break; } } UNPROTECT(3); return; } UNPROTECT(3); RETURN_TRUE; }
static int add_double(zval* list, char* id, double num) { if(id) return add_assoc_double(list, id, num); else return add_next_index_double(list, num); }