Explorar o código

TSRM/ZTS fixes.

Stefan Siegl %!s(int64=11) %!d(string=hai) anos
pai
achega
61eee4cbd6
Modificáronse 4 ficheiros con 18 adicións e 7 borrados
  1. 2 0
      php_v8js_macros.h
  2. 6 1
      v8js.cc
  3. 7 5
      v8js_convert.cc
  4. 3 1
      v8js_methods.cc

+ 2 - 0
php_v8js_macros.h

@@ -164,6 +164,8 @@ ZEND_END_MODULE_GLOBALS(v8js)
 
 extern zend_v8js_globals v8js_globals;
 
+ZEND_EXTERN_MODULE_GLOBALS(v8js)
+
 #ifdef ZTS
 # define V8JSG(v) TSRMG(v8js_globals_id, zend_v8js_globals *, v)
 #else

+ 6 - 1
v8js.cc

@@ -770,7 +770,7 @@ static PHP_METHOD(V8Js, __construct)
 	V8JS_GLOBAL->Set(object_name_js, php_obj, v8::ReadOnly);
 
 	/* Export public property values */
-	HashTable *properties = zend_std_get_properties(getThis());
+	HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
 	HashPosition pos;
 	zval **value;
 	ulong index;
@@ -1496,6 +1496,11 @@ static PHP_MINIT_FUNCTION(v8js)
 {
 	zend_class_entry ce;
 
+#ifdef ZTS
+	std::mutex mutex;
+	memcpy(&V8JSG(timer_mutex), &mutex, sizeof(V8JSG(timer_mutex)));
+#endif
+
 	/* V8Object Class */
 	INIT_CLASS_ENTRY(ce, "V8Object", NULL);
 	php_ce_v8_object = zend_register_internal_class(&ce TSRMLS_CC);

+ 7 - 5
v8js_convert.cc

@@ -56,7 +56,7 @@ typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::Fu
 typedef std::map<TemplateCacheKey, TemplateCacheEntry> TemplateCache;
 
 /* Callback for PHP methods and functions */
-static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
+static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value>& info TSRMLS_DC) /* {{{ */
 {
 	v8::Handle<v8::Value> return_value;
 	zend_fcall_info fci;
@@ -169,8 +169,8 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
 	zval *value = reinterpret_cast<zval *>(info.Holder()->GetAlignedPointerFromInternalField(0));
 	v8::Isolate *isolate = reinterpret_cast<v8::Isolate *>(info.Holder()->GetAlignedPointerFromInternalField(1));
 	zend_function *method_ptr;
-	zend_class_entry *ce = Z_OBJCE_P(value);
 	TSRMLS_FETCH();
+	zend_class_entry *ce = Z_OBJCE_P(value);
 
 	/* Set method_ptr from v8::External or fetch the closure invoker */
 	if (!info.Data().IsEmpty() && info.Data()->IsExternal()) {
@@ -179,7 +179,7 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
 		method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC);
 	}
 
-	return php_v8js_call_php_func(value, ce, method_ptr, isolate, info);
+	return php_v8js_call_php_func(value, ce, method_ptr, isolate, info TSRMLS_CC);
 }
 
 /* Callback for PHP constructor calls */
@@ -212,11 +212,11 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
 		}
 
 		MAKE_STD_ZVAL(value);
-		object_init_ex(value, ce TSRMLS_CC);
+		object_init_ex(value, ce);
 
 		// Call __construct function
 		if (ctor_ptr != NULL) {
-			php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info);
+			php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
 		}
 	}
 
@@ -365,6 +365,8 @@ static void php_v8js_property_query(v8::Local<v8::String> property, const v8::Pr
 
 static void php_v8js_weak_object_callback(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, zval *value)
 {
+	TSRMLS_FETCH();
+
 	if (READY_TO_DESTROY(value)) {
 		zval_dtor(value);
 		FREE_ZVAL(value);

+ 3 - 1
v8js_methods.cc

@@ -163,6 +163,8 @@ V8JS_METHOD(var_dump) /* {{{ */
 
 V8JS_METHOD(require)
 {
+	TSRMLS_FETCH();
+
 	// Get the extension context
 	v8::Handle<v8::External> data = v8::Handle<v8::External>::Cast(info.Data());
 	php_v8js_ctx *c = static_cast<php_v8js_ctx*>(data->Value());
@@ -234,7 +236,7 @@ V8JS_METHOD(require)
 		efree(normalised_path);
 
 		// Clear the PHP exception and throw it in V8 instead
-		zend_clear_exception(TSRMLS_CC);
+		zend_clear_exception(TSRMLS_C);
 		info.GetReturnValue().Set(v8::ThrowException(v8::String::New("Module loader callback exception")));
 		return;
 	}