/src/php-src/Zend/zend_smart_string.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright (c) The PHP Group | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to version 3.01 of the PHP license, | |
6 | | | that is bundled with this package in the file LICENSE, and is | |
7 | | | available through the world-wide-web at the following url: | |
8 | | | https://www.php.net/license/3_01.txt | |
9 | | | If you did not receive a copy of the PHP license and are unable to | |
10 | | | obtain it through the world-wide-web, please send a note to | |
11 | | | license@php.net so we can mail you a copy immediately. | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Author: Sascha Schumann <sascha@schumann.cx> | |
14 | | | Xinchen Hui <laruence@php.net> | |
15 | | +----------------------------------------------------------------------+ |
16 | | */ |
17 | | |
18 | | #ifndef PHP_SMART_STRING_H |
19 | | #define PHP_SMART_STRING_H |
20 | | |
21 | | #include "zend_smart_string_public.h" |
22 | | |
23 | | #include <stdlib.h> |
24 | | #include <zend.h> |
25 | | |
26 | | /* wrapper */ |
27 | | |
28 | | #define smart_string_appends_ex(str, src, what) \ |
29 | | smart_string_appendl_ex((str), (src), strlen(src), (what)) |
30 | | #define smart_string_appends(str, src) \ |
31 | 0 | smart_string_appendl((str), (src), strlen(src)) |
32 | | #define smart_string_append_ex(str, src, what) \ |
33 | | smart_string_appendl_ex((str), ((smart_string *)(src))->c, \ |
34 | | ((smart_string *)(src))->len, (what)); |
35 | | #define smart_string_sets(str, src) \ |
36 | | smart_string_setl((str), (src), strlen(src)); |
37 | | |
38 | | #define smart_string_appendc(str, c) \ |
39 | 119M | smart_string_appendc_ex((str), (c), 0) |
40 | | #define smart_string_free(s) \ |
41 | 0 | smart_string_free_ex((s), 0) |
42 | | #define smart_string_appendl(str, src, len) \ |
43 | 10.7M | smart_string_appendl_ex((str), (src), (len), 0) |
44 | | #define smart_string_append(str, src) \ |
45 | | smart_string_append_ex((str), (src), 0) |
46 | | #define smart_string_append_long(str, val) \ |
47 | | smart_string_append_long_ex((str), (val), 0) |
48 | | #define smart_string_append_unsigned(str, val) \ |
49 | | smart_string_append_unsigned_ex((str), (val), 0) |
50 | | |
51 | | ZEND_API void smart_string_append_printf(smart_string *dest, const char *format, ...) |
52 | | ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); |
53 | | |
54 | | ZEND_API void ZEND_FASTCALL _smart_string_alloc_persistent(smart_string *str, size_t len); |
55 | | ZEND_API void ZEND_FASTCALL _smart_string_alloc(smart_string *str, size_t len); |
56 | | |
57 | 132M | static zend_always_inline size_t smart_string_alloc(smart_string *str, size_t len, bool persistent) { |
58 | 132M | if (UNEXPECTED(!str->c) || UNEXPECTED(len >= str->a - str->len)) { |
59 | 11.4M | if (persistent) { |
60 | 0 | _smart_string_alloc_persistent(str, len); |
61 | 11.4M | } else { |
62 | 11.4M | _smart_string_alloc(str, len); |
63 | 11.4M | } |
64 | 11.4M | } |
65 | 132M | return str->len + len; |
66 | 132M | } Unexecuted instantiation: main.c:smart_string_alloc Unexecuted instantiation: php_syslog.c:smart_string_alloc Unexecuted instantiation: rfc1867.c:smart_string_alloc spprintf.c:smart_string_alloc Line | Count | Source | 57 | 132M | static zend_always_inline size_t smart_string_alloc(smart_string *str, size_t len, bool persistent) { | 58 | 132M | if (UNEXPECTED(!str->c) || UNEXPECTED(len >= str->a - str->len)) { | 59 | 11.4M | if (persistent) { | 60 | 0 | _smart_string_alloc_persistent(str, len); | 61 | 11.4M | } else { | 62 | 11.4M | _smart_string_alloc(str, len); | 63 | 11.4M | } | 64 | 11.4M | } | 65 | 132M | return str->len + len; | 66 | 132M | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_alloc Unexecuted instantiation: zend.c:smart_string_alloc |
67 | | |
68 | 0 | static zend_always_inline void smart_string_free_ex(smart_string *str, bool persistent) { |
69 | 0 | if (str->c) { |
70 | 0 | pefree(str->c, persistent); |
71 | 0 | str->c = NULL; |
72 | 0 | } |
73 | 0 | str->a = str->len = 0; |
74 | 0 | } Unexecuted instantiation: main.c:smart_string_free_ex Unexecuted instantiation: php_syslog.c:smart_string_free_ex Unexecuted instantiation: rfc1867.c:smart_string_free_ex Unexecuted instantiation: spprintf.c:smart_string_free_ex Unexecuted instantiation: zend_smart_str.c:smart_string_free_ex Unexecuted instantiation: zend.c:smart_string_free_ex |
75 | | |
76 | 11.4M | static zend_always_inline void smart_string_0(smart_string *str) { |
77 | 11.4M | if (str->c) { |
78 | 11.4M | str->c[str->len] = '\0'; |
79 | 11.4M | } |
80 | 11.4M | } Unexecuted instantiation: main.c:smart_string_0 Unexecuted instantiation: php_syslog.c:smart_string_0 Unexecuted instantiation: rfc1867.c:smart_string_0 Unexecuted instantiation: spprintf.c:smart_string_0 Unexecuted instantiation: zend_smart_str.c:smart_string_0 Line | Count | Source | 76 | 11.4M | static zend_always_inline void smart_string_0(smart_string *str) { | 77 | 11.4M | if (str->c) { | 78 | 11.4M | str->c[str->len] = '\0'; | 79 | 11.4M | } | 80 | 11.4M | } |
|
81 | | |
82 | 119M | static zend_always_inline void smart_string_appendc_ex(smart_string *dest, char ch, bool persistent) { |
83 | 119M | dest->len = smart_string_alloc(dest, 1, persistent); |
84 | 119M | dest->c[dest->len - 1] = ch; |
85 | 119M | } Unexecuted instantiation: main.c:smart_string_appendc_ex Unexecuted instantiation: php_syslog.c:smart_string_appendc_ex Unexecuted instantiation: rfc1867.c:smart_string_appendc_ex spprintf.c:smart_string_appendc_ex Line | Count | Source | 82 | 119M | static zend_always_inline void smart_string_appendc_ex(smart_string *dest, char ch, bool persistent) { | 83 | 119M | dest->len = smart_string_alloc(dest, 1, persistent); | 84 | 119M | dest->c[dest->len - 1] = ch; | 85 | 119M | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_appendc_ex Unexecuted instantiation: zend.c:smart_string_appendc_ex |
86 | | |
87 | 10.7M | static zend_always_inline void smart_string_appendl_ex(smart_string *dest, const char *str, size_t len, bool persistent) { |
88 | 10.7M | size_t new_len = smart_string_alloc(dest, len, persistent); |
89 | 10.7M | memcpy(dest->c + dest->len, str, len); |
90 | 10.7M | dest->len = new_len; |
91 | | |
92 | 10.7M | } Unexecuted instantiation: main.c:smart_string_appendl_ex Unexecuted instantiation: php_syslog.c:smart_string_appendl_ex Unexecuted instantiation: rfc1867.c:smart_string_appendl_ex spprintf.c:smart_string_appendl_ex Line | Count | Source | 87 | 10.7M | static zend_always_inline void smart_string_appendl_ex(smart_string *dest, const char *str, size_t len, bool persistent) { | 88 | 10.7M | size_t new_len = smart_string_alloc(dest, len, persistent); | 89 | 10.7M | memcpy(dest->c + dest->len, str, len); | 90 | 10.7M | dest->len = new_len; | 91 | | | 92 | 10.7M | } |
Unexecuted instantiation: zend_smart_str.c:smart_string_appendl_ex Unexecuted instantiation: zend.c:smart_string_appendl_ex |
93 | | |
94 | 0 | static zend_always_inline void smart_string_append_long_ex(smart_string *dest, zend_long num, bool persistent) { |
95 | 0 | char buf[32]; |
96 | 0 | char *result = zend_print_long_to_buf(buf + sizeof(buf) - 1, num); |
97 | 0 | smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); |
98 | 0 | } Unexecuted instantiation: main.c:smart_string_append_long_ex Unexecuted instantiation: php_syslog.c:smart_string_append_long_ex Unexecuted instantiation: rfc1867.c:smart_string_append_long_ex Unexecuted instantiation: spprintf.c:smart_string_append_long_ex Unexecuted instantiation: zend_smart_str.c:smart_string_append_long_ex Unexecuted instantiation: zend.c:smart_string_append_long_ex |
99 | | |
100 | 0 | static zend_always_inline void smart_string_append_unsigned_ex(smart_string *dest, zend_ulong num, bool persistent) { |
101 | 0 | char buf[32]; |
102 | 0 | char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num); |
103 | 0 | smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); |
104 | 0 | } Unexecuted instantiation: main.c:smart_string_append_unsigned_ex Unexecuted instantiation: php_syslog.c:smart_string_append_unsigned_ex Unexecuted instantiation: rfc1867.c:smart_string_append_unsigned_ex Unexecuted instantiation: spprintf.c:smart_string_append_unsigned_ex Unexecuted instantiation: zend_smart_str.c:smart_string_append_unsigned_ex Unexecuted instantiation: zend.c:smart_string_append_unsigned_ex |
105 | | |
106 | 0 | static zend_always_inline void smart_string_setl(smart_string *dest, char *src, size_t len) { |
107 | 0 | dest->len = len; |
108 | 0 | dest->a = len + 1; |
109 | 0 | dest->c = src; |
110 | 0 | } Unexecuted instantiation: main.c:smart_string_setl Unexecuted instantiation: php_syslog.c:smart_string_setl Unexecuted instantiation: rfc1867.c:smart_string_setl Unexecuted instantiation: spprintf.c:smart_string_setl Unexecuted instantiation: zend_smart_str.c:smart_string_setl Unexecuted instantiation: zend.c:smart_string_setl |
111 | | |
112 | 0 | static zend_always_inline void smart_string_reset(smart_string *str) { |
113 | 0 | str->len = 0; |
114 | 0 | } Unexecuted instantiation: main.c:smart_string_reset Unexecuted instantiation: php_syslog.c:smart_string_reset Unexecuted instantiation: rfc1867.c:smart_string_reset Unexecuted instantiation: spprintf.c:smart_string_reset Unexecuted instantiation: zend_smart_str.c:smart_string_reset Unexecuted instantiation: zend.c:smart_string_reset |
115 | | |
116 | | #endif |