From 828e52578d34671cc539362d4cf4f4c47f5584fa Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 8 Jul 2015 01:58:35 +0200 Subject: [PATCH] Allow a long (provided it is not overflowing) where an int is accepted --- .../interrogate/interfaceMakerPythonNative.cxx | 15 ++++++--------- dtool/src/interrogatedb/py_panda.h | 2 ++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index ec7e84adfe..cf6434508b 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -4774,10 +4774,9 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else if (TypeManager::is_unsigned_short(type)) { if (args_type == AT_single_arg) { - // This is defined to PyLong_Check for Python 3 by py_panda.h. - type_check = "PyInt_Check(arg)"; + type_check = "PyLongOrInt_Check(arg)"; extra_convert - << "long " << param_name << " = PyInt_AS_LONG(arg);\n"; + << "long " << param_name << " = PyLongOrInt_AS_LONG(arg);\n"; pexpr_string = "(" + type->get_local_name(&parser) + ")" + param_name; } else { @@ -4804,12 +4803,11 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else if (TypeManager::is_short(type)) { if (args_type == AT_single_arg) { - // This is defined to PyLong_Check for Python 3 by py_panda.h. - type_check = "PyInt_Check(arg)"; + type_check = "PyLongOrInt_Check(arg)"; // Perform overflow checking in debug builds. extra_convert - << "long arg_val = PyInt_AS_LONG(arg);\n" + << "long arg_val = PyLongOrInt_AS_LONG(arg);\n" << "#ifndef NDEBUG\n" << "if (arg_val < SHRT_MIN || arg_val > SHRT_MAX) {\n"; @@ -4867,14 +4865,13 @@ write_function_instance(ostream &out, FunctionRemap *remap, } else if (TypeManager::is_integer(type)) { if (args_type == AT_single_arg) { - // This is defined to PyLong_Check for Python 3 by py_panda.h. - type_check = "PyInt_Check(arg)"; + type_check = "PyLongOrInt_Check(arg)"; // Perform overflow checking in debug builds. Note that Python 2 // stores longs internally, for ints, so we don't do it on Windows, // where longs are the same size as ints. extra_convert - << "long arg_val = PyInt_AS_LONG(arg);\n" + << "long arg_val = PyLongOrInt_AS_LONG(arg);\n" << "#if (SIZEOF_LONG > SIZEOF_INT) && !defined(NDEBUG)\n" << "if (arg_val < INT_MIN || arg_val > INT_MAX) {\n"; diff --git a/dtool/src/interrogatedb/py_panda.h b/dtool/src/interrogatedb/py_panda.h index babf870934..7ad2e5857a 100644 --- a/dtool/src/interrogatedb/py_panda.h +++ b/dtool/src/interrogatedb/py_panda.h @@ -114,6 +114,7 @@ inline PyObject* doPy_RETURN_FALSE() #define PyLongOrInt_FromSize_t PyLong_FromSize_t #define PyLongOrInt_FromLong PyLong_FromLong #define PyLongOrInt_FromUnsignedLong PyLong_FromUnsignedLong +#define PyLongOrInt_AS_LONG PyLong_AS_LONG #define PyInt_Check PyLong_Check #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG @@ -122,6 +123,7 @@ inline PyObject* doPy_RETURN_FALSE() // PyInt_FromSize_t automatically picks the right type. #define PyLongOrInt_FromSize_t PyInt_FromSize_t #define PyLongOrInt_FromLong PyInt_FromLong +#define PyLongOrInt_AS_LONG PyInt_AsLong // For more portably defining hash functions. typedef long Py_hash_t;