예제 #1
0
/**
 * Changes the padding scheme used
 *
 * @param int scheme
 */
PHP_METHOD(Phalcon_Crypt, setPadding) {

	zval *scheme_param = NULL, *_0;
	int scheme;

	zephir_fetch_params(0, 1, 0, &scheme_param);

	if (unlikely(Z_TYPE_P(scheme_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'scheme' must be a long/integer") TSRMLS_CC);
		RETURN_NULL();
	}

	scheme = Z_LVAL_P(scheme_param);


	ZEPHIR_INIT_ZVAL_NREF(_0);
	ZVAL_LONG(_0, scheme);
	zephir_update_property_this(this_ptr, SL("_padding"), _0 TSRMLS_CC);
	RETURN_THISW();

}
예제 #2
0
/**
 * Gets an attribute a message using the array syntax
 *
 *<code>
 * print_r(
 *     $messages[0]
 * );
 *</code>
 *
 * @param int index
 * @return \Phalcon\Validation\Message
 */
PHP_METHOD(Phalcon_Validation_Message_Group, offsetGet) {

	zval *index_param = NULL, *message = NULL, *_0;
	int index;

	zephir_fetch_params(0, 1, 0, &index_param);

	if (unlikely(Z_TYPE_P(index_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'index' must be a int") TSRMLS_CC);
		RETURN_NULL();
	}
	index = Z_LVAL_P(index_param);


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY_CC);
	if (zephir_array_isset_long_fetch(&message, _0, index, 1 TSRMLS_CC)) {
		RETURN_CTORW(message);
	}
	RETURN_BOOL(0);

}
예제 #3
0
파일: multi.c 프로젝트: ARYANJASHWAL/php7
void _php_curl_multi_cleanup_list(void *data) /* {{{ */
{
	zval *z_ch = (zval *)data;
	php_curl *ch;
	TSRMLS_FETCH();

	if (!z_ch) {
		return;
	}
	
	ch = (php_curl *) zend_fetch_resource(&z_ch TSRMLS_CC, -1, le_curl_name, NULL, 1, le_curl);
	if (!ch) {
		return;
	}

	if (ch->uses) {	
		ch->uses--;
	} else {
		zend_list_delete(Z_LVAL_P(z_ch));
	}
}
예제 #4
0
파일: twig.c 프로젝트: Clempops/prenomea
int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key)
{
	if (Z_TYPE_P(array) != IS_ARRAY) {
		return 0;
	}

	switch (Z_TYPE_P(key)) {
		case IS_NULL:
			return zend_hash_exists(Z_ARRVAL_P(array), "", 1);

		case IS_BOOL:
		case IS_DOUBLE:
			convert_to_long(key);
		case IS_LONG:
			return zend_hash_index_exists(Z_ARRVAL_P(array), Z_LVAL_P(key));

		default:
			convert_to_string(key);
			return zend_symtable_exists(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1);
	}
}
예제 #5
0
/**
 * Sets Cache headers to use HTTP cache
 *
 *<code>
 *	$this->response->setCache(60);
 *</code>
 */
PHP_METHOD(Phalcon_Http_Response, setCache) {

	zval *_1, *_3;
	zval *minutes_param = NULL, *date, _0, _2, *_4;
	int minutes, ZEPHIR_LAST_CALL_STATUS;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &minutes_param);

	if (unlikely(Z_TYPE_P(minutes_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'minutes' must be a int") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	minutes = Z_LVAL_P(minutes_param);


	ZEPHIR_INIT_VAR(date);
	object_init_ex(date, php_date_get_date_ce());
	ZEPHIR_CALL_METHOD(NULL, date, "__construct", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_SINIT_VAR(_0);
	ZVAL_LONG(&_0, minutes);
	ZEPHIR_INIT_VAR(_1);
	ZEPHIR_CONCAT_SVS(_1, "+", &_0, " minutes");
	ZEPHIR_CALL_METHOD(NULL, date, "modify", NULL, 0, _1);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(NULL, this_ptr, "setexpires", NULL, 0, date);
	zephir_check_call_status();
	ZEPHIR_SINIT_VAR(_2);
	ZVAL_LONG(&_2, ((minutes * 60)));
	ZEPHIR_INIT_VAR(_3);
	ZEPHIR_CONCAT_SV(_3, "max-age=", &_2);
	ZEPHIR_INIT_VAR(_4);
	ZVAL_STRING(_4, "Cache-Control", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(NULL, this_ptr, "setheader", NULL, 0, _4, _3);
	zephir_check_temp_parameter(_4);
	zephir_check_call_status();
	RETURN_THIS();

}
예제 #6
0
static
void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTable* spec) {
    // SET and LIST have 'elem' => array('type', [optional] 'class')
    // MAP has 'val' => array('type', [optiona] 'class')
    zend_class_entry* ce = Z_OBJCE_P(zthis);
    while (true) {
        int8_t ttype = transport.readI8();
        if (ttype == T_STOP) {
            return;
        }

        int16_t fieldno = transport.readI16();
        zval* val_ptr = zend_hash_index_find(spec, fieldno);
        if (val_ptr != nullptr) {
            HashTable* fieldspec = Z_ARRVAL_P(val_ptr);
            // pull the field name
            val_ptr = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
            char* varname = Z_STRVAL_P(val_ptr);

            // and the type
            val_ptr = zend_hash_str_find(fieldspec, "type", sizeof("type")-1);
            if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr);
            int8_t expected_ttype = Z_LVAL_P(val_ptr);

            if (ttypes_are_compatible(ttype, expected_ttype)) {
                zval rv;
                ZVAL_UNDEF(&rv);

                binary_deserialize(ttype, transport, &rv, fieldspec);
                zend_update_property(ce, zthis, varname, strlen(varname), &rv);

                zval_ptr_dtor(&rv);
            } else {
                skip_element(ttype, transport);
            }
        } else {
            skip_element(ttype, transport);
        }
    }
}
예제 #7
0
ZEND_METHOD(Vedis, decrby)
{
    char *key;
    int key_len;
    zval *zv;
    VEDIS_ARGS_PARAM(DECRBY, 6, 2);

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
                              &key, &key_len, &zv) == FAILURE) {
        return;
    }

    VEDIS_SELF(intern);

    VEDIS_ARGS_STRING(key, key_len);

    switch (Z_TYPE_P(zv)) {
        case IS_LONG:
            VEDIS_ARGS_INT(Z_LVAL_P(zv));
            break;
        case IS_DOUBLE:
            VEDIS_ARGS_DOUBLE(Z_DVAL_P(zv));
            break;
        case IS_STRING:
            if (is_numeric_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv),
                                   NULL, NULL, 0)) {
                VEDIS_ARGS_STRING(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
            } else {
                RETURN_FALSE;
            }
            break;
        default:
            RETURN_FALSE;
            break;
    }

    VEDIS_ARGS_EXEC(RETURN_FALSE);

    VEDIS_RETURN_LONG();
}
예제 #8
0
/* {{{ proto int dl(string extension_filename)
   Load a PHP extension at runtime */
PHPAPI PHP_FUNCTION(dl)
{
	char *filename;
	int filename_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
		return;
	}

	if (!PG(enable_dl)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extensions aren't enabled");
		RETURN_FALSE;
	} else if (PG(safe_mode)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extensions aren't allowed when running in Safe Mode");
		RETURN_FALSE;
	}

	if (filename_len >= MAXPATHLEN) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "File name exceeds the maximum allowed length of %d characters", MAXPATHLEN);
		RETURN_FALSE;
	}

	if ((strncmp(sapi_module.name, "cgi", 3) != 0) &&
		(strcmp(sapi_module.name, "cli") != 0) &&
		(strncmp(sapi_module.name, "embed", 5) != 0)
	) {
#ifdef ZTS
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in multithreaded Web servers - use extension=%s in your php.ini", filename);
		RETURN_FALSE;
#else
		php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "dl() is deprecated - use extension=%s in your php.ini", filename);
#endif
	}

	php_dl(filename, MODULE_TEMPORARY, return_value, 0 TSRMLS_CC);
	if (Z_LVAL_P(return_value) == 1) {
		EG(full_tables_cleanup) = 1;
	}
}
예제 #9
0
PHP_METHOD(SpotifyPlaylist, removeTrack)
{
	zval *z_index;

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

	int *tracks = (int*)emalloc(sizeof(int) * 1);
	tracks[0] = Z_LVAL_P(z_index);

	spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
	sp_error error = sp_playlist_remove_tracks(p->playlist, tracks, 1);

	efree(tracks);

	if (SP_ERROR_OK == error) {
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}
예제 #10
0
/* {{{ proto bool ImagickPixelIterator::newPixelRegionIterator(Imagick source, int x, int y, int columns, int rows)
	Returns a new pixel iterator.
*/
PHP_METHOD(imagickpixeliterator, newpixelregioniterator)
{
	zval *magick_object;
	php_imagickpixeliterator_object *internpix;
	php_imagick_object *intern;
	zval *x, *y, *columns, *rows;

	/* Parse parameters given to function */
	if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "Ozzzz", &magick_object, php_imagick_sc_entry, &x, &y, &columns, &rows) == FAILURE ) {
		return;
	}

	if ( Z_TYPE_P( x ) != IS_LONG || Z_TYPE_P( y ) != IS_LONG || Z_TYPE_P( columns ) != IS_LONG || Z_TYPE_P( rows ) != IS_LONG ) {

		IMAGICK_THROW_EXCEPTION_WITH_MESSAGE( IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator::newPixelRegionIterator() parameters should be integers", 3  );
	}

	
	internpix = (php_imagickpixeliterator_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
	intern = (php_imagick_object *)zend_object_store_get_object(magick_object TSRMLS_CC);

	if ( intern->magick_wand == (MagickWand *)NULL || !IsMagickWand( intern->magick_wand ) ) {
		IMAGICK_THROW_EXCEPTION_WITH_MESSAGE( IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed", 3 );
	}

	IMAGICK_CHECK_NOT_EMPTY( intern->magick_wand, 1, 1 );

	internpix->pixel_iterator = NewPixelRegionIterator( intern->magick_wand, Z_LVAL_P( x ), Z_LVAL_P(y), Z_LVAL_P(columns), Z_LVAL_P(rows) );
	internpix->iterator_type = 2;
#if MagickLibVersion <= 0x628
	count_pixeliterator_rows( internpix TSRMLS_CC );
#endif
	if ( internpix->pixel_iterator == (PixelIterator *)NULL || !IsPixelIterator( internpix->pixel_iterator ) ) {
		IMAGICK_THROW_EXCEPTION_WITH_MESSAGE( IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator", 3 );
	}

	internpix->instanciated_correctly = 1;
	RETURN_TRUE;
}
예제 #11
0
/* {{{ proto void Runkit_Sandbox_Parent::die(mixed message)
	MALIAS(exit)
	PATRICIDE!!!!!!!! */
PHP_METHOD(Runkit_Sandbox_Parent,die)
{
	php_runkit_sandbox_parent_object *objval;
	zval *message = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &message) == FAILURE) {
		RETURN_FALSE;
	}

	RETVAL_NULL();

	if (message && Z_TYPE_P(message) != IS_LONG) {
		convert_to_string(message);
	}

	PHP_RUNKIT_SANDBOX_PARENT_FETCHBOX_VERIFY_ACCESS(objval, this_ptr);
	if (!objval->self->parent_die) {
		php_error_docref(NULL, E_WARNING, "Patricide is disabled.  Shame on you Oedipus.");
		/* Sent as a warning, but we'll really implement it as an E_ERROR */
		objval->self->active = 0;
		RETURN_FALSE;
	}

	CG(unclean_shutdown) = 1;
	CG(in_compilation) = EG(in_execution) = 0;
	EG(current_execute_data) = NULL;

	PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval)
		if (message) {
			if (Z_TYPE_P(message) == IS_LONG) {
				EG(exit_status) = Z_LVAL_P(message);
			} else {
				PHPWRITE(Z_STRVAL_P(message), Z_STRLEN_P(message));
			}
		}
		zend_bailout();
		/* More of a murder-suicide really... */
	PHP_RUNKIT_SANDBOX_PARENT_END(objval)
}
예제 #12
0
파일: struct.c 프로젝트: krakjoe/jitfu
PHP_METHOD(Struct, getFieldType) {
	zval *zoffset;
	php_jit_struct_t *pstruct;
	zend_ulong of = 0;
	
	if (php_jit_parameters("z", &zoffset) != SUCCESS || !zoffset) {
		php_jit_exception("unexpected parameters, expected (string|integer field)");
		return;
	}
	
	pstruct = PHP_JIT_FETCH_STRUCT(getThis());
	
	switch (Z_TYPE_P(zoffset)) {
		case IS_STRING:
			if (!pstruct->names) {
				php_jit_exception("no names available");
				return;
			}
			
			of = jit_type_find_name
				(pstruct->type, Z_STRVAL_P(zoffset));
		break;
		
		case IS_LONG: of = Z_LVAL_P(zoffset); break;
		
		default:
			php_jit_exception("unexpected parameters, expected (string|integer field)");
			return;
	}
	
	if (of < pstruct->nfields) {
	    ZVAL_COPY_VALUE(return_value, &pstruct->zfields[of]);
	    zval_copy_ctor(return_value);
		return;
	}
	
	php_jit_exception("failed to find the requested field");
}
예제 #13
0
int uopz_no_exit_handler(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
	if (UOPZ(exit)) {
		if (uopz_exit_handler)
			return uopz_exit_handler(UOPZ_OPCODE_HANDLER_ARGS_PASSTHRU);

		return ZEND_USER_OPCODE_DISPATCH;
	}

	if (EX(opline)->op1_type != IS_UNUSED) {
		zval *estatus;

		if (EX(opline)->op1_type == IS_CONST) {
			estatus = EX_CONSTANT(EX(opline)->op1);
		} else estatus = EX_VAR(EX(opline)->op1.var);

		if (Z_ISREF_P(estatus)) {
			estatus = Z_REFVAL_P(estatus);
		}

		if (Z_TYPE_P(estatus) == IS_LONG) {
			EG(exit_status) = Z_LVAL_P(estatus);
		} else EG(exit_status) = 0;

		ZVAL_COPY(&UOPZ(estatus), estatus);
	}

	if (EX(opline) < &EX(func)->op_array.opcodes[EX(func)->op_array.last - 1]) {
		EX(opline)++;

		while (EX(opline)->opcode == ZEND_EXT_STMT) {
			EX(opline)++;
		}

		return ZEND_USER_OPCODE_CONTINUE;
	} else {
		return ZEND_USER_OPCODE_RETURN;
	}
} /* }}} */
예제 #14
0
static
void binary_serialize_spec(zval* zthis, PHPOutputTransport& transport, HashTable* spec) {

  validate_thrift_object(zthis);

  HashPosition key_ptr;
  zval* val_ptr;

  for (zend_hash_internal_pointer_reset_ex(spec, &key_ptr);
       (val_ptr = zend_hash_get_current_data_ex(spec, &key_ptr)) != nullptr;
       zend_hash_move_forward_ex(spec, &key_ptr)) {

    zend_ulong fieldno;
    if (zend_hash_get_current_key_ex(spec, nullptr, &fieldno, &key_ptr) != HASH_KEY_IS_LONG) {
      throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA);
      return;
    }
    HashTable* fieldspec = Z_ARRVAL_P(val_ptr);

    // field name
    val_ptr = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
    char* varname = Z_STRVAL_P(val_ptr);

    // thrift type
    val_ptr = zend_hash_str_find(fieldspec, "type", sizeof("type")-1);
    if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr);
    int8_t ttype = Z_LVAL_P(val_ptr);

    zval rv;
    zval* prop = zend_read_property(Z_OBJCE_P(zthis), zthis, varname, strlen(varname), false, &rv);
    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
}
예제 #15
0
/** {{{ Mylogs::err
*/
PHP_METHOD(Mylogs, err) {
	char *msg;
	int msg_len;
	zval *instance, *level, **_level;
	zend_class_entry *ce;

	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &msg, &msg_len) == FAILURE)
		return;	

	instance = _getInstance();
	ce = Z_OBJCE_P(instance);
	level = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_LEVEL), 0 TSRMLS_CC);
	zend_hash_find(&ce->constants_table, ZEND_STRS(LOG_ERR), (void **)&_level);

	if(Z_LVAL_P(level) > Z_LVAL_PP(_level)) {
		RETURN_TRUE;
	}

	if(_log(msg) == SUCCESS) {
		RETURN_TRUE;
	}
	RETURN_FALSE;
}
예제 #16
0
파일: share.c 프로젝트: Crell/php-src
static int _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
{
	CURLSHcode error = CURLSHE_OK;

	switch (option) {
		case CURLSHOPT_SHARE:
		case CURLSHOPT_UNSHARE:
			convert_to_long_ex(zvalue);
			error = curl_share_setopt(sh->share, option, Z_LVAL_P(zvalue));
			break;

		default:
			php_error_docref(NULL, E_WARNING, "Invalid curl share configuration option");
			error = CURLSHE_BAD_OPTION;
			break;
	}

	if (error != CURLSHE_OK) {
		return 1;
	} else {
		return 0;
	}
}
예제 #17
0
파일: spl_engine.c 프로젝트: Sobak/php-src
PHPAPI zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
{
	zend_ulong idx;

	switch (Z_TYPE_P(offset)) {
	case IS_STRING:
		if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), idx)) {
			return idx;
		}
		break;
	case IS_DOUBLE:
		return (zend_long)Z_DVAL_P(offset);
	case IS_LONG:
		return Z_LVAL_P(offset);
	case IS_FALSE:
		return 0;
	case IS_TRUE:
		return 1;
	case IS_RESOURCE:
		return Z_RES_HANDLE_P(offset);
	}
	return -1;
}
예제 #18
0
파일: math.c 프로젝트: moriyoshi/mod_himote
/*
 * Convert a long to a string containing a base(2-36) representation of
 * the number.
 */
