From 61eee4cbd6004dc88f4bf4bf1a13f817acb357ad Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 19 Oct 2013 20:11:17 +0000 Subject: [PATCH] TSRM/ZTS fixes. --- php_v8js_macros.h | 2 ++ v8js.cc | 7 ++++++- v8js_convert.cc | 12 +++++++----- v8js_methods.cc | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 688698e..4f689ce 100644 --- a/php_v8js_macros.h +++ b/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 diff --git a/v8js.cc b/v8js.cc index 4cf2f08..c7e053e 100644 --- a/v8js.cc +++ b/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); diff --git a/v8js_convert.cc b/v8js_convert.cc index fdcc2a9..ff64819 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -56,7 +56,7 @@ typedef v8::Persistent 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& info) /* {{{ */ +static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo& info TSRMLS_DC) /* {{{ */ { v8::Handle return_value; zend_fcall_info fci; @@ -169,8 +169,8 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo& inf zval *value = reinterpret_cast(info.Holder()->GetAlignedPointerFromInternalField(0)); v8::Isolate *isolate = reinterpret_cast(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& 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 property, const v8::Pr static void php_v8js_weak_object_callback(v8::Isolate *isolate, v8::Persistent *object, zval *value) { + TSRMLS_FETCH(); + if (READY_TO_DESTROY(value)) { zval_dtor(value); FREE_ZVAL(value); diff --git a/v8js_methods.cc b/v8js_methods.cc index 463e2bd..761a40f 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -163,6 +163,8 @@ V8JS_METHOD(var_dump) /* {{{ */ V8JS_METHOD(require) { + TSRMLS_FETCH(); + // Get the extension context v8::Handle data = v8::Handle::Cast(info.Data()); php_v8js_ctx *c = static_cast(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; }