Esempio n. 1
0
/* {{{ mlfi_header()
*/
static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
{
	zval function_name, retval, *param[2];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	ALLOC_ZVAL(param[1]);
	INIT_PZVAL(param[0]);
	INIT_PZVAL(param[1]);
	
	ZVAL_STRING(&function_name, "milter_header", 0);
	ZVAL_STRING(param[0], headerf, 1);
	ZVAL_STRING(param[1], headerv, 1);

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_HEADER;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	
	zval_ptr_dtor(&param[0]);
	zval_ptr_dtor(&param[1]);	
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}
	
	return SMFIS_CONTINUE;
}
Esempio n. 2
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. 3
0
/* {{{ mlfi_connect()
*/
static sfsistat	mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
{
	zend_file_handle file_handle;
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* request startup */
	if (php_request_startup(TSRMLS_C)==FAILURE) {
		SG(headers_sent) = 1;
		SG(request_info).no_headers = 1;
		php_request_shutdown((void *) 0);

		return SMFIS_TEMPFAIL;
	}
	
	/* disable headers */
	SG(headers_sent) = 1;
	SG(request_info).no_headers = 1;
	
	if (filename == NULL) {
		php_printf("No input file specified");
		return SMFIS_TEMPFAIL;
	}
	
	if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) {
		php_printf("Could not open input file: %s\n", filename);
		return SMFIS_TEMPFAIL;
	}

	file_handle.type = ZEND_HANDLE_FP;
	file_handle.filename = filename;
	file_handle.free_filename = 0;
	file_handle.opened_path = NULL;

	php_execute_script(&file_handle TSRMLS_CC);
	
	/* call userland */
	INIT_ZVAL(function_name);

	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_connect", 0);
	ZVAL_STRING(param[0], hostname, 1);

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_CONNECT;

	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	zval_ptr_dtor(param);
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}
	
	return SMFIS_CONTINUE;
}
Esempio n. 4
0
/* {{{ mlfi_body()
*/
static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
{
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_body", 0);
	ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/
	
	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_BODY;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	
	zval_ptr_dtor(param);	

	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
Esempio n. 5
0
/* {{{ unset an object property */
void pthreads_unset_property(PTHREADS_UNSET_PROPERTY_PASSTHRU_D) {
	zval *mstring = NULL;
	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);

	if (Z_TYPE_P(member) != IS_STRING) {
		ALLOC_ZVAL(mstring);
		*mstring = *member;
		zval_copy_ctor(
			mstring
		);
		INIT_PZVAL(mstring);
		convert_to_string(mstring);
		member = mstring;
#if PHP_VERSION_ID > 50399
		key = NULL;
#endif
	}

	if (Z_TYPE_P(member) == IS_STRING) {
		if (pthreads_store_delete(pthreads->store, Z_STRVAL_P(member), Z_STRLEN_P(member) TSRMLS_CC)!=SUCCESS){
			zend_error(
				E_WARNING, 
				"pthreads has experienced an internal error while deleting %s::$%s", 
				Z_OBJCE_P(object)->name, Z_STRVAL_P(member)
			);
		}
	} else zend_error(E_WARNING, "pthreads detected an attempt to use an unsupported kind of key in %s", Z_OBJCE_P(object)->name);
	
	if (mstring != NULL) {
		zval_ptr_dtor(&mstring);
	}
}
Esempio n. 6
0
/* {{{ proto int error.next()
   Returns a ref to the next errorObj in the list, or NULL if we reached the last one */
PHP_METHOD(errorObj, next)
{
  zval *zobj = getThis();
  php_error_object *php_error;
  errorObj *error = NULL;

  PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
  if (zend_parse_parameters_none() == FAILURE) {
    PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
    return;
  }
  PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);

  php_error = (php_error_object *) zend_object_store_get_object(zobj TSRMLS_CC);

  if (php_error->error->next == NULL)
    RETURN_NULL();

  /* Make sure 'self' is still valid.  It may have been deleted by
   * msResetErrorList() */
  error = msGetErrorObj();
  while(error != php_error->error) {
    if (error->next == NULL) {
      mapscript_throw_exception("Trying to access an errorObj that has expired." TSRMLS_CC);
      return;
    }
    error = error->next;
  }

  php_error->error = php_error->error->next;
  *return_value = *zobj;
  zval_copy_ctor(return_value);
  INIT_PZVAL(return_value);
}
Esempio n. 7
0
/* {{{ mlfi_envform()
*/
static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
{
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_envfrom", 0);
	array_init(param[0]);

	while (*argv) {
		add_next_index_string(param[0], *argv, 1);
		argv++;
	}

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_ENVFROM;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	zval_ptr_dtor(param);
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
Esempio n. 8
0
/* {{{ check if a thread has a property set, wherever it is available */
int pthreads_has_property(PTHREADS_HAS_PROPERTY_PASSTHRU_D) {
	int isset = 0;
	zval *mstring = NULL;

	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);

	if (Z_TYPE_P(member) != IS_STRING) {
		ALLOC_ZVAL(mstring);
		*mstring = *member;
		zval_copy_ctor(
			mstring
		);
		INIT_PZVAL(mstring);
		convert_to_string(mstring);
		member = mstring;
#if PHP_VERSION_ID > 50399
		key = NULL;
#endif
	}

	if (Z_TYPE_P(member) == IS_STRING) {
		isset = pthreads_store_isset(pthreads->store, Z_STRVAL_P(member), Z_STRLEN_P(member), has_set_exists TSRMLS_CC);
	} else zend_error(E_WARNING, "pthreads has detected an attempt to use an unsupported kind of key in %s", Z_OBJCE_P(object)->name);

	if (mstring != NULL) {
		zval_ptr_dtor(&mstring);
	}

	return isset;
}
Esempio n. 9
0
ZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array)
{
	void **p;
	int arg_count;
	zval *param_ptr;
	ELS_FETCH();

	p = EG(argument_stack).top_element-2;
	arg_count = (ulong) *p;

	if (param_count>arg_count) {
		return FAILURE;
	}

	while (param_count-->0) {
		param_ptr = *(p-arg_count);
		if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
			zval *new_tmp;

			ALLOC_ZVAL(new_tmp);
			*new_tmp = *param_ptr;
			zval_copy_ctor(new_tmp);
			INIT_PZVAL(new_tmp);
			param_ptr = new_tmp;
			((zval *) *(p-arg_count))->refcount--;
			*(p-arg_count) = param_ptr;
		}
		*(argument_array++) = param_ptr;
		arg_count--;
	}

	return SUCCESS;
}
Esempio n. 10
0
int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
{
	zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS);
	INIT_PZVAL(property);
	ZVAL_BOOL(property, value);
	return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
}
Esempio n. 11
0
static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
{
	zval *retval_ptr = NULL;
	zval fname;

	if (Z_TYPE_PP(rval) != IS_OBJECT) {
		return 0;
	}

	if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) {
		return 0;
	}

	if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY &&
		zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup"))) {
		INIT_PZVAL(&fname);
		ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
		UNSERIALIZE2_G(serialize_lock)++;
		call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
		UNSERIALIZE2_G(serialize_lock)--;
	}

	if (retval_ptr) {
		zval_ptr_dtor(&retval_ptr);
	}

	if (EG(exception)) {
		return 0;
	}

	return finish_nested_data(UNSERIALIZE_PASSTHRU);

}
Esempio n. 12
0
zval * mysqlnd_alloc_get_zval(MYSQLND_ZVAL_CACHE * const cache)
{
	zval *ret = NULL;

#ifndef MYSQLND_SILENT
	php_printf("[mysqlnd_alloc_get_zval %p] *last_added=%p free_items=%d  ", cache, cache? cache->free_list->last_added:NULL, cache->free_items);
#endif

	if (cache) {
		if ((ret = *cache->free_list->last_added)) {
			*cache->free_list->last_added++ = NULL;

			--cache->free_items;
			++cache->get_hits;
		} else {
			++cache->get_misses;
		}
	}
	if (!ret) {
		ALLOC_ZVAL(ret);
	}
	INIT_PZVAL(ret);

#ifndef MYSQLND_SILENT
	php_printf("ret=%p\n", ret);
#endif
	return ret;
}
Esempio n. 13
0
/*
 * save a corba object to a php object
 */
void orbit_save_data(zval * php_object, int type, void * data)
{
    pval * orbit_data_handle = NULL;
    long id = zend_list_insert(
                  data, 										/* data */
                  type								/* type */
              );


    /*
     * do it like they do in php_COM_call_function_handler
     * (insert into some magic hash index)
     */
    ALLOC_ZVAL(orbit_data_handle);	/* allocate memory for value */

    orbit_data_handle->type = IS_LONG;
    orbit_data_handle->value.lval = id;

    pval_copy_constructor(orbit_data_handle);	/* why? */

    INIT_PZVAL(orbit_data_handle);	/* set reference count */

    zend_hash_index_update(
        php_object->value.obj.properties, /* hashtable */
        0, 																/* hash??? */
        &orbit_data_handle,								/* data */
        sizeof(pval *),										/* data size */
        NULL															/* destination */
    );
}
Esempio n. 14
0
/* {{{ sdo_make_long_class_constant
 * creates a class constant
 */