HIMOTEAPI char * _himote_math_longtobase(zval *arg, int base)
{
	static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
	char buf[(sizeof(unsigned long) << 3) + 1];
	char *ptr, *end;
	unsigned long value;

	if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) {
		return STR_EMPTY_ALLOC();
	}

	value = Z_LVAL_P(arg);

	end = ptr = buf + sizeof(buf) - 1;
	*ptr = '\0';

	do {
		*--ptr = digits[value % base];
		value /= base;
	} while (ptr > buf && value);

	return estrndup(ptr, end - ptr);
}
예제 #19
0
파일: pageset.c 프로젝트: eixom/zoeeyphp
/** {{{ public ZePageSet::isCurrent($page)
 */
PHP_METHOD(ze_pageset, isCurrent) {
	zval * self        = NULL;
	zval * current     = NULL;
	int    page        = 0;
	zval * show        = NULL;
	zval * else_show    = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l"
							, &page
							) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	self = getThis();

	current = zend_read_property(ze_pageset_ce, self, ZEND_STRL(ZE_CURRENT), 0 TSRMLS_CC);

	if (Z_LVAL_P(current) != page) {
	   RETURN_FALSE;
	}

	RETURN_TRUE;
}
예제 #20
0
파일: math.c 프로젝트: MiRacLe-RPZ/php-src
/*
 * Convert a long to a string containing a base(2-36) representation of
 * the number.
 */
PHPAPI zend_string * _php_math_longtobase(zval *arg, int base)
{
	static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
	char buf[(sizeof(zend_ulong) << 3) + 1];
	char *ptr, *end;
	zend_ulong value;

	if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) {
		return ZSTR_EMPTY_ALLOC();
	}

	value = Z_LVAL_P(arg);

	end = ptr = buf + sizeof(buf) - 1;
	*ptr = '\0';

	do {
		*--ptr = digits[value % base];
		value /= base;
	} while (ptr > buf && value);

	return zend_string_init(ptr, end - ptr, 0);
}
예제 #21
0
파일: python.c 프로젝트: demos/Motif
/* {{{ convert_pyobject_to_zobject(PyObject *obj)
   Convert Python object to a PHP (Zend) object */
static zval *
convert_pyobject_to_zobject(PyObject *obj)
{
	pval *ret;
	zval *handle;
	TSRMLS_FETCH();

	/* Create a PHP Python object */
	MAKE_STD_ZVAL(ret);
	object_init_ex(ret, &python_class_entry);
	ret->is_ref = 1;
	ret->refcount = 1;

	/* Assign the current PyObject to the new PHP Python object */
	ALLOC_ZVAL(handle);
	Z_TYPE_P(handle) = IS_LONG;
	Z_LVAL_P(handle) = zend_list_insert(obj, le_pyobject);
	pval_copy_constructor(handle);
	INIT_PZVAL(handle);
	zend_hash_index_update(Z_OBJPROP_P(ret), 0, &handle, sizeof(pval *), NULL);

	return ret;
}
예제 #22
0
파일: struct.c 프로젝트: krakjoe/jitfu
PHP_METHOD(Struct, getOffset) {
	zval *zoffset;
	php_jit_struct_t *pstruct;
	zend_ulong of = 0;
	
	if (php_jit_parameters("z", &zoffset) != SUCCESS || !zoffset) {
		php_jit_exception("unexpected parameters, expected (string|integer field)");
		return;
	}
	
	pstruct = PHP_JIT_FETCH_STRUCT(getThis());
	
	switch (Z_TYPE_P(zoffset)) {
		case IS_STRING:
			if (!pstruct->names) {
				php_jit_exception("no names available");
			}
			
			of = jit_type_find_name
				(pstruct->type, Z_STRVAL_P(zoffset));
		break;
		
		case IS_LONG:	
			of = Z_LVAL_P(zoffset);
		break;
		
		default:
			php_jit_exception("unexpected parameters, expected (string|integer field)");
			return;
	}
	
	if (of < pstruct->nfields) {
		RETURN_LONG(jit_type_get_offset(pstruct->type, of));
	}
	
	php_jit_exception("failed to find offset of requested field");
}
예제 #23
0
static uint32_t add_static_slot(HashTable     *hash,
                                zend_op_array *op_array,
                                uint32_t       op1,
                                uint32_t       op2,
                                uint32_t       kind,
                                int           *cache_size)
{
	uint32_t ret;
	zend_string *key;
	size_t key_len;
	zval *class_name = &op_array->literals[op1];
	zval *prop_name = &op_array->literals[op2];
	zval *pos, tmp;

	key_len = Z_STRLEN_P(class_name) + sizeof("::") - 1 + Z_STRLEN_P(prop_name);
	key = zend_string_alloc(key_len, 0);
	memcpy(ZSTR_VAL(key), Z_STRVAL_P(class_name), Z_STRLEN_P(class_name));
	memcpy(ZSTR_VAL(key) + Z_STRLEN_P(class_name), "::", sizeof("::") - 1);
	memcpy(ZSTR_VAL(key) + Z_STRLEN_P(class_name) + sizeof("::") - 1,
		Z_STRVAL_P(prop_name),
		Z_STRLEN_P(prop_name) + 1);

	ZSTR_H(key) = zend_string_hash_func(key);
	ZSTR_H(key) += kind;

	pos = zend_hash_find(hash, key);
	if (pos) {
		ret = Z_LVAL_P(pos);
	} else {
		ret = *cache_size;
		*cache_size += 2 * sizeof(void *);
		ZVAL_LONG(&tmp, ret);
		zend_hash_add(hash, key, &tmp);
	}
	zend_string_release_ex(key, 0);
	return ret;
}
예제 #24
0
파일: array.c 프로젝트: meibk/cphalcon
/**
 * Unsets zval index from array
 */
