From 39cc821f9122276c3c186643128eba4f86a8327a Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 25 Oct 2013 23:46:03 -0400 Subject: [PATCH] Store tsrm_ls in php_v8js_ctx. This avoids the need to ever do a (slow) TSRMLS_FETCH(). --- php_v8js_macros.h | 9 +++++++++ v8js.cc | 1 + v8js_convert.cc | 13 +++++++------ v8js_methods.cc | 6 +++--- v8js_variables.cc | 5 +++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 67a5469..adfd5b1 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -161,9 +161,18 @@ struct php_v8js_ctx { std::vector modules_stack; std::vector modules_base; std::map template_cache; +#ifdef ZTS + void ***zts_ctx; +#endif }; /* }}} */ +#ifdef ZTS +# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData())->zts_ctx); +#else +# define V8JS_TSRMLS_FETCH() +#endif + // Timer context struct php_v8js_timer_ctx { diff --git a/v8js.cc b/v8js.cc index 8681103..df91314 100644 --- a/v8js.cc +++ b/v8js.cc @@ -563,6 +563,7 @@ static zend_object_value php_v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */ c = (php_v8js_ctx *) ecalloc(1, sizeof(*c)); zend_object_std_init(&c->std, ce TSRMLS_CC); + TSRMLS_SET_CTX(c->zts_ctx); #if PHP_VERSION_ID >= 50400 object_properties_init(&c->std, ce); diff --git a/v8js_convert.cc b/v8js_convert.cc index 51c54d9..c59e820 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -154,7 +154,7 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo& inf v8::Isolate *isolate = info.GetIsolate(); v8::Local self = info.Holder(); - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zval *value = reinterpret_cast(v8::External::Cast(*self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)))->Value()); zend_function *method_ptr; zend_class_entry *ce = Z_OBJCE_P(value); @@ -192,7 +192,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo::Cast(info[0]); } else { // Object created from JavaScript context. Need to create PHP object first. - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zend_class_entry *ce = static_cast(ext_ce->Value()); zend_function *ctor_ptr = ce->constructor; @@ -241,8 +241,9 @@ static int _php_v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */ /* }}} */ static void php_v8js_weak_object_callback(const v8::WeakCallbackData &data) { - TSRMLS_FETCH(); + v8::Isolate *isolate = data.GetIsolate(); zval *value = data.GetParameter(); + V8JS_TSRMLS_FETCH(); if (READY_TO_DESTROY(value)) { zval_dtor(value); FREE_ZVAL(value); @@ -280,7 +281,7 @@ static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo result = v8::Array::New(0); uint32_t result_len = 0; - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zend_class_entry *ce; zend_function *method_ptr; HashTable *proptable; @@ -403,7 +404,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo& i char *error; int error_len; - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zend_class_entry *ce; zval *object = reinterpret_cast(v8::External::Cast(*self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)))->Value()); ce = Z_OBJCE_P(object); @@ -497,7 +498,7 @@ static inline v8::Local php_v8js_named_property_callback(v8::Local ret_value; v8::Local cb; - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zend_class_entry *scope = NULL; /* XXX? */ zend_class_entry *ce; zend_function *method_ptr = NULL; diff --git a/v8js_methods.cc b/v8js_methods.cc index dc763d7..0c0d5f2 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -45,7 +45,7 @@ V8JS_METHOD(print) /* {{{ */ { v8::Isolate *isolate = info.GetIsolate(); int ret = 0; - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); for (int i = 0; i < info.Length(); i++) { v8::String::Utf8Value str(info[i]); @@ -184,7 +184,7 @@ static void _php_v8js_dumper(v8::Isolate *isolate, v8::Local var, int V8JS_METHOD(var_dump) /* {{{ */ { v8::Isolate *isolate = info.GetIsolate(); - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); for (int i = 0; i < info.Length(); i++) { _php_v8js_dumper(isolate, info[i], 1 TSRMLS_CC); @@ -197,7 +197,7 @@ V8JS_METHOD(var_dump) /* {{{ */ V8JS_METHOD(require) { v8::Isolate *isolate = info.GetIsolate(); - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); // Get the extension context v8::Handle data = v8::Handle::Cast(info.Data()); diff --git a/v8js_variables.cc b/v8js_variables.cc index c039271..fa81b64 100644 --- a/v8js_variables.cc +++ b/v8js_variables.cc @@ -36,14 +36,15 @@ static void php_v8js_fetch_php_variable(v8::Local name, const v8::Pr { v8::Handle data = v8::Handle::Cast(info.Data()); php_v8js_accessor_ctx *ctx = static_cast(data->Value()); + v8::Isolate *isolate = ctx->isolate; zval **variable; - TSRMLS_FETCH(); + V8JS_TSRMLS_FETCH(); zend_is_auto_global(ctx->variable_name_string, ctx->variable_name_string_len TSRMLS_CC); if (zend_hash_find(&EG(symbol_table), ctx->variable_name_string, ctx->variable_name_string_len + 1, (void **) &variable) == SUCCESS) { - info.GetReturnValue().Set(zval_to_v8js(*variable, ctx->isolate TSRMLS_CC)); + info.GetReturnValue().Set(zval_to_v8js(*variable, isolate TSRMLS_CC)); return; } }