Skip to content

Commit 9281130

Browse files
committed
feat: add share options as class property
Notably, I needed to expose php_array_data_compare_unstable_i, in order to avoid re-implementing a comparison function. ext/intl/collator_sort.c chose to copy the implementation, and could maybe benefit from using the exposed function instead.
1 parent d1ab12f commit 9281130

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

ext/curl/curl.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,7 @@ final class CurlShareHandle
36743674
*/
36753675
final class CurlPersistentShareHandle
36763676
{
3677+
public readonly array $options;
36773678
}
36783679

36793680
function curl_close(CurlHandle $handle): void {}

ext/curl/curl_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/share.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#endif
2222

2323
#include "php.h"
24+
#include "ext/standard/php_array.h"
2425
#include "Zend/zend_exceptions.h"
2526

2627
#include "curl_private.h"
@@ -150,7 +151,7 @@ PHP_FUNCTION(curl_persistent_share_init)
150151
CURLSHcode error;
151152

152153
ZEND_PARSE_PARAMETERS_START(1, 1)
153-
Z_PARAM_ARRAY(share_opts)
154+
Z_PARAM_ARRAY_EX(share_opts, 0, 1)
154155
ZEND_PARSE_PARAMETERS_END();
155156

156157
object_init_ex(return_value, curl_persistent_share_ce);
@@ -175,6 +176,9 @@ PHP_FUNCTION(curl_persistent_share_init)
175176
persistent_id += 1 << option;
176177
} ZEND_HASH_FOREACH_END();
177178

179+
zend_array_sort(Z_ARRVAL_P(share_opts), php_array_data_compare_unstable_i, 1);
180+
zend_update_property(curl_persistent_share_ce, Z_OBJ_P(return_value), "options", sizeof("options") - 1, share_opts);
181+
178182
if (persistent_id) {
179183
zval *persisted = zend_hash_index_find(&CURL_G(persistent_curlsh), persistent_id);
180184

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static zend_always_inline int php_array_key_compare_string_locale_unstable_i(Buc
283283
}
284284
/* }}} */
285285

286-
static zend_always_inline int php_array_data_compare_unstable_i(Bucket *f, Bucket *s) /* {{{ */
286+
PHPAPI zend_always_inline int php_array_data_compare_unstable_i(Bucket *f, Bucket *s) /* {{{ */
287287
{
288288
int result = zend_compare(&f->val, &s->val);
289289
/* Special enums handling for array_unique. We don't want to add this logic to zend_compare as

ext/standard/php_array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PHP_MSHUTDOWN_FUNCTION(array);
2828
PHPAPI int php_array_merge(HashTable *dest, HashTable *src);
2929
PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src);
3030
PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src);
31+
PHPAPI int php_array_data_compare_unstable_i(Bucket *f, Bucket *s);
3132
PHPAPI int php_multisort_compare(const void *a, const void *b);
3233
PHPAPI zend_long php_count_recursive(HashTable *ht);
3334

0 commit comments

Comments
 (0)