int PHALCON_FASTCALL phalcon_array_unset(zval *arr, zval *index){

	zval *copy;
	int exists, copied = 0;

	if (Z_TYPE_P(arr) != IS_ARRAY) {
		return 0;
	}

	if (Z_TYPE_P(index) == IS_NULL) {
		ALLOC_INIT_ZVAL(copy);
		ZVAL_ZVAL(copy, index, 1, 0);
		convert_to_string(copy);
		index = copy;
		copied = 1;
	} else {
		if (Z_TYPE_P(index) == IS_BOOL || Z_TYPE_P(index) == IS_DOUBLE) {
			ALLOC_INIT_ZVAL(copy);
			ZVAL_ZVAL(copy, index, 1, 0);
			convert_to_long(copy);
			index = copy;
			copied = 1;
		}
	}

	if (Z_TYPE_P(index) == IS_STRING) {
		exists = zend_hash_del(Z_ARRVAL_P(arr), Z_STRVAL_P(index), Z_STRLEN_P(index)+1);
	} else {
		exists = zend_hash_index_del(Z_ARRVAL_P(arr), Z_LVAL_P(index));
	}

	if (copied) {
		zval_ptr_dtor(&copy);
	}

	return exists;
}
예제 #25
0
/* {{{ bool MongoDB::setWriteConcern(mixed w [, int wtimeout])
 * Set the MongoDB write concern, which will be inherited by constructed
 * MongoCollection objects. */
