Skip to content

Commit

Permalink
Fixing broken windows builds on python < 3.8 (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Prokazov <sergey.prokazov@redis.com>
Co-authored-by: zalmane <oren.elias@gmail.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 2, 2023
1 parent dd4c562 commit 879ab11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,11 @@ def get_sources():
return sorted(glob.glob("src/*.c") + ["vendor/hiredis/%s.c" % src for src in hiredis_sources])


def get_linker_args():
if 'win32' in sys.platform or 'darwin' in sys.platform:
return []
else:
return ["-Wl,-Bsymbolic",]


def get_compiler_args():
if 'win32' in sys.platform:
return []
else:
return ["-std=c99",]
return ["-std=c99", "-static-libstdc++", "-O2"]


def get_libraries():
Expand All @@ -46,7 +39,6 @@ def get_libraries():
ext = Extension("hiredis.hiredis",
sources=get_sources(),
extra_compile_args=get_compiler_args(),
extra_link_args=get_linker_args(),
libraries=get_libraries(),
include_dirs=["vendor"])

Expand Down
19 changes: 17 additions & 2 deletions src/pack.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#include "pack.h"

#ifndef _MSC_VER
#include <hiredis/hiredis.h>
#else
/* Workaround for https://bugs.python.org/issue11717.
* <hiredis/hiredis.h> defines ssize_t which can conflict
* with Python's definition.
*/
extern long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
typedef char *sds;
extern void sds_free(void *ptr);
extern sds sdsempty(void);
extern void sdsfreesplitres(sds *tokens, int count);
extern sds sdscpylen(sds s, const char *t, size_t len);
extern sds sdsnewlen(const void *init, size_t initlen);
#endif

#include <hiredis/sdsalloc.h>

PyObject *
Expand All @@ -15,7 +31,7 @@ pack_command(PyObject *cmd)
return NULL;
}

int tokens_number = PyTuple_Size(cmd);
Py_ssize_t tokens_number = PyTuple_Size(cmd);
sds *tokens = s_malloc(sizeof(sds) * tokens_number);
if (tokens == NULL)
{
Expand All @@ -32,7 +48,6 @@ pack_command(PyObject *cmd)
}

Py_ssize_t len = 0;

for (Py_ssize_t i = 0; i < PyTuple_Size(cmd); i++)
{
PyObject *item = PyTuple_GetItem(cmd, i);
Expand Down

0 comments on commit 879ab11

Please sign in to comment.