Esempio n. 1
0
/* {{{ proto bool SplPriorityQueue::insert(mixed $value, mixed $priority)
	   Push $value with the priority $priodiry on the priorityqueue */
SPL_METHOD(SplPriorityQueue, insert)
{
	zval *data, *priority, elem;
	spl_heap_object *intern;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &data, &priority) == FAILURE) {
		return;
	}

	intern = Z_SPLHEAP_P(getThis());

	if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
		zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0);
		return;
	}

	if (Z_REFCOUNTED_P(data)) Z_ADDREF_P(data);
	if (Z_REFCOUNTED_P(priority)) Z_ADDREF_P(priority);

	array_init(&elem);
	add_assoc_zval_ex(&elem, "data", sizeof("data") - 1, data);
	add_assoc_zval_ex(&elem, "priority", sizeof("priority") - 1, priority);

	spl_ptr_heap_insert(intern->heap, &elem, getThis());

	RETURN_TRUE;
}
Esempio n. 2
0
/**
 * Shows a HTML warning message
 *
 * 
 * 
 *
 * @param string $message
 * @param string $classes
 * @return string
 */
PHP_METHOD(Phalcon_Flash, warning){

	zval *v0 = NULL, *v1 = NULL;
	zval *r0 = NULL;
	zval *p0[] = { NULL, NULL };

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &v0, &v1) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	
	if (!v1) {
		PHALCON_INIT_VAR(v1);
		ZVAL_STRING(v1, "warningMessage", 1);
	}
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	Z_ADDREF_P(v0);
	p0[0] = v0;
	Z_ADDREF_P(v1);
	p0[1] = v1;
	PHALCON_CALL_SELF_PARAMS(r0, this_ptr, "_showmessage", 2, p0);
	Z_DELREF_P(p0[0]);
	Z_DELREF_P(p0[1]);
	PHALCON_RETURN_DZVAL(r0);
}
Esempio n. 3
0
static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(phalcon)
{
	TSRMLS_FETCH();

#ifndef PHALCON_RELEASE
	if (!CG(unclean_shutdown)) {
		//phalcon_verify_permanent_zvals(1 TSRMLS_CC);
	}
#endif

	if (CG(unclean_shutdown)) {
		zend_phalcon_globals *pg = PHALCON_VGLOBAL;

		INIT_ZVAL(*pg->z_null);
		Z_ADDREF_P(pg->z_null);

		INIT_PZVAL(pg->z_false);
		Z_ADDREF_P(pg->z_false);
		ZVAL_FALSE(pg->z_false);

		INIT_PZVAL(pg->z_true);
		Z_ADDREF_P(pg->z_true);
		ZVAL_TRUE(pg->z_true);

		INIT_PZVAL(pg->z_zero);
		Z_ADDREF_P(pg->z_zero);
		ZVAL_LONG(pg->z_zero, 0);

		INIT_PZVAL(pg->z_one);
		Z_ADDREF_P(pg->z_one);
		ZVAL_LONG(pg->z_one, 1);
	}

	return SUCCESS;
}
Esempio n. 4
0
/**
 * Commits the transaction
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Transaction, commit){

	zval *t0 = NULL, *t1 = NULL, *t2 = NULL;
	zval *a0 = NULL, *a1 = NULL;
	zval *r0 = NULL;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY_FETCH TSRMLS_CC);
	if (!PHALCON_COMPARE_STRING(t0, "")) {
		PHALCON_INIT_VAR(a0);
		array_init(a0);
		PHALCON_ALLOC_ZVAL_MM(t1);
		phalcon_read_property(&t1, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY_FETCH TSRMLS_CC);
		Z_ADDREF_P(t1);
		PHALCON_SEPARATE_ARRAY(a0);
		add_next_index_zval(a0, t1);
		add_next_index_stringl(a0, "notifyCommit", strlen("notifyCommit"), 1);
		Z_ADDREF_P(a0);
		PHALCON_INIT_VAR(a1);
		array_init(a1);
		Z_ADDREF_P(this_ptr);
		PHALCON_SEPARATE_ARRAY(a1);
		add_next_index_zval(a1, this_ptr);
		Z_ADDREF_P(a1);
		PHALCON_CALL_FUNC_PARAMS_2_NORETURN("call_user_func_array", a0, a1, 0x001);
		Z_DELREF_P(a0);
		Z_DELREF_P(a1);
	}
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_ALLOC_ZVAL_MM(t2);
	phalcon_read_property(&t2, this_ptr, "_connection", sizeof("_connection")-1, PHALCON_NOISY_FETCH TSRMLS_CC);
	PHALCON_CALL_METHOD(r0, t2, "commit", PHALCON_CALL_DEFAULT);
	PHALCON_RETURN_DZVAL(r0);
}
Esempio n. 5
0
/* {{{ Mosquitto\Client::onPublish() */
PHP_METHOD(Mosquitto_Client, onPublish)
{
	mosquitto_client_object *object;
	zend_fcall_info publish_callback = empty_fcall_info;
	zend_fcall_info_cache publish_callback_cache = empty_fcall_info_cache;

	PHP_MOSQUITTO_ERROR_HANDLING();
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!",
				&publish_callback, &publish_callback_cache)  == FAILURE) {

		PHP_MOSQUITTO_RESTORE_ERRORS();
		return;
	}
	PHP_MOSQUITTO_RESTORE_ERRORS();

	object = (mosquitto_client_object *) mosquitto_client_object_get(getThis() TSRMLS_CC);

	if (!ZEND_FCI_INITIALIZED(publish_callback)) {
		zend_throw_exception(mosquitto_ce_exception, "Need a valid callback", 0 TSRMLS_CC);
	}

	object->publish_callback = publish_callback;
	object->publish_callback_cache = publish_callback_cache;
	Z_ADDREF_P(publish_callback.function_name);

	if (publish_callback.object_ptr != NULL) {
		Z_ADDREF_P(publish_callback.object_ptr);
	}

	mosquitto_publish_callback_set(object->client, php_mosquitto_publish_callback);
}
Esempio n. 6
0
void test_phalcon_separate_param(void)
{
	startup_php(__func__);
	zend_first_try {
		zval* x;
		zval* orig;

		PHALCON_MM_GROW();
			MAKE_STD_ZVAL(x);
			ZVAL_LONG(x, 0xB61964F6l);
			Z_ADDREF_P(x);
			Z_ADDREF_P(x);
			Z_ADDREF_P(x);
			orig = x;

			CU_ASSERT_EQUAL(Z_REFCOUNT_P(x), 4);
			CU_ASSERT_EQUAL(Z_ISREF_P(x), 0);

			PHALCON_SEPARATE_PARAM(x);

			CU_ASSERT_EQUAL(Z_REFCOUNT_P(x), 1);
			CU_ASSERT_EQUAL(Z_ISREF_P(x), 0);
			CU_ASSERT_PTR_NOT_EQUAL(x, orig);
			CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 4);
			CU_ASSERT_EQUAL(Z_ISREF_P(orig), 0);

			CU_ASSERT_EQUAL(Z_TYPE_P(x), IS_LONG);
			CU_ASSERT_EQUAL(Z_LVAL_P(x), 0xB61964F6l);

			CU_ASSERT_EQUAL(Z_TYPE_P(x), Z_TYPE_P(orig));
			CU_ASSERT_EQUAL(Z_LVAL_P(x), Z_LVAL_P(orig));

			zval_ptr_dtor(&orig);
			CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 3);

			zval_ptr_dtor(&orig);
			CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 2);

			zval_ptr_dtor(&orig);
			CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
			CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 1);

			zval_ptr_dtor(&orig);
			CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1);
		PHALCON_MM_RESTORE();
	}
	zend_catch {
		CU_ASSERT(0);
	}
	zend_end_try();

	shutdown_php();
	CU_ASSERT_EQUAL(leaks, 0);
}
Esempio n. 7
0
PHP_METHOD(FutureRows, get)
{
  zval* timeout = NULL;
  cassandra_rows* rows = NULL;
  const CassResult* result = NULL;

  cassandra_future_rows* self =
    (cassandra_future_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->rows) {
    *return_value = *self->rows;
    Z_ADDREF_P(return_value);
    return;
  }

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  if (php_cassandra_future_wait_timed(self->future, timeout TSRMLS_CC) == FAILURE) {
    return;
  }

  if (php_cassandra_future_is_error(self->future TSRMLS_CC) == FAILURE) {
    return;
  }

  result = cass_future_get_result(self->future);

  if (!result) {
    zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                            "Future doesn't contain a result.");
    return;
  }

  MAKE_STD_ZVAL(self->rows);
  object_init_ex(self->rows, cassandra_rows_ce);
  Z_ADDREF_P(self->rows);
  rows = (cassandra_rows*) zend_object_store_get_object(self->rows TSRMLS_CC);

  if (php_cassandra_get_result(result, &rows->rows TSRMLS_CC) == FAILURE) {
    cass_result_free(result);
    zval_ptr_dtor(&self->rows);
    return;
  }

  if (self->statement) {
    Z_ADDREF_P(self->session);
    rows->statement = php_cassandra_add_ref(self->statement);
    rows->session   = self->session;
    rows->result    = result;
  } else {
    cass_result_free(result);
  }

  *return_value = *self->rows;
  Z_ADDREF_P(return_value);
}
Esempio n. 8
0
/**
 * @brief Fetches @a index if it exists from the array @a arr
 * @param[out] fetched <code>&$arr[$index]</code>; @a fetched is modified only when the function returns 1
 * @param arr Array
 * @param index Index
 * @return isset($arr[$index])
 * @retval 0 Not exists, @a arr is not an array or @a index is of not supported type
 * @retval 1 Exists
 * @note @c index will be handled as follows: @c NULL is treated as an empty string, @c double values are cast to @c integer, @c bool or @c resource are treated as @c integer
 * @note $arr[$index] is returned as is: no copying occurs, reference copunt is not updated
 * @throw E_WARNING if @a offset is not a scalar
 */
