Commit 96080385 authored by Marius Wachtler's avatar Marius Wachtler

Fix int(None)

parent b0991a74
...@@ -1129,7 +1129,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S ...@@ -1129,7 +1129,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
return NULL; return NULL;
} }
if (val == None) { if (val == NULL) {
PyErr_SetString(PyExc_TypeError, "int() missing string argument"); PyErr_SetString(PyExc_TypeError, "int() missing string argument");
return NULL; return NULL;
} }
...@@ -1142,7 +1142,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S ...@@ -1142,7 +1142,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
if (!PyInt_Check(_base)) if (!PyInt_Check(_base))
raiseExcHelper(TypeError, "an integer is required"); raiseExcHelper(TypeError, "an integer is required");
if (val == None) if (val == NULL)
raiseExcHelper(TypeError, "int() missing string argument"); raiseExcHelper(TypeError, "int() missing string argument");
if (!PyString_Check(val) && !PyUnicode_Check(val)) if (!PyString_Check(val) && !PyUnicode_Check(val))
...@@ -1150,7 +1150,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S ...@@ -1150,7 +1150,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
} }
base = static_cast<BoxedInt*>(_base)->n; base = static_cast<BoxedInt*>(_base)->n;
} else { } else {
if (val == None) if (val == NULL)
return PyInt_FromLong(0L); return PyInt_FromLong(0L);
Box* r = PyNumber_Int(val); Box* r = PyNumber_Int(val);
...@@ -1441,7 +1441,7 @@ void setupInt() { ...@@ -1441,7 +1441,7 @@ void setupInt() {
auto int_new = FunctionMetadata::create((void*)intNew<CXX>, UNKNOWN, 3, false, false, auto int_new = FunctionMetadata::create((void*)intNew<CXX>, UNKNOWN, 3, false, false,
ParamNames({ "", "x", "base" }, "", ""), CXX); ParamNames({ "", "x", "base" }, "", ""), CXX);
int_new->addVersion((void*)intNew<CAPI>, UNKNOWN, CAPI); int_new->addVersion((void*)intNew<CAPI>, UNKNOWN, CAPI);
int_cls->giveAttr("__new__", new BoxedFunction(int_new, { None, NULL })); int_cls->giveAttr("__new__", new BoxedFunction(int_new, { NULL, NULL }));
int_cls->giveAttr("bit_length", new BoxedFunction(FunctionMetadata::create((void*)intBitLength, BOXED_INT, 1))); int_cls->giveAttr("bit_length", new BoxedFunction(FunctionMetadata::create((void*)intBitLength, BOXED_INT, 1)));
......
...@@ -63,6 +63,10 @@ print type(int(2**100)) ...@@ -63,6 +63,10 @@ print type(int(2**100))
print type(int(2L)) print type(int(2L))
print type(int.__new__(int, 2**100)) print type(int.__new__(int, 2**100))
print type(int.__new__(int, 2L)) print type(int.__new__(int, 2L))
try:
print int(None)
except TypeError, e:
print e
try: try:
print type(int.__new__(C, 2**100)) print type(int.__new__(C, 2**100))
except OverflowError, e: except OverflowError, e:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment