Merge branch 'release/1.9.x'
This commit is contained in:
commit
036adff924
|
|
@ -5033,17 +5033,32 @@ write_function_instance(ostream &out, FunctionRemap *remap,
|
|||
// Windows, where longs are the same size as ints.
|
||||
// BUG: does not catch negative values on Windows when going through
|
||||
// the PyArg_ParseTuple case.
|
||||
extra_convert
|
||||
<< "#if (SIZEOF_LONG > SIZEOF_INT) && !defined(NDEBUG)\n"
|
||||
<< "if (" << param_name << " > UINT_MAX) {\n";
|
||||
if (!TypeManager::is_long(type)) {
|
||||
extra_convert
|
||||
<< "#if (SIZEOF_LONG > SIZEOF_INT) && !defined(NDEBUG)\n"
|
||||
<< "if (" << param_name << " > UINT_MAX) {\n";
|
||||
|
||||
error_raise_return(extra_convert, 2, return_flags, "OverflowError",
|
||||
"value %lu out of range for unsigned integer",
|
||||
param_name);
|
||||
extra_convert
|
||||
<< "}\n"
|
||||
<< "#endif\n";
|
||||
error_raise_return(extra_convert, 2, return_flags, "OverflowError",
|
||||
"value %lu out of range for unsigned integer",
|
||||
param_name);
|
||||
|
||||
extra_convert
|
||||
<< "}\n"
|
||||
<< "#endif\n";
|
||||
}
|
||||
expected_params += "int";
|
||||
only_pyobjects = false;
|
||||
|
||||
} else if (TypeManager::is_long(type)) {
|
||||
// Signed longs are equivalent to Python's int type.
|
||||
if (args_type == AT_single_arg) {
|
||||
pexpr_string = "PyLongOrInt_AS_LONG(arg)";
|
||||
type_check = "PyLongOrInt_Check(arg)";
|
||||
} else {
|
||||
indent(out, indent_level) << "long " << param_name << default_expr << ";\n";
|
||||
format_specifiers += "l";
|
||||
parameter_list += ", &" + param_name;
|
||||
}
|
||||
expected_params += "int";
|
||||
only_pyobjects = false;
|
||||
|
||||
|
|
@ -5062,6 +5077,7 @@ write_function_instance(ostream &out, FunctionRemap *remap,
|
|||
error_raise_return(extra_convert, 2, return_flags, "OverflowError",
|
||||
"value %ld out of range for signed integer",
|
||||
"arg_val");
|
||||
|
||||
extra_convert
|
||||
<< "}\n"
|
||||
<< "#endif\n";
|
||||
|
|
@ -6177,6 +6193,10 @@ pack_return_value(ostream &out, int indent_level, FunctionRemap *remap,
|
|||
indent(out, indent_level)
|
||||
<< "return PyBool_FromLong(" << return_expr << ");\n";
|
||||
|
||||
} else if (TypeManager::is_ssize(type)) {
|
||||
indent(out, indent_level)
|
||||
<< "return PyLongOrInt_FromSsize_t(" << return_expr << ");\n";
|
||||
|
||||
} else if (TypeManager::is_size(type)) {
|
||||
indent(out, indent_level)
|
||||
<< "return PyLongOrInt_FromSize_t(" << return_expr << ");\n";
|
||||
|
|
@ -6203,22 +6223,12 @@ pack_return_value(ostream &out, int indent_level, FunctionRemap *remap,
|
|||
<< "return PyLong_FromLongLong(" << return_expr << ");\n";
|
||||
|
||||
} else if (TypeManager::is_unsigned_integer(type)){
|
||||
out << "#if PY_MAJOR_VERSION >= 3\n";
|
||||
indent(out, indent_level)
|
||||
<< "return PyLong_FromUnsignedLong(" << return_expr << ");\n";
|
||||
out << "#else\n";
|
||||
indent(out, indent_level)
|
||||
<< "return PyLongOrInt_FromUnsignedLong(" << return_expr << ");\n";
|
||||
out << "#endif\n";
|
||||
|
||||
} else if (TypeManager::is_integer(type)) {
|
||||
out << "#if PY_MAJOR_VERSION >= 3\n";
|
||||
indent(out, indent_level)
|
||||
<< "return PyLong_FromLong(" << return_expr << ");\n";
|
||||
out << "#else\n";
|
||||
indent(out, indent_level)
|
||||
<< "return PyInt_FromLong(" << return_expr << ");\n";
|
||||
out << "#endif\n";
|
||||
<< "return PyLongOrInt_FromLong(" << return_expr << ");\n";
|
||||
|
||||
} else if (TypeManager::is_float(type)) {
|
||||
indent(out, indent_level)
|
||||
|
|
|
|||
|
|
@ -1176,6 +1176,9 @@ is_size(CPPType *type) {
|
|||
// Access: Public, Static
|
||||
// Description: Returns true if the indicated type is the "ssize_t"
|
||||
// type, or a const ssize_t, or a typedef to either.
|
||||
// ptrdiff_t and streamsize are also accepted, since
|
||||
// they are usually also defined as the signed
|
||||
// counterpart to size_t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool TypeManager::
|
||||
is_ssize(CPPType *type) {
|
||||
|
|
@ -1185,7 +1188,9 @@ is_ssize(CPPType *type) {
|
|||
|
||||
case CPPDeclaration::ST_typedef:
|
||||
if (type->get_simple_name() == "Py_ssize_t" ||
|
||||
type->get_simple_name() == "ssize_t") {
|
||||
type->get_simple_name() == "ssize_t" ||
|
||||
type->get_simple_name() == "ptrdiff_t" ||
|
||||
type->get_simple_name() == "streamsize") {
|
||||
return is_integer(type->as_typedef_type()->_type);
|
||||
} else {
|
||||
return is_ssize(type->as_typedef_type()->_type);
|
||||
|
|
@ -1198,6 +1203,38 @@ is_ssize(CPPType *type) {
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TypeManager::is_long
|
||||
// Access: Public, Static
|
||||
// Description: Returns true if the indicated type is the "long"
|
||||
// type, whether signed or unsigned.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool TypeManager::
|
||||
is_long(CPPType *type) {
|
||||
switch (type->get_subtype()) {
|
||||
case CPPDeclaration::ST_const:
|
||||
return is_long(type->as_const_type()->_wrapped_around);
|
||||
|
||||
case CPPDeclaration::ST_simple:
|
||||
{
|
||||
CPPSimpleType *simple_type = type->as_simple_type();
|
||||
if (simple_type != (CPPSimpleType *)NULL) {
|
||||
return (simple_type->_type == CPPSimpleType::T_int &&
|
||||
(simple_type->_flags & CPPSimpleType::F_long) != 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CPPDeclaration::ST_typedef:
|
||||
return is_long(type->as_typedef_type()->_type);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TypeManager::is_short
|
||||
// Access: Public, Static
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ public:
|
|||
static bool is_unsigned_integer(CPPType *type);
|
||||
static bool is_size(CPPType *type);
|
||||
static bool is_ssize(CPPType *type);
|
||||
static bool is_long(CPPType *type);
|
||||
static bool is_short(CPPType *type);
|
||||
static bool is_unsigned_short(CPPType *type);
|
||||
static bool is_longlong(CPPType *type);
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ inline PyObject* doPy_RETURN_FALSE()
|
|||
|
||||
#define PyLongOrInt_Check(x) PyLong_Check(x)
|
||||
#define PyLongOrInt_FromSize_t PyLong_FromSize_t
|
||||
#define PyLongOrInt_FromSsize_t PyLong_FromSsize_t
|
||||
#define PyLongOrInt_FromLong PyLong_FromLong
|
||||
#define PyLongOrInt_FromUnsignedLong PyLong_FromUnsignedLong
|
||||
#define PyLongOrInt_AS_LONG PyLong_AS_LONG
|
||||
|
|
@ -122,6 +123,7 @@ inline PyObject* doPy_RETURN_FALSE()
|
|||
#define PyLongOrInt_Check(x) (PyInt_Check(x) || PyLong_Check(x))
|
||||
// PyInt_FromSize_t automatically picks the right type.
|
||||
#define PyLongOrInt_FromSize_t PyInt_FromSize_t
|
||||
#define PyLongOrInt_FromSsize_t PyInt_FromSsize_t
|
||||
#define PyLongOrInt_FromLong PyInt_FromLong
|
||||
#define PyLongOrInt_AS_LONG PyInt_AsLong
|
||||
|
||||
|
|
|
|||
|
|
@ -50,8 +50,14 @@ protected:
|
|||
class ios : public ios_base {
|
||||
__published:
|
||||
typedef long fmtflags;
|
||||
#if defined(_WIN64) || !defined(_WIN32)
|
||||
typedef unsigned long long streampos;
|
||||
typedef long long streamoff;
|
||||
#else
|
||||
// 32-bit Windows uses 32-bit stream offsets.
|
||||
typedef unsigned long streampos;
|
||||
typedef long streamoff;
|
||||
#endif
|
||||
|
||||
bool good() const;
|
||||
bool eof() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue