Skip to content

Commit 879ab11

Browse files
prokazovprokazov-rediszalmanechayim
authored
Fixing broken windows builds on python < 3.8 (#151)
Co-authored-by: Sergey Prokazov <[email protected]> Co-authored-by: zalmane <[email protected]> Co-authored-by: Chayim <[email protected]>
1 parent dd4c562 commit 879ab11

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

setup.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,11 @@ def get_sources():
2222
return sorted(glob.glob("src/*.c") + ["vendor/hiredis/%s.c" % src for src in hiredis_sources])
2323

2424

25-
def get_linker_args():
26-
if 'win32' in sys.platform or 'darwin' in sys.platform:
27-
return []
28-
else:
29-
return ["-Wl,-Bsymbolic",]
30-
31-
3225
def get_compiler_args():
3326
if 'win32' in sys.platform:
3427
return []
3528
else:
36-
return ["-std=c99",]
29+
return ["-std=c99", "-static-libstdc++", "-O2"]
3730

3831

3932
def get_libraries():
@@ -46,7 +39,6 @@ def get_libraries():
4639
ext = Extension("hiredis.hiredis",
4740
sources=get_sources(),
4841
extra_compile_args=get_compiler_args(),
49-
extra_link_args=get_linker_args(),
5042
libraries=get_libraries(),
5143
include_dirs=["vendor"])
5244

src/pack.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#include "pack.h"
2+
3+
#ifndef _MSC_VER
24
#include <hiredis/hiredis.h>
5+
#else
6+
/* Workaround for https://bugs.python.org/issue11717.
7+
* <hiredis/hiredis.h> defines ssize_t which can conflict
8+
* with Python's definition.
9+
*/
10+
extern long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
11+
typedef char *sds;
12+
extern void sds_free(void *ptr);
13+
extern sds sdsempty(void);
14+
extern void sdsfreesplitres(sds *tokens, int count);
15+
extern sds sdscpylen(sds s, const char *t, size_t len);
16+
extern sds sdsnewlen(const void *init, size_t initlen);
17+
#endif
18+
319
#include <hiredis/sdsalloc.h>
420

521
PyObject *
@@ -15,7 +31,7 @@ pack_command(PyObject *cmd)
1531
return NULL;
1632
}
1733

18-
int tokens_number = PyTuple_Size(cmd);
34+
Py_ssize_t tokens_number = PyTuple_Size(cmd);
1935
sds *tokens = s_malloc(sizeof(sds) * tokens_number);
2036
if (tokens == NULL)
2137
{
@@ -32,7 +48,6 @@ pack_command(PyObject *cmd)
3248
}
3349

3450
Py_ssize_t len = 0;
35-
3651
for (Py_ssize_t i = 0; i < PyTuple_Size(cmd); i++)
3752
{
3853
PyObject *item = PyTuple_GetItem(cmd, i);

0 commit comments

Comments
 (0)