Allow a long (provided it is not overflowing) where an int is accepted

This commit is contained in:
rdb 2015-07-08 01:58:35 +02:00
parent 2514ca29d8
commit 828e52578d
2 changed files with 8 additions and 9 deletions

View File

@ -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";

View File

@ -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;