Cleanup: use const variables where possible in the Python API
This commit is contained in:
@@ -207,7 +207,7 @@ PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len)
|
||||
*/
|
||||
void PyC_Tuple_Fill(PyObject *tuple, PyObject *value)
|
||||
{
|
||||
uint tot = PyTuple_GET_SIZE(tuple);
|
||||
const uint tot = PyTuple_GET_SIZE(tuple);
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < tot; i++) {
|
||||
@@ -218,7 +218,7 @@ void PyC_Tuple_Fill(PyObject *tuple, PyObject *value)
|
||||
|
||||
void PyC_List_Fill(PyObject *list, PyObject *value)
|
||||
{
|
||||
uint tot = PyList_GET_SIZE(list);
|
||||
const uint tot = PyList_GET_SIZE(list);
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < tot; i++) {
|
||||
@@ -377,7 +377,7 @@ void PyC_StackSpit(void)
|
||||
}
|
||||
|
||||
/* lame but handy */
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyRun_SimpleString("__import__('traceback').print_stack()");
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
@@ -948,7 +948,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
FILE *fp = fopen(filepath, "r");
|
||||
|
||||
if (fp) {
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
va_list vargs;
|
||||
|
||||
@@ -1423,7 +1423,7 @@ bool PyC_RunString_AsString(const char *imports[],
|
||||
*/
|
||||
int PyC_Long_AsBool(PyObject *value)
|
||||
{
|
||||
int test = _PyLong_AsInt(value);
|
||||
const int test = _PyLong_AsInt(value);
|
||||
if (UNLIKELY((uint)test > 1)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Python number not a bool (0/1)");
|
||||
return -1;
|
||||
@@ -1433,7 +1433,7 @@ int PyC_Long_AsBool(PyObject *value)
|
||||
|
||||
int8_t PyC_Long_AsI8(PyObject *value)
|
||||
{
|
||||
int test = _PyLong_AsInt(value);
|
||||
const int test = _PyLong_AsInt(value);
|
||||
if (UNLIKELY(test < INT8_MIN || test > INT8_MAX)) {
|
||||
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int8");
|
||||
return -1;
|
||||
@@ -1443,7 +1443,7 @@ int8_t PyC_Long_AsI8(PyObject *value)
|
||||
|
||||
int16_t PyC_Long_AsI16(PyObject *value)
|
||||
{
|
||||
int test = _PyLong_AsInt(value);
|
||||
const int test = _PyLong_AsInt(value);
|
||||
if (UNLIKELY(test < INT16_MIN || test > INT16_MAX)) {
|
||||
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int16");
|
||||
return -1;
|
||||
@@ -1458,7 +1458,7 @@ int16_t PyC_Long_AsI16(PyObject *value)
|
||||
|
||||
uint8_t PyC_Long_AsU8(PyObject *value)
|
||||
{
|
||||
ulong test = PyLong_AsUnsignedLong(value);
|
||||
const ulong test = PyLong_AsUnsignedLong(value);
|
||||
if (UNLIKELY(test > UINT8_MAX)) {
|
||||
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint8");
|
||||
return (uint8_t)-1;
|
||||
@@ -1468,7 +1468,7 @@ uint8_t PyC_Long_AsU8(PyObject *value)
|
||||
|
||||
uint16_t PyC_Long_AsU16(PyObject *value)
|
||||
{
|
||||
ulong test = PyLong_AsUnsignedLong(value);
|
||||
const ulong test = PyLong_AsUnsignedLong(value);
|
||||
if (UNLIKELY(test > UINT16_MAX)) {
|
||||
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint16");
|
||||
return (uint16_t)-1;
|
||||
@@ -1478,7 +1478,7 @@ uint16_t PyC_Long_AsU16(PyObject *value)
|
||||
|
||||
uint32_t PyC_Long_AsU32(PyObject *value)
|
||||
{
|
||||
ulong test = PyLong_AsUnsignedLong(value);
|
||||
const ulong test = PyLong_AsUnsignedLong(value);
|
||||
if (UNLIKELY(test > UINT32_MAX)) {
|
||||
PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint32");
|
||||
return (uint32_t)-1;
|
||||
|
||||
Reference in New Issue
Block a user