From f9eebda67326de8a7c00f81caf46d9dd54957b29 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Wed, 18 Dec 2013 14:25:52 +0100 Subject: [PATCH] fix segfault with optimized code; initialize TSRM stuff --- SConstruct | 2 +- src/bindings/php/hammer.i | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index dac01075..a9f9c670 100644 --- a/SConstruct +++ b/SConstruct @@ -69,7 +69,7 @@ dbg = env.Clone(VARIANT='debug') dbg.Append(CCFLAGS=['-g']) opt = env.Clone(VARIANT='opt') -opt.Append(CCFLAGS="-O3") +opt.Append(CCFLAGS=["-O3"]) if GetOption("variant") == 'debug': env = dbg diff --git a/src/bindings/php/hammer.i b/src/bindings/php/hammer.i index 63038ccf..92857db9 100644 --- a/src/bindings/php/hammer.i +++ b/src/bindings/php/hammer.i @@ -1,5 +1,8 @@ %module hammer; %include "exception.i"; +%{ +#include "allocator.h" + %} %ignore HCountedArray_; @@ -8,6 +11,7 @@ %} %init %{ + TSRMLS_FETCH(); h_tt_php = h_allocate_token_type("com.upstandinghackers.hammer.php"); %} @@ -161,9 +165,11 @@ } static HParsedToken* call_action(const HParseResult *p, void *user_data) { - zval *args[1]; + zval **args; zval func; zval *ret; + args = (zval**)h_arena_malloc(p->arena, sizeof(*args) * 1); // one-element array of pointers + MAKE_STD_ZVAL(args[0]); ALLOC_INIT_ZVAL(ret); ZVAL_STRING(&func, (const char*)user_data, 0); hpt_to_php(p->ast, args[0]); @@ -179,9 +185,11 @@ } static int call_predicate(HParseResult *p, void *user_data) { - zval *args[1]; + zval **args; zval func; zval *ret; + args = (zval**)h_arena_malloc(p->arena, sizeof(*args) * 1); // one-element array of pointers + MAKE_STD_ZVAL(args[0]); ALLOC_INIT_ZVAL(ret); ZVAL_STRING(&func, (const char*)user_data, 0); hpt_to_php(p->ast, args[0]); -- GitLab