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)
{
{
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;
}
/* ZEND */
-#ifdef PHP_DEBUG
+#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)
+# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
+ ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args)
+# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
+ ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args)
+#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) {
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;
}
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); \