Browse files

WIP for removing _GNU_SOURCE

  • Loading branch information...
1 parent 352b8b4 commit c6aa2faa83dc8787d7cefcb27faa7f07f4aae6f0 @cataphract committed Jan 10, 2013
Showing with 20 additions and 7 deletions.
  1. +9 −3 Zend/zend_qsort.c
  2. +3 −1 Zend/zend_qsort.h
  3. +8 −3 ext/standard/string.c
View
12 Zend/zend_qsort.c
@@ -19,6 +19,7 @@
/* $Id$ */
#include "zend.h"
+#include "zend_qsort.h"
#include <limits.h>
@@ -53,7 +54,7 @@ static void _zend_qsort_swap(void *a, void *b, size_t siz)
}
}
-ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
+void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC)

Why not make this one ZEND_API too? What if some extension needs the same use case?

Especially as in the header This one is marked as ZEND_API, but zend_qsort not. MAke all ZEND_API so it's exported for consumers in other dll's, exe's, so's, dynlib's ...

@cataphract
Owner

It was an oversight in the header, obviously. I did not want to make zend_qsort not exported anymore.
In the case, the idea of not exporting zend_qsort_r was that it would be added to PHP 5.4, hence experience shared extension modules should not depend on it, otherwise they would not be compatible with older versions of 5.4. It could be exported in 5.5.

I'm not sure I feel good about adding the extra parameter hack to 5.4 without being 100% sure it will work properly on all systems. Can we live without this hack on 5.4?

@cataphract
Owner

Depends on what we want to do with 5.4. If we don't want this new implementation of strtr in it, then the point is moot. If we do, but we don't want the changes in zend_qsort.c, then the only options I see are introducing a global or write a small naive quick sort routine in strings.c just for this purpose (extreme efficency in sorting the replacement patterns should not be that important).

I wouldn't mind new strtr, but only if there's a way to do it without stability risk. Maybe special-purpose qsort is better for 5.4 indeed? qsort is not that big, especially if you don't need to make it generic :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
{
void *begin_stack[QSORT_STACK_SIZE];
void *end_stack[QSORT_STACK_SIZE];
@@ -80,10 +81,10 @@ ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t co
seg2 = end;
while (1) {
- for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC) > 0;
+ for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC, arg) > 0;
seg1 += siz);
- for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC) > 0;
+ for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC, arg) > 0;
seg2 -= siz);
if (seg1 >= seg2)
@@ -117,6 +118,11 @@ ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t co
}
}
+ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
+{
+ zend_qsort_r(base, nmemb, siz, (compare_r_func_t)compare, NULL TSRMLS_CC);
+}
+
/*
* Local Variables:
* c-basic-offset: 4
View
4 Zend/zend_qsort.h
@@ -22,7 +22,9 @@
#define ZEND_QSORT_H
BEGIN_EXTERN_C()
-ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC);
+typedef int (*compare_r_func_t)(const void *, const void * TSRMLS_DC, void *);
+void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC);
+ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC);
END_EXTERN_C()
#endif /* ZEND_QSORT_H */
View
11 ext/standard/string.c
@@ -22,7 +22,6 @@
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
-#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdint.h>
#include "php.h"
@@ -2848,7 +2847,7 @@ static inline void php_strtr_populate_shift(PATNREPL *patterns, int patnum, int
}
/* }}} */
/* {{{ php_strtr_compare_hash_suffix */
-static int php_strtr_compare_hash_suffix(const void *a, const void *b, void *ctx_g)
+static int php_strtr_compare_hash_suffix(const void *a, const void *b TSRMLS_DC, void *ctx_g)
{
const PPRES *res = ctx_g;
const PATNREPL *pnr_a = a,
@@ -2971,7 +2970,13 @@ static PPRES *php_strtr_array_prepare(STR *text, PATNREPL *patterns, int patnum,
res->patterns = safe_emalloc(patnum, sizeof(*res->patterns), 0);
memcpy(res->patterns, patterns, sizeof(*patterns) * patnum);
- qsort_r(res->patterns, patnum, sizeof(*res->patterns), php_strtr_compare_hash_suffix, res);
+#ifdef ZTS
+ zend_qsort_r(res->patterns, patnum, sizeof(*res->patterns),
+ php_strtr_compare_hash_suffix, res, NULL); /* tsrmls not needed */
+#else
+ zend_qsort_r(res->patterns, patnum, sizeof(*res->patterns),
+ php_strtr_compare_hash_suffix, res);
+#endif
res->prefix = safe_emalloc(patnum, sizeof(*res->prefix), 0);
for (i = 0; i < patnum; i++) {

0 comments on commit c6aa2fa

Please sign in to comment.