mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 05:23:34 +00:00
Merge Windows build fixes for SDS library, from https://github.com/LynnKirby/sds fork commit 1ea0479693a8fd85351b75a6d41cef40a8e3e67c
This commit is contained in:
parent
a46b4afbb8
commit
b01a349275
|
@ -1,5 +1,6 @@
|
||||||
/* SDSLib 2.0 -- A C dynamic strings library
|
/* SDSLib 2.x -- A C dynamic strings library
|
||||||
*
|
*
|
||||||
|
* Copyright (c) 2018 Lynn Kirby <lynn@arrak.is>
|
||||||
* Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
|
* Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
* Copyright (c) 2015, Oran Agra
|
* Copyright (c) 2015, Oran Agra
|
||||||
* Copyright (c) 2015, Redis Labs, Inc
|
* Copyright (c) 2015, Redis Labs, Inc
|
||||||
|
@ -1246,9 +1247,8 @@ int sdsTest(void) {
|
||||||
memcmp(y,"\"\\a\\n\\x00foo\\r\"",15) == 0)
|
memcmp(y,"\"\\a\\n\\x00foo\\r\"",15) == 0)
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned int oldfree;
|
|
||||||
char *p;
|
char *p;
|
||||||
int step = 10, j, i;
|
size_t step = 10, j, i;
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
|
@ -1258,14 +1258,13 @@ int sdsTest(void) {
|
||||||
/* Run the test a few times in order to hit the first two
|
/* Run the test a few times in order to hit the first two
|
||||||
* SDS header types. */
|
* SDS header types. */
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
int oldlen = sdslen(x);
|
size_t oldlen = sdslen(x);
|
||||||
x = sdsMakeRoomFor(x,step);
|
x = sdsMakeRoomFor(x,step);
|
||||||
int type = x[-1]&SDS_TYPE_MASK;
|
int type = x[-1]&SDS_TYPE_MASK;
|
||||||
|
|
||||||
test_cond("sdsMakeRoomFor() len", sdslen(x) == oldlen);
|
test_cond("sdsMakeRoomFor() len", sdslen(x) == oldlen);
|
||||||
if (type != SDS_TYPE_5) {
|
if (type != SDS_TYPE_5) {
|
||||||
test_cond("sdsMakeRoomFor() free", sdsavail(x) >= step);
|
test_cond("sdsMakeRoomFor() free", sdsavail(x) >= step);
|
||||||
oldfree = sdsavail(x);
|
|
||||||
}
|
}
|
||||||
p = x+oldlen;
|
p = x+oldlen;
|
||||||
for (j = 0; j < step; j++) {
|
for (j = 0; j < step; j++) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* SDSLib 2.0 -- A C dynamic strings library
|
/* SDSLib 2.x -- A C dynamic strings library
|
||||||
*
|
*
|
||||||
|
* Copyright (c) 2018 Lynn Kirby <lynn@arrak.is>
|
||||||
* Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
|
* Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
* Copyright (c) 2015, Oran Agra
|
* Copyright (c) 2015, Oran Agra
|
||||||
* Copyright (c) 2015, Redis Labs, Inc
|
* Copyright (c) 2015, Redis Labs, Inc
|
||||||
|
@ -42,36 +43,51 @@ const char *SDS_NOINIT;
|
||||||
|
|
||||||
typedef char *sds;
|
typedef char *sds;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define PACK(decl) __pragma(pack(push, 1)) decl __pragma(pack(pop))
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef __int64 ssize_t;
|
||||||
|
#else
|
||||||
|
typedef long ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define PACK(decl) decl __attribute__((__packed__))
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
||||||
* However is here to document the layout of type 5 SDS strings. */
|
* However is here to document the layout of type 5 SDS strings. */
|
||||||
struct __attribute__ ((__packed__)) sdshdr5 {
|
PACK(struct sdshdr5 {
|
||||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
});
|
||||||
struct __attribute__ ((__packed__)) sdshdr8 {
|
PACK(struct sdshdr8 {
|
||||||
uint8_t len; /* used */
|
uint8_t len; /* used */
|
||||||
uint8_t alloc; /* excluding the header and null terminator */
|
uint8_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
});
|
||||||
struct __attribute__ ((__packed__)) sdshdr16 {
|
PACK(struct sdshdr16 {
|
||||||
uint16_t len; /* used */
|
uint16_t len; /* used */
|
||||||
uint16_t alloc; /* excluding the header and null terminator */
|
uint16_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
});
|
||||||
struct __attribute__ ((__packed__)) sdshdr32 {
|
PACK(struct sdshdr32 {
|
||||||
uint32_t len; /* used */
|
uint32_t len; /* used */
|
||||||
uint32_t alloc; /* excluding the header and null terminator */
|
uint32_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
});
|
||||||
struct __attribute__ ((__packed__)) sdshdr64 {
|
PACK(struct sdshdr64 {
|
||||||
uint64_t len; /* used */
|
uint64_t len; /* used */
|
||||||
uint64_t alloc; /* excluding the header and null terminator */
|
uint64_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
});
|
||||||
|
|
||||||
|
#undef PACK
|
||||||
|
|
||||||
#define SDS_TYPE_5 0
|
#define SDS_TYPE_5 0
|
||||||
#define SDS_TYPE_8 1
|
#define SDS_TYPE_8 1
|
||||||
|
@ -80,7 +96,7 @@ struct __attribute__ ((__packed__)) sdshdr64 {
|
||||||
#define SDS_TYPE_64 4
|
#define SDS_TYPE_64 4
|
||||||
#define SDS_TYPE_MASK 7
|
#define SDS_TYPE_MASK 7
|
||||||
#define SDS_TYPE_BITS 3
|
#define SDS_TYPE_BITS 3
|
||||||
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
|
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T)));
|
||||||
#define SDS_HDR(T,s) ((struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T))))
|
#define SDS_HDR(T,s) ((struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T))))
|
||||||
#define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS)
|
#define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue