berns 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/berns/sds.h ADDED
@@ -0,0 +1,274 @@
1
+ /* SDSLib 2.0 -- A C dynamic strings library
2
+ *
3
+ * Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
4
+ * Copyright (c) 2015, Oran Agra
5
+ * Copyright (c) 2015, Redis Labs, Inc
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions are met:
10
+ *
11
+ * * Redistributions of source code must retain the above copyright notice,
12
+ * this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * * Neither the name of Redis nor the names of its contributors may be used
17
+ * to endorse or promote products derived from this software without
18
+ * specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ #ifndef __SDS_H
34
+ #define __SDS_H
35
+
36
+ #define SDS_MAX_PREALLOC (1024*1024)
37
+ extern const char *SDS_NOINIT;
38
+
39
+ #include <sys/types.h>
40
+ #include <stdarg.h>
41
+ #include <stdint.h>
42
+
43
+ typedef char *sds;
44
+
45
+ /* Note: sdshdr5 is never used, we just access the flags byte directly.
46
+ * However is here to document the layout of type 5 SDS strings. */
47
+ struct __attribute__ ((__packed__)) sdshdr5 {
48
+ unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
49
+ char buf[];
50
+ };
51
+ struct __attribute__ ((__packed__)) sdshdr8 {
52
+ uint8_t len; /* used */
53
+ uint8_t alloc; /* excluding the header and null terminator */
54
+ unsigned char flags; /* 3 lsb of type, 5 unused bits */
55
+ char buf[];
56
+ };
57
+ struct __attribute__ ((__packed__)) sdshdr16 {
58
+ uint16_t len; /* used */
59
+ uint16_t alloc; /* excluding the header and null terminator */
60
+ unsigned char flags; /* 3 lsb of type, 5 unused bits */
61
+ char buf[];
62
+ };
63
+ struct __attribute__ ((__packed__)) sdshdr32 {
64
+ uint32_t len; /* used */
65
+ uint32_t alloc; /* excluding the header and null terminator */
66
+ unsigned char flags; /* 3 lsb of type, 5 unused bits */
67
+ char buf[];
68
+ };
69
+ struct __attribute__ ((__packed__)) sdshdr64 {
70
+ uint64_t len; /* used */
71
+ uint64_t alloc; /* excluding the header and null terminator */
72
+ unsigned char flags; /* 3 lsb of type, 5 unused bits */
73
+ char buf[];
74
+ };
75
+
76
+ #define SDS_TYPE_5 0
77
+ #define SDS_TYPE_8 1
78
+ #define SDS_TYPE_16 2
79
+ #define SDS_TYPE_32 3
80
+ #define SDS_TYPE_64 4
81
+ #define SDS_TYPE_MASK 7
82
+ #define SDS_TYPE_BITS 3
83
+ #define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
84
+ #define SDS_HDR(T,s) ((struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T))))
85
+ #define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS)
86
+
87
+ static inline size_t sdslen(const sds s) {
88
+ unsigned char flags = s[-1];
89
+ switch(flags&SDS_TYPE_MASK) {
90
+ case SDS_TYPE_5:
91
+ return SDS_TYPE_5_LEN(flags);
92
+ case SDS_TYPE_8:
93
+ return SDS_HDR(8,s)->len;
94
+ case SDS_TYPE_16:
95
+ return SDS_HDR(16,s)->len;
96
+ case SDS_TYPE_32:
97
+ return SDS_HDR(32,s)->len;
98
+ case SDS_TYPE_64:
99
+ return SDS_HDR(64,s)->len;
100
+ }
101
+ return 0;
102
+ }
103
+
104
+ static inline size_t sdsavail(const sds s) {
105
+ unsigned char flags = s[-1];
106
+ switch(flags&SDS_TYPE_MASK) {
107
+ case SDS_TYPE_5: {
108
+ return 0;
109
+ }
110
+ case SDS_TYPE_8: {
111
+ SDS_HDR_VAR(8,s);
112
+ return sh->alloc - sh->len;
113
+ }
114
+ case SDS_TYPE_16: {
115
+ SDS_HDR_VAR(16,s);
116
+ return sh->alloc - sh->len;
117
+ }
118
+ case SDS_TYPE_32: {
119
+ SDS_HDR_VAR(32,s);
120
+ return sh->alloc - sh->len;
121
+ }
122
+ case SDS_TYPE_64: {
123
+ SDS_HDR_VAR(64,s);
124
+ return sh->alloc - sh->len;
125
+ }
126
+ }
127
+ return 0;
128
+ }
129
+
130
+ static inline void sdssetlen(sds s, size_t newlen) {
131
+ unsigned char flags = s[-1];
132
+ switch(flags&SDS_TYPE_MASK) {
133
+ case SDS_TYPE_5:
134
+ {
135
+ unsigned char *fp = ((unsigned char*)s)-1;
136
+ *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
137
+ }
138
+ break;
139
+ case SDS_TYPE_8:
140
+ SDS_HDR(8,s)->len = newlen;
141
+ break;
142
+ case SDS_TYPE_16:
143
+ SDS_HDR(16,s)->len = newlen;
144
+ break;
145
+ case SDS_TYPE_32:
146
+ SDS_HDR(32,s)->len = newlen;
147
+ break;
148
+ case SDS_TYPE_64:
149
+ SDS_HDR(64,s)->len = newlen;
150
+ break;
151
+ }
152
+ }
153
+
154
+ static inline void sdsinclen(sds s, size_t inc) {
155
+ unsigned char flags = s[-1];
156
+ switch(flags&SDS_TYPE_MASK) {
157
+ case SDS_TYPE_5:
158
+ {
159
+ unsigned char *fp = ((unsigned char*)s)-1;
160
+ unsigned char newlen = SDS_TYPE_5_LEN(flags)+inc;
161
+ *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
162
+ }
163
+ break;
164
+ case SDS_TYPE_8:
165
+ SDS_HDR(8,s)->len += inc;
166
+ break;
167
+ case SDS_TYPE_16:
168
+ SDS_HDR(16,s)->len += inc;
169
+ break;
170
+ case SDS_TYPE_32:
171
+ SDS_HDR(32,s)->len += inc;
172
+ break;
173
+ case SDS_TYPE_64:
174
+ SDS_HDR(64,s)->len += inc;
175
+ break;
176
+ }
177
+ }
178
+
179
+ /* sdsalloc() = sdsavail() + sdslen() */
180
+ static inline size_t sdsalloc(const sds s) {
181
+ unsigned char flags = s[-1];
182
+ switch(flags&SDS_TYPE_MASK) {
183
+ case SDS_TYPE_5:
184
+ return SDS_TYPE_5_LEN(flags);
185
+ case SDS_TYPE_8:
186
+ return SDS_HDR(8,s)->alloc;
187
+ case SDS_TYPE_16:
188
+ return SDS_HDR(16,s)->alloc;
189
+ case SDS_TYPE_32:
190
+ return SDS_HDR(32,s)->alloc;
191
+ case SDS_TYPE_64:
192
+ return SDS_HDR(64,s)->alloc;
193
+ }
194
+ return 0;
195
+ }
196
+
197
+ static inline void sdssetalloc(sds s, size_t newlen) {
198
+ unsigned char flags = s[-1];
199
+ switch(flags&SDS_TYPE_MASK) {
200
+ case SDS_TYPE_5:
201
+ /* Nothing to do, this type has no total allocation info. */
202
+ break;
203
+ case SDS_TYPE_8:
204
+ SDS_HDR(8,s)->alloc = newlen;
205
+ break;
206
+ case SDS_TYPE_16:
207
+ SDS_HDR(16,s)->alloc = newlen;
208
+ break;
209
+ case SDS_TYPE_32:
210
+ SDS_HDR(32,s)->alloc = newlen;
211
+ break;
212
+ case SDS_TYPE_64:
213
+ SDS_HDR(64,s)->alloc = newlen;
214
+ break;
215
+ }
216
+ }
217
+
218
+ sds sdsnewlen(const void *init, size_t initlen);
219
+ sds sdsnew(const char *init);
220
+ sds sdsempty(void);
221
+ sds sdsdup(const sds s);
222
+ void sdsfree(sds s);
223
+ sds sdsgrowzero(sds s, size_t len);
224
+ sds sdscatlen(sds s, const void *t, size_t len);
225
+ sds sdscat(sds s, const char *t);
226
+ sds sdscatsds(sds s, const sds t);
227
+ sds sdscpylen(sds s, const char *t, size_t len);
228
+ sds sdscpy(sds s, const char *t);
229
+
230
+ sds sdscatvprintf(sds s, const char *fmt, va_list ap);
231
+ #ifdef __GNUC__
232
+ sds sdscatprintf(sds s, const char *fmt, ...)
233
+ __attribute__((format(printf, 2, 3)));
234
+ #else
235
+ sds sdscatprintf(sds s, const char *fmt, ...);
236
+ #endif
237
+
238
+ sds sdscatfmt(sds s, char const *fmt, ...);
239
+ sds sdstrim(sds s, const char *cset);
240
+ void sdsrange(sds s, ssize_t start, ssize_t end);
241
+ void sdsupdatelen(sds s);
242
+ void sdsclear(sds s);
243
+ int sdscmp(const sds s1, const sds s2);
244
+ sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *count);
245
+ void sdsfreesplitres(sds *tokens, int count);
246
+ void sdstolower(sds s);
247
+ void sdstoupper(sds s);
248
+ sds sdsfromlonglong(long long value);
249
+ sds sdscatrepr(sds s, const char *p, size_t len);
250
+ sds *sdssplitargs(const char *line, int *argc);
251
+ sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
252
+ sds sdsjoin(char **argv, int argc, char *sep);
253
+ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);
254
+
255
+ /* Low level functions exposed to the user API */
256
+ sds sdsMakeRoomFor(sds s, size_t addlen);
257
+ void sdsIncrLen(sds s, ssize_t incr);
258
+ sds sdsRemoveFreeSpace(sds s);
259
+ size_t sdsAllocSize(sds s);
260
+ void *sdsAllocPtr(sds s);
261
+
262
+ /* Export the allocator used by SDS to the program using SDS.
263
+ * Sometimes the program SDS is linked to, may use a different set of
264
+ * allocators, but may want to allocate or free things that SDS will
265
+ * respectively free or allocate. */
266
+ void *sds_malloc(size_t size);
267
+ void *sds_realloc(void *ptr, size_t size);
268
+ void sds_free(void *ptr);
269
+
270
+ #ifdef REDIS_TEST
271
+ int sdsTest(int argc, char *argv[]);
272
+ #endif
273
+
274
+ #endif
@@ -0,0 +1,42 @@
1
+ /* SDSLib 2.0 -- A C dynamic strings library
2
+ *
3
+ * Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
4
+ * Copyright (c) 2015, Oran Agra
5
+ * Copyright (c) 2015, Redis Labs, Inc
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions are met:
10
+ *
11
+ * * Redistributions of source code must retain the above copyright notice,
12
+ * this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * * Neither the name of Redis nor the names of its contributors may be used
17
+ * to endorse or promote products derived from this software without
18
+ * specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ /* SDS allocator selection.
34
+ *
35
+ * This file is used in order to change the SDS allocator at compile time.
36
+ * Just define the following defines to what you want to use. Also add
37
+ * the include of your alternate allocator if needed (not needed in order
38
+ * to use the default libc allocator). */
39
+
40
+ #define s_malloc malloc
41
+ #define s_realloc realloc
42
+ #define s_free free
Binary file
data/lib/berns/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Berns
3
- VERSION = '3.5.0'
3
+ VERSION = '4.0.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berns
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Beck
@@ -9,148 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-15 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: benchmark-ips
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: bundler
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: minitest
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: rake-compiler
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: rubocop
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: rubocop-minitest
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- - !ruby/object:Gem::Dependency
113
- name: rubocop-packaging
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: rubocop-performance
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: '0'
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- - !ruby/object:Gem::Dependency
141
- name: rubocop-rake
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: '0'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- version: '0'
12
+ date: 2022-05-24 00:00:00.000000000 Z
13
+ dependencies: []
154
14
  description: A utility library for generating HTML strings.
155
15
  email:
156
16
  - beck.taylorg@gmail.com
@@ -166,6 +26,9 @@ files:
166
26
  - ext/berns/extconf.rb
167
27
  - ext/berns/hescape.c
168
28
  - ext/berns/hescape.h
29
+ - ext/berns/sds.c
30
+ - ext/berns/sds.h
31
+ - ext/berns/sdsalloc.h
169
32
  - lib/berns.rb
170
33
  - lib/berns/berns.bundle
171
34
  - lib/berns/builder.rb
@@ -175,6 +38,8 @@ licenses:
175
38
  - MIT
176
39
  metadata:
177
40
  bug_tracker_uri: https://github.com/evanleck/berns/issues
41
+ changelog_uri: https://github.com/evanleck/berns/blob/main/CHANGELOG.org
42
+ homepage_uri: https://github.com/evanleck/berns
178
43
  rubygems_mfa_required: 'true'
179
44
  source_code_uri: https://github.com/evanleck/berns
180
45
  post_install_message:
@@ -185,14 +50,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
50
  requirements:
186
51
  - - ">="
187
52
  - !ruby/object:Gem::Version
188
- version: 2.5.0
53
+ version: 2.7.0
189
54
  required_rubygems_version: !ruby/object:Gem::Requirement
190
55
  requirements:
191
56
  - - ">="
192
57
  - !ruby/object:Gem::Version
193
58
  version: '2.0'
194
59
  requirements: []
195
- rubygems_version: 3.3.3
60
+ rubygems_version: 3.3.7
196
61
  signing_key:
197
62
  specification_version: 4
198
63
  summary: A utility library for generating HTML strings.