void sdo_make_long_class_constant(zend_class_entry *ce, char *name, long value)
{
	/* Cannot emalloc the storage for this constant, it must endure beyond the current request */
	zval *z_constant = (zval *)malloc(sizeof(zval));
	INIT_PZVAL(z_constant);
	ZVAL_LONG(z_constant, value);
	zend_hash_update(&ce->constants_table, name, 1 + strlen(name), &z_constant, sizeof(zval *), NULL);
}
Esempio n. 15
0
RedisArray*
ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC)
{
	int i, host_len, id;
	int count = zend_hash_num_elements(hosts);
	char *host, *p;
	short port;
	zval **zpData, z_cons, z_ret;
	RedisSock *redis_sock  = NULL;

	/* function calls on the Redis object */
	ZVAL_STRING(&z_cons, "__construct", 0);

	/* init connections */
	for(i = 0; i < count; ++i) {
		if(FAILURE == zend_hash_quick_find(hosts, NULL, 0, i, (void**)&zpData)) {
			efree(ra);
			return NULL;
		}

		ra->hosts[i] = estrdup(Z_STRVAL_PP(zpData));

		/* default values */
		host = Z_STRVAL_PP(zpData);
		host_len = Z_STRLEN_PP(zpData);
		port = 6379;

		if((p = strchr(host, ':'))) { /* found port */
			host_len = p - host;
			port = (short)atoi(p+1);
		}

		/* create Redis object */
		MAKE_STD_ZVAL(ra->redis[i]);
		object_init_ex(ra->redis[i], redis_ce);
		INIT_PZVAL(ra->redis[i]);
		call_user_function(&redis_ce->function_table, &ra->redis[i], &z_cons, &z_ret, 0, NULL TSRMLS_CC);

		/* create socket */
		redis_sock = redis_sock_create(host, host_len, port, 0, 0, NULL, retry_interval); /* TODO: persistence? */

		/* connect */
		redis_sock_server_open(redis_sock, 1 TSRMLS_CC);

		/* attach */
#if PHP_VERSION_ID >= 50400
		id = zend_list_insert(redis_sock, le_redis_sock TSRMLS_CC);
#else
		id = zend_list_insert(redis_sock, le_redis_sock);
#endif
		add_property_resource(ra->redis[i], "socket", id);
	}

	return ra;
}
Esempio n. 16
0
/**
 * Convert a php Array to a map
 *
 * @param t the php Array to convert
 * @return the created map
 */
map* php_map_from_HasTable(HashTable* t){
#ifdef DEBUG
  fprintf(stderr,"mapsFromPHPArray start\n");
#endif
  map* final_res=(map*)malloc(MAP_SIZE);
  final_res=NULL;
  char key[1024];
  for(zend_hash_internal_pointer_reset(t);
      zend_hash_has_more_elements(t) == SUCCESS;
      zend_hash_move_forward(t)) {
    char *key;
    uint keylen;
    ulong idx;
    int type;
    int len;
    zval **ppzval, tmpcopy;
    type = zend_hash_get_current_key_ex(t, &key, &keylen, &idx, 0, NULL); 
    if (zend_hash_get_current_data(t, (void**)&ppzval) == FAILURE) { 
      /* Should never actually fail * since the key is known to exist. */ 
      continue; 
    }
    /**
     * Duplicate the zval so that * the orignal’s contents are not destroyed 
     */ 
    tmpcopy = **ppzval; 
    zval_copy_ctor(&tmpcopy); 
    /**
     * Reset refcount & Convert 
     */ 
    INIT_PZVAL(&tmpcopy); 
    convert_to_string(&tmpcopy);
    if(strncmp(key,"value",5)==0){
      len=Z_STRLEN_P(&tmpcopy);      
	  final_res = addToMapWithSize(final_res,key,Z_STRVAL_P(&tmpcopy),len);
    }
    else{
      if(final_res==NULL){
#ifdef DEBUG
	fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
#endif
	final_res=createMap(key,Z_STRVAL(tmpcopy));
      }
      else{
#ifdef DEBUG
	fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
#endif
	addToMap(final_res,key,Z_STRVAL(tmpcopy));
      }
    }
    /* Toss out old copy */ 
    zval_dtor(&tmpcopy); 
  }
  return final_res;
}
Esempio n. 17
0
static void curlfile_get_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
	zval *res;
	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}
	res = zend_read_property(curl_CURLFile_class, getThis(), name, strlen(name), 1 TSRMLS_CC);
	*return_value = *res;
	zval_copy_ctor(return_value);
	INIT_PZVAL(return_value);
}
Esempio n. 18
0
int php_print_r_zval_and_key(zval **val,int num_args,va_list args,zend_hash_key *hash_key)
{
    //重新copy一个zval,防止破坏原数据
    zval tmpcopy = **val;
    zval *tmpcopy_ptr = &tmpcopy;
    
    /* tsrm_ls is needed by output functions */
    TSRMLS_FETCH();
    zval_copy_ctor(&tmpcopy);
    INIT_PZVAL(&tmpcopy);
    
    //执行输出
    php_printf("The value of ");
    if (hash_key->nKeyLength){
        //如果是字符串类型的key
        PHPWRITE(hash_key->arKey, hash_key->nKeyLength);
    }else{
        //如果是数字类型的key
        php_printf("%ld", hash_key->h);
    }
    
    php_printf(" is: ");
    
    //调用print_r函数
    zval *function,*ret = NULL;
    //函数名
    MAKE_STD_ZVAL(function);
    ZVAL_STRING(function, "print_r", 0);
    
    //参数是一个zval* 数组
    zval **params[1] = {&tmpcopy_ptr};
    
    zend_fcall_info fci = {
        sizeof(fci),
        EG(function_table),
        function,
        NULL,
        &ret,
        1,
        (zval ***)params,
        NULL,
        1
    };
    zend_call_function(&fci, NULL TSRMLS_CC);
    
    php_printf("\n");
    zval_dtor(function);
    
    //毁尸灭迹
    zval_dtor(&tmpcopy);
    /* continue; */
    return ZEND_HASH_APPLY_KEEP;
}
Esempio n. 19
0
static void add_offset_pair(zval *result, char *string, int string_len, int offset)
{
    zval *match_pair;

    ALLOC_ZVAL(match_pair);
    array_init(match_pair);
    INIT_PZVAL(match_pair);

    add_next_index_stringl(match_pair, string, string_len, FALSE);
    add_next_index_long(match_pair, offset);
    zend_hash_next_index_insert(Z_ARRVAL_P(result), &match_pair, sizeof(zval *), NULL);
}
Esempio n. 20
0
	SharedString KPHPObject::DisplayString(int levels)
	{
		// Make a copy of our object zval* and then convert it to a string.
		zval* tempObject = NULL;
		ALLOC_ZVAL(tempObject);
		*tempObject = *object;
		INIT_PZVAL(tempObject);
		zval_copy_ctor(tempObject);

		convert_to_string(tempObject);
		return new std::string(Z_STRVAL_P(tempObject));
	}
Esempio n. 21
0
void JObjectToZval(JNIEnv *env, jobject object, zval** rval) {
    if (object == NULL) {
        ZVAL_NULL(*rval);
    } else if ((*env)->IsInstanceOf(env, object, (*env)->FindClass(env, "java/lang/String"))) {
        const char* stringValue= (*env)->GetStringUTFChars(env, object, 0);
        ZVAL_STRING(*rval, (char *)stringValue, 1);
        (*env)->ReleaseStringUTFChars(env, object, stringValue);
    } else {
        printf("Unknown type");
        /* ZVAL_NULL(*val); */
    }

    INIT_PZVAL(*rval);
}
Esempio n. 22
0
VALUE new_php_embed_value(zval *value) {

    VALUE new_value;
    zval* new_zval;
    VALUE arg = INT2FIX(0);

    ALLOC_ZVAL(new_zval);
    *new_zval = *value;
    zval_copy_ctor(new_zval);
    INIT_PZVAL(new_zval);

    new_value = php_value_alloc(cPhpEmbedValue);
    set_zval(new_value, new_zval);

    return new_value;
}
Esempio n. 23
0
/* {{ reads a property from a thread, wherever it is available */
zval * pthreads_read_property (PTHREADS_READ_PROPERTY_PASSTHRU_D) {
	zval *value = NULL, *mstring = NULL;
	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);
	
	if (Z_TYPE_P(member) != IS_STRING) {
		ALLOC_ZVAL(mstring);
		*mstring = *member;
		zval_copy_ctor(
			mstring
		);
		INIT_PZVAL(mstring);
		zend_try {
			convert_to_string(mstring);
		} zend_end_try();
		member = mstring;
#if PHP_VERSION_ID > 50399
		key = NULL;
#endif
	}
