10 +# if defined __has_attribute
11 +# if __has_attribute (pure)
12 +# define ATTR_PURE __attribute__ ((pure))
20 /* byte_chr returns the smallest integer i between 0 and len-1
21 * inclusive such that one[i] equals needle, or len if not found. */
22 -size_t byte_chr(const void* haystack, size_t len, char needle) __pure__;
23 +size_t byte_chr(const void* haystack, size_t len, char needle) ATTR_PURE;
25 /* byte_rchr returns the largest integer i between 0 and len-1 inclusive
26 * such that one[i] equals needle, or len if not found. */
27 -size_t byte_rchr(const void* haystack,size_t len,char needle) __pure__;
28 +size_t byte_rchr(const void* haystack,size_t len,char needle) ATTR_PURE;
30 /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
32 @@ -34,14 +41,14 @@ void byte_copyr(void* out, size_t len, c
33 * than, equal to, or greater than the string b[0], b[1], ...,
34 * b[len-1]. When the strings are different, byte_diff does not read
35 * bytes past the first difference. */
36 -int byte_diff(const void* a, size_t len, const void* b) __pure__;
37 +int byte_diff(const void* a, size_t len, const void* b) ATTR_PURE;
39 /* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */
40 void byte_zero(void* out, size_t len);
42 #define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
44 -int byte_equal_notimingattack(const void* a, size_t len,const void* b) __pure__;
45 +int byte_equal_notimingattack(const void* a, size_t len,const void* b) ATTR_PURE;
47 #if defined(__i386__) || defined(__x86_64__)
48 #define UNALIGNED_ACCESS_OK
55 -/* for __pure__ if we are compiling under dietlibc */
56 +/* for ATTR_PURE if we are compiling under dietlibc */
62 +# if defined __has_attribute
63 +# if __has_attribute (pure)
64 +# define ATTR_PURE __attribute__ ((pure))
76 -int critbit0_contains(critbit0_tree *t, const char *u) __pure__;
77 +int critbit0_contains(critbit0_tree *t, const char *u) ATTR_PURE;
78 int critbit0_insert(critbit0_tree *t, const char *u);
79 int critbit0_delete(critbit0_tree *t, const char *u);
80 void critbit0_clear(critbit0_tree *t);
90 +# if defined __has_attribute
91 +# if __has_attribute (pure)
92 +# define ATTR_PURE __attribute__ ((pure))
100 /* This file declared functions used to decode / scan / unmarshal
101 @@ -84,18 +91,18 @@ size_t scan_double(const char *in, doubl
102 size_t scan_plusminus(const char *src,signed int *dest);
104 /* return the highest integer n<=limit so that isspace(in[i]) for all 0<=i<=n */
105 -size_t scan_whitenskip(const char *in,size_t limit) __pure__;
106 +size_t scan_whitenskip(const char *in,size_t limit) ATTR_PURE;
108 /* return the highest integer n<=limit so that !isspace(in[i]) for all 0<=i<=n */
109 -size_t scan_nonwhitenskip(const char *in,size_t limit) __pure__;
110 +size_t scan_nonwhitenskip(const char *in,size_t limit) ATTR_PURE;
112 /* return the highest integer n<=limit so that in[i] is element of
113 * charset (ASCIIZ string) for all 0<=i<=n */
114 -size_t scan_charsetnskip(const char *in,const char *charset,size_t limit) __pure__;
115 +size_t scan_charsetnskip(const char *in,const char *charset,size_t limit) ATTR_PURE;
117 /* return the highest integer n<=limit so that in[i] is not element of
118 * charset (ASCIIZ string) for all 0<=i<=n */
119 -size_t scan_noncharsetnskip(const char *in,const char *charset,size_t limit) __pure__;
120 +size_t scan_noncharsetnskip(const char *in,const char *charset,size_t limit) ATTR_PURE;
122 /* try to parse ASCII GMT date; does not understand time zones. */
124 @@ -103,17 +110,17 @@ size_t scan_noncharsetnskip(const char *
125 * "Sunday, 06-Nov-94 08:49:37 GMT"
126 * "Sun Nov 6 08:49:37 1994"
128 -size_t scan_httpdate(const char *in,time_t *t) __pure__;
129 +size_t scan_httpdate(const char *in,time_t *t) ATTR_PURE;
131 /* try to parse ASCII ISO-8601 date; does not understand time zones. */
132 /* example date: "2014-05-27T19:22:16Z" */
133 -size_t scan_iso8601(const char* in,struct timespec* t) __pure__;
134 +size_t scan_iso8601(const char* in,struct timespec* t) ATTR_PURE;
136 /* some variable length encodings for integers */
137 -size_t scan_utf8(const char* in,size_t len,uint32_t* n) __pure__;
138 -size_t scan_utf8_sem(const char* in,size_t len,uint32_t* n) __pure__;
139 -size_t scan_asn1derlength(const char* in,size_t len,unsigned long long* n) __pure__;
140 -size_t scan_asn1dertag(const char* in,size_t len,unsigned long long* n) __pure__;
141 +size_t scan_utf8(const char* in,size_t len,uint32_t* n) ATTR_PURE;
142 +size_t scan_utf8_sem(const char* in,size_t len,uint32_t* n) ATTR_PURE;
143 +size_t scan_asn1derlength(const char* in,size_t len,unsigned long long* n) ATTR_PURE;
144 +size_t scan_asn1dertag(const char* in,size_t len,unsigned long long* n) ATTR_PURE;
146 /* Google protocol buffers */
147 /* A protocol buffer is a sequence of (tag,value).
148 @@ -122,15 +129,15 @@ size_t scan_asn1dertag(const char* in,si
149 * 0, double type 1, strings type 2 and floats type 5. However, you
150 * have to check this yourself.
152 -size_t scan_varint(const char* in,size_t len, unsigned long long* n) __pure__; /* internal */
153 -size_t scan_pb_tag(const char* in,size_t len, size_t* fieldno,unsigned char* type) __pure__;
154 +size_t scan_varint(const char* in,size_t len, unsigned long long* n) ATTR_PURE; /* internal */
155 +size_t scan_pb_tag(const char* in,size_t len, size_t* fieldno,unsigned char* type) ATTR_PURE;
157 /* Then, depending on the field number, validate the type and call the
158 * corresponding of these functions to parse the value */
159 -size_t scan_pb_type0_int(const char* in,size_t len,unsigned long long* l) __pure__;
160 -size_t scan_pb_type0_sint(const char* in,size_t len,signed long long* l) __pure__;
161 -size_t scan_pb_type1_double(const char* in,size_t len,double* d) __pure__;
162 -size_t scan_pb_type1_fixed64(const char* in,size_t len,uint64_t* b) __pure__;
163 +size_t scan_pb_type0_int(const char* in,size_t len,unsigned long long* l) ATTR_PURE;
164 +size_t scan_pb_type0_sint(const char* in,size_t len,signed long long* l) ATTR_PURE;
165 +size_t scan_pb_type1_double(const char* in,size_t len,double* d) ATTR_PURE;
166 +size_t scan_pb_type1_fixed64(const char* in,size_t len,uint64_t* b) ATTR_PURE;
167 /* NOTE: scan_pb_type2_stringlen only parses the length of the string,
168 * not the string itself. It will return the number of bytes parsed in
169 * the length, then set slen to the value of the length integer it just
170 @@ -141,9 +148,9 @@ size_t scan_pb_type1_fixed64(const char*
171 * parsing early without having to read and allocate memory for the rest
172 * (potentially gigabytes) of the data announced by one unreasonable
173 * string length value. */
174 -size_t scan_pb_type2_stringlen(const char* in,size_t len,const char** string, size_t* slen) __pure__;
175 -size_t scan_pb_type5_float(const char* in,size_t len,float* f) __pure__;
176 -size_t scan_pb_type5_fixed32(const char* in,size_t len,uint32_t* b) __pure__;
177 +size_t scan_pb_type2_stringlen(const char* in,size_t len,const char** string, size_t* slen) ATTR_PURE;
178 +size_t scan_pb_type5_float(const char* in,size_t len,float* f) ATTR_PURE;
179 +size_t scan_pb_type5_fixed32(const char* in,size_t len,uint32_t* b) ATTR_PURE;
181 /* parse a netstring, input buffer is in (len bytes).
182 * if parsing is successful:
183 @@ -153,7 +160,7 @@ size_t scan_pb_type5_fixed32(const char*
185 * Note: *dest will point inside the input buffer!
187 -size_t scan_netstring(const char* in,size_t len,char** dest,size_t* slen) __pure__;
188 +size_t scan_netstring(const char* in,size_t len,char** dest,size_t* slen) ATTR_PURE;
190 /* internal function that might be useful independently */
191 /* convert from hex ASCII, return 0 to 15 for success or -1 for failure */
201 +# if defined __has_attribute
202 +# if __has_attribute (pure)
203 +# define ATTR_PURE __attribute__ ((pure))
211 /* str_copy copies leading bytes from in to out until \0.
212 @@ -21,7 +28,7 @@ size_t str_copy(char *out,const char *in
213 * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
214 * If the strings are different, str_diff does not read bytes past the
215 * first difference. */
216 -int str_diff(const char *a,const char *b) __pure__;
217 +int str_diff(const char *a,const char *b) ATTR_PURE;
219 /* str_diffn returns negative, 0, or positive, depending on whether the
220 * string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
221 @@ -29,24 +36,24 @@ int str_diff(const char *a,const char *b
222 * If the strings are different, str_diffn does not read bytes past the
223 * first difference. The strings will be considered equal if the first
224 * limit characters match. */
225 -int str_diffn(const char *a,const char *b,size_t limit) __pure__;
226 +int str_diffn(const char *a,const char *b,size_t limit) ATTR_PURE;
230 #define str_len(foo) strlen(foo)
232 /* str_len returns the index of \0 in s */
233 -size_t str_len(const char *s) __pure__;
234 +size_t str_len(const char *s) ATTR_PURE;
237 /* str_chr returns the index of the first occurance of needle or \0 in haystack */
238 -size_t str_chr(const char *haystack,char needle) __pure__;
239 +size_t str_chr(const char *haystack,char needle) ATTR_PURE;
241 /* str_rchr returns the index of the last occurance of needle or \0 in haystack */
242 -size_t str_rchr(const char *haystack,char needle) __pure__;
243 +size_t str_rchr(const char *haystack,char needle) ATTR_PURE;
245 /* str_start returns 1 if the b is a prefix of a, 0 otherwise */
246 -int str_start(const char *a,const char *b) __pure__;
247 +int str_start(const char *a,const char *b) ATTR_PURE;
249 /* convenience shortcut to test for string equality */
250 #define str_equal(s,t) (!str_diff((s),(t)))
260 +# if defined __has_attribute
261 +# if __has_attribute (pure)
262 +# define ATTR_PURE __attribute__ ((pure))
270 /* stralloc is the internal data structure all functions are working on.
271 @@ -101,17 +108,17 @@ static inline int stralloc_APPEND(strall
272 /* stralloc_starts returns 1 if the \0-terminated string in "in", without
273 * the terminating \0, is a prefix of the string stored in sa. Otherwise
274 * it returns 0. sa must already be allocated. */
275 -int stralloc_starts(stralloc* sa,const char* in) __pure__;
276 +int stralloc_starts(stralloc* sa,const char* in) ATTR_PURE;
278 /* stralloc_diff returns negative, 0, or positive, depending on whether
279 * a is lexicographically smaller than, equal to, or greater than the
281 -int stralloc_diff(const stralloc* a,const stralloc* b) __pure__;
282 +int stralloc_diff(const stralloc* a,const stralloc* b) ATTR_PURE;
284 /* stralloc_diffs returns negative, 0, or positive, depending on whether
285 * a is lexicographically smaller than, equal to, or greater than the
286 * string b[0], b[1], ..., b[n]=='\0'. */
287 -int stralloc_diffs(const stralloc* a,const char* b) __pure__;
288 +int stralloc_diffs(const stralloc* a,const char* b) ATTR_PURE;
290 #define stralloc_equal(a,b) (!stralloc_diff((a),(b)))
291 #define stralloc_equals(a,b) (!stralloc_diffs((a),(b)))