RNA: Add missing raw types for DNA types #115761

Merged
Brecht Van Lommel merged 7 commits from Mysteryem/blender:fix_missing_raw_types_pr into main 2024-01-10 18:19:33 +01:00
2 changed files with 38 additions and 47 deletions
Showing only changes of commit 93169bb632 - Show all commits

View File

@ -1636,7 +1636,11 @@ bool PyC_RunString_AsString(const char *imports[],
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
ulong PyC_Long_AsUnsignedLong(PyObject *value)
/* #PyLong_AsUnsignedLong, unlike #PyLong_AsLong, does not fall back to calling #PyNumber_Index
* when its argument is not a `PyLongObject` instance. To match parsing signed integer types with
* #PyLong_AsLong, this function performs the #PyNumber_Index fallback, if necessary, before
* calling #PyLong_AsUnsignedLong. */
static ulong pyc_Long_AsUnsignedLong(PyObject *value)
{
if (value == nullptr) {
/* Let PyLong_AsUnsignedLong handle error raising. */
@ -1658,29 +1662,6 @@ ulong PyC_Long_AsUnsignedLong(PyObject *value)
return to_return;
}
unsigned long long PyC_Long_AsUnsignedLongLong(PyObject *value)
{
if (value == nullptr) {
/* Let PyLong_AsUnsignedLongLong handle error raising. */
return PyLong_AsUnsignedLongLong(value);
}
if (PyLong_Check(value)) {
return PyLong_AsUnsignedLongLong(value);
}
/* Call `__index__` like PyLong_AsLongLong. */
PyObject *value_converted = PyNumber_Index(value);
if (value_converted == nullptr) {
/* A `TypeError` will have been raised. */
return unsigned long long(-1);
}
unsigned long long to_return = PyLong_AsUnsignedLongLong(value_converted);
Py_DECREF(value_converted);
return to_return;
}
int PyC_Long_AsBool(PyObject *value)
{
const int test = _PyLong_AsInt(value);
@ -1727,7 +1708,7 @@ int16_t PyC_Long_AsI16(PyObject *value)
uint8_t PyC_Long_AsU8(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
const ulong test = pyc_Long_AsUnsignedLong(value);
if (UNLIKELY(test == ulong(-1) && PyErr_Occurred())) {
return uint8_t(-1);
}
@ -1740,7 +1721,7 @@ uint8_t PyC_Long_AsU8(PyObject *value)
uint16_t PyC_Long_AsU16(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
const ulong test = pyc_Long_AsUnsignedLong(value);
if (UNLIKELY(test == ulong(-1) && PyErr_Occurred())) {
return uint16_t(-1);
}
@ -1753,7 +1734,7 @@ uint16_t PyC_Long_AsU16(PyObject *value)
uint32_t PyC_Long_AsU32(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
const ulong test = pyc_Long_AsUnsignedLong(value);
if (UNLIKELY(test == ulong(-1) && PyErr_Occurred())) {
return uint32_t(-1);
}
@ -1764,9 +1745,32 @@ uint32_t PyC_Long_AsU32(PyObject *value)
return uint32_t(test);
}
/* Inlined in header:
* PyC_Long_AsU64
*/
/* #PyLong_AsUnsignedLongLong, unlike #PyLong_AsLongLong, does not fall back to calling
* #PyNumber_Index when its argument is not a `PyLongObject` instance. To match parsing signed
* integer types with #PyLong_AsLongLong, this function performs the #PyNumber_Index fallback, if
* necessary, before calling #PyLong_AsUnsignedLongLong. */
uint64_t PyC_Long_AsU64(PyObject *value)
{
if (value == nullptr) {
/* Let PyLong_AsUnsignedLongLong handle error raising. */
return uint64_t(PyLong_AsUnsignedLongLong(value));
}
if (PyLong_Check(value)) {
return uint64_t(PyLong_AsUnsignedLongLong(value));
}
/* Call `__index__` like PyLong_AsLongLong. */
PyObject *value_converted = PyNumber_Index(value);
if (value_converted == nullptr) {
/* A `TypeError` will have been raised. */
return uint64_t(-1);
}
uint64_t to_return = uint64_t(PyLong_AsUnsignedLongLong(value_converted));
Py_DECREF(value_converted);
return to_return;
}
#ifdef __GNUC__
# pragma warning(pop)

View File

@ -268,17 +268,6 @@ const char *PyC_StringEnum_FindIDFromValue(const struct PyC_StringEnumItems *ite
*/
int PyC_CheckArgs_DeepCopy(PyObject *args);
/* Unsigned integer parsing that calls `__index__` like signed integer parsing. */
/**
* #PyLong_AsLong and #PyLong_AsLongLong call the Python `__index__` method of the input `value` if
* it is not a `PyLongObject`.
*
* #PyLong_AsUnsignedLong and #PyLong_AsUnsignedLongLong, however, do not call `__index__`, which
* means they cannot parse NumPy scalars and other numeric types.
*/
ulong PyC_Long_AsUnsignedLong(PyObject *value);
unsigned long long PyC_Long_AsUnsignedLongLong(PyObject *value);
/* Integer parsing (with overflow checks), -1 on error. */
/**
* Comparison with #PyObject_IsTrue
@ -313,12 +302,14 @@ int32_t PyC_Long_AsI32(PyObject *value);
int64_t PyC_Long_AsI64(PyObject *value);
#endif
/* Unlike Python's #PyLong_AsUnsignedLong and #PyLong_AsUnsignedLongLong, these unsigned integer
* parsing functions fall back to calling #PyNumber_Index when their argument is not a
* `PyLongObject`. This matches Python's signed integer parsing functions which also fall back to
* calling #PyNumber_Index. */
uint8_t PyC_Long_AsU8(PyObject *value);
uint16_t PyC_Long_AsU16(PyObject *value);
uint32_t PyC_Long_AsU32(PyObject *value);
#if 0 /* inline */
uint64_t PyC_Long_AsU64(PyObject *value);
#endif
/* inline so type signatures match as expected */
Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value)
@ -329,10 +320,6 @@ Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value)
{
return (int64_t)PyLong_AsLongLong(value);
}
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_StructFmt_type_from_str(const char *typestr);