Esempio n. 24
0
File: hash.c Progetto: 117311730/PHP
void mongo_util_hash_copy_to_np(void *pDest) {
  zval **p = (zval**)pDest;
  zval *temp = *p;

  ALLOC_ZVAL(*p);
  memcpy(*p, temp, sizeof(zval));
  INIT_PZVAL(*p);

  switch(Z_TYPE_PP(p)) {
  case IS_STRING: {
    Z_STRVAL_PP(p) = estrndup(Z_STRVAL_P(temp), Z_STRLEN_P(temp));
    break;
  }
  case IS_ARRAY: {
    TSRMLS_FETCH();
    mongo_util_hash_to_zval(p, &temp TSRMLS_CC);
    break;
  }
  }
}
/* {{{ static void yaf_config_ini_zval_deep_copy(zval **p)
 */
static void yaf_config_ini_zval_deep_copy(zval **p) {
	zval *value;
	ALLOC_ZVAL(value);
	*value = **p;

	switch (Z_TYPE_PP(p)) {
		case IS_ARRAY:
			{
				array_init(value);
				zend_hash_copy(Z_ARRVAL_P(value), Z_ARRVAL_PP(p),
						(copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *));
			}
			break;
		default:
			zval_copy_ctor(value);
			Z_TYPE_P(value) = Z_TYPE_PP(p);
	}

	INIT_PZVAL(value);
	*p = value;
}
Esempio n. 26
0
File: hash.c Progetto: 117311730/PHP
void mongo_util_hash_copy_to_p(void *pDest) {
  zval **p = (zval**)pDest;
  zval *temp = *p;

  *p = (zval*)malloc(sizeof(zval));
  memcpy(*p, temp, sizeof(zval));
  INIT_PZVAL(*p);

  switch (Z_TYPE_PP(p)) {
  case IS_STRING: {
    Z_STRVAL_PP(p) = (char*)malloc(Z_STRLEN_P(temp)+1);
    memcpy(Z_STRVAL_PP(p), Z_STRVAL_P(temp), Z_STRLEN_P(temp)+1);
    break;
  }
  case IS_ARRAY: {
    TSRMLS_FETCH();
    mongo_util_hash_to_pzval(p, &temp TSRMLS_CC);
    break;
  }
  }
}
Esempio n. 27
0
/* {{{ pip_pyobject_to_zobject(PyObject *obj)
   Convert Python object to a PHP (Zend) object */
zval *
pip_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);
	ZVAL_RESOURCE(handle, zend_list_insert(obj, le_pyobject));
	zval_copy_ctor(handle);
	INIT_PZVAL(handle);
	zend_hash_index_update(Z_OBJPROP_P(ret), 0, &handle, sizeof(zval *), NULL);

	return ret;
}
Esempio n. 28
0
PHPAPI int php_stream_context_set_option(php_stream_context *context,
    const char *wrappername, const char *optionname, zval *optionvalue)
{
  zval **wrapperhash;
  zval *category, *copied_val;

  ALLOC_INIT_ZVAL(copied_val);
  *copied_val = *optionvalue;
  zval_copy_ctor(copied_val);
  INIT_PZVAL(copied_val);

  if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) {
    MAKE_STD_ZVAL(category);
    array_init(category);
    if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&category, sizeof(zval *), NULL)) {
      return FAILURE;
    }

    wrapperhash = &category;
  }
  return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL);
}
Esempio n. 29
0
/* this function doesn't check for too many parameters */
ZEND_API int zend_get_parameters(int ht, int param_count, ...)
{
	void **p;
	int arg_count;
	va_list ptr;
	zval **param, *param_ptr;
	ELS_FETCH();

	p = EG(argument_stack).top_element-2;
	arg_count = (ulong) *p;

	if (param_count>arg_count) {
		return FAILURE;
	}

	va_start(ptr, param_count);

	while (param_count-->0) {
		param = va_arg(ptr, zval **);
		param_ptr = *(p-arg_count);
		if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
			zval *new_tmp;

			ALLOC_ZVAL(new_tmp);
			*new_tmp = *param_ptr;
			zval_copy_ctor(new_tmp);
			INIT_PZVAL(new_tmp);
			param_ptr = new_tmp;
			((zval *) *(p-arg_count))->refcount--;
			*(p-arg_count) = param_ptr;
		}
		*param = param_ptr;
		arg_count--;
	}
	va_end(ptr);

	return SUCCESS;
}
Esempio n. 30
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;
}