From 9f55409246afee482212220ff4ecda513cfd0ba4 Mon Sep 17 00:00:00 2001
From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com>
Date: Sun, 1 Dec 2013 20:55:04 -0800
Subject: [PATCH] EndTest is still failing, but the void*[] typemap isn't
 segfaulting anymore

---
 src/bindings/php/Tests/EndTest.php |  4 +++-
 src/bindings/swig/hammer.i         | 24 ++++++++++++++----------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/bindings/php/Tests/EndTest.php b/src/bindings/php/Tests/EndTest.php
index 92e49650..0b7ef429 100644
--- a/src/bindings/php/Tests/EndTest.php
+++ b/src/bindings/php/Tests/EndTest.php
@@ -12,12 +12,14 @@ class EndPTest extends PHPUnit_Framework_TestCase
 
     public function testSuccess()
     {
-        $result = h_parse($this->parser, "a");
+        $result = h_parse($this->parser, ["a"]);
+        var_dump($result);
         $this->assertEquals("a", $result);
     }
     public function testFailure()
     {
         $result = h_parse($this->parser, "aa");
+        var_dump($result);
         $this->assertEquals(NULL, $result);
     }
 }
diff --git a/src/bindings/swig/hammer.i b/src/bindings/swig/hammer.i
index eb6428a5..53118738 100644
--- a/src/bindings/swig/hammer.i
+++ b/src/bindings/swig/hammer.i
@@ -171,18 +171,22 @@
     int size = zend_hash_num_elements(arr);
     int i = 0;
     int res = 0;
-    $1 = (void**)malloc((size+1)*sizeof(HParser*));
-    for (zend_hash_internal_pointer_reset_ex(arr, &pointer);
-         zend_hash_get_current_data_ex(arr, (void**)&data, &pointer);
-         zend_hash_move_forward_ex(arr, &pointer), i++) {
-      res = SWIG_ConvertPtr(*data, &($1[i]), SWIGTYPE_p_HParser_, 0 | 0);
-      if (!SWIG_IsOk(res)) {
-	// TODO do we not *have* SWIG_TypeError?
-	SWIG_exception_fail(res, "that wasn't an HParser");
+    $1 = (void**)malloc((size)*sizeof(HParser*));
+    for (i=0; i<size; i++) {
+      HParser *p;
+      if (zend_hash_index_find(arr, i, (void**)&p) == FAILURE) {
+	// FIXME raise some error
+	$1 = NULL;
+      } else {
+	res = SWIG_ConvertPtr(*data, &($1[i]), SWIGTYPE_p_HParser_, 0 | 0);
+	if (!SWIG_IsOK(res)) {
+	  // TODO do we not *have* SWIG_TypeError?
+	  SWIG_exception_fail(res, "that wasn't an HParser");
+	}
       }
-    }
+    } 
   } else {
-    // FIXME raise some error
+    // FIXME some error
     $1 = NULL;
   }
  }
-- 
GitLab