int zephir_array_isset_fetch(zval **fetched, const zval *arr, zval *index, int readonly TSRMLS_DC) {

    HashTable *h;
    zval **val;
    int result;

    if (Z_TYPE_P(arr) != IS_ARRAY) {
        *fetched = ZEPHIR_GLOBAL(global_null);
        if (!readonly) {
            Z_ADDREF_P(*fetched);
        }
        return 0;
    }

    h = Z_ARRVAL_P(arr);
    switch (Z_TYPE_P(index)) {
    case IS_NULL:
        result = zephir_hash_find(h, SS(""), (void**)&val);
        break;

    case IS_DOUBLE:
        result = zend_hash_index_find(h, (ulong)Z_DVAL_P(index), (void**)&val);
        break;

    case IS_LONG:
    case IS_BOOL:
    case IS_RESOURCE:
        result = zend_hash_index_find(h, Z_LVAL_P(index), (void**)&val);
        break;

    case IS_STRING:
        result = zend_symtable_find(h, (Z_STRLEN_P(index) ? Z_STRVAL_P(index) : ""), Z_STRLEN_P(index)+1, (void**)&val);
        break;

    default:
        zend_error(E_WARNING, "Illegal offset type");
        *fetched = ZEPHIR_GLOBAL(global_null);
        if (!readonly) {
            Z_ADDREF_P(*fetched);
        }
        return 0;
    }

    if (result == SUCCESS) {
        *fetched = *val;
        if (!readonly) {
            Z_ADDREF_P(*fetched);
        }
        return 1;
    }

    *fetched = ZEPHIR_GLOBAL(global_null);
    if (!readonly) {
        Z_ADDREF_P(*fetched);
    }
    return 0;
}
Esempio n. 9
0
PHP_METHOD(air_mysql_waiter, step_2) {
	AIR_INIT_THIS;
	zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC);
	zval *responses = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_responses"), 0 TSRMLS_CC);
	zval *context = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_context"), 0 TSRMLS_CC);
	zval *m2s = air_arr_find(context, ZEND_STRS("m2s"));
	zval *reads = air_arr_find(context, ZEND_STRS("reads"));
	zval *waited = air_arr_find(context, ZEND_STRS("waited"));
	zval *processed = air_arr_find(context, ZEND_STRS("processed"));
	zval *step = air_arr_find(context, ZEND_STRS("step"));
	zend_class_entry *mysqli_ce = air_get_ce(ZEND_STRL("mysqli") TSRMLS_CC);

	ulong idx;
	char *key;
	int key_len;
	zval *mysqli;
	AIR_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(reads), idx, key, key_len, mysqli){
		zval *service_id = air_arr_idx_find(m2s, air_mysqli_get_id(mysqli TSRMLS_CC));
		zval *service = air_arr_idx_find(services, Z_LVAL_P(service_id));
		zval *mysql = zend_read_property(air_async_service_ce, service, ZEND_STRL("_request"), 0 TSRMLS_CC);
		zval **trigger_params[2];
		zval *event;
		MAKE_STD_ZVAL(event);
		zval *event_params;
		MAKE_STD_ZVAL(event_params);
		array_init(event_params);
		Z_ADDREF_P(mysqli);
		add_next_index_zval(event_params, mysqli);
		zval *mysqli_result = NULL;
		if(air_mysqli_get_errno(mysqli TSRMLS_CC)){
			ZVAL_STRING(event, "error", 1);
		}else{
			ZVAL_STRING(event, "success", 1);
			air_call_method(&mysqli, mysqli_ce, NULL, ZEND_STRL("reap_async_query"), &mysqli_result, 0, NULL TSRMLS_CC);
			Z_ADDREF_P(mysqli_result);
			add_next_index_zval(event_params, mysqli_result);
		}
		trigger_params[0] = &event;
		trigger_params[1] = &event_params;
		zval *results = NULL;
		air_call_method(&mysql, air_mysql_ce, NULL, ZEND_STRL("trigger"), &results, 2, trigger_params TSRMLS_CC);
		if(results){
			add_index_zval(responses, Z_LVAL_P(service_id), results);
		}else{
			php_error(E_WARNING, "error on trigger event %s with no results", Z_STRVAL_P(event));
		}
		zend_hash_index_del(Z_ARRVAL_P(services), Z_LVAL_P(service_id));
		zval_ptr_dtor(&event);
		zval_ptr_dtor(&event_params);
		if(mysqli_result){
			zval_ptr_dtor(&mysqli_result);
		}
		zval *mysql_config = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_config"), 0 TSRMLS_CC);
		zval *mode = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_mode"), 0 TSRMLS_CC);
		zval **release_params[3] = {&mysqli, &mysql_config, &mode};
		air_call_static_method(air_mysql_keeper_ce, "release", NULL, 3, release_params);
	}AIR_HASH_FOREACH_END();
Esempio n. 10
0
/**
 * Throws a zval object as exception
 */
void zephir_throw_exception_debug(zval *object, const char *file, zend_uint line)
{
	zend_class_entry *default_exception_ce;
	int ZEPHIR_LAST_CALL_STATUS = 0;
	zval curline;
	zval object_copy;

	ZVAL_UNDEF(&curline);

	ZEPHIR_MM_GROW();

	if (Z_TYPE_P(object) != IS_OBJECT) {
		ZVAL_COPY_VALUE(&object_copy, object);
		object_init_ex(object, zend_exception_get_default());
		ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, 0, &object_copy);
		zval_ptr_dtor(&object_copy);
	}

	Z_ADDREF_P(object);

	if (line > 0) {
		ZEPHIR_CALL_METHOD(&curline, object, "getline", NULL, 0);
		zephir_check_call_status();
		if (ZEPHIR_IS_LONG(&curline, 0)) {
			default_exception_ce = zend_exception_get_default();
			zend_update_property_string(default_exception_ce, object, SL("file"), file);
			zend_update_property_long(default_exception_ce, object, SL("line"), line);
		}
	}

	if (ZEPHIR_LAST_CALL_STATUS != FAILURE) {
		zend_throw_exception_object(object);
	}
	ZEPHIR_MM_RESTORE();
}
Esempio n. 11
0
/**
 * Appends every element of an array at the end of the left array
 */
void zephir_merge_append(zval *left, zval *values) {

    zval         **tmp;
    HashTable      *arr_values;
    HashPosition   pos;

    if (Z_TYPE_P(left) != IS_ARRAY) {
        zend_error(E_NOTICE, "First parameter of zephir_merge_append must be an array");
        return;
    }

    if (Z_TYPE_P(values) == IS_ARRAY) {

        arr_values = Z_ARRVAL_P(values);
        zend_hash_internal_pointer_reset_ex(arr_values, &pos);

        while (zend_hash_get_current_data_ex(arr_values, (void **) &tmp, &pos) == SUCCESS) {

            Z_ADDREF_PP(tmp);
            add_next_index_zval(left, *tmp);

            zend_hash_move_forward_ex(arr_values, &pos);
        }

    } else {
        Z_ADDREF_P(values);
        add_next_index_zval(left, values);
    }
}
Esempio n. 12
0
PHP_METHOD(FuturePreparedStatement, get)
{
  zval* timeout = NULL;
  cassandra_prepared_statement* prepared_statement = NULL;

  cassandra_future_prepared_statement* self =
    (cassandra_future_prepared_statement*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->prepared_statement) {
    RETURN_ZVAL(self->prepared_statement, 1, 0);
  }

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  if (php_cassandra_future_wait_timed(self->future, timeout TSRMLS_CC) == FAILURE) {
    return;
  }

  if (php_cassandra_future_is_error(self->future TSRMLS_CC) == FAILURE) {
    return;
  }

  object_init_ex(return_value, cassandra_prepared_statement_ce);
  self->prepared_statement = return_value;
  Z_ADDREF_P(self->prepared_statement);

  prepared_statement = (cassandra_prepared_statement*) zend_object_store_get_object(return_value TSRMLS_CC);

  prepared_statement->prepared = cass_future_get_prepared(self->future);
}
Esempio n. 13
0
static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state)
{

	zval *ret;

	MAKE_STD_ZVAL(ret);
	array_init(ret);

	add_assoc_long(ret, "type", PHANNOT_T_ANNOTATION);

	if (name) {
		add_assoc_stringl(ret, "name", name->token, name->token_len, 0);
		efree(name);
	}

	if (arguments) {
		add_assoc_zval(ret, "arguments", arguments);
	}

	Z_ADDREF_P(state->active_file);
	add_assoc_zval(ret, "file", state->active_file);
	add_assoc_long(ret, "line", state->active_line);

	return ret;
}
Esempio n. 14
0
static zend_bool php_auto_globals_create_server(zend_string *name)
{
	if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
		php_register_server_variables();

		if (PG(register_argc_argv)) {
			if (SG(request_info).argc) {
				zval *argc, *argv;

				if ((argc = zend_hash_str_find(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL &&
					(argv = zend_hash_str_find(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) {
					Z_ADDREF_P(argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc);
				}
			} else {
				php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]);
			}
		}

	} else {
		zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
		array_init(&PG(http_globals)[TRACK_VARS_SERVER]);
	}

	zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_SERVER]);
	Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]);

	return 0; /* don't rearm */
}
Esempio n. 15
0
/**
 * Phalcon_Acl_Role description
 *
 * @param string $name
 * @param string $description
 */
PHP_METHOD(Phalcon_Acl_Role, __construct){

	zval *v0 = NULL, *v1 = NULL;
	zval *i0 = NULL;
	zval *p0[] = { NULL };

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &v0, &v1) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	
	if (!v1) {
		PHALCON_INIT_VAR(v1);
		ZVAL_STRING(v1, "", 1);
	}
	
	if (PHALCON_COMPARE_STRING(v0, "*")) {
		PHALCON_ALLOC_ZVAL_MM(i0);
		object_init_ex(i0, phalcon_acl_exception_class_entry);
		PHALCON_INIT_VAR(p0[0]);
		ZVAL_STRING(p0[0], "Role name cannot be \"*\"", 1);
		PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 1, p0, PHALCON_CALL_CHECK);
		zend_throw_exception_object(i0 TSRMLS_CC);
		Z_ADDREF_P(i0);
		PHALCON_MM_RESTORE();
		return;
	}
	phalcon_update_property_zval(this_ptr, "_name", strlen("_name"), v0 TSRMLS_CC);
	phalcon_update_property_zval(this_ptr, "_description", strlen("_description"), v1 TSRMLS_CC);
	PHALCON_MM_RESTORE();
	RETURN_NULL();
}
Esempio n. 16
0
PHP_METHOD(air_view, assign) {
	AIR_INIT_THIS;

	int argc = ZEND_NUM_ARGS();
	zval *data = zend_read_property(air_view_ce, self, ZEND_STRL("_data"), 0 TSRMLS_CC);
	if(argc == 1){
		zval *arr;
		if( zend_parse_parameters(argc TSRMLS_CC, "a", &arr) == FAILURE ){
			AIR_NEW_EXCEPTION(1, "param 1 must be an array when only 1 param passed in");
		}
		if(Z_TYPE_P(arr) == IS_ARRAY){
			zend_hash_copy(Z_ARRVAL_P(data), Z_ARRVAL_P(arr), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
		}
	}else{
		char *key;
		int key_len = 0;
		zval *val;
		if( zend_parse_parameters(argc TSRMLS_CC, "sz", &key, &key_len, &val) == FAILURE ){
			AIR_NEW_EXCEPTION(1, "invalid params");
		}
		Z_ADDREF_P(val);
		zend_hash_update(Z_ARRVAL_P(data), key, key_len+1, &val, sizeof(zval *), NULL);
	}

	AIR_RET_THIS;
}
Esempio n. 17
0
static zval *oauth_provider_call_cb(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
{
	php_oauth_provider *sop;
	php_oauth_provider_fcall *cb = NULL;
	zval args, *pthis;
	char *errstr = "";
	zend_string *callable = NULL;

	pthis = getThis();
	sop = fetch_sop_object(pthis);

	switch(type) {
		case OAUTH_PROVIDER_CONSUMER_CB:
			cb = sop->consumer_handler;
			errstr = "Consumer key/secret handler not specified, did you set a valid callback via OAuthProvider::consumerHandler()?";
			break;
		case OAUTH_PROVIDER_TOKEN_CB:
			cb = sop->token_handler;
			errstr = "Token handler not specified, did you set a valid callback via OAuthProvider::tokenHandler()?";
			break;
		case OAUTH_PROVIDER_TSNONCE_CB:
			cb = sop->tsnonce_handler;
			errstr = "Timestamp/nonce handler not specified, did you set a valid callback via OAuthProvider::timestampNonceHandler()?";
			break;
		default:
			php_error_docref(NULL, E_ERROR, "Invalid callback type for OAuthProvider");
			return NULL;
	}

	if(!cb) {
		php_error_docref(NULL, E_ERROR, "%s", errstr);
		return NULL;
	}

	array_init(&args);
	add_next_index_zval(&args, pthis);
	Z_ADDREF_P(pthis);
	Z_ADDREF(args);

	errstr = NULL;
	if (!zend_is_callable(&cb->fcall_info->function_name, 0, &callable)) {
		if (errstr) {
			php_error_docref(NULL, E_WARNING, "Invalid callback: %s, %s", Z_STRVAL(cb->fcall_info->function_name), errstr);
			efree(errstr);
		} else {
			php_error_docref(NULL, E_WARNING, "Invalid callback: %s.", Z_STRVAL(cb->fcall_info->function_name));
		}
	} else if (errstr) {
		php_error_docref(NULL, E_WARNING, "%s", errstr);
		efree(errstr);
	}

	if (zend_fcall_info_call(cb->fcall_info, &cb->fcall_info_cache, return_value, &args)!=SUCCESS) {
		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed calling callback %s", Z_STRVAL(cb->fcall_info->function_name));
	}

	zval_ptr_dtor(&args);

	return return_value;
}
Esempio n. 18
0
PHP_METHOD(Test_TryTest, testTry10) {

	zval e;
	int ZEPHIR_LAST_CALL_STATUS;
		zval this_zv;
	zval *this_ptr = getThis();
	if (EXPECTED(this_ptr)) {
		ZVAL_OBJ(&this_zv, Z_OBJ_P(this_ptr));
		this_ptr = &this_zv;
	} else this_ptr = NULL;
	
	ZVAL_UNDEF(&e);

	ZEPHIR_MM_GROW();


	/* try_start_1: */

		ZEPHIR_CALL_METHOD(NULL, this_ptr, "somemethod2", NULL, 77);
		zephir_check_call_status_or_jump(try_end_1);
		RETURN_MM_STRING("not catched");

	try_end_1:

	if (EG(exception)) {
		ZVAL_OBJ(&e, EG(exception));
		Z_ADDREF_P(&e);
		if (zephir_instance_of_ev(&e, spl_ce_RuntimeException TSRMLS_CC)) {
			zend_clear_exception(TSRMLS_C);
			RETURN_MM_STRING("domain error");
		}
	}
	RETURN_MM_BOOL(0);

}
Esempio n. 19
0
SPL_METHOD(SplCharIterator, __construct)
{
	zval *val;
	long chunk;
	FETCH_OBJECT

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &val, &chunk) == FAILURE) {
		return;
	}
	if (ZEND_NUM_ARGS() == 1) {
		chunk = 1;
	}
	if (chunk > Z_STRLEN_P(val)) {
		zend_throw_exception(spl_ce_OutOfRangeException, "Chunk is larger than string length", 0L);
		return;
	}
	if (chunk < 0) {
		zend_throw_exception(spl_ce_OutOfRangeException, "Chunk size must be positive", 0L);
		return;
	}
	obj->charval    = val;
	obj->chunk_size = chunk;
	obj->max_offset = Z_STRLEN_P(val) / obj->chunk_size + (Z_STRLEN_P(val) % obj->chunk_size ? 1 : 0) - 1;

	Z_ADDREF_P(val);
}
Esempio n. 20
0
PHP_METHOD(Test_Exceptions, issue1325) {

	zval e, status, _0;
	zend_long ZEPHIR_LAST_CALL_STATUS;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&e);
	ZVAL_UNDEF(&status);
	ZVAL_UNDEF(&_0);

	ZEPHIR_MM_GROW();


	/* try_start_1: */

		ZEPHIR_CALL_METHOD(&status, this_ptr, "donoopexception", NULL, 27);
		zephir_check_call_status_or_jump(try_end_1);

	try_end_1:

	if (EG(exception)) {
		ZEPHIR_INIT_VAR(&_0);
		ZVAL_OBJ(&_0, EG(exception));
		Z_ADDREF_P(&_0);
		if (zephir_instance_of_ev(&_0, zend_exception_get_default(TSRMLS_C) TSRMLS_CC)) {
			zend_clear_exception(TSRMLS_C);
			ZEPHIR_CPY_WRT(&e, &_0);
			ZEPHIR_INIT_NVAR(&status);
			ZVAL_STRING(&status, "woop");
		}
	}
	RETURN_MM_LONG(1);

}
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false])
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue)
{
	zval *instance = getThis();
	zval *value, **fields, *name;
	zend_bool force = 0;
	char *property;
	int property_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) {
		return;
	}

	zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0);
	if (zend_hash_find(Z_OBJPROP_P(instance), property, property_len, (void **)&fields) == SUCCESS) {
		if (php_protocolbuffers_read_protected_property(value, ZEND_STRS("name"), &name TSRMLS_CC)) {
			if (zend_hash_exists(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name))) {
				if (force < 1) {
					zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name));
				}
				efree(property);
				return;
			}
		}

		Z_ADDREF_P(value);
		zend_hash_update(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name)+1, &value, sizeof(zval), NULL);
	}
	efree(property);

}
Esempio n. 22
0
ZEND_RESULT_CODE php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval *retval_ptr, int argc, zval *args)
{
	ZEND_RESULT_CODE rv;
	zval retval;

	ZVAL_UNDEF(&retval);
	Z_ADDREF_P(zobject);
	cb->fci.object = Z_OBJ_P(zobject);
	cb->fcc.object = Z_OBJ_P(zobject);

	cb->fci.retval = retval_ptr ? retval_ptr : &retval;

	cb->fci.param_count = argc;
	cb->fci.params = args;

	if (cb->fcc.called_scope != Z_OBJCE_P(zobject)) {
		cb->fcc.called_scope = Z_OBJCE_P(zobject);
		cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&Z_OBJ_P(zobject), Z_STR(cb->fci.function_name), NULL);
	}

	rv = zend_call_function(&cb->fci, &cb->fcc);

	zval_ptr_dtor(zobject);
	if (!retval_ptr && !Z_ISUNDEF(retval)) {
		zval_ptr_dtor(&retval);
	}

	return rv;
}
Esempio n. 23
0
static int php_get_if_index_from_zval(zval *val, unsigned *out)
{
	int ret;

	if (Z_TYPE_P(val) == IS_LONG) {
		if (Z_LVAL_P(val) < 0 || (zend_ulong)Z_LVAL_P(val) > UINT_MAX) {
			php_error_docref(NULL, E_WARNING,
				"the interface index cannot be negative or larger than %u;"
				" given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(val));
			ret = FAILURE;
		} else {
			*out = Z_LVAL_P(val);
			ret = SUCCESS;
		}
	} else {
		if (Z_REFCOUNTED_P(val)) {
			Z_ADDREF_P(val);
		}
		convert_to_string_ex(val);
		ret = php_string_to_if_index(Z_STRVAL_P(val), out);
		zval_ptr_dtor(val);
	}

	return ret;
}
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false])
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue)
{
	zval *instance = getThis();
	zval *value, *fields, *name;
	zend_bool force = 0;
//	char *property;
	int property_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) {
		return;
	}

	zend_string *property_key = zend_mangle_property_name((char*)"*", 1, (char*)ZEND_STRL("values"), 0);
	if ((fields=zend_hash_find(Z_OBJPROP_P(instance), property_key)) != NULL) {
		if (php_protocolbuffers_read_protected_property(value, ZEND_STRL("name"), &name TSRMLS_CC)) {
			zend_string *name_key = zend_string_init(Z_STRVAL_P(name), Z_STRLEN_P(name),0);
			if (zend_hash_exists(Z_ARRVAL_P(fields), name_key)) {
				if (force < 1) {
					zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name));
				}
				zend_string_release(property_key);
				zend_string_release(name_key);
				return;
			}
		}

		Z_ADDREF_P(value);
		zend_string *name_key = zend_string_init(Z_STRVAL_P(name), Z_STRLEN_P(name)+1,0);
		zend_hash_update(Z_ARRVAL_P(fields), name_key, value);
		zend_string_release(name_key);
	}
	zend_string_release(property_key);

}
Esempio n. 25
0
PHP_METHOD(Test_TryTest, testTry11) {

	zval ex;
		zval this_zv;
	zval *this_ptr = getThis();
	if (EXPECTED(this_ptr)) {
		ZVAL_OBJ(&this_zv, Z_OBJ_P(this_ptr));
		this_ptr = &this_zv;
	} else this_ptr = NULL;
	
	ZVAL_UNDEF(&ex);



	/* try_start_1: */

		RETURN_STRING("test");

	try_end_1:

	if (EG(exception)) {
		ZVAL_OBJ(&ex, EG(exception));
		Z_ADDREF_P(&ex);
		if (zephir_instance_of_ev(&ex, zend_exception_get_default(TSRMLS_C) TSRMLS_CC)) {
			zend_clear_exception(TSRMLS_C);
		}
	}

}
Esempio n. 26
0
static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *param)
{
	zval *param_owner, *retval_ptr = NULL;
	php_git2_cb_t *p = (php_git2_cb_t*)param;
	php_git2_t *_param_owner;
	long retval = 0;
	GIT2_TSRMLS_SET(p->tsrm_ls)

	Z_ADDREF_P(p->payload);
	MAKE_STD_ZVAL(param_owner);
	if (php_git2_make_resource(&_param_owner, PHP_GIT2_TYPE_REMOTE, owner, 0 TSRMLS_CC)) {
		return 0;
	}
	ZVAL_RESOURCE(param_owner, GIT2_RVAL_P(_param_owner));

	if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, &param_owner, &p->payload)) {
		return GIT_EUSER;
	}

	/* TODO(chobie): implement this */

	retval = Z_LVAL_P(retval_ptr);
	zval_ptr_dtor(&retval_ptr);
	return retval;
}
PHP_METHOD(ArrayList, toValue) {
	array_init(return_value);
	list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
    if (obj->object != NULL) {
		if(obj->type == TYPE_LONG) {
			ArrayList<long>* list = (ArrayList<long>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_long(return_value,*it);
			}
		} else if (obj->type == TYPE_DOUBLE) {
			ArrayList<double>* list = (ArrayList<double>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_double(return_value,*it);
			}
		} else if (obj->type == TYPE_BOOLEAN) {
			ArrayList<char>* list = (ArrayList<char>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_bool(return_value,*it);
			}
		} else if (obj->type == TYPE_STRING) {
			ArrayList<char*>* list = (ArrayList<char*>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_string(return_value,*it,1);
			}
		} else {
			ArrayList<zval*>* list = (ArrayList<zval*>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				Z_ADDREF_P(*it);
				add_next_index_zval(return_value,*it);
			}
		}
    }
}
Esempio n. 28
0
PHP_METHOD(Test_Exceptions, testExceptionRethrow) {

	zval e;
	int ZEPHIR_LAST_CALL_STATUS;
	ZEPHIR_INIT_THIS();

	ZVAL_UNDEF(&e);

	ZEPHIR_MM_GROW();


	/* try_start_1: */

		ZEPHIR_CALL_METHOD(NULL, this_ptr, "testexception1", NULL, 0);
		zephir_check_call_status_or_jump(try_end_1);

	try_end_1:

	if (EG(exception)) {
		ZVAL_OBJ(&e, EG(exception));
		Z_ADDREF_P(&e);
		if (zephir_instance_of_ev(&e, zend_exception_get_default(TSRMLS_C) TSRMLS_CC)) {
			zend_clear_exception(TSRMLS_C);
			zephir_throw_exception_debug(&e, "test/exceptions.zep", 80 TSRMLS_CC);
			ZEPHIR_MM_RESTORE();
			return;
		}
	}
	ZEPHIR_MM_RESTORE();

}
Esempio n. 29
0
/* {{{ proto void SplFixedArray::__wakeup()
*/
SPL_METHOD(SplFixedArray, __wakeup)
{
	spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(getThis());
	HashTable *intern_ht = zend_std_get_properties(getThis());
	zval *data;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	if (!intern->array) {
		int index = 0;
		int size = zend_hash_num_elements(intern_ht);

		intern->array = emalloc(sizeof(spl_fixedarray));
		spl_fixedarray_init(intern->array, size);

		ZEND_HASH_FOREACH_VAL(intern_ht, data) {
			if (Z_REFCOUNTED_P(data)) {
				Z_ADDREF_P(data);
			}
			ZVAL_COPY_VALUE(&intern->array->elements[index], data);
			index++;
		} ZEND_HASH_FOREACH_END();

		/* Remove the unserialised properties, since we now have the elements
		 * within the spl_fixedarray_object structure. */
		zend_hash_clean(intern_ht);
	}
Esempio n. 30
0
/* {{{ php_autoglobal_merge
 */
static void php_autoglobal_merge(HashTable *dest, HashTable *src)
{
	zval *src_entry, *dest_entry;
	zend_string *string_key;
	zend_ulong num_key;
	int globals_check = (dest == (&EG(symbol_table)));

	ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) {
		if (Z_TYPE_P(src_entry) != IS_ARRAY
			|| (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL)
			|| (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL)
			|| Z_TYPE_P(dest_entry) != IS_ARRAY) {
			if (Z_REFCOUNTED_P(src_entry)) {
				Z_ADDREF_P(src_entry);
			}
			if (string_key) {
				if (!globals_check || string_key->len != sizeof("GLOBALS") - 1
						|| memcmp(string_key->val, "GLOBALS", sizeof("GLOBALS") - 1)) {
					zend_hash_update(dest, string_key, src_entry);
				} else if (Z_REFCOUNTED_P(src_entry)) {
					Z_DELREF_P(src_entry);
				}
			} else {
				zend_hash_index_update(dest, num_key, src_entry);
			}
		} else {
			SEPARATE_ZVAL(dest_entry);
			php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry));
		}
	} ZEND_HASH_FOREACH_END();
}