Skip to content

Commit

Permalink
Fix pair reflection bugs by avoiding __get and __set
Browse files Browse the repository at this point in the history
  • Loading branch information
rtheunissen committed Nov 18, 2018
1 parent c475c51 commit 9f1ba41
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 277 deletions.
1 change: 0 additions & 1 deletion config.m4
Expand Up @@ -13,7 +13,6 @@ dnl Internal
src/ds/ds_set.c \
src/ds/ds_map.c \
src/ds/ds_stack.c \
src/ds/ds_pair.c \
src/ds/ds_priority_queue.c \
src/ds/ds_queue.c \
\
Expand Down
1 change: 0 additions & 1 deletion config.w32
Expand Up @@ -30,7 +30,6 @@ if (PHP_DS != "no") {
"ds_set.c",
"ds_map.c",
"ds_stack.c",
"ds_pair.c",
"ds_priority_queue.c",
"ds_queue.c",
]);
Expand Down
10 changes: 4 additions & 6 deletions package.xml
Expand Up @@ -16,10 +16,10 @@
<email>krakjoe@php.net</email>
<active>yes</active>
</lead>
<date>2018-05-24</date>
<time>00:22:59</time>
<date>2018-11-18</date>
<time>12:31:19</time>
<version>
<release>1.2.6</release>
<release>1.2.7</release>
<api>1.1.0</api>
</version>
<stability>
Expand All @@ -28,7 +28,7 @@
</stability>
<license uri="https://opensource.org/licenses/MIT">MIT License</license>
<notes>
- Fixed not clearing memory after buffer reallocation. #114
- Fixed pair reflection bugs. #119
</notes>
<contents>
<dir name="/">
Expand All @@ -51,8 +51,6 @@
<file role="src" name="ds_htable.h"/>
<file role="src" name="ds_map.c"/>
<file role="src" name="ds_map.h"/>
<file role="src" name="ds_pair.c"/>
<file role="src" name="ds_pair.h"/>
<file role="src" name="ds_priority_queue.c"/>
<file role="src" name="ds_priority_queue.h"/>
<file role="src" name="ds_queue.c"/>
Expand Down
1 change: 0 additions & 1 deletion src/ds/ds_htable.c
@@ -1,6 +1,5 @@
#include "../common.h"

#include "ds_pair.h"
#include "ds_htable.h"
#include "ds_set.h"
#include "ds_vector.h"
Expand Down
13 changes: 6 additions & 7 deletions src/ds/ds_map.c
Expand Up @@ -8,7 +8,6 @@
#include "ds_vector.h"
#include "ds_map.h"
#include "ds_set.h"
#include "ds_pair.h"

static ds_map_t *ds_map_ex(ds_htable_t *table)
{
Expand Down Expand Up @@ -245,7 +244,7 @@ ds_map_t *ds_map_union(ds_map_t *map, ds_map_t *other)
return ds_map_ex(ds_htable_merge(map->table, other->table));
}

ds_pair_t *ds_map_first(ds_map_t *map)
php_ds_pair_t *ds_map_first(ds_map_t *map)
{
ds_htable_bucket_t *bucket = ds_htable_first(map->table);

Expand All @@ -254,10 +253,10 @@ ds_pair_t *ds_map_first(ds_map_t *map)
return NULL;
}

return ds_pair_ex(&bucket->key, &bucket->value);
return php_ds_pair_ex(&bucket->key, &bucket->value);
}

ds_pair_t *ds_map_last(ds_map_t *map)
php_ds_pair_t *ds_map_last(ds_map_t *map)
{
ds_htable_bucket_t *bucket = ds_htable_last(map->table);

Expand All @@ -266,10 +265,10 @@ ds_pair_t *ds_map_last(ds_map_t *map)
return NULL;
}

return ds_pair_ex(&bucket->key, &bucket->value);
return php_ds_pair_ex(&bucket->key, &bucket->value);
}

ds_pair_t *ds_map_skip(ds_map_t *map, zend_long position)
php_ds_pair_t *ds_map_skip(ds_map_t *map, zend_long position)
{
ds_htable_bucket_t *bucket = ds_htable_lookup_by_position(map->table, position);

Expand All @@ -278,7 +277,7 @@ ds_pair_t *ds_map_skip(ds_map_t *map, zend_long position)
return NULL;
}

