Skip to content

Commit 03134cb

Browse files
llllllllllTomAugspurger
authored andcommitted
BUG: use internal linkage (static variables) in move.c (pandas-dev#24113)
* BUG: use internal linkage (static variables) in move.c move.c declared global variables without explicitly declaring them static, so they had global visibility. This meant that if you linked against a shared object that provided the same symbols, the wrong data would be read. In particular: linking to libgtk, which provides the symbol 'methods', would cause an import error of pandas.util._move. * DOC: whatsnew entry for pandas.util._move static variables
1 parent b78aa8d commit 03134cb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ Other
15911591
- Logical operations ``&, |, ^`` between :class:`Series` and :class:`Index` will no longer raise ``ValueError`` (:issue:`22092`)
15921592
- Checking PEP 3141 numbers in :func:`~pandas.api.types.is_scalar` function returns ``True`` (:issue:`22903`)
15931593
- Bug in :meth:`DataFrame.combine_first` in which column types were unexpectedly converted to float (:issue:`20699`)
1594+
- Bug where C variables were declared with external linkage causing import errors if certain other C libraries were imported before Pandas. (:issue:`24113`)
15941595

15951596
.. _whatsnew_0.24.0.contributors:
15961597

pandas/util/move.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
2121
#endif
2222

23-
PyObject *badmove; /* bad move exception class */
23+
static PyObject *badmove; /* bad move exception class */
2424

2525
typedef struct {
2626
PyObject_HEAD
2727
/* the bytes that own the buffer we are mutating */
2828
PyObject *invalid_bytes;
2929
} stolenbufobject;
3030

31-
PyTypeObject stolenbuf_type; /* forward declare type */
31+
static PyTypeObject stolenbuf_type; /* forward declare type */
3232

3333
static void
3434
stolenbuf_dealloc(stolenbufobject *self)
@@ -71,7 +71,7 @@ stolenbuf_getsegcount(stolenbufobject *self, Py_ssize_t *len)
7171
return 1;
7272
}
7373

74-
PyBufferProcs stolenbuf_as_buffer = {
74+
static PyBufferProcs stolenbuf_as_buffer = {
7575
(readbufferproc) stolenbuf_getreadwritebuf,
7676
(writebufferproc) stolenbuf_getreadwritebuf,
7777
(segcountproc) stolenbuf_getsegcount,
@@ -81,7 +81,7 @@ PyBufferProcs stolenbuf_as_buffer = {
8181

8282
#else /* Python 3 */
8383

84-
PyBufferProcs stolenbuf_as_buffer = {
84+
static PyBufferProcs stolenbuf_as_buffer = {
8585
(getbufferproc) stolenbuf_getbuffer,
8686
NULL,
8787
};
@@ -91,7 +91,7 @@ PyBufferProcs stolenbuf_as_buffer = {
9191
PyDoc_STRVAR(stolenbuf_doc,
9292
"A buffer that is wrapping a stolen bytes object's buffer.");
9393

94-
PyTypeObject stolenbuf_type = {
94+
static PyTypeObject stolenbuf_type = {
9595
PyVarObject_HEAD_INIT(NULL, 0)
9696
"pandas.util._move.stolenbuf", /* tp_name */
9797
sizeof(stolenbufobject), /* tp_basicsize */
@@ -185,7 +185,7 @@ move_into_mutable_buffer(PyObject *self, PyObject *bytes_rvalue)
185185
return (PyObject*) ret;
186186
}
187187

188-
PyMethodDef methods[] = {
188+
static PyMethodDef methods[] = {
189189
{"move_into_mutable_buffer",
190190
(PyCFunction) move_into_mutable_buffer,
191191
METH_O,
@@ -196,7 +196,7 @@ PyMethodDef methods[] = {
196196
#define MODULE_NAME "pandas.util._move"
197197

198198
#if !COMPILING_IN_PY2
199-
PyModuleDef _move_module = {
199+
static PyModuleDef move_module = {
200200
PyModuleDef_HEAD_INIT,
201201
MODULE_NAME,
202202
NULL,
@@ -242,7 +242,7 @@ init_move(void)
242242
}
243243

244244
#if !COMPILING_IN_PY2
245-
if (!(m = PyModule_Create(&_move_module)))
245+
if (!(m = PyModule_Create(&move_module)))
246246
#else
247247
if (!(m = Py_InitModule(MODULE_NAME, methods)))
248248
#endif /* !COMPILING_IN_PY2 */

0 commit comments

Comments
 (0)