Skip to content

Commit 946f261

Browse files
committed
Rework the asserts.
1 parent 7d3bb10 commit 946f261

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Modules/_ctypes/cfield.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,15 @@ PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
111111
}
112112

113113
if (bit_size_obj != Py_None) {
114-
115-
Py_ssize_t bit_size;
116-
117-
if (PyLong_Check(bit_size_obj)) {
118-
bit_size = PyLong_AsSsize_t(bit_size_obj);
119-
} else {
120-
PyErr_Format(
121-
PyExc_ValueError,
122-
"bit size of field %R must be an integer size for bit fields",
123-
self->name
124-
);
125-
goto error;
126-
}
114+
#ifdef Py_DEBUG
115+
Py_ssize_t bit_size = NUM_BITS(size);
127116
assert(bit_size > 0);
128117
assert(bit_size <= info->size * 8);
118+
// Currently, the bit size is specified redundantly
119+
// in NUM_BITS(size) and bit_size_obj.
120+
// Verify that they match.
121+
assert(PyLong_AsSsize_t(bit_size_obj) == bit_size);
122+
#endif
129123
switch(info->ffi_type_pointer.type) {
130124
case FFI_TYPE_UINT8:
131125
case FFI_TYPE_UINT16:

0 commit comments

Comments
 (0)