Skip to content

Commit

Permalink
Revert "Update deps/sds"
Browse files Browse the repository at this point in the history
This reverts commit def8807.
  • Loading branch information
soveran committed Apr 18, 2018
1 parent def8807 commit cd2e3b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
21 changes: 16 additions & 5 deletions deps/sds/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
all: sds-test
STD=
WARN= -Wall
OPT= -Os

sds-test: sds.c sds.h testhelp.h
$(CC) -o sds-test sds.c -Wall -std=c99 -pedantic -O2 -DSDS_TEST_MAIN
@echo ">>> Type ./sds-test to run the sds.c unit tests."
R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
R_LDFLAGS= $(LDFLAGS)
DEBUG= -g

R_CC=$(CC) $(R_CFLAGS)
R_LD=$(CC) $(R_LDFLAGS)

sds.o: sds.h sds.c

.c.o:
$(R_CC) -c $<

clean:
rm -f sds-test
rm -f *.o

40 changes: 16 additions & 24 deletions deps/sds/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void sdsfree(sds s) {
* the output will be "6" as the string was modified but the logical length
* remains 6 bytes. */
void sdsupdatelen(sds s) {
size_t reallen = strlen(s);
int reallen = strlen(s);
sdssetlen(s, reallen);
}

Expand Down Expand Up @@ -248,23 +248,16 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
sds sdsRemoveFreeSpace(sds s) {
void *sh, *newsh;
char type, oldtype = s[-1] & SDS_TYPE_MASK;
int hdrlen, oldhdrlen = sdsHdrSize(oldtype);
int hdrlen;
size_t len = sdslen(s);
sh = (char*)s-oldhdrlen;
sh = (char*)s-sdsHdrSize(oldtype);

/* Check what would be the minimum SDS header that is just good enough to
* fit this string. */
type = sdsReqType(len);
hdrlen = sdsHdrSize(type);

/* If the type is the same, or at least a large enough type is still
* required, we just realloc(), letting the allocator to do the copy
* only if really needed. Otherwise if the change is huge, we manually
* reallocate the string to use the different header type. */
if (oldtype==type || type > SDS_TYPE_8) {
newsh = s_realloc(sh, oldhdrlen+len+1);
if (oldtype==type) {
newsh = s_realloc(sh, hdrlen+len+1);
if (newsh == NULL) return NULL;
s = (char*)newsh+oldhdrlen;
s = (char*)newsh+hdrlen;
} else {
newsh = s_malloc(hdrlen+len+1);
if (newsh == NULL) return NULL;
Expand Down Expand Up @@ -319,7 +312,7 @@ void *sdsAllocPtr(sds s) {
* ... check for nread <= 0 and handle it ...
* sdsIncrLen(s, nread);
*/
void sdsIncrLen(sds s, ssize_t incr) {
void sdsIncrLen(sds s, int incr) {
unsigned char flags = s[-1];
size_t len;
switch(flags&SDS_TYPE_MASK) {
Expand Down Expand Up @@ -589,7 +582,7 @@ sds sdscatprintf(sds s, const char *fmt, ...) {
sds sdscatfmt(sds s, char const *fmt, ...) {
size_t initlen = sdslen(s);
const char *f = fmt;
long i;
int i;
va_list ap;

va_start(ap,fmt);
Expand Down Expand Up @@ -721,7 +714,7 @@ sds sdstrim(sds s, const char *cset) {
* s = sdsnew("Hello World");
* sdsrange(s,1,-1); => "ello World"
*/
void sdsrange(sds s, ssize_t start, ssize_t end) {
void sdsrange(sds s, int start, int end) {
size_t newlen, len = sdslen(s);

if (len == 0) return;
Expand All @@ -735,9 +728,9 @@ void sdsrange(sds s, ssize_t start, ssize_t end) {
}
newlen = (start > end) ? 0 : (end-start)+1;
if (newlen != 0) {
if (start >= (ssize_t)len) {
if (start >= (signed)len) {
newlen = 0;
} else if (end >= (ssize_t)len) {
} else if (end >= (signed)len) {
end = len-1;
newlen = (start > end) ? 0 : (end-start)+1;
}
Expand All @@ -751,14 +744,14 @@ void sdsrange(sds s, ssize_t start, ssize_t end) {

/* Apply tolower() to every character of the sds string 's'. */
void sdstolower(sds s) {
size_t len = sdslen(s), j;
int len = sdslen(s), j;

for (j = 0; j < len; j++) s[j] = tolower(s[j]);
}

/* Apply toupper() to every character of the sds string 's'. */
void sdstoupper(sds s) {
size_t len = sdslen(s), j;
int len = sdslen(s), j;

for (j = 0; j < len; j++) s[j] = toupper(s[j]);
}
Expand All @@ -782,7 +775,7 @@ int sdscmp(const sds s1, const sds s2) {
l2 = sdslen(s2);
minlen = (l1 < l2) ? l1 : l2;
cmp = memcmp(s1,s2,minlen);
if (cmp == 0) return l1>l2? 1: (l1<l2? -1: 0);
if (cmp == 0) return l1-l2;
return cmp;
}

Expand All @@ -802,9 +795,8 @@ int sdscmp(const sds s1, const sds s2) {
* requires length arguments. sdssplit() is just the
* same function but for zero-terminated strings.
*/
sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *count) {
int elements = 0, slots = 5;
long start = 0, j;
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count) {
int elements = 0, slots = 5, start = 0, j;
sds *tokens;

if (seplen < 1 || len < 0) return NULL;
Expand Down
6 changes: 3 additions & 3 deletions deps/sds/sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ sds sdscatprintf(sds s, const char *fmt, ...);

sds sdscatfmt(sds s, char const *fmt, ...);
sds sdstrim(sds s, const char *cset);
void sdsrange(sds s, ssize_t start, ssize_t end);
void sdsrange(sds s, int start, int end);
void sdsupdatelen(sds s);
void sdsclear(sds s);
int sdscmp(const sds s1, const sds s2);
sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *count);
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
void sdsfreesplitres(sds *tokens, int count);
void sdstolower(sds s);
void sdstoupper(sds s);
Expand All @@ -253,7 +253,7 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);

/* Low level functions exposed to the user API */
sds sdsMakeRoomFor(sds s, size_t addlen);
void sdsIncrLen(sds s, ssize_t incr);
void sdsIncrLen(sds s, int incr);
sds sdsRemoveFreeSpace(sds s);
size_t sdsAllocSize(sds s);
void *sdsAllocPtr(sds s);
Expand Down

0 comments on commit cd2e3b1

Please sign in to comment.