PHP_METHOD(MongoDB, setWriteConcern)
{
	zval *write_concern;
	long  wtimeout;

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

	if (Z_TYPE_P(write_concern) == IS_LONG) {
		zend_update_property_long(mongo_ce_DB, getThis(), "w", strlen("w"), Z_LVAL_P(write_concern) TSRMLS_CC);
	} else if (Z_TYPE_P(write_concern) == IS_STRING) {
		zend_update_property_stringl(mongo_ce_DB, getThis(), "w", strlen("w"), Z_STRVAL_P(write_concern), Z_STRLEN_P(write_concern) TSRMLS_CC);
	} else {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects parameter 1 to be an string or integer, %s given", zend_get_type_by_const(Z_TYPE_P(write_concern)));
		RETURN_FALSE;
	}

	if (ZEND_NUM_ARGS() > 1) {
		zend_update_property_long(mongo_ce_DB, getThis(), "wtimeout", strlen("wtimeout"), wtimeout TSRMLS_CC);
	}

	RETURN_TRUE;
}
예제 #26
0
파일: money.c 프로젝트: Peekmo/money
PHP_METHOD(Money, extractPercentage)
{
	long percentage;
	double result;
	zval *new_money_percentage, *amount, *new_money_subtotal;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &percentage) == FAILURE) {
		return;
	}

	ALLOC_INIT_ZVAL(new_money_percentage);ALLOC_INIT_ZVAL(new_money_subtotal);

	amount = zend_read_property(money_ce, getThis(), MONEY_PROP_AMOUNT_WS, 0);
	result = Z_LVAL_P(amount) / (100 + percentage) * percentage;

	CREATE_NEW_MONEY_OBJ(new_money_percentage, zend_dval_to_lval(result), zend_read_property(money_ce, getThis(), MONEY_PROP_CURRENCY_WS, 0))

	array_init(return_value);
	add_assoc_zval(return_value, "percentage", new_money_percentage);

	money_handler_do_operation(ZEND_SUB, new_money_subtotal, getThis(), new_money_percentage);

	add_assoc_zval(return_value, "subtotal", new_money_subtotal);
}
예제 #27
0
파일: value.c 프로젝트: Epictetus/php_embed
VALUE php_value_obj_equal(VALUE self, VALUE rhs) {
    zval *lhs_zv;
    zval *rhs_zv;
    zval *result;
    int cmp_ret;

    lhs_zv = get_zval(self);
    if (lhs_zv == NULL) {
        return Qnil;
    }

    if (cPhpEmbedValue == CLASS_OF(rhs)) {
        rhs_zv = get_zval(rhs);
    } else {
        rhs_zv = value_to_zval(rhs);
    }

    MAKE_STD_ZVAL(result);
    compare_function(result, lhs_zv, rhs_zv TSRMLS_CC);
    cmp_ret = Z_LVAL_P(result);
    FREE_ZVAL(result);

    return cmp_ret == 0 ? Qtrue : Qfalse;
}
예제 #28
0
bool samphp::callBool(char *fn, char *argspec, ...)
{
    bool rrv = false;

    zval *rv;

    va_list ap;
    va_start(ap, argspec);
    rv = call(fn, argspec, ap TSRMLS_CC);
    va_end(ap);

    if(rv)
    {
        if(Z_TYPE_P(rv) != IS_BOOL)
        {
            // copy rv into new memory for the in place conversion
            zval *cp;
            MAKE_STD_ZVAL(cp);
            *cp = *rv;
            zval_copy_ctor(cp);
            INIT_PZVAL(cp);

            // destroy the original now that we have a copy
            zval_ptr_dtor(&rv);

            // rename rv to our copy
            rv = cp;
            convert_to_boolean_ex(&rv);
        }

        rrv = (bool)Z_LVAL_P(rv);
        zval_ptr_dtor(&rv);
    }

    return rrv;
}
예제 #29
0
파일: index.c 프로젝트: yunwuxin/php-git
static int php_git2_index_matched_path_cb(const char *path, const char *matched_pathspec, void *payload)
{
	zval *param_path, *param_matched_pathspec, *retval_ptr = NULL;
	php_git2_cb_t *p = (php_git2_cb_t*)payload;
	long retval = 0;
	GIT2_TSRMLS_SET(p->tsrm_ls)

	Z_ADDREF_P(p->payload);
	MAKE_STD_ZVAL(param_path);
	MAKE_STD_ZVAL(param_matched_pathspec);
	ZVAL_STRING(param_path, path, 1);
	ZVAL_STRING(param_matched_pathspec, matched_pathspec, 1);

	if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, &param_path, &param_matched_pathspec, &p->payload)) {
		zval_ptr_dtor(&param_path);
		zval_ptr_dtor(&param_matched_pathspec);
		zval_ptr_dtor(&p->payload);
		return 0;
	}

	retval = Z_LVAL_P(retval_ptr);
	zval_ptr_dtor(&retval_ptr);
	return retval;
}
예제 #30
0
static void regexp_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
    zval *object;
    Regexp_object *ro;
    char *pattern;
    int32_t pattern_len;
    UChar *upattern = NULL;
    int32_t upattern_len = 0;
    zval *zflags = NULL;
    uint32_t flags = 0;
    UParseError pe = { -1, -1, {0}, {0} };

    intl_error_reset(NULL TSRMLS_CC);
    object = return_value;
    if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &pattern, &pattern_len, &zflags)) {
        intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "bad arguments", 0 TSRMLS_CC);
        zval_dtor(object);
        RETURN_NULL();
    }
    if (NULL != zflags) {
        switch (Z_TYPE_P(zflags)) {
            case IS_LONG:
                flags = (uint32_t) Z_LVAL_P(zflags);
                break;
            case IS_STRING:
            {
                const char *p;

                for (p = Z_STRVAL_P(zflags); '\0' != *p; p++) {
                    switch (*p) {
                        case 'i': flags |= UREGEX_CASE_INSENSITIVE; break;
                        case 'm': flags |= UREGEX_MULTILINE;        break;
                        case 's': flags |= UREGEX_DOTALL;           break;
                        case 'x': flags |= UREGEX_COMMENTS;         break;
                        case 'w': flags |= UREGEX_UWORD;            break;
                        default:
                            intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid modifier", 0 TSRMLS_CC);
                            zval_dtor(object);
                            RETURN_NULL();
                    }
                }
                break;
            }
            default:
                intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "bad arguments", 0 TSRMLS_CC);
                zval_dtor(object);
                RETURN_NULL();
        }
    }
    ro = (Regexp_object *) zend_object_store_get_object(object TSRMLS_CC);
    intl_convert_utf8_to_utf16(&upattern, &upattern_len, pattern, pattern_len, REGEXP_ERROR_CODE_P(ro));
    INTL_CTOR_CHECK_STATUS(ro, "string conversion of pattern to UTF-16 failed");
    ro->uregex = uregex_open(upattern, upattern_len, flags, &pe, REGEXP_ERROR_CODE_P(ro));
    efree(upattern);
    if (U_FAILURE(REGEXP_ERROR_CODE(ro))) {
        intl_error_set_code(NULL, REGEXP_ERROR_CODE(ro) TSRMLS_CC);
        if (-1 != pe.line) {
            regexp_parse_error_to_string(pe, pattern, pattern_len);
        } else {
            intl_error_set_custom_msg(NULL, "unable to compile ICU regular expression", 0 TSRMLS_CC);
        }
        zval_dtor(object);
        RETURN_NULL();
    }
}