convert_to_explicit_type has been removed upstream
[m6w6/ext-http] / src / php_http_misc.h
index ae3359c3b00921eb9e75486396715361bf58f132..19eb75cb894276f3021452b330e413dbea2e7c61 100644 (file)
@@ -67,47 +67,7 @@ char *php_http_pretty_key(register char *key, size_t key_len, zend_bool uctitle,
 size_t php_http_boundary(char *buf, size_t len);
 int php_http_select_str(const char *cmp, int argc, ...);
 
-/* See "A Reusable Duff Device" By Ralf Holly, August 01, 2005 */
-#define PHP_HTTP_DUFF_BREAK() times_=1
-#define PHP_HTTP_DUFF(c, a) do { \
-       size_t count_ = (c); \
-       size_t times_ = (count_ + 7) >> 3; \
-       switch (count_ & 7){ \
-               case 0: do { \
-                       a; \
-               case 7: \
-                       a; \
-               case 6: \
-                       a; \
-               case 5: \
-                       a; \
-               case 4: \
-                       a; \
-               case 3: \
-                       a; \
-               case 2: \
-                       a; \
-               case 1: \
-                       a; \
-                                       } while (--times_ > 0); \
-       } \
-} while (0)
-
-static inline const char *php_http_locate_str(register const char *h, size_t h_len, const char *n, size_t n_len)
-{
-       if (!n_len || !h_len || h_len < n_len) {
-               return NULL;
-       }
-
-       PHP_HTTP_DUFF(h_len - n_len + 1,
-               if (*h == *n && !strncmp(h + 1, n + 1, n_len - 1)) {
-                       return h;
-               }
-               ++h;
-       );
-
-       return NULL;
-}
+#define php_http_locate_str(h, h_len, n, n_len) zend_memnstr((h), (n), (n_len), (h)+(h_len))
 
 static inline const char *php_http_locate_eol(const char *line, int *eol_len)
 {
@@ -123,16 +83,14 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i
 {
        register const char *eol = bin;
 
-       if (len > 0) {
-               PHP_HTTP_DUFF(len,
-                       if (*eol == '\r' || *eol == '\n') {
-                               if (eol_len) {
-                                       *eol_len = ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
-                               }
-                               return eol;
+       while (len--) {
+               if (UNEXPECTED(*eol == '\r' || *eol == '\n')) {
+                       if (EXPECTED(eol_len)) {
+                               *eol_len = (EXPECTED(eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
                        }
-                       ++eol;
-               );
+                       return eol;
+               }
+               ++eol;
        }
        return NULL;
 }
@@ -141,9 +99,51 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i
 
 #if PHP_DEBUG
 #      undef  HASH_OF
-#      define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL))))
+#      define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL))))
 #endif
 
+#if PHP_VERSION_ID >= 80100
+# define php_http_mem_stream_open(type, zstr) php_stream_memory_open((type), (zstr))
+#else
+# define php_http_mem_stream_open(type, zstr) php_stream_memory_open((type), (zstr)->val, (zstr)->len)
+#endif
+
+#define HT_IS_RECURSIVE(ht) GC_IS_RECURSIVE(ht)
+#define HT_PROTECT_RECURSION(ht) GC_PROTECT_RECURSION(ht)
+#define HT_UNPROTECT_RECURSION(ht) GC_UNPROTECT_RECURSION(ht)
+
+#ifndef convert_to_explicit_type
+# define convert_to_explicit_type(pzv, type) \
+       do { \
+               switch (type) { \
+                       case IS_NULL: \
+                               convert_to_null(pzv); \
+                               break; \
+                       case IS_LONG: \
+                               convert_to_long(pzv); \
+                               break; \
+                       case IS_DOUBLE: \
+                               convert_to_double(pzv); \
+                               break; \
+                       case _IS_BOOL: \
+                               convert_to_boolean(pzv); \
+                               break; \
+                       case IS_ARRAY: \
+                               convert_to_array(pzv); \
+                               break; \
+                       case IS_OBJECT: \
+                               convert_to_object(pzv); \
+                               break; \
+                       case IS_STRING: \
+                               convert_to_string(pzv); \
+                               break; \
+                       default: \
+                               assert(0); \
+                               break; \
+               } \
+       } while (0);
+
+#endif
 static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv)
 {
        if (!zo) {
@@ -154,16 +154,8 @@ static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv)
 
 static inline zend_string *php_http_cs2zs(char *s, size_t l)
 {
-       zend_string *str = erealloc(s, sizeof(*str) + l);
-
-       memmove(str->val, str, l);
-       str->val[l] = 0;
-       str->len = l;
-       str->h = 0;
-
-       GC_REFCOUNT(str) = 1;
-       GC_TYPE_INFO(str) = IS_STRING;
-
+       zend_string *str = zend_string_init(s, l, 0);
+       efree(s);
        return str;
 }
 
@@ -184,9 +176,6 @@ static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t n
        return FAILURE;
 }
 
-#define Z_ISUSER(zv) (Z_TYPE(zv) <= 10)
-#define Z_ISUSER_P(zvp) Z_ISUSER(*(zvp))
-
 /* return object(values) */
 #define ZVAL_OBJECT(z, o, addref) \
        ZVAL_OBJ(z, o); \