return ds_pair_ex(&bucket->key, &bucket->value);
return php_ds_pair_ex(&bucket->key, &bucket->value);
}

static int iterator_add(zend_object_iterator *iterator, void *puser)
Expand Down
8 changes: 4 additions & 4 deletions src/ds/ds_map.h
Expand Up @@ -3,7 +3,7 @@

#include "../common.h"
#include "ds_htable.h"
#include "ds_pair.h"
#include "../php/objects/php_pair.h"

typedef struct _ds_map_t {
ds_htable_t *table;
Expand Down Expand Up @@ -62,9 +62,9 @@ ds_map_t *ds_map_diff(ds_map_t *map, ds_map_t *other);
ds_map_t *ds_map_intersect(ds_map_t *map, ds_map_t *other);
ds_map_t *ds_map_union(ds_map_t *map, ds_map_t *other);

ds_pair_t *ds_map_first(ds_map_t *map);
ds_pair_t *ds_map_last(ds_map_t *map);
ds_pair_t *ds_map_skip(ds_map_t *map, zend_long position);
php_ds_pair_t *ds_map_first(ds_map_t *map);
php_ds_pair_t *ds_map_last(ds_map_t *map);
php_ds_pair_t *ds_map_skip(ds_map_t *map, zend_long position);

void ds_map_sum(ds_map_t *map, zval *return_value);
void ds_map_reduce(ds_map_t *map, FCI_PARAMS, zval *initial, zval *return_value);
Expand Down
54 changes: 0 additions & 54 deletions src/ds/ds_pair.c

This file was deleted.

18 changes: 0 additions & 18 deletions src/ds/ds_pair.h

This file was deleted.

22 changes: 9 additions & 13 deletions src/php/classes/php_pair_ce.c
@@ -1,11 +1,8 @@
#include "../../common.h"

#include "../parameters.h"
#include "../arginfo.h"

#include "../objects/php_pair.h"
#include "../handlers/php_pair_handlers.h"

#include "php_pair_ce.h"

#define METHOD(name) PHP_METHOD(Pair, name)
Expand All @@ -16,38 +13,34 @@ METHOD(__construct)
{
PARSE_OPTIONAL_ZVAL_OPTIONAL_ZVAL(key, value);
{
ds_pair_t *pair = THIS_DS_PAIR();
php_ds_pair_t *pair = THIS_DS_PAIR();

if (key) {
ZVAL_COPY(&pair->key, key);
} else {
ZVAL_NULL(&pair->key);
php_ds_pair_set_key(pair, key);
}

if (value) {
ZVAL_COPY(&pair->value, value);
} else {
ZVAL_NULL(&pair->value);
php_ds_pair_set_value(pair, value);
}
}
}

METHOD(copy)
{
PARSE_NONE;
RETURN_DS_PAIR(ds_pair_clone(THIS_DS_PAIR()));
RETURN_DS_PAIR(php_ds_pair_create_clone(THIS_DS_PAIR()));
}

METHOD(toArray)
{
PARSE_NONE;
ds_pair_to_array(THIS_DS_PAIR(), return_value);
php_ds_pair_to_array(THIS_DS_PAIR(), return_value);
}

METHOD(jsonSerialize)
{
PARSE_NONE;
ds_pair_to_array(THIS_DS_PAIR(), return_value);
php_ds_pair_to_array(THIS_DS_PAIR(), return_value);
}

void php_ds_register_pair()
Expand All @@ -70,6 +63,9 @@ void php_ds_register_pair()
php_ds_pair_ce->serialize = php_ds_pair_serialize;
php_ds_pair_ce->unserialize = php_ds_pair_unserialize;

zend_declare_property_null(php_ds_pair_ce, STR_AND_LEN("key"), ZEND_ACC_PUBLIC);
zend_declare_property_null(php_ds_pair_ce, STR_AND_LEN("value"), ZEND_ACC_PUBLIC);

zend_class_implements(php_ds_pair_ce, 1, php_json_serializable_ce);
php_ds_register_pair_handlers();
}

0 comments on commit 9f1ba41

Please sign in to comment.