Cleanup: rename checks for Python struct strings
Using 'format' prefix made this read as if t was for string formatting. Use 'PyC_StructFmt' prefix instead since these values are compatible with formatting from Python's 'struct' module.
This commit is contained in:
@@ -480,15 +480,15 @@ int BGL_typeSize(int type)
|
||||
|
||||
static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer)
|
||||
{
|
||||
const char format = PyC_Formatchar_get(pybuffer->format);
|
||||
const char format = PyC_StructFmt_type_from_str(pybuffer->format);
|
||||
Py_ssize_t itemsize = pybuffer->itemsize;
|
||||
|
||||
if (PyC_Formatchar_is_floating_type(format)) {
|
||||
if (PyC_StructFmt_type_is_float_any(format)) {
|
||||
if (itemsize == 4) return GL_FLOAT;
|
||||
if (itemsize == 8) return GL_DOUBLE;
|
||||
}
|
||||
if (PyC_Formatchar_is_byte_type(format) ||
|
||||
PyC_Formatchar_is_integer_type(format))
|
||||
if (PyC_StructFmt_type_is_byte(format) ||
|
||||
PyC_StructFmt_type_is_int_any(format))
|
||||
{
|
||||
if (itemsize == 1) return GL_BYTE;
|
||||
if (itemsize == 2) return GL_SHORT;
|
||||
|
@@ -424,13 +424,13 @@ static IDProperty *idp_from_PyBytes(const char *name, PyObject *ob)
|
||||
|
||||
static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_t itemsize)
|
||||
{
|
||||
char format = PyC_Formatchar_get(typestr);
|
||||
char format = PyC_StructFmt_type_from_str(typestr);
|
||||
|
||||
if (PyC_Formatchar_is_floating_type(format)) {
|
||||
if (PyC_StructFmt_type_is_float_any(format)) {
|
||||
if (itemsize == 4) return IDP_FLOAT;
|
||||
if (itemsize == 8) return IDP_DOUBLE;
|
||||
}
|
||||
if (PyC_Formatchar_is_integer_type(format)) {
|
||||
if (PyC_StructFmt_type_is_int_any(format)) {
|
||||
if (itemsize == 4) return IDP_INT;
|
||||
}
|
||||
|
||||
@@ -540,9 +540,9 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
|
||||
|
||||
if (PyObject_CheckBuffer(ob)) {
|
||||
PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT);
|
||||
char format = PyC_Formatchar_get(buffer.format);
|
||||
if (PyC_Formatchar_is_floating_type(format) ||
|
||||
(PyC_Formatchar_is_integer_type(format) && buffer.itemsize == 4))
|
||||
char format = PyC_StructFmt_type_from_str(buffer.format);
|
||||
if (PyC_StructFmt_type_is_float_any(format) ||
|
||||
(PyC_StructFmt_type_is_int_any(format) && buffer.itemsize == 4))
|
||||
{
|
||||
use_buffer = true;
|
||||
}
|
||||
|
@@ -1333,7 +1333,7 @@ uint32_t PyC_Long_AsU32(PyObject *value)
|
||||
*
|
||||
* \{ */
|
||||
|
||||
char PyC_Formatchar_get(const char *typestr)
|
||||
char PyC_StructFmt_type_from_str(const char *typestr)
|
||||
{
|
||||
switch (typestr[0]) {
|
||||
case '!':
|
||||
@@ -1347,7 +1347,7 @@ char PyC_Formatchar_get(const char *typestr)
|
||||
}
|
||||
}
|
||||
|
||||
bool PyC_Formatchar_is_floating_type(char format)
|
||||
bool PyC_StructFmt_type_is_float_any(char format)
|
||||
{
|
||||
switch (format) {
|
||||
case 'f':
|
||||
@@ -1359,7 +1359,7 @@ bool PyC_Formatchar_is_floating_type(char format)
|
||||
}
|
||||
}
|
||||
|
||||
bool PyC_Formatchar_is_integer_type(char format)
|
||||
bool PyC_StructFmt_type_is_int_any(char format)
|
||||
{
|
||||
switch (format) {
|
||||
case 'i':
|
||||
@@ -1381,7 +1381,7 @@ bool PyC_Formatchar_is_integer_type(char format)
|
||||
}
|
||||
}
|
||||
|
||||
bool PyC_Formatchar_is_byte_type(char format)
|
||||
bool PyC_StructFmt_type_is_byte(char format)
|
||||
{
|
||||
switch (format) {
|
||||
case 'c':
|
||||
@@ -1393,7 +1393,7 @@ bool PyC_Formatchar_is_byte_type(char format)
|
||||
}
|
||||
}
|
||||
|
||||
bool PyC_Formatchar_is_boolean_type(char format)
|
||||
bool PyC_StructFmt_type_is_bool(char format)
|
||||
{
|
||||
switch (format) {
|
||||
case '?':
|
||||
|
@@ -132,10 +132,10 @@ Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLo
|
||||
Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); }
|
||||
|
||||
/* utils for format string in `struct` module style syntax */
|
||||
char PyC_Formatchar_get(const char *typestr);
|
||||
bool PyC_Formatchar_is_floating_type(char format);
|
||||
bool PyC_Formatchar_is_integer_type(char format);
|
||||
bool PyC_Formatchar_is_byte_type(char format);
|
||||
bool PyC_Formatchar_is_boolean_type(char format);
|
||||
char PyC_StructFmt_type_from_str(const char *typestr);
|
||||
bool PyC_StructFmt_type_is_float_any(char format);
|
||||
bool PyC_StructFmt_type_is_int_any(char format);
|
||||
bool PyC_StructFmt_type_is_byte(char format);
|
||||
bool PyC_StructFmt_type_is_bool(char format);
|
||||
|
||||
#endif /* __PY_CAPI_UTILS_H__ */
|
||||
|
Reference in New Issue
Block a user