Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix crashes and bugs here and there

  • Loading branch information...
commit 1eaf8bfc0dcf41ee5a37cce88b1a76789369661a 1 parent 289d3ea
Etienne Kneuss authored

Showing 2 changed files with 39 additions and 12 deletions. Show diff stats Hide diff stats

  1. +26 0 tests/weakmap_002.phpt
  2. +13 12 wr_weakmap.c
26 tests/weakmap_002.phpt
... ... @@ -0,0 +1,26 @@
  1 +--TEST--
  2 +WeakMap: unsetting
  3 +--FILE--
  4 +<?php
  5 +$wm = new WeakMap();
  6 +
  7 +$o = new StdClass;
  8 +
  9 +class A {
  10 + public function __destruct() {
  11 + echo "Dead!\n";
  12 + }
  13 +}
  14 +
  15 +$wm[$o] = new A;
  16 +
  17 +var_dump(count($wm));
  18 +unset($wm[$o]);
  19 +var_dump(count($wm));
  20 +?>
  21 +==END==
  22 +--EXPECTF--
  23 +int(1)
  24 +Dead!
  25 +int(0)
  26 +==END==
25 wr_weakmap.c
@@ -138,9 +138,9 @@ static zend_object_value wr_weakmap_object_new(zend_class_entry *class_type TSRM
138 138 }
139 139 /* }}} */
140 140
141   -static inline zval *wr_weakmap_object_read_dimension_helper(wr_weakmap_object *intern, zval *offset TSRMLS_DC) /* {{{ */
  141 +static inline zval **wr_weakmap_object_read_dimension_helper(wr_weakmap_object *intern, zval *offset TSRMLS_DC) /* {{{ */
142 142 {
143   - zval *retval;
  143 + zval **retval;
144 144
145 145 if (!offset || Z_TYPE_P(offset) != IS_OBJECT) {
146 146 zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
@@ -158,7 +158,6 @@ static inline zval *wr_weakmap_object_read_dimension_helper(wr_weakmap_object *i
158 158 static zval *wr_weakmap_object_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */
159 159 {
160 160 wr_weakmap_object *intern;
161   - zval *retval;
162 161
163 162 intern = (wr_weakmap_object *)zend_object_store_get_object(object TSRMLS_CC);
164 163
@@ -172,13 +171,15 @@ static zval *wr_weakmap_object_read_dimension(zval *object, zval *offset, int ty
172 171 return rv;
173 172 }
174 173 return EG(uninitialized_zval_ptr);
175   - }
  174 + } else {
  175 + zval **retval;
176 176
177   - retval = wr_weakmap_object_read_dimension_helper(intern, offset TSRMLS_CC);
178   - if (retval) {
179   - return retval;
  177 + retval = wr_weakmap_object_read_dimension_helper(intern, offset TSRMLS_CC);
  178 + if (retval) {
  179 + return *retval;
  180 + }
  181 + return NULL;
180 182 }
181   - return NULL;
182 183 }
183 184 /* }}} */
184 185
@@ -366,7 +367,7 @@ PHP_METHOD(WeakMap, offsetExists)
366 367 Returns the value at the specified $index. */
367 368 PHP_METHOD(WeakMap, offsetGet)
368 369 {
369   - zval *zindex, *value_p;
  370 + zval *zindex, **value_pp;
370 371 wr_weakmap_object *intern;
371 372
372 373 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
@@ -374,10 +375,10 @@ PHP_METHOD(WeakMap, offsetGet)
374 375 }
375 376
376 377 intern = (wr_weakmap_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
377   - value_p = wr_weakmap_object_read_dimension_helper(intern, zindex TSRMLS_CC);
  378 + value_pp = wr_weakmap_object_read_dimension_helper(intern, zindex TSRMLS_CC);
378 379
379   - if (value_p) {
380   - RETURN_ZVAL(value_p, 1, 0);
  380 + if (value_pp) {
  381 + RETURN_ZVAL(*value_pp, 1, 0);
381 382 }
382 383 RETURN_NULL();
383 384 } /* }}} */

0 comments on commit 1eaf8bf

Please sign in to comment.
Something went wrong with that request. Please try again.