Skip to content

Commit 5d95318

Browse files
committed
Issue python#14779: Get sizeof(void *) directly rather than relying on sysconfig.
1 parent e34a209 commit 5d95318

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/test/test_buffer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,8 @@ def ndarray_print(nd):
747747
class TestBufferProtocol(unittest.TestCase):
748748

749749
def setUp(self):
750-
self.sizeof_void_p = get_config_var('SIZEOF_VOID_P') \
751-
if sys.platform != 'darwin' else None
752-
if not self.sizeof_void_p:
753-
self.sizeof_void_p = 8 if sys.maxsize > 2**32 else 4
750+
# The suboffsets tests need sizeof(void *).
751+
self.sizeof_void_p = get_sizeof_void_p()
754752

755753
def verify(self, result, obj=-1,
756754
itemsize={1}, fmt=-1, readonly={1},

Modules/_testbuffer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,12 @@ get_pointer(PyObject *self, PyObject *args)
23372337
return ret;
23382338
}
23392339

2340+
static PyObject *
2341+
get_sizeof_void_p(PyObject *self)
2342+
{
2343+
return PyLong_FromSize_t(sizeof(void *));
2344+
}
2345+
23402346
static char
23412347
get_ascii_order(PyObject *order)
23422348
{
@@ -2726,6 +2732,7 @@ static PyTypeObject StaticArray_Type = {
27262732
static struct PyMethodDef _testbuffer_functions[] = {
27272733
{"slice_indices", slice_indices, METH_VARARGS, NULL},
27282734
{"get_pointer", get_pointer, METH_VARARGS, NULL},
2735+
{"get_sizeof_void_p", (PyCFunction)get_sizeof_void_p, METH_NOARGS, NULL},
27292736
{"get_contiguous", get_contiguous, METH_VARARGS, NULL},
27302737
{"is_contiguous", is_contiguous, METH_VARARGS, NULL},
27312738
{"cmp_contig", cmp_contig, METH_VARARGS, NULL},

0 commit comments

Comments
 (0)