Merge branch 'blender-v3.0-release'

This commit is contained in:
Campbell Barton 2021-11-05 16:04:40 +11:00
commit 5cc21b095a
1 changed files with 18 additions and 0 deletions

View File

@ -1677,6 +1677,9 @@ bool PyC_RunString_AsString(const char *imports[],
int PyC_Long_AsBool(PyObject *value)
{
const int test = _PyLong_AsInt(value);
if (UNLIKELY(test == -1 && PyErr_Occurred())) {
return -1;
}
if (UNLIKELY((uint)test > 1)) {
PyErr_SetString(PyExc_TypeError, "Python number not a bool (0/1)");
return -1;
@ -1687,6 +1690,9 @@ int PyC_Long_AsBool(PyObject *value)
int8_t PyC_Long_AsI8(PyObject *value)
{
const int test = _PyLong_AsInt(value);
if (UNLIKELY(test == -1 && PyErr_Occurred())) {
return -1;
}
if (UNLIKELY(test < INT8_MIN || test > INT8_MAX)) {
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int8");
return -1;
@ -1697,6 +1703,9 @@ int8_t PyC_Long_AsI8(PyObject *value)
int16_t PyC_Long_AsI16(PyObject *value)
{
const int test = _PyLong_AsInt(value);
if (UNLIKELY(test == -1 && PyErr_Occurred())) {
return -1;
}
if (UNLIKELY(test < INT16_MIN || test > INT16_MAX)) {
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int16");
return -1;
@ -1712,6 +1721,9 @@ int16_t PyC_Long_AsI16(PyObject *value)
uint8_t PyC_Long_AsU8(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
if (UNLIKELY(test == (ulong)-1 && PyErr_Occurred())) {
return (uint8_t)-1;
}
if (UNLIKELY(test > UINT8_MAX)) {
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint8");
return (uint8_t)-1;
@ -1722,6 +1734,9 @@ uint8_t PyC_Long_AsU8(PyObject *value)
uint16_t PyC_Long_AsU16(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
if (UNLIKELY(test == (ulong)-1 && PyErr_Occurred())) {
return (uint16_t)-1;
}
if (UNLIKELY(test > UINT16_MAX)) {
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint16");
return (uint16_t)-1;
@ -1732,6 +1747,9 @@ uint16_t PyC_Long_AsU16(PyObject *value)
uint32_t PyC_Long_AsU32(PyObject *value)
{
const ulong test = PyLong_AsUnsignedLong(value);
if (UNLIKELY(test == (ulong)-1 && PyErr_Occurred())) {
return (uint32_t)-1;
}
if (UNLIKELY(test > UINT32_MAX)) {
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint32");
return (uint32_t)-1;