Exemplo n.º 1
0
/* {{{ */
void pthreads_write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_D) {
	pthreads_object_t* threaded = PTHREADS_FETCH_FROM(Z_OBJ_P(object));
	zend_bool nulled = 0;

	rebuild_object_properties(&threaded->std);

	switch(Z_TYPE_P(value)){
		case IS_UNDEF:
		case IS_STRING:
		case IS_LONG:
		case IS_ARRAY:
		case IS_OBJECT:
		case IS_NULL:
		case IS_DOUBLE:
		case IS_RESOURCE:
		case IS_TRUE:
		case IS_FALSE: {
			zend_long *guard = NULL;
			if ((member && Z_TYPE_P(member) != IS_NULL) && 
				Z_OBJCE_P(object)->__set && 
				(guard = pthreads_get_guard(&threaded->std, member)) && !((*guard) & IN_SET)) {
				zend_fcall_info fci = empty_fcall_info;
				zend_fcall_info_cache fcc = empty_fcall_info_cache;
				zval rv;

				ZVAL_UNDEF(&rv);

				fci.size = sizeof(zend_fcall_info);
				fci.retval = &rv;
				fci.object = &threaded->std;
				zend_fcall_info_argn(&fci, 2, member, value);
				fcc.initialized = 1;
				fcc.function_handler = Z_OBJCE_P(object)->__set;
				fcc.object = &threaded->std;

				(*guard) |= IN_SET;
				zend_call_function(&fci, &fcc);
				(*guard) &= ~IN_SET;

				if (Z_TYPE(rv) != IS_UNDEF)
					zval_dtor(&rv);
				zend_fcall_info_args_clear(&fci, 1);
			} else {
				pthreads_store_write(object, member, value);
			}
		} break;
	
		default: {
			zend_throw_exception_ex(
				spl_ce_RuntimeException, 0,
				"pthreads detected an attempt to use unsupported data (%s) for %s::$%s", 
				zend_get_type_by_const(Z_TYPE_P(value)), 
				ZSTR_VAL(Z_OBJCE_P(object)->name), Z_STRVAL_P(member));
		}
	}
}
Exemplo n.º 2
0
/* {{{ writes a property to a thread in the appropriate way */
void pthreads_write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_D) {
	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);
	if (Z_TYPE_P(member)==IS_STRING) {
		switch(Z_TYPE_P(value)){
			case IS_STRING:
			case IS_LONG:
			case IS_ARRAY:
			case IS_OBJECT:
			case IS_NULL:
			case IS_DOUBLE:
			case IS_BOOL: {
				if (pthreads_store_write(pthreads->store, Z_STRVAL_P(member), Z_STRLEN_P(member), &value TSRMLS_CC)!=SUCCESS){
					zend_error_noreturn(
						E_WARNING, 
						"pthreads failed to write member %s::$%s", 
						Z_OBJCE_P(object)->name, Z_STRVAL_P(member)
					);
				} else zend_handlers->write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_C);
			} break;
			
			default: zend_handlers->write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_C);
		}
	} else zend_handlers->write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_C);
} 
Exemplo n.º 3
0
/* {{{ writes a property to a thread in the appropriate way */
void pthreads_write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_D) {
	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);
	zval *mstring = NULL;
	zend_bool nulled = 0;
	zend_bool locked;
	
	if (member == NULL || Z_TYPE_P(member) == IS_NULL) {
	    /* for anonymous members, 
	        we acquire the lock and increment a counter
	        we do not store any additional information or perform any lookups */
		pthreads_lock_acquire(pthreads->store->lock, &locked TSRMLS_CC);
		{
			if (member == NULL) {
			    MAKE_STD_ZVAL(member);
			    
			    nulled = 1;
			}
			
			ZVAL_LONG(member, pthreads->store->next++);
		}
		pthreads_lock_release(pthreads->store->lock, locked TSRMLS_CC);
	}

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

	if (Z_TYPE_P(member)==IS_STRING) {
		switch(Z_TYPE_P(value)){
			case IS_STRING:
			case IS_LONG:
			case IS_ARRAY:
			case IS_OBJECT:
			case IS_NULL:
			case IS_DOUBLE:
			case IS_RESOURCE:
			case IS_BOOL: {
				if (pthreads_store_write(pthreads->store, Z_STRVAL_P(member), Z_STRLEN_P(member), &value TSRMLS_CC)!=SUCCESS){
					zend_error(
						E_WARNING, 
						"pthreads failed to write member %s::$%s", 
						Z_OBJCE_P(object)->name, Z_STRVAL_P(member)
					);
				}
			} break;
			
			default: {
				zend_error(
					E_WARNING, 
					"pthreads detected an attempt to use an unsupported kind of data for %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);
	}
}