Skip to content

Commit

Permalink
Rename state to hiredis_py_module_state
Browse files Browse the repository at this point in the history
Previously, the variable could alias variables named state in other
shared objects, which was causing segfaults when imported after pytorch.
This change makes it less likely that they overlap and cause undefined
behavior.

See also pytorch/pytorch#11471
  • Loading branch information
drawoc authored and ifduyue committed Sep 13, 2018
1 parent dbc0fd7 commit 10c474d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static struct PyModuleDef hiredis_ModuleDef = {
NULL /* m_free */
};
#else
struct hiredis_ModuleState state;
struct hiredis_ModuleState hiredis_py_module_state;
#endif

/* Keep pointer around for other classes to access the module state. */
Expand Down
4 changes: 2 additions & 2 deletions src/hiredis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct hiredis_ModuleState {
#if IS_PY3K
#define GET_STATE(__s) ((struct hiredis_ModuleState*)PyModule_GetState(__s))
#else
extern struct hiredis_ModuleState state;
#define GET_STATE(__s) (&state)
extern struct hiredis_ModuleState hiredis_py_module_state;
#define GET_STATE(__s) (&hiredis_py_module_state)
#endif

/* Keep pointer around for other classes to access the module state. */
Expand Down

0 comments on commit 10c474d

Please sign in to comment.