Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Features
- `__autoload` & `unserialize_callback_func`
- `__sleep` & `__wakeup`
- `__serialize` & `__unserialize` (only used in php 7.4+)
- The `allowed_classes` and `max_depth` options of `unserialize()`
- Serializable -interface
- Data portability between platforms (32/64bit, endianness)
- Tested on Linux amd64, Linux ARM, Mac OSX x86, HP-UX PA-RISC and NetBSD sparc64
Expand Down
6 changes: 5 additions & 1 deletion igbinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ function igbinary_serialize($value);
* then NULL is returned and an E_WARNING is issued.
*
* @param string $str The serialized string.
* @param array $options The same options as unserialize():
* - "allowed_classes": an array of the names of the classes to instantiate, false to instantiate none, or true to instantiate all (the default).
* The other classes are unserialized as __PHP_Incomplete_Class objects. Enums are not affected.
* - "max_depth": the maximum depth of nested arrays and objects, or 0 to disable the limit. Defaults to the unserialize_max_depth ini setting.
* @return mixed The unserialized value is returned. It can be a boolean, integer, float, string, array, object or null.
* @link http://www.php.net/manual/en/function.unserialize.php PHP's default unserialize
* @link https://secure.php.net/serializable Serializable interface
*/
function igbinary_unserialize($str);
function igbinary_unserialize($str, array $options = []);
16 changes: 16 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ memcached or similar memory based storages for serialized data.</description>
<file name="igbinary_016.phpt" role="test" />
<file name="igbinary_017.phpt" role="test" />
<file name="igbinary_018.phpt" role="test" />
<file name="igbinary_018_php7.phpt" role="test" />
<file name="igbinary_019.phpt" role="test" />
<file name="igbinary_020.phpt" role="test" />
<file name="igbinary_021.phpt" role="test" />
Expand Down Expand Up @@ -179,6 +180,7 @@ memcached or similar memory based storages for serialized data.</description>
<file name="igbinary_063_php72.phpt" role="test" />
<file name="igbinary_064.phpt" role="test" />
<file name="igbinary_065.phpt" role="test" />
<file name="igbinary_065_php7.phpt" role="test" />
<file name="igbinary_066.phpt" role="test" />
<file name="igbinary_067.phpt" role="test" />
<file name="igbinary_068.phpt" role="test" />
Expand All @@ -205,6 +207,8 @@ memcached or similar memory based storages for serialized data.</description>
<file name="igbinary_086.phpt" role="test" />
<file name="igbinary_087.phpt" role="test" />
<file name="igbinary_088.phpt" role="test" />
<file name="igbinary_088_php7.phpt" role="test" />
<file name="igbinary_088_php80.phpt" role="test" />
<file name="igbinary_089.phpt" role="test" />
<file name="igbinary_089_32bit.phpt" role="test" />
<file name="igbinary_090.phpt" role="test" />
Expand All @@ -219,20 +223,32 @@ memcached or similar memory based storages for serialized data.</description>
<file name="igbinary_099.phpt" role="test" />
<file name="igbinary_100.phpt" role="test" />
<file name="igbinary_101.phpt" role="test" />
<file name="igbinary_102.phpt" role="test" />
<file name="igbinary_bug54662.phpt" role="test" />
<file name="igbinary_bug72134.phpt" role="test" />
<file name="igbinary_enums_1.phpt" role="test" />
<file name="igbinary_enums_2.phpt" role="test" />
<file name="igbinary_enums_3.phpt" role="test" />
<file name="igbinary_enums_3_php83.phpt" role="test" />
<file name="igbinary_serialize_deep_nesting.phpt" role="test" />
<file name="igbinary_unserialize_max_depth.phpt" role="test" />
<file name="igbinary_unserialize_max_depth_boundary.phpt" role="test" />
<file name="igbinary_unserialize_options.phpt" role="test" />
<file name="igbinary_unserialize_v1_compatible.phpt" role="test" />
<file name="php82_suppress_dynamic_properties_warning.inc" role="test" />
<file name="serialize_array_ref_reentrancy.phpt" role="test" />
<file name="serialize_declared_properties.phpt" role="test" />
<file name="serialize_object_as_null.phpt" role="test" />
<file name="sleep_mangled_name_clash.phpt" role="test" />
<file name="typed_property_ref_assignment_failure.phpt" role="test" />
<file name="typed_property_ref_overwrite.phpt" role="test" />
<file name="typed_property_ref_overwrite2.phpt" role="test" />
<file name="typed_property_refs.phpt" role="test" />
<file name="typed_property_refs_php74.phpt" role="test" />
<file name="unserialize_class_name_checks.phpt" role="test" />
<file name="unserialize_failure_cleanup.phpt" role="test" />
<file name="unserialize_readonly_default.phpt" role="test" />
<file name="unserialize_serializable_format.phpt" role="test" />
</dir>
</dir>
</contents>
Expand Down
15 changes: 15 additions & 0 deletions src/php7/hash_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ static zend_always_inline size_t hash_si_ptr_size(struct hash_si_ptr *h) {
*/
size_t hash_si_ptr_find_or_insert(struct hash_si_ptr *h, const uintptr_t key, uint32_t value);

/**
* Returns the value associated with key, or SIZE_MAX if key does not exist.
* @param h Pointer to hash_si_ptr struct.
* @param key key to look up
*/
size_t hash_si_ptr_find(const struct hash_si_ptr *h, const uintptr_t key);

/**
* Changes the value associated with a key that exists in the map.
* @param h Pointer to hash_si_ptr struct.
* @param key key to update
* @param value new value
*/
void hash_si_ptr_set(struct hash_si_ptr *h, const uintptr_t key, uint32_t value);

/** Returns capacity of hash_si_ptr.
* @param h Pointer to hash_si_ptr struct.
* @return Capacity of hash_si_ptr.
Expand Down
36 changes: 36 additions & 0 deletions src/php7/hash_si_ptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,42 @@ size_t hash_si_ptr_find_or_insert(struct hash_si_ptr *h, const uintptr_t key, ui
}
}
/* }}} */
/* {{{ hash_si_ptr_find */
/**
* @param h the pointer to the hash map.
* @param key the key to look up
* @return the value, or SIZE_MAX if the key does not exist.
*/
size_t hash_si_ptr_find(const struct hash_si_ptr *h, const uintptr_t key) {
size_t mask = h->size - 1;
uint32_t hv = inline_hash_of_address(key) & mask;

while (h->data[hv].key != HASH_PTR_KEY_INVALID) {
if (h->data[hv].key == key) {
return h->data[hv].value;
}
hv = (hv + 1) & mask;
}
return SIZE_MAX;
}
/* }}} */
/* {{{ hash_si_ptr_set */
/**
* @param h the pointer to the hash map.
* @param key a key that exists in the map
* @param value the new value to associate with key
*/
void hash_si_ptr_set(struct hash_si_ptr *h, const uintptr_t key, uint32_t value) {
size_t mask = h->size - 1;
uint32_t hv = inline_hash_of_address(key) & mask;

while (h->data[hv].key != key) {
ZEND_ASSERT(h->data[hv].key != HASH_PTR_KEY_INVALID);
hv = (hv + 1) & mask;
}
h->data[hv].value = value;
}
/* }}} */

/*
* Local variables:
Expand Down
Loading