Added support for compiling the parser code with Microsoft Visual C compiler.

For hiredis-py and others support on windows.
This commit is contained in:
tzickel 2015-03-13 15:58:23 +02:00
parent 37c06facda
commit ec229678c2
4 changed files with 58 additions and 11 deletions

2
read.c
View File

@ -33,7 +33,9 @@
#include "fmacros.h"
#include <string.h>
#include <stdlib.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <assert.h>
#include <errno.h>
#include <ctype.h>

22
sds.c
View File

@ -103,7 +103,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) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
int reallen = strlen(s);
sh->free += (sh->len-reallen);
sh->len = reallen;
@ -114,7 +114,7 @@ void sdsupdatelen(sds s) {
* so that next append operations will not require allocations up to the
* number of bytes previously available. */
void sdsclear(sds s) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
sh->free += sh->len;
sh->len = 0;
sh->buf[0] = '\0';
@ -133,7 +133,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
if (free >= addlen) return s;
len = sdslen(s);
sh = (void*) (s-sizeof *sh);;
sh = (void*) (s-sizeof *sh);
newlen = (len+addlen);
if (newlen < SDS_MAX_PREALLOC)
newlen *= 2;
@ -155,7 +155,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
sds sdsRemoveFreeSpace(sds s) {
struct sdshdr *sh;
sh = (void*) (s-sizeof *sh);;
sh = (void*) (s-sizeof *sh);
sh = realloc(sh, sizeof *sh+sh->len+1);
sh->free = 0;
return sh->buf;
@ -169,7 +169,7 @@ sds sdsRemoveFreeSpace(sds s) {
* 4) The implicit null term.
*/
size_t sdsAllocSize(sds s) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
return sizeof(*sh)+sh->len+sh->free+1;
}
@ -198,7 +198,7 @@ size_t sdsAllocSize(sds s) {
* sdsIncrLen(s, nread);
*/
void sdsIncrLen(sds s, int incr) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
assert(sh->free >= incr);
sh->len += incr;
@ -240,7 +240,7 @@ sds sdscatlen(sds s, const void *t, size_t len) {
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
sh = (void*) (s-sizeof *sh);;
sh = (void*) (s-sizeof *sh);
memcpy(s+curlen, t, len);
sh->len = curlen+len;
sh->free = sh->free-len;
@ -267,13 +267,13 @@ sds sdscatsds(sds s, const sds t) {
/* Destructively modify the sds string 's' to hold the specified binary
* safe string pointed by 't' of length 'len' bytes. */
sds sdscpylen(sds s, const char *t, size_t len) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
size_t totlen = sh->free+sh->len;
if (totlen < len) {
s = sdsMakeRoomFor(s,len-sh->len);
if (s == NULL) return NULL;
sh = (void*) (s-sizeof *sh);;
sh = (void*) (s-sizeof *sh);
totlen = sh->free+sh->len;
}
memcpy(s, t, len);
@ -541,7 +541,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
* Output will be just "Hello World".
*/
void sdstrim(sds s, const char *cset) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
char *start, *end, *sp, *ep;
size_t len;
@ -573,7 +573,7 @@ void sdstrim(sds s, const char *cset) {
* sdsrange(s,1,-1); => "ello World"
*/
void sdsrange(sds s, int start, int end) {
struct sdshdr *sh = (void*) (s-sizeof *sh);;
struct sdshdr *sh = (void*) (s-sizeof *sh);
size_t newlen, len = sdslen(s);
if (len == 0) return;

3
sds.h
View File

@ -35,6 +35,9 @@
#include <sys/types.h>
#include <stdarg.h>
#ifdef _MSC_VER
#include "win32.h"
#endif
typedef char *sds;

42
win32.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef _WIN32_HELPER_INCLUDE
#define _WIN32_HELPER_INCLUDE
#ifdef _MSC_VER
#ifndef inline
#define inline __inline
#endif
#ifndef va_copy
#define va_copy(d,s) ((d) = (s))
#endif
#ifndef snprintf
#define snprintf c99_snprintf
__inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
__inline int c99_snprintf(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(str, size, format, ap);
va_end(ap);
return count;
}
#endif
#endif
#endif