| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| #define NEED_sv_2pvbyte |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| |
| 7 |
|
| #define BUFFER_MAX_REUSE_SIZE (4 * 1024) |
| 8 |
|
| #define BUFFER_PIECE_SIZE 64 |
| 9 |
|
| |
| 10 |
|
| #include <assert.h> |
| 11 |
|
| #include <stdlib.h> |
| 12 |
|
| #include <string.h> |
| 13 |
|
| |
| 14 |
|
| #include <arpa/inet.h> |
| 15 |
|
| |
| 16 |
|
| #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) |
| 17 |
|
| #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 18 |
|
| #define __LITTLE_ENDIAN__ |
| 19 |
|
| #elif __BYTE_ORDER == __BIG_ENDIAN |
| 20 |
|
| #define __BIG_ENDIAN__ |
| 21 |
|
| #endif |
| 22 |
|
| #endif |
| 23 |
|
| |
| 24 |
|
| typedef struct { |
| 25 |
|
| char* ptr; |
| 26 |
|
| size_t used; |
| 27 |
|
| size_t size; |
| 28 |
|
| } buffer; |
| 29 |
|
| |
| 30 |
|
| static buffer* buffer_init(void); |
| 31 |
|
| static buffer* buffer_init_buffer(buffer* b); |
| 32 |
|
| static buffer* buffer_init_string(const char* str); |
| 33 |
|
| static void buffer_free(buffer* b); |
| 34 |
|
| static void buffer_reset(buffer* b); |
| 35 |
|
| |
| 36 |
|
| static int buffer_prepare_copy(buffer* b, size_t size); |
| 37 |
|
| static int buffer_prepare_append(buffer* b, size_t size); |
| 38 |
|
| |
| 39 |
|
| static int buffer_copy_string(buffer* b, const char* s); |
| 40 |
|
| static int buffer_copy_string_len(buffer* b, const char* s, size_t s_len); |
| 41 |
|
| static int buffer_copy_string_buffer(buffer* b, const buffer* src); |
| 42 |
|
| |
| 43 |
|
| static int buffer_append_string(buffer* b, const char* s); |
| 44 |
|
| static int buffer_append_string_len(buffer* b, const char* s, size_t s_len); |
| 45 |
|
| static int buffer_append_string_buffer(buffer* b, const buffer* src); |
| 46 |
|
| |
| 47 |
|
| static int buffer_spin(buffer* b, size_t len); |
| 48 |
|
| |
| 49 |
22 |
| static buffer* buffer_init(void) { |
| 50 |
|
| buffer* b; |
| 51 |
|
| |
| 52 |
22 |
| b = calloc(1, sizeof(buffer)); |
| 53 |
|
| assert(b); |
| 54 |
|
| |
| 55 |
22 |
| return b; |
| 56 |
|
| } |
| 57 |
|
| |
| 58 |
0 |
| static buffer* buffer_init_buffer(buffer* src) { |
| 59 |
0 |
| buffer* b = buffer_init(); |
| 60 |
0 |
| buffer_copy_string_buffer(b, src); |
| 61 |
0 |
| return b; |
| 62 |
|
| } |
| 63 |
|
| |
| 64 |
22 |
| static void buffer_free(buffer* b) { |
| 65 |
22 |
▶ | if (!b) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) return; |
0 |
22 |
22 |
|
| 66 |
|
| |
| 67 |
22 |
| free(b->ptr); |
| 68 |
22 |
| free(b); |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
16 |
| static void buffer_reset(buffer* b) { |
| 72 |
16 |
▶ | if (!b) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) return; |
0 |
16 |
16 |
|
| 73 |
|
| |
| 74 |
16 |
▶ | if (b->size > BUFFER_MAX_REUSE_SIZE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (b->size > BUFFER_MAX_REUSE_SIZE) { |
0 |
16 |
16 |
|
| 75 |
0 |
| free(b->ptr); |
| 76 |
0 |
| b->ptr = NULL; |
| 77 |
0 |
| b->size = 0; |
| 78 |
|
| } |
| 79 |
16 |
▶ | else if (b->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (b->size) { |
16 |
0 |
16 |
|
| 80 |
16 |
| b->ptr[0] = '\0'; |
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
16 |
| b->used = 0; |
| 84 |
|
| } |
| 85 |
|
| |
| 86 |
0 |
| static int buffer_prepare_copy(buffer* b, size_t size) { |
| 87 |
0 |
▶ | if (!b) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) return -1; |
0 |
0 |
0 |
|
| 88 |
|
| |
| 89 |
0 |
▶ | if ((0 == b->size) || (size > b->size)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((0 == b->size) || (size > b->size)) { |
0 |
0 |
0 |
| if ((0 == b->size) || (size > b->size)) { |
0 |
0 |
0 |
|
| 90 |
0 |
▶ | if (b->size) free(b->ptr); |
Branch: 1 branch
| Branch | True | False | Total |
| if (b->size) free(b->ptr); |
0 |
0 |
0 |
|
| 91 |
|
| |
| 92 |
0 |
| b->size = size; |
| 93 |
0 |
| b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
| 94 |
|
| |
| 95 |
0 |
| b->ptr = malloc(b->size); |
| 96 |
|
| assert(b->ptr); |
| 97 |
|
| } |
| 98 |
|
| |
| 99 |
0 |
| b->used = 0; |
| 100 |
0 |
| return 0; |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
62 |
| static int buffer_prepare_append(buffer* b, size_t size) { |
| 104 |
62 |
▶ | if (!b) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) return -1; |
0 |
62 |
62 |
|
| 105 |
|
| |
| 106 |
62 |
▶ | if (0 == b->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == b->size) { |
22 |
40 |
62 |
|
| 107 |
22 |
| b->size = size; |
| 108 |
22 |
| b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
| 109 |
|
| |
| 110 |
22 |
| b->ptr = malloc(b->size); |
| 111 |
|
| assert(b->ptr); |
| 112 |
22 |
| b->used = 0; |
| 113 |
|
| } |
| 114 |
40 |
▶ | else if (b->used + size > b->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (b->used + size > b->size) { |
0 |
40 |
40 |
|
| 115 |
0 |
| b->size += size; |
| 116 |
0 |
| b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
| 117 |
|
| |
| 118 |
0 |
| b->ptr = realloc(b->ptr, b->size); |
| 119 |
|
| assert(b->ptr); |
| 120 |
|
| } |
| 121 |
62 |
| return 0; |
| 122 |
|
| } |
| 123 |
|
| |
| 124 |
0 |
| static int buffer_copy_string(buffer* b, const char* s) { |
| 125 |
|
| size_t s_len; |
| 126 |
0 |
▶ | if (!s || !b) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!s || !b) return -1; |
0 |
0 |
0 |
| if (!s || !b) return -1; |
0 |
0 |
0 |
|
| 127 |
|
| |
| 128 |
0 |
| s_len = strlen(s) + 1; |
| 129 |
0 |
| buffer_prepare_append(b, s_len); |
| 130 |
|
| |
| 131 |
0 |
| memcpy(b->ptr, s, s_len); |
| 132 |
0 |
| b->used = s_len; |
| 133 |
|
| |
| 134 |
0 |
| return 0; |
| 135 |
|
| } |
| 136 |
|
| |
| 137 |
0 |
| static int buffer_copy_string_len(buffer* b, const char* s, size_t s_len) { |
| 138 |
0 |
▶ | if (!b || !s) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!b || !s) return -1; |
0 |
0 |
0 |
| if (!b || !s) return -1; |
0 |
0 |
0 |
|
| 139 |
|
| |
| 140 |
0 |
| buffer_prepare_copy(b, s_len+1); |
| 141 |
|
| |
| 142 |
0 |
| memcpy(b->ptr, s, s_len); |
| 143 |
0 |
| b->ptr[s_len] = '\0'; |
| 144 |
0 |
| b->used = s_len + 1; |
| 145 |
|
| |
| 146 |
0 |
| return 0; |
| 147 |
|
| } |
| 148 |
|
| |
| 149 |
0 |
| static int buffer_copy_string_buffer(buffer* b, const buffer* src) { |
| 150 |
0 |
▶ | if (!src) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!src) return -1; |
0 |
0 |
0 |
|
| 151 |
|
| |
| 152 |
0 |
▶ | if (src->used == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (src->used == 0) { |
0 |
0 |
0 |
|
| 153 |
0 |
| buffer_reset(b); |
| 154 |
0 |
| return 0; |
| 155 |
|
| } |
| 156 |
0 |
| return buffer_copy_string_len(b, src->ptr, src->used - 1); |
| 157 |
|
| } |
| 158 |
|
| |
| 159 |
0 |
| static int buffer_append_string(buffer* b, const char* s) { |
| 160 |
|
| size_t s_len; |
| 161 |
|
| |
| 162 |
0 |
▶ | if (!s || !b) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!s || !b) return -1; |
0 |
0 |
0 |
| if (!s || !b) return -1; |
0 |
0 |
0 |
|
| 163 |
|
| |
| 164 |
0 |
| s_len = strlen(s); |
| 165 |
0 |
| buffer_prepare_append(b, s_len + 1); |
| 166 |
0 |
▶ | if (0 == b->used) b->used++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == b->used) b->used++; |
0 |
0 |
0 |
|
| 167 |
|
| |
| 168 |
0 |
| memcpy(b->ptr + b->used - 1, s, s_len + 1); |
| 169 |
0 |
| b->used += s_len; |
| 170 |
|
| |
| 171 |
0 |
| return 0; |
| 172 |
|
| } |
| 173 |
|
| |
| 174 |
62 |
| static int buffer_append_string_len(buffer* b, const char* s, size_t s_len) { |
| 175 |
62 |
▶ | if (!s || !b) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!s || !b) return -1; |
62 |
0 |
62 |
| if (!s || !b) return -1; |
0 |
62 |
62 |
|
| 176 |
62 |
▶ | if (0 == s_len) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == s_len) return 0; |
0 |
62 |
62 |
|
| 177 |
|
| |
| 178 |
62 |
| buffer_prepare_append(b, s_len + 1); |
| 179 |
62 |
▶ | if (0 == b->used) b->used++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == b->used) b->used++; |
34 |
28 |
62 |
|
| 180 |
|
| |
| 181 |
62 |
| memcpy(b->ptr + b->used - 1, s, s_len); |
| 182 |
62 |
| b->used += s_len; |
| 183 |
62 |
| b->ptr[b->used - 1] = '\0'; |
| 184 |
|
| |
| 185 |
62 |
| return 0; |
| 186 |
|
| } |
| 187 |
|
| |
| 188 |
0 |
| static int buffer_append_string_buffer(buffer* b, const buffer* src) { |
| 189 |
0 |
▶ | if (!src) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!src) return -1; |
0 |
0 |
0 |
|
| 190 |
0 |
▶ | if (0 == src->used) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == src->used) return 0; |
0 |
0 |
0 |
|
| 191 |
|
| |
| 192 |
0 |
| return buffer_append_string_len(b, src->ptr, src->used - 1); |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
8 |
| static int buffer_spin(buffer* b, size_t len) { |
| 196 |
8 |
▶ | if (!b) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) return -1; |
0 |
8 |
8 |
|
| 197 |
8 |
▶ | if (0 == b->used) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (0 == b->used) return 0; |
0 |
8 |
8 |
|
| 198 |
|
| |
| 199 |
8 |
| size_t rest = b->used - len; |
| 200 |
8 |
▶ | if (rest > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rest > 0) { |
8 |
0 |
8 |
|
| 201 |
8 |
| memmove(b->ptr, b->ptr + len, rest); |
| 202 |
8 |
| b->used -= len; |
| 203 |
|
| } |
| 204 |
|
| else { |
| 205 |
0 |
| buffer_reset(b); |
| 206 |
|
| } |
| 207 |
|
| |
| 208 |
8 |
| return 0; |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
8 |
| static inline void buffer_append_u24(buffer* b, uint32_t n) { |
| 212 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 213 |
8 |
| buffer_append_string_len(b, (const char*)&n, 3); |
| 214 |
|
| #else |
| 215 |
|
| buffer_append_string_len(b, (const char*)&n + 1, 3); |
| 216 |
|
| #endif |
| 217 |
8 |
| } |
| 218 |
|
| |
| 219 |
6 |
| static inline void buffer_append_n32(buffer* b, uint32_t n) { |
| 220 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 221 |
6 |
| n = htonl(n); |
| 222 |
|
| #endif |
| 223 |
6 |
| buffer_append_string_len(b, (const char*)&n, 4); |
| 224 |
6 |
| } |
| 225 |
|
| |
| 226 |
6 |
| static inline void buffer_append_n24(buffer* b, uint32_t n) { |
| 227 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 228 |
6 |
| n = htonl(n); |
| 229 |
|
| #endif |
| 230 |
6 |
| buffer_append_string_len(b, (const char*)&n + 1, 3); |
| 231 |
6 |
| } |
| 232 |
|
| |
| 233 |
6 |
| static inline void buffer_append_n16(buffer* b, uint16_t n) { |
| 234 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 235 |
6 |
| n = htons(n); |
| 236 |
|
| #endif |
| 237 |
6 |
| buffer_append_string_len(b, (const char*)&n, 2); |
| 238 |
6 |
| } |
| 239 |
|
| |
| 240 |
2 |
| static inline uint32_t buffer_get_u24(buffer* b, int cursor) { |
| 241 |
2 |
| uint32_t i = 0; |
| 242 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 243 |
2 |
| memcpy(&i, b->ptr + cursor, 3); |
| 244 |
|
| #else |
| 245 |
|
| memcpy(&i + 1, b->ptr + cursor, 3); |
| 246 |
|
| #endif |
| 247 |
|
| |
| 248 |
2 |
| return i; |
| 249 |
|
| } |
| 250 |
|
| |
| 251 |
4 |
| static inline int32_t buffer_get_i24(buffer* b, int cursor) { |
| 252 |
4 |
| int32_t i = 0; |
| 253 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 254 |
4 |
| memcpy(&i, b->ptr + cursor, 3); |
| 255 |
|
| #else |
| 256 |
|
| memcpy(&i + 1, b->ptr + cursor, 3); |
| 257 |
|
| #endif |
| 258 |
|
| |
| 259 |
4 |
▶ | if (i & 0x800000) i |= 0xff000000; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i & 0x800000) i |= 0xff000000; |
2 |
2 |
4 |
|
| 260 |
|
| |
| 261 |
4 |
| return i; |
| 262 |
|
| } |
| 263 |
|
| |
| 264 |
4 |
| static inline uint32_t buffer_get_n32(buffer* b, int cursor) { |
| 265 |
4 |
| uint32_t i = *((uint32_t*)(b->ptr + cursor)); |
| 266 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 267 |
4 |
| i = ntohl(i); |
| 268 |
|
| #endif |
| 269 |
4 |
| return i; |
| 270 |
|
| } |
| 271 |
|
| |
| 272 |
4 |
| static inline uint32_t buffer_get_n24(buffer* b, int cursor) { |
| 273 |
4 |
| uint32_t i = 0; |
| 274 |
4 |
| memcpy((uint8_t*)&i + 1, b->ptr + cursor, 3); /* network order */ |
| 275 |
|
| |
| 276 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 277 |
4 |
| i = ntohl(i); |
| 278 |
|
| #endif |
| 279 |
4 |
| return i; |
| 280 |
|
| } |
| 281 |
|
| |
| 282 |
4 |
| static inline uint16_t buffer_get_n16(buffer* b, int cursor) { |
| 283 |
4 |
| uint16_t i = *((uint16_t*)(b->ptr + cursor)); |
| 284 |
|
| #ifdef __LITTLE_ENDIAN__ |
| 285 |
4 |
| i = ntohs(i); |
| 286 |
|
| #endif |
| 287 |
4 |
| return i; |
| 288 |
|
| } |
| 289 |
|
| |
| 290 |
|
| typedef struct { |
| 291 |
|
| int cursor; |
| 292 |
|
| buffer* buffer; |
| 293 |
|
| } txn_buffer_t; |
| 294 |
|
| |
| 295 |
|
| #define BUFARGS \ |
| 296 |
|
| MAGIC* m; \ |
| 297 |
|
| buffer* b; \ |
| 298 |
|
| txn_buffer_t* context = NULL; \ |
| 299 |
|
| m = mg_find(SvRV(sv_obj), PERL_MAGIC_ext); \ |
| 300 |
|
| if (NULL != m) context = (txn_buffer_t*)m->mg_obj; \ |
| 301 |
|
| if (NULL == context) croak("This is not Data::TxnBuffer object\n"); \ |
| 302 |
|
| b = context->buffer; |
| 303 |
|
| |
| 304 |
|
| MODULE = Data::TxnBuffer PACKAGE = Data::TxnBuffer |
| 305 |
|
| |
| 306 |
|
| SV* |
| 307 |
|
| new(char* class, SV* sv_data=NULL) |
| 308 |
|
| CODE: |
| 309 |
|
| { |
| 310 |
|
| HV* hv; |
| 311 |
|
| SV* sv; |
| 312 |
|
| HV* stash; |
| 313 |
|
| txn_buffer_t* context; |
| 314 |
|
| buffer* b; |
| 315 |
22 |
| char* data = NULL; |
| 316 |
|
| STRLEN len; |
| 317 |
|
| |
| 318 |
22 |
| hv = (HV*)sv_2mortal((SV*)newHV()); |
| 319 |
22 |
| sv = sv_2mortal(newRV_inc((SV*)hv)); |
| 320 |
|
| |
| 321 |
22 |
| stash = gv_stashpv(class, 0); |
| 322 |
|
| assert(NULL != stash); |
| 323 |
22 |
| sv_bless(sv, stash); |
| 324 |
|
| |
| 325 |
22 |
| b = buffer_init(); |
| 326 |
|
| |
| 327 |
22 |
| context = malloc(sizeof(txn_buffer_t)); |
| 328 |
22 |
| context->cursor = 0; |
| 329 |
22 |
| context->buffer = b; |
| 330 |
|
| |
| 331 |
22 |
| sv_magic((SV*)hv, NULL, PERL_MAGIC_ext, NULL, 0); |
| 332 |
22 |
| mg_find((SV*)hv, PERL_MAGIC_ext)->mg_obj = (void*)context; |
| 333 |
|
| |
| 334 |
22 |
▶ | if (NULL != sv_data) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL != sv_data) { |
2 |
20 |
22 |
|
| 335 |
2 |
| data = SvPVbyte(sv_data, len); |
| 336 |
|
| assert(NULL != data); |
| 337 |
2 |
| buffer_append_string_len(b, data, len); |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
22 |
| ST(0) = sv; |
| 341 |
|
| } |
| 342 |
|
| |
| 343 |
|
| void |
| 344 |
|
| DESTROY(SV* sv_obj) |
| 345 |
|
| CODE: |
| 346 |
|
| { |
| 347 |
22 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
22 |
0 |
22 |
| BUFARGS; |
0 |
22 |
22 |
|
| 348 |
22 |
| buffer_free(b); |
| 349 |
22 |
| free(context); |
| 350 |
|
| } |
| 351 |
|
| |
| 352 |
|
| SV* |
| 353 |
|
| data(SV* sv_obj) |
| 354 |
|
| CODE: |
| 355 |
|
| { |
| 356 |
|
| SV* sv; |
| 357 |
24 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
24 |
0 |
24 |
| BUFARGS; |
0 |
24 |
24 |
|
| 358 |
|
| |
| 359 |
24 |
| sv = sv_2mortal(newSV(0)); |
| 360 |
24 |
▶ | if (b->used > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (b->used > 0) { |
22 |
2 |
24 |
|
| 361 |
22 |
| sv_setpvn(sv, b->ptr, b->used - 1); |
| 362 |
|
| } |
| 363 |
|
| else { |
| 364 |
2 |
| sv_setpvn(sv, "", 0); |
| 365 |
|
| } |
| 366 |
|
| |
| 367 |
24 |
| ST(0) = sv; |
| 368 |
|
| } |
| 369 |
|
| |
| 370 |
|
| int |
| 371 |
|
| cursor(SV* sv_obj) |
| 372 |
|
| CODE: |
| 373 |
|
| { |
| 374 |
6 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
6 |
0 |
6 |
| BUFARGS; |
0 |
6 |
6 |
|
| 375 |
6 |
▶ | RETVAL = context->cursor; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = context->cursor; |
0 |
6 |
6 |
|
| 376 |
|
| } |
| 377 |
|
| OUTPUT: |
| 378 |
|
| RETVAL |
| 379 |
|
| |
| 380 |
|
| SV* |
| 381 |
|
| spin(SV* sv_obj) |
| 382 |
|
| CODE: |
| 383 |
|
| { |
| 384 |
|
| SV* sv; |
| 385 |
|
| int r; |
| 386 |
|
| unsigned char* data; |
| 387 |
8 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
8 |
0 |
8 |
| BUFARGS; |
0 |
8 |
8 |
|
| 388 |
|
| |
| 389 |
8 |
| sv = sv_2mortal(newSV(0)); |
| 390 |
8 |
▶ | if (context->cursor > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor > 0) { |
8 |
0 |
8 |
|
| 391 |
8 |
| sv_setpvn(sv, b->ptr, context->cursor); |
| 392 |
8 |
| buffer_spin(b, context->cursor); |
| 393 |
8 |
| context->cursor = 0; |
| 394 |
|
| } |
| 395 |
|
| else { |
| 396 |
0 |
| sv_setpvn(sv, "", 0); |
| 397 |
|
| } |
| 398 |
|
| |
| 399 |
8 |
| ST(0) = sv; |
| 400 |
|
| } |
| 401 |
|
| |
| 402 |
|
| void |
| 403 |
|
| reset(SV* sv_obj) |
| 404 |
|
| CODE: |
| 405 |
|
| { |
| 406 |
10 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
10 |
0 |
10 |
| BUFARGS; |
0 |
10 |
10 |
|
| 407 |
10 |
| context->cursor = 0; |
| 408 |
|
| } |
| 409 |
|
| |
| 410 |
|
| void |
| 411 |
|
| clear(SV* sv_obj) |
| 412 |
|
| CODE: |
| 413 |
|
| { |
| 414 |
16 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
16 |
0 |
16 |
| BUFARGS; |
0 |
16 |
16 |
|
| 415 |
16 |
| context->cursor = 0; |
| 416 |
16 |
| buffer_reset(b); |
| 417 |
|
| } |
| 418 |
|
| |
| 419 |
|
| int |
| 420 |
|
| length(SV* sv_obj) |
| 421 |
|
| CODE: |
| 422 |
|
| { |
| 423 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 424 |
4 |
▶ | RETVAL = b->used > 0 ? b->used - 1 : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = b->used > 0 ? b->used - 1 : 0; |
4 |
0 |
4 |
| RETVAL = b->used > 0 ? b->used - 1 : 0; |
0 |
4 |
4 |
|
| 425 |
|
| } |
| 426 |
|
| OUTPUT: |
| 427 |
|
| RETVAL |
| 428 |
|
| |
| 429 |
|
| void |
| 430 |
|
| write(SV* sv_obj, SV* sv_buf) |
| 431 |
|
| CODE: |
| 432 |
|
| { |
| 433 |
10 |
| char* buf = NULL; |
| 434 |
|
| STRLEN len; |
| 435 |
10 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
10 |
0 |
10 |
| BUFARGS; |
0 |
10 |
10 |
|
| 436 |
|
| |
| 437 |
10 |
| buf = SvPVbyte(sv_buf, len); |
| 438 |
|
| assert(NULL != buf); |
| 439 |
|
| |
| 440 |
10 |
| buffer_append_string_len(b, buf, len); |
| 441 |
|
| } |
| 442 |
|
| |
| 443 |
|
| SV* |
| 444 |
|
| read(SV* sv_obj, int len) |
| 445 |
|
| CODE: |
| 446 |
|
| { |
| 447 |
|
| SV* sv; |
| 448 |
22 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
22 |
0 |
22 |
| BUFARGS; |
0 |
22 |
22 |
|
| 449 |
|
| |
| 450 |
22 |
▶ | if (len <= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len <= 0) { |
0 |
22 |
22 |
|
| 451 |
0 |
| croak("positive value is required for read. got %d\n", len); |
| 452 |
|
| } |
| 453 |
22 |
▶ | if (context->cursor + len > b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + len > b->used) { |
4 |
18 |
22 |
|
| 454 |
4 |
| croak("No enough data in buffer for read\n"); |
| 455 |
|
| } |
| 456 |
|
| |
| 457 |
18 |
| sv = sv_2mortal(newSV(0)); |
| 458 |
18 |
| sv_setpvn(sv, context->buffer->ptr + context->cursor, len); |
| 459 |
18 |
| context->cursor += len; |
| 460 |
|
| |
| 461 |
18 |
| ST(0) = sv; |
| 462 |
|
| } |
| 463 |
|
| |
| 464 |
|
| void |
| 465 |
|
| write_u32(SV* sv_obj, U32 n) |
| 466 |
|
| ALIAS: |
| 467 |
|
| write_u32 = 0 |
| 468 |
|
| write_i32 = 1 |
| 469 |
|
| CODE: |
| 470 |
|
| { |
| 471 |
8 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
8 |
0 |
8 |
| BUFARGS; |
0 |
8 |
8 |
|
| 472 |
8 |
| buffer_append_string_len(b, (const char*)&n, 4); |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
|
| U32 |
| 476 |
|
| read_u32(SV* sv_obj) |
| 477 |
|
| CODE: |
| 478 |
|
| { |
| 479 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 480 |
2 |
▶ | if (context->cursor + 4 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 4 >= b->used) { |
0 |
2 |
2 |
|
| 481 |
0 |
| croak("No enough data in buffer for read\n"); |
| 482 |
|
| } |
| 483 |
|
| |
| 484 |
2 |
| U32 n = *((U32*)(context->buffer->ptr + context->cursor)); |
| 485 |
2 |
| context->cursor += 4; |
| 486 |
|
| |
| 487 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 488 |
|
| } |
| 489 |
|
| OUTPUT: |
| 490 |
|
| RETVAL |
| 491 |
|
| |
| 492 |
|
| I32 |
| 493 |
|
| read_i32(SV* sv_obj) |
| 494 |
|
| CODE: |
| 495 |
|
| { |
| 496 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 497 |
4 |
▶ | if (context->cursor + 4 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 4 >= b->used) { |
0 |
4 |
4 |
|
| 498 |
0 |
| croak("No enough data in buffer for read\n"); |
| 499 |
|
| } |
| 500 |
|
| |
| 501 |
4 |
| I32 n = *((I32*)(context->buffer->ptr + context->cursor)); |
| 502 |
4 |
| context->cursor += 4; |
| 503 |
|
| |
| 504 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 505 |
|
| } |
| 506 |
|
| OUTPUT: |
| 507 |
|
| RETVAL |
| 508 |
|
| |
| 509 |
|
| void |
| 510 |
|
| write_u24(SV* sv_obj, U32 n) |
| 511 |
|
| ALIAS: |
| 512 |
|
| write_u24 = 0 |
| 513 |
|
| write_i24 = 1 |
| 514 |
|
| CODE: |
| 515 |
|
| { |
| 516 |
8 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
8 |
0 |
8 |
| BUFARGS; |
0 |
8 |
8 |
|
| 517 |
8 |
| buffer_append_u24(b, (uint32_t)n); |
| 518 |
|
| } |
| 519 |
|
| |
| 520 |
|
| U32 |
| 521 |
|
| read_u24(SV* sv_obj) |
| 522 |
|
| CODE: |
| 523 |
|
| { |
| 524 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 525 |
2 |
▶ | if (context->cursor + 3 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 3 >= b->used) { |
0 |
2 |
2 |
|
| 526 |
0 |
| croak("No enough data in buffer for read\n"); |
| 527 |
|
| } |
| 528 |
|
| |
| 529 |
2 |
| U32 n = buffer_get_u24(b, context->cursor); |
| 530 |
2 |
| context->cursor += 3; |
| 531 |
|
| |
| 532 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 533 |
|
| } |
| 534 |
|
| OUTPUT: |
| 535 |
|
| RETVAL |
| 536 |
|
| |
| 537 |
|
| I32 |
| 538 |
|
| read_i24(SV* sv_obj) |
| 539 |
|
| CODE: |
| 540 |
|
| { |
| 541 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 542 |
4 |
▶ | if (context->cursor + 3 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 3 >= b->used) { |
0 |
4 |
4 |
|
| 543 |
0 |
| croak("No enough data in buffer for read\n"); |
| 544 |
|
| } |
| 545 |
|
| |
| 546 |
4 |
| I32 n = buffer_get_i24(b, context->cursor); |
| 547 |
4 |
| context->cursor += 3; |
| 548 |
|
| |
| 549 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 550 |
|
| } |
| 551 |
|
| OUTPUT: |
| 552 |
|
| RETVAL |
| 553 |
|
| |
| 554 |
|
| void |
| 555 |
|
| write_u16(SV* sv_obj, U16 n) |
| 556 |
|
| ALIAS: |
| 557 |
|
| write_u16 = 0 |
| 558 |
|
| write_i16 = 1 |
| 559 |
|
| CODE: |
| 560 |
|
| { |
| 561 |
8 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
8 |
0 |
8 |
| BUFARGS; |
0 |
8 |
8 |
|
| 562 |
8 |
| buffer_append_string_len(b, (const char*)&n, 2); |
| 563 |
|
| } |
| 564 |
|
| |
| 565 |
|
| U16 |
| 566 |
|
| read_u16(SV* sv_obj) |
| 567 |
|
| CODE: |
| 568 |
|
| { |
| 569 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 570 |
2 |
▶ | if (context->cursor + 2 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 2 >= b->used) { |
0 |
2 |
2 |
|
| 571 |
0 |
| croak("No enough data in buffer for read\n"); |
| 572 |
|
| } |
| 573 |
|
| |
| 574 |
2 |
| U16 n = *((U16*)(context->buffer->ptr + context->cursor)); |
| 575 |
2 |
| context->cursor += 2; |
| 576 |
|
| |
| 577 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 578 |
|
| } |
| 579 |
|
| OUTPUT: |
| 580 |
|
| RETVAL |
| 581 |
|
| |
| 582 |
|
| I16 |
| 583 |
|
| read_i16(SV* sv_obj) |
| 584 |
|
| CODE: |
| 585 |
|
| { |
| 586 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 587 |
4 |
▶ | if (context->cursor + 2 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 2 >= b->used) { |
0 |
4 |
4 |
|
| 588 |
0 |
| croak("No enough data in buffer for read\n"); |
| 589 |
|
| } |
| 590 |
|
| |
| 591 |
4 |
| I16 n = *((I16*)(context->buffer->ptr + context->cursor)); |
| 592 |
4 |
| context->cursor += 2; |
| 593 |
|
| |
| 594 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 595 |
|
| } |
| 596 |
|
| OUTPUT: |
| 597 |
|
| RETVAL |
| 598 |
|
| |
| 599 |
|
| void |
| 600 |
|
| write_u8(SV* sv_obj, U8 n) |
| 601 |
|
| ALIAS: |
| 602 |
|
| write_u8 = 0 |
| 603 |
|
| write_i8 = 1 |
| 604 |
|
| CODE: |
| 605 |
|
| { |
| 606 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 607 |
4 |
| buffer_append_string_len(b, (const char*)&n, 1); |
| 608 |
|
| } |
| 609 |
|
| |
| 610 |
|
| U8 |
| 611 |
|
| read_u8(SV* sv_obj) |
| 612 |
|
| CODE: |
| 613 |
|
| { |
| 614 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 615 |
2 |
▶ | if (context->cursor + 1 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 1 >= b->used) { |
0 |
2 |
2 |
|
| 616 |
0 |
| croak("No enough data in buffer for read\n"); |
| 617 |
|
| } |
| 618 |
|
| |
| 619 |
2 |
| U8 n = *((U8*)(context->buffer->ptr + context->cursor)); |
| 620 |
2 |
| context->cursor += 1; |
| 621 |
|
| |
| 622 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 623 |
|
| } |
| 624 |
|
| OUTPUT: |
| 625 |
|
| RETVAL |
| 626 |
|
| |
| 627 |
|
| I8 |
| 628 |
|
| read_i8(SV* sv_obj) |
| 629 |
|
| CODE: |
| 630 |
|
| { |
| 631 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 632 |
2 |
▶ | if (context->cursor + 1 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 1 >= b->used) { |
0 |
2 |
2 |
|
| 633 |
0 |
| croak("No enough data in buffer for read\n"); |
| 634 |
|
| } |
| 635 |
|
| |
| 636 |
2 |
| I8 n = *((I8*)(context->buffer->ptr + context->cursor)); |
| 637 |
2 |
| context->cursor += 1; |
| 638 |
|
| |
| 639 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 640 |
|
| } |
| 641 |
|
| OUTPUT: |
| 642 |
|
| RETVAL |
| 643 |
|
| |
| 644 |
|
| void |
| 645 |
|
| write_n32(SV* sv_obj, U32 n) |
| 646 |
|
| CODE: |
| 647 |
|
| { |
| 648 |
6 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
6 |
0 |
6 |
| BUFARGS; |
0 |
6 |
6 |
|
| 649 |
6 |
| buffer_append_n32(b, n); |
| 650 |
|
| } |
| 651 |
|
| |
| 652 |
|
| U32 |
| 653 |
|
| read_n32(SV* sv_obj) |
| 654 |
|
| CODE: |
| 655 |
|
| { |
| 656 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 657 |
4 |
▶ | if (context->cursor + 4 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 4 >= b->used) { |
0 |
4 |
4 |
|
| 658 |
0 |
| croak("No enough data in buffer for read\n"); |
| 659 |
|
| } |
| 660 |
|
| |
| 661 |
4 |
| U32 n = buffer_get_n32(b, context->cursor); |
| 662 |
4 |
| context->cursor += 4; |
| 663 |
|
| |
| 664 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 665 |
|
| } |
| 666 |
|
| OUTPUT: |
| 667 |
|
| RETVAL |
| 668 |
|
| |
| 669 |
|
| void |
| 670 |
|
| write_n24(SV* sv_obj, U32 n) |
| 671 |
|
| CODE: |
| 672 |
|
| { |
| 673 |
6 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
6 |
0 |
6 |
| BUFARGS; |
0 |
6 |
6 |
|
| 674 |
6 |
| buffer_append_n24(b, n); |
| 675 |
|
| } |
| 676 |
|
| |
| 677 |
|
| U32 |
| 678 |
|
| read_n24(SV* sv_obj) |
| 679 |
|
| CODE: |
| 680 |
|
| { |
| 681 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 682 |
4 |
▶ | if (context->cursor + 3 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 3 >= b->used) { |
0 |
4 |
4 |
|
| 683 |
0 |
| croak("No enough data in buffer for read\n"); |
| 684 |
|
| } |
| 685 |
|
| |
| 686 |
4 |
| U32 n = buffer_get_n24(b, context->cursor); |
| 687 |
4 |
| context->cursor += 3; |
| 688 |
|
| |
| 689 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 690 |
|
| } |
| 691 |
|
| OUTPUT: |
| 692 |
|
| RETVAL |
| 693 |
|
| |
| 694 |
|
| void |
| 695 |
|
| write_n16(SV* sv_obj, U16 n) |
| 696 |
|
| CODE: |
| 697 |
|
| { |
| 698 |
6 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
6 |
0 |
6 |
| BUFARGS; |
0 |
6 |
6 |
|
| 699 |
6 |
| buffer_append_n16(b, n); |
| 700 |
|
| } |
| 701 |
|
| |
| 702 |
|
| U16 |
| 703 |
|
| read_n16(SV* sv_obj) |
| 704 |
|
| CODE: |
| 705 |
|
| { |
| 706 |
4 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
4 |
0 |
4 |
| BUFARGS; |
0 |
4 |
4 |
|
| 707 |
4 |
▶ | if (context->cursor + 2 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 2 >= b->used) { |
0 |
4 |
4 |
|
| 708 |
0 |
| croak("No enough data in buffer for read\n"); |
| 709 |
|
| } |
| 710 |
|
| |
| 711 |
4 |
| U16 n = buffer_get_n16(b, context->cursor); |
| 712 |
4 |
| context->cursor += 2; |
| 713 |
|
| |
| 714 |
4 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
4 |
4 |
|
| 715 |
|
| } |
| 716 |
|
| OUTPUT: |
| 717 |
|
| RETVAL |
| 718 |
|
| |
| 719 |
|
| void |
| 720 |
|
| write_float(SV* sv_obj, float n) |
| 721 |
|
| CODE: |
| 722 |
|
| { |
| 723 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 724 |
2 |
| buffer_append_string_len(b, (const char*)&n, 4); |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
|
| float |
| 728 |
|
| read_float(SV* sv_obj) |
| 729 |
|
| CODE: |
| 730 |
|
| { |
| 731 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 732 |
2 |
▶ | if (context->cursor + 4 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 4 >= b->used) { |
0 |
2 |
2 |
|
| 733 |
0 |
| croak("No enough data in buffer for read\n"); |
| 734 |
|
| } |
| 735 |
|
| |
| 736 |
2 |
| float n = *((float*)(b->ptr + context->cursor)); |
| 737 |
2 |
| context->cursor += 4; |
| 738 |
|
| |
| 739 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 740 |
|
| } |
| 741 |
|
| OUTPUT: |
| 742 |
|
| RETVAL |
| 743 |
|
| |
| 744 |
|
| void |
| 745 |
|
| write_double(SV* sv_obj, double n) |
| 746 |
|
| CODE: |
| 747 |
|
| { |
| 748 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 749 |
2 |
| buffer_append_string_len(b, (const char*)&n, 8); |
| 750 |
|
| } |
| 751 |
|
| |
| 752 |
|
| double |
| 753 |
|
| read_double(SV* sv_obj) |
| 754 |
|
| CODE: |
| 755 |
|
| { |
| 756 |
2 |
▶ | BUFARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| BUFARGS; |
2 |
0 |
2 |
| BUFARGS; |
0 |
2 |
2 |
|
| 757 |
2 |
▶ | if (context->cursor + 8 >= b->used) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context->cursor + 8 >= b->used) { |
0 |
2 |
2 |
|
| 758 |
0 |
| croak("No enough data in buffer for read\n"); |
| 759 |
|
| } |
| 760 |
|
| |
| 761 |
2 |
| double n = *((double*)(b->ptr + context->cursor)); |
| 762 |
2 |
| context->cursor += 8; |
| 763 |
|
| |
| 764 |
2 |
▶ | RETVAL = n; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = n; |
0 |
2 |
2 |
|
| 765 |
|
| } |
| 766 |
|
| OUTPUT: |
| 767 |
|
| RETVAL |
| 768 |
|
| |