Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
077fffc6
Commit
077fffc6
authored
Feb 25, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'exceptions'
parents
e3016cd2
acf80b82
Changes
23
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
2553 additions
and
391 deletions
+2553
-391
Makefile
Makefile
+1
-1
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-1
from_cpython/Include/osdefs.h
from_cpython/Include/osdefs.h
+65
-0
from_cpython/Include/pyerrors.h
from_cpython/Include/pyerrors.h
+51
-106
from_cpython/Objects/exceptions.c
from_cpython/Objects/exceptions.c
+2236
-0
from_cpython/Python/formatter_unicode.c
from_cpython/Python/formatter_unicode.c
+20
-0
src/capi/errors.cpp
src/capi/errors.cpp
+67
-1
src/capi/object.cpp
src/capi/object.cpp
+4
-0
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+4
-0
src/core/types.h
src/core/types.h
+0
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+0
-196
src/runtime/capi.cpp
src/runtime/capi.cpp
+13
-5
src/runtime/dict.cpp
src/runtime/dict.cpp
+15
-18
src/runtime/import.cpp
src/runtime/import.cpp
+7
-0
src/runtime/int.cpp
src/runtime/int.cpp
+2
-1
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+1
-1
src/runtime/objmodel.h
src/runtime/objmodel.h
+1
-0
src/runtime/set.cpp
src/runtime/set.cpp
+1
-6
src/runtime/stacktrace.cpp
src/runtime/stacktrace.cpp
+6
-17
src/runtime/types.cpp
src/runtime/types.cpp
+37
-1
src/runtime/types.h
src/runtime/types.h
+21
-4
src/runtime/unicode.cpp
src/runtime/unicode.cpp
+0
-28
test/tests/exceptions_nonreprable.py
test/tests/exceptions_nonreprable.py
+0
-3
No files found.
Makefile
View file @
077fffc6
...
@@ -292,7 +292,7 @@ STDLIB_RELEASE_OBJS := stdlib.release.bc.o
...
@@ -292,7 +292,7 @@ STDLIB_RELEASE_OBJS := stdlib.release.bc.o
ASM_SRCS
:=
$(
wildcard
src/runtime/
*
.S
)
ASM_SRCS
:=
$(
wildcard
src/runtime/
*
.S
)
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c
$(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c
$(EXTRA_STDMODULE_SRCS)
STDOBJECT_SRCS
:=
structseq.c capsule.c stringobject.c
$(EXTRA_STDOBJECT_SRCS)
STDOBJECT_SRCS
:=
structseq.c capsule.c stringobject.c
exceptions.c
$(EXTRA_STDOBJECT_SRCS)
STDPYTHON_SRCS
:=
pyctype.c getargs.c formatter_string.c pystrtod.c dtoa.c
$(EXTRA_STDPYTHON_SRCS)
STDPYTHON_SRCS
:=
pyctype.c getargs.c formatter_string.c pystrtod.c dtoa.c
$(EXTRA_STDPYTHON_SRCS)
FROM_CPYTHON_SRCS
:=
$(
addprefix
from_cpython/Modules/,
$(STDMODULE_SRCS)
)
$(
addprefix
from_cpython/Objects/,
$(STDOBJECT_SRCS)
)
$(
addprefix
from_cpython/Python/,
$(STDPYTHON_SRCS)
)
FROM_CPYTHON_SRCS
:=
$(
addprefix
from_cpython/Modules/,
$(STDMODULE_SRCS)
)
$(
addprefix
from_cpython/Objects/,
$(STDOBJECT_SRCS)
)
$(
addprefix
from_cpython/Python/,
$(STDPYTHON_SRCS)
)
...
...
from_cpython/CMakeLists.txt
View file @
077fffc6
...
@@ -18,7 +18,7 @@ add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
...
@@ -18,7 +18,7 @@ add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c
)
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c datetimemodule.c _functoolsmodule.c _collectionsmodule.c itertoolsmodule.c resource.c signalmodule.c selectmodule.c fcntlmodule.c timemodule.c arraymodule.c zlibmodule.c _codecsmodule.c socketmodule.c
)
# compile specified files in from_cpython/Objects
# compile specified files in from_cpython/Objects
file
(
GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c
)
file
(
GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c
exceptions.c
)
# compile specified files in from_cpython/Python
# compile specified files in from_cpython/Python
file
(
GLOB_RECURSE STDPYTHON_SRCS Python getargs.c pyctype.c formatter_string.c pystrtod.c dtoa.c
)
file
(
GLOB_RECURSE STDPYTHON_SRCS Python getargs.c pyctype.c formatter_string.c pystrtod.c dtoa.c
)
...
...
from_cpython/Include/osdefs.h
0 → 100644
View file @
077fffc6
// This file is originally from CPython 2.7, with modifications for Pyston
#ifndef Py_OSDEFS_H
#define Py_OSDEFS_H
#ifdef __cplusplus
extern
"C"
{
#endif
/* Operating system dependencies */
/* Mod by chrish: QNX has WATCOM, but isn't DOS */
#if !defined(__QNX__)
#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)
#if defined(PYOS_OS2) && defined(PYCC_GCC)
#define MAXPATHLEN 260
#define SEP '/'
#define ALTSEP '\\'
#else
#define SEP '\\'
#define ALTSEP '/'
#define MAXPATHLEN 256
#endif
#define DELIM ';'
#endif
#endif
#ifdef RISCOS
#define SEP '.'
#define MAXPATHLEN 256
#define DELIM ','
#endif
/* Filename separator */
#ifndef SEP
#define SEP '/'
#endif
/* Max pathname length */
#ifdef __hpux
#include <sys/param.h>
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX MAXPATHLEN
#endif
#endif
#ifndef MAXPATHLEN
#if defined(PATH_MAX) && PATH_MAX > 1024
#define MAXPATHLEN PATH_MAX
#else
#define MAXPATHLEN 1024
#endif
#endif
/* Search path entry delimiter */
#ifndef DELIM
#define DELIM ':'
#endif
#ifdef __cplusplus
}
#endif
#endif
/* !Py_OSDEFS_H */
from_cpython/Include/pyerrors.h
View file @
077fffc6
...
@@ -8,8 +8,6 @@ extern "C" {
...
@@ -8,8 +8,6 @@ extern "C" {
/* Error objects */
/* Error objects */
// Pyston change: these are not our object formats
#if 0
typedef
struct
{
typedef
struct
{
PyObject_HEAD
PyObject_HEAD
PyObject
*
dict
;
PyObject
*
dict
;
...
@@ -74,8 +72,6 @@ typedef struct {
...
@@ -74,8 +72,6 @@ typedef struct {
PyObject
*
winerror
;
PyObject
*
winerror
;
}
PyWindowsErrorObject
;
}
PyWindowsErrorObject
;
#endif
#endif
#endif
// (Pyston TODO: add opaque definitions of those names)
/* Error handling definitions */
/* Error handling definitions */
...
@@ -132,119 +128,68 @@ PyAPI_FUNC(PyObject*) PyExceptionInstance_Class(PyObject*) PYSTON_NOEXCEPT;
...
@@ -132,119 +128,68 @@ PyAPI_FUNC(PyObject*) PyExceptionInstance_Class(PyObject*) PYSTON_NOEXCEPT;
// as PyTypeObject's.
// as PyTypeObject's.
// TODO not sure if this is worth it -- a fair amount of confusion (duplicating these names) for fairly
// TODO not sure if this is worth it -- a fair amount of confusion (duplicating these names) for fairly
// little gain (getting to treat them as PyTypeObject's and using our own names)
// little gain (getting to treat them as PyTypeObject's and using our own names)
#define PyExc_BaseException ((PyObject*)BaseException)
PyAPI_DATA
(
PyObject
*
)
PyExc_BaseException
;
PyAPI_DATA
(
PyTypeObject
*
)
BaseException
;
PyAPI_DATA
(
PyObject
*
)
PyExc_Exception
;
#define PyExc_Exception ((PyObject*)Exception)
PyAPI_DATA
(
PyObject
*
)
PyExc_StopIteration
;
PyAPI_DATA
(
PyTypeObject
*
)
Exception
;
PyAPI_DATA
(
PyObject
*
)
PyExc_GeneratorExit
;
#define PyExc_StopIteration ((PyObject*)StopIteration)
PyAPI_DATA
(
PyObject
*
)
PyExc_StandardError
;
PyAPI_DATA
(
PyTypeObject
*
)
StopIteration
;
PyAPI_DATA
(
PyObject
*
)
PyExc_ArithmeticError
;
#define PyExc_GeneratorExit ((PyObject*)GeneratorExit)
PyAPI_DATA
(
PyObject
*
)
PyExc_LookupError
;
PyAPI_DATA
(
PyTypeObject
*
)
GeneratorExit
;
#define PyExc_StandardError ((PyObject*)StandardError)
PyAPI_DATA
(
PyObject
*
)
PyExc_AssertionError
;
PyAPI_DATA
(
PyTypeObject
*
)
StandardError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_AttributeError
;
#define PyExc_ArithmeticError ((PyObject*)ArithmeticError)
PyAPI_DATA
(
PyObject
*
)
PyExc_EOFError
;
PyAPI_DATA
(
PyTypeObject
*
)
ArithmeticError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_FloatingPointError
;
#define PyExc_LookupError ((PyObject*)LookupError)
PyAPI_DATA
(
PyObject
*
)
PyExc_EnvironmentError
;
PyAPI_DATA
(
PyTypeObject
*
)
LookupError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_IOError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_OSError
;
#define PyExc_AssertionError ((PyObject*)AssertionError)
PyAPI_DATA
(
PyObject
*
)
PyExc_ImportError
;
PyAPI_DATA
(
PyTypeObject
*
)
AssertionError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_IndexError
;
#define PyExc_AttributeError ((PyObject*)AttributeError)
PyAPI_DATA
(
PyObject
*
)
PyExc_KeyError
;
PyAPI_DATA
(
PyTypeObject
*
)
AttributeError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_KeyboardInterrupt
;
#define PyExc_EOFError ((PyObject*)EOFError)
PyAPI_DATA
(
PyObject
*
)
PyExc_MemoryError
;
PyAPI_DATA
(
PyTypeObject
*
)
EOFError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_NameError
;
#define PyExc_FloatingPointError ((PyObject*)FloatingPointError)
PyAPI_DATA
(
PyObject
*
)
PyExc_OverflowError
;
PyAPI_DATA
(
PyTypeObject
*
)
FloatingPointError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_RuntimeError
;
#define PyExc_EnvironmentError ((PyObject*)EnvironmentError)
PyAPI_DATA
(
PyObject
*
)
PyExc_NotImplementedError
;
PyAPI_DATA
(
PyTypeObject
*
)
EnvironmentError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_SyntaxError
;
#define PyExc_IOError ((PyObject*)IOError)
PyAPI_DATA
(
PyObject
*
)
PyExc_IndentationError
;
PyAPI_DATA
(
PyTypeObject
*
)
IOError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_TabError
;
#define PyExc_OSError ((PyObject*)OSError)
PyAPI_DATA
(
PyObject
*
)
PyExc_ReferenceError
;
PyAPI_DATA
(
PyTypeObject
*
)
OSError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_SystemError
;
#define PyExc_ImportError ((PyObject*)ImportError)
PyAPI_DATA
(
PyObject
*
)
PyExc_SystemExit
;
PyAPI_DATA
(
PyTypeObject
*
)
ImportError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_TypeError
;
#define PyExc_IndexError ((PyObject*)IndexError)
PyAPI_DATA
(
PyObject
*
)
PyExc_UnboundLocalError
;
PyAPI_DATA
(
PyTypeObject
*
)
IndexError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_UnicodeError
;
#define PyExc_KeyError ((PyObject*)KeyError)
PyAPI_DATA
(
PyObject
*
)
PyExc_UnicodeEncodeError
;
PyAPI_DATA
(
PyTypeObject
*
)
KeyError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_UnicodeDecodeError
;
#define PyExc_KeyboardInterrupt ((PyObject*)KeyboardInterrupt)
PyAPI_DATA
(
PyObject
*
)
PyExc_UnicodeTranslateError
;
PyAPI_DATA
(
PyTypeObject
*
)
KeyboardInterrupt
;
PyAPI_DATA
(
PyObject
*
)
PyExc_ValueError
;
#define PyExc_MemoryError ((PyObject*)MemoryError)
PyAPI_DATA
(
PyObject
*
)
PyExc_ZeroDivisionError
;
PyAPI_DATA
(
PyTypeObject
*
)
MemoryError
;
#define PyExc_NameError ((PyObject*)NameError)
PyAPI_DATA
(
PyTypeObject
*
)
NameError
;
#define PyExc_OverflowError ((PyObject*)OverflowError)
PyAPI_DATA
(
PyTypeObject
*
)
OverflowError
;
#define PyExc_RuntimeError ((PyObject*)RuntimeError)
PyAPI_DATA
(
PyTypeObject
*
)
RuntimeError
;
#define PyExc_NotImplementedError ((PyObject*)NotImplementedError)
PyAPI_DATA
(
PyTypeObject
*
)
NotImplementedError
;
#define PyExc_SyntaxError ((PyObject*)SyntaxError)
PyAPI_DATA
(
PyTypeObject
*
)
SyntaxError
;
#define PyExc_IndentationError ((PyObject*)IndentationError)
PyAPI_DATA
(
PyTypeObject
*
)
IndentationError
;
#define PyExc_TabError ((PyObject*)TabError)
PyAPI_DATA
(
PyTypeObject
*
)
TabError
;
#define PyExc_ReferenceError ((PyObject*)ReferenceError)
PyAPI_DATA
(
PyTypeObject
*
)
ReferenceError
;
#define PyExc_SystemError ((PyObject*)SystemError)
PyAPI_DATA
(
PyTypeObject
*
)
SystemError
;
#define PyExc_SystemExit ((PyObject*)SystemExit)
PyAPI_DATA
(
PyTypeObject
*
)
SystemExit
;
#define PyExc_TypeError ((PyObject*)TypeError)
PyAPI_DATA
(
PyTypeObject
*
)
TypeError
;
#define PyExc_UnboundLocalError ((PyObject*)UnboundLocalError)
PyAPI_DATA
(
PyTypeObject
*
)
UnboundLocalError
;
#define PyExc_UnicodeError ((PyObject*)UnicodeError)
PyAPI_DATA
(
PyTypeObject
*
)
UnicodeError
;
#define PyExc_UnicodeEncodeError ((PyObject*)UnicodeEncodeError)
PyAPI_DATA
(
PyTypeObject
*
)
UnicodeEncodeError
;
#define PyExc_UnicodeDecodeError ((PyObject*)UnicodeDecodeError)
PyAPI_DATA
(
PyTypeObject
*
)
UnicodeDecodeError
;
#define PyExc_UnicodeTranslateError ((PyObject*)UnicodeTranslateError)
PyAPI_DATA
(
PyTypeObject
*
)
UnicodeTranslateError
;
#define PyExc_ValueError ((PyObject*)ValueError)
PyAPI_DATA
(
PyTypeObject
*
)
ValueError
;
#define PyExc_ZeroDivisionError ((PyObject*)ZeroDivisionError)
PyAPI_DATA
(
PyTypeObject
*
)
ZeroDivisionError
;
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
#define PyExc_WindowsError ((PyObject*)WindowsError)
PyAPI_DATA
(
PyObject
*
)
PyExc_WindowsError
;
PyAPI_DATA
(
PyTypeObject
*
)
WindowsError
;
#endif
#endif
#ifdef __VMS
#ifdef __VMS
#define PyExc_VMSError ((PyObject*)VMSError)
PyAPI_DATA
(
PyObject
*
)
PyExc_VMSError
;
PyAPI_DATA
(
PyTypeObject
*
)
VMSError
;
#endif
#endif
#define PyExc_BufferError ((PyObject*)BufferError)
PyAPI_DATA
(
PyObject
*
)
PyExc_BufferError
;
PyAPI_DATA
(
PyTypeObject
*
)
BufferError
;
PyAPI_DATA
(
PyObject
*
)
PyExc_MemoryErrorInst
;
PyAPI_DATA
(
PyObject
*
)
PyExc_MemoryErrorInst
;
PyAPI_DATA
(
PyObject
*
)
PyExc_RecursionErrorInst
;
PyAPI_DATA
(
PyObject
*
)
PyExc_RecursionErrorInst
;
/* Predefined warning categories */
/* Predefined warning categories */
#define PyExc_Warning ((PyObject*)Warning)
PyAPI_DATA
(
PyObject
*
)
PyExc_Warning
;
PyAPI_DATA
(
PyTypeObject
*
)
Warning
;
PyAPI_DATA
(
PyObject
*
)
PyExc_UserWarning
;
#define PyExc_UserWarning ((PyObject*)UserWarning)
PyAPI_DATA
(
PyObject
*
)
PyExc_DeprecationWarning
;
PyAPI_DATA
(
PyTypeObject
*
)
UserWarning
;
PyAPI_DATA
(
PyObject
*
)
PyExc_PendingDeprecationWarning
;
#define PyExc_DeprecationWarning ((PyObject*)DeprecationWarning)
PyAPI_DATA
(
PyObject
*
)
PyExc_SyntaxWarning
;
PyAPI_DATA
(
PyTypeObject
*
)
DeprecationWarning
;
PyAPI_DATA
(
PyObject
*
)
PyExc_RuntimeWarning
;
#define PyExc_PendingDeprecationWarning ((PyObject*)PendingDeprecationWarning)
PyAPI_DATA
(
PyObject
*
)
PyExc_FutureWarning
;
PyAPI_DATA
(
PyTypeObject
*
)
PendingDeprecationWarning
;
PyAPI_DATA
(
PyObject
*
)
PyExc_ImportWarning
;
#define PyExc_SyntaxWarning ((PyObject*)SyntaxWarning)
PyAPI_DATA
(
PyObject
*
)
PyExc_UnicodeWarning
;
PyAPI_DATA
(
PyTypeObject
*
)
SyntaxWarning
;
PyAPI_DATA
(
PyObject
*
)
PyExc_BytesWarning
;
#define PyExc_RuntimeWarning ((PyObject*)RuntimeWarning)
PyAPI_DATA
(
PyTypeObject
*
)
RuntimeWarning
;
#define PyExc_FutureWarning ((PyObject*)FutureWarning)
PyAPI_DATA
(
PyTypeObject
*
)
FutureWarning
;
#define PyExc_ImportWarning ((PyObject*)ImportWarning)
PyAPI_DATA
(
PyTypeObject
*
)
ImportWarning
;
#define PyExc_UnicodeWarning ((PyObject*)UnicodeWarning)
PyAPI_DATA
(
PyTypeObject
*
)
UnicodeWarning
;
#define PyExc_BytesWarning ((PyObject*)BytesWarning)
PyAPI_DATA
(
PyTypeObject
*
)
BytesWarning
;
/* Convenience functions */
/* Convenience functions */
...
...
from_cpython/Objects/exceptions.c
0 → 100644
View file @
077fffc6
This diff is collapsed.
Click to expand it.
from_cpython/Python/formatter_unicode.c
0 → 100644
View file @
077fffc6
// This file is originally from CPython 2.7, with modifications for Pyston
/* Implements the unicode (as opposed to string) version of the
built-in formatter for unicode. That is, unicode.__format__(). */
#include "Python.h"
#ifdef Py_USING_UNICODE
#include "../Objects/stringlib/unicodedefs.h"
#define FORMAT_STRING _PyUnicode_FormatAdvanced
/* don't define FORMAT_LONG, FORMAT_FLOAT, and FORMAT_COMPLEX, since
we can live with only the string versions of those. The builtin
format() will convert them to unicode. */
#include "../Objects/stringlib/formatter.h"
#endif
src/capi/errors.cpp
View file @
077fffc6
...
@@ -188,7 +188,73 @@ extern "C" void PyErr_WriteUnraisable(PyObject* obj) noexcept {
...
@@ -188,7 +188,73 @@ extern "C" void PyErr_WriteUnraisable(PyObject* obj) noexcept {
static
int
parse_syntax_error
(
PyObject
*
err
,
PyObject
**
message
,
const
char
**
filename
,
int
*
lineno
,
int
*
offset
,
static
int
parse_syntax_error
(
PyObject
*
err
,
PyObject
**
message
,
const
char
**
filename
,
int
*
lineno
,
int
*
offset
,
const
char
**
text
)
noexcept
{
const
char
**
text
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
long
hold
;
PyObject
*
v
;
/* old style errors */
if
(
PyTuple_Check
(
err
))
return
PyArg_ParseTuple
(
err
,
"O(ziiz)"
,
message
,
filename
,
lineno
,
offset
,
text
);
*
message
=
NULL
;
/* new style errors. `err' is an instance */
*
message
=
PyObject_GetAttrString
(
err
,
"msg"
);
if
(
!*
message
)
goto
finally
;
v
=
PyObject_GetAttrString
(
err
,
"filename"
);
if
(
!
v
)
goto
finally
;
if
(
v
==
Py_None
)
{
Py_DECREF
(
v
);
*
filename
=
NULL
;
}
else
{
*
filename
=
PyString_AsString
(
v
);
Py_DECREF
(
v
);
if
(
!*
filename
)
goto
finally
;
}
v
=
PyObject_GetAttrString
(
err
,
"lineno"
);
if
(
!
v
)
goto
finally
;
hold
=
PyInt_AsLong
(
v
);
Py_DECREF
(
v
);
if
(
hold
<
0
&&
PyErr_Occurred
())
goto
finally
;
*
lineno
=
(
int
)
hold
;
v
=
PyObject_GetAttrString
(
err
,
"offset"
);
if
(
!
v
)
goto
finally
;
if
(
v
==
Py_None
)
{
*
offset
=
-
1
;
Py_DECREF
(
v
);
}
else
{
hold
=
PyInt_AsLong
(
v
);
Py_DECREF
(
v
);
if
(
hold
<
0
&&
PyErr_Occurred
())
goto
finally
;
*
offset
=
(
int
)
hold
;
}
v
=
PyObject_GetAttrString
(
err
,
"text"
);
if
(
!
v
)
goto
finally
;
if
(
v
==
Py_None
)
{
Py_DECREF
(
v
);
*
text
=
NULL
;
}
else
{
*
text
=
PyString_AsString
(
v
);
Py_DECREF
(
v
);
if
(
!*
text
)
goto
finally
;
}
return
1
;
finally:
Py_XDECREF
(
*
message
);
return
0
;
}
}
static
void
print_error_text
(
PyObject
*
f
,
int
offset
,
const
char
*
text
)
noexcept
{
static
void
print_error_text
(
PyObject
*
f
,
int
offset
,
const
char
*
text
)
noexcept
{
...
...
src/capi/object.cpp
View file @
077fffc6
...
@@ -72,6 +72,10 @@ extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject*
...
@@ -72,6 +72,10 @@ extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject*
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
}
}
extern
"C"
int
PyObject_SetAttr
(
PyObject
*
v
,
PyObject
*
name
,
PyObject
*
value
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
PyObject
*
PyObject_GetAttrString
(
PyObject
*
o
,
const
char
*
attr
)
noexcept
{
extern
"C"
PyObject
*
PyObject_GetAttrString
(
PyObject
*
o
,
const
char
*
attr
)
noexcept
{
// TODO do something like this? not sure if this is safe; will people expect that calling into a known function
// TODO do something like this? not sure if this is safe; will people expect that calling into a known function
// won't end up doing a GIL check?
// won't end up doing a GIL check?
...
...
src/capi/typeobject.cpp
View file @
077fffc6
...
@@ -1784,6 +1784,10 @@ void PystonType_Ready(BoxedClass* cls) {
...
@@ -1784,6 +1784,10 @@ void PystonType_Ready(BoxedClass* cls) {
}
}
}
}
extern
"C"
void
PyType_Modified
(
PyTypeObject
*
type
)
noexcept
{
// We don't cache anything yet that would need to be invalidated:
}
extern
"C"
int
PyType_Ready
(
PyTypeObject
*
cls
)
noexcept
{
extern
"C"
int
PyType_Ready
(
PyTypeObject
*
cls
)
noexcept
{
gc
::
registerNonheapRootObject
(
cls
);
gc
::
registerNonheapRootObject
(
cls
);
...
...
src/core/types.h
View file @
077fffc6
...
@@ -522,8 +522,6 @@ void appendToSysPath(const std::string& path);
...
@@ -522,8 +522,6 @@ void appendToSysPath(const std::string& path);
void
prependToSysPath
(
const
std
::
string
&
path
);
void
prependToSysPath
(
const
std
::
string
&
path
);
void
addToSysArgv
(
const
char
*
str
);
void
addToSysArgv
(
const
char
*
str
);
std
::
string
formatException
(
Box
*
e
);
// Raise a SyntaxError that occurs at a specific location.
// Raise a SyntaxError that occurs at a specific location.
// The traceback given to the user will include this,
// The traceback given to the user will include this,
// even though the execution didn't actually arrive there.
// even though the execution didn't actually arrive there.
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
077fffc6
...
@@ -589,19 +589,6 @@ Box* eval(Box* code) {
...
@@ -589,19 +589,6 @@ Box* eval(Box* code) {
BoxedClass
*
notimplemented_cls
;
BoxedClass
*
notimplemented_cls
;
BoxedModule
*
builtins_module
;
BoxedModule
*
builtins_module
;
// TODO looks like CPython and pypy put this into an "exceptions" module:
extern
"C"
{
BoxedClass
*
BaseException
,
*
Exception
,
*
StandardError
,
*
AssertionError
,
*
AttributeError
,
*
GeneratorExit
,
*
TypeError
,
*
NameError
,
*
KeyError
,
*
IndexError
,
*
IOError
,
*
OSError
,
*
ZeroDivisionError
,
*
ValueError
,
*
UnboundLocalError
,
*
RuntimeError
,
*
ImportError
,
*
StopIteration
,
*
Warning
,
*
SyntaxError
,
*
OverflowError
,
*
DeprecationWarning
,
*
MemoryError
,
*
LookupError
,
*
EnvironmentError
,
*
ArithmeticError
,
*
BufferError
,
*
KeyboardInterrupt
,
*
SystemExit
,
*
SystemError
,
*
NotImplementedError
,
*
PendingDeprecationWarning
,
*
EOFError
,
*
UnicodeError
,
*
UnicodeEncodeError
,
*
UnicodeDecodeError
,
*
UnicodeTranslateError
;
Box
*
PyExc_RecursionErrorInst
;
Box
*
PyExc_MemoryErrorInst
;
}
class
BoxedException
:
public
Box
{
class
BoxedException
:
public
Box
{
public:
public:
HCAttrs
attrs
;
HCAttrs
attrs
;
...
@@ -879,123 +866,6 @@ Box* pydumpAddr(Box* p) {
...
@@ -879,123 +866,6 @@ Box* pydumpAddr(Box* p) {
return
None
;
return
None
;
}
}
class
BoxedEnvironmentError
:
public
BoxedException
{
public:
// Box* args, *message, *myerrno, *strerror, *filename;
Box
*
myerrno
,
*
strerror
,
*
filename
;
static
Box
*
__init__
(
BoxedEnvironmentError
*
self
,
Box
*
errno_
,
Box
*
strerror
,
Box
**
_args
)
{
Box
*
filename
=
_args
[
0
];
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
EnvironmentError
),
""
);
self
->
myerrno
=
errno_
;
self
->
strerror
=
strerror
;
self
->
filename
=
filename
;
return
None
;
}
static
Box
*
__reduce__
(
Box
*
self
)
{
Py_FatalError
(
"unimplemented"
);
}
static
PyObject
*
__str__
(
BoxedEnvironmentError
*
self
)
noexcept
{
PyObject
*
rtnval
=
NULL
;
if
(
self
->
filename
)
{
PyObject
*
fmt
;
PyObject
*
repr
;
PyObject
*
tuple
;
fmt
=
PyString_FromString
(
"[Errno %s] %s: %s"
);
if
(
!
fmt
)
return
NULL
;
repr
=
PyObject_Repr
(
self
->
filename
);
if
(
!
repr
)
{
Py_DECREF
(
fmt
);
return
NULL
;
}
tuple
=
PyTuple_New
(
3
);
if
(
!
tuple
)
{
Py_DECREF
(
repr
);
Py_DECREF
(
fmt
);
return
NULL
;
}
if
(
self
->
myerrno
)
{
Py_INCREF
(
self
->
myerrno
);
PyTuple_SET_ITEM
(
tuple
,
0
,
self
->
myerrno
);
}
else
{
Py_INCREF
(
Py_None
);
PyTuple_SET_ITEM
(
tuple
,
0
,
Py_None
);
}
if
(
self
->
strerror
)
{
Py_INCREF
(
self
->
strerror
);
PyTuple_SET_ITEM
(
tuple
,
1
,
self
->
strerror
);
}
else
{
Py_INCREF
(
Py_None
);
PyTuple_SET_ITEM
(
tuple
,
1
,
Py_None
);
}
PyTuple_SET_ITEM
(
tuple
,
2
,
repr
);
rtnval
=
PyString_Format
(
fmt
,
tuple
);
Py_DECREF
(
fmt
);
Py_DECREF
(
tuple
);
}
else
if
(
self
->
myerrno
&&
self
->
strerror
)
{
PyObject
*
fmt
;
PyObject
*
tuple
;
fmt
=
PyString_FromString
(
"[Errno %s] %s"
);
if
(
!
fmt
)
return
NULL
;
tuple
=
PyTuple_New
(
2
);
if
(
!
tuple
)
{
Py_DECREF
(
fmt
);
return
NULL
;
}
if
(
self
->
myerrno
)
{
Py_INCREF
(
self
->
myerrno
);
PyTuple_SET_ITEM
(
tuple
,
0
,
self
->
myerrno
);
}
else
{
Py_INCREF
(
Py_None
);
PyTuple_SET_ITEM
(
tuple
,
0
,
Py_None
);
}
if
(
self
->
strerror
)
{
Py_INCREF
(
self
->
strerror
);
PyTuple_SET_ITEM
(
tuple
,
1
,
self
->
strerror
);
}
else
{
Py_INCREF
(
Py_None
);
PyTuple_SET_ITEM
(
tuple
,
1
,
Py_None
);
}
rtnval
=
PyString_Format
(
fmt
,
tuple
);
Py_DECREF
(
fmt
);
Py_DECREF
(
tuple
);
}
else
rtnval
=
exceptionStr
(
self
);
return
rtnval
;
}
static
void
gcHandler
(
GCVisitor
*
v
,
Box
*
_b
)
{
assert
(
isSubclass
(
_b
->
cls
,
EnvironmentError
));
boxGCHandler
(
v
,
_b
);
BoxedEnvironmentError
*
ee
=
static_cast
<
BoxedEnvironmentError
*>
(
_b
);
if
(
ee
->
myerrno
)
v
->
visit
(
ee
->
myerrno
);
if
(
ee
->
strerror
)
v
->
visit
(
ee
->
strerror
);
if
(
ee
->
filename
)
v
->
visit
(
ee
->
filename
);
}
};
void
setupBuiltins
()
{
void
setupBuiltins
()
{
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
);
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
);
...
@@ -1018,67 +888,6 @@ void setupBuiltins() {
...
@@ -1018,67 +888,6 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"all"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
),
"all"
));
builtins_module
->
giveAttr
(
"all"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
),
"all"
));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
),
"any"
));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
),
"any"
));
BaseException
=
makeBuiltinException
(
object_cls
,
"BaseException"
,
sizeof
(
BoxedException
));
Exception
=
makeBuiltinException
(
BaseException
,
"Exception"
);
StandardError
=
makeBuiltinException
(
Exception
,
"StandardError"
);
AssertionError
=
makeBuiltinException
(
StandardError
,
"AssertionError"
);
AttributeError
=
makeBuiltinException
(
StandardError
,
"AttributeError"
);
GeneratorExit
=
makeBuiltinException
(
BaseException
,
"GeneratorExit"
);
TypeError
=
makeBuiltinException
(
StandardError
,
"TypeError"
);
NameError
=
makeBuiltinException
(
StandardError
,
"NameError"
);
LookupError
=
makeBuiltinException
(
StandardError
,
"LookupError"
);
KeyError
=
makeBuiltinException
(
LookupError
,
"KeyError"
);
IndexError
=
makeBuiltinException
(
LookupError
,
"IndexError"
);
EnvironmentError
=
makeBuiltinException
(
StandardError
,
"EnvironmentError"
,
sizeof
(
BoxedEnvironmentError
));
IOError
=
makeBuiltinException
(
EnvironmentError
,
"IOError"
);
OSError
=
makeBuiltinException
(
EnvironmentError
,
"OSError"
);
ArithmeticError
=
makeBuiltinException
(
StandardError
,
"ArithmeticError"
);
ZeroDivisionError
=
makeBuiltinException
(
ArithmeticError
,
"ZeroDivisionError"
);
ValueError
=
makeBuiltinException
(
StandardError
,
"ValueError"
);
UnboundLocalError
=
makeBuiltinException
(
NameError
,
"UnboundLocalError"
);
RuntimeError
=
makeBuiltinException
(
StandardError
,
"RuntimeError"
);
ImportError
=
makeBuiltinException
(
StandardError
,
"ImportError"
);
StopIteration
=
makeBuiltinException
(
Exception
,
"StopIteration"
);
Warning
=
makeBuiltinException
(
Exception
,
"Warning"
);
SyntaxError
=
makeBuiltinException
(
StandardError
,
"SyntaxError"
);
OverflowError
=
makeBuiltinException
(
ArithmeticError
,
"OverflowError"
);
/*ImportWarning =*/
makeBuiltinException
(
Warning
,
"ImportWarning"
);
DeprecationWarning
=
makeBuiltinException
(
Warning
,
"DeprecationWarning"
);
/*BytesWarning =*/
makeBuiltinException
(
Warning
,
"BytesWarning"
);
MemoryError
=
makeBuiltinException
(
StandardError
,
"MemoryError"
);
BufferError
=
makeBuiltinException
(
StandardError
,
"BufferError"
);
KeyboardInterrupt
=
makeBuiltinException
(
BaseException
,
"KeyboardInterrupt"
);
SystemExit
=
makeBuiltinException
(
BaseException
,
"SystemExit"
);
SystemError
=
makeBuiltinException
(
StandardError
,
"SystemError"
);
NotImplementedError
=
makeBuiltinException
(
RuntimeError
,
"NotImplementedError"
);
PendingDeprecationWarning
=
makeBuiltinException
(
Warning
,
"PendingDeprecationWarning"
);
EOFError
=
makeBuiltinException
(
StandardError
,
"EOFError"
);
// Unicode errors
UnicodeError
=
makeBuiltinException
(
ValueError
,
"UnicodeError"
);
UnicodeEncodeError
=
makeBuiltinException
(
UnicodeError
,
"UnicodeEncodeError"
);
UnicodeDecodeError
=
makeBuiltinException
(
UnicodeError
,
"UnicodeDecodeError"
);
UnicodeTranslateError
=
makeBuiltinException
(
UnicodeError
,
"UnicodeTranslateError"
);
BaseException
->
giveAttr
(
"__reduce__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedException
::
__reduce__
,
UNKNOWN
,
1
)));
EnvironmentError
->
giveAttr
(
"__reduce__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnvironmentError
::
__reduce__
,
UNKNOWN
,
1
)));
EnvironmentError
->
gc_visit
=
BoxedEnvironmentError
::
gcHandler
;
EnvironmentError
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnvironmentError
::
__init__
,
NONE
,
4
,
3
,
false
,
false
),
{
NULL
,
NULL
,
NULL
}));
EnvironmentError
->
giveAttr
(
"errno"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedEnvironmentError
,
myerrno
)));
EnvironmentError
->
giveAttr
(
"strerror"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedEnvironmentError
,
strerror
)));
EnvironmentError
->
giveAttr
(
"filename"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedEnvironmentError
,
filename
)));
EnvironmentError
->
giveAttr
(
"__str__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnvironmentError
::
__str__
,
UNKNOWN
,
1
)));
repr_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
),
"repr"
);
repr_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
),
"repr"
);
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
...
@@ -1228,10 +1037,5 @@ void setupBuiltins() {
...
@@ -1228,10 +1037,5 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"classmethod"
,
classmethod_cls
);
builtins_module
->
giveAttr
(
"classmethod"
,
classmethod_cls
);
builtins_module
->
giveAttr
(
builtins_module
->
giveAttr
(
"eval"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
eval
,
UNKNOWN
,
1
,
0
,
false
,
false
),
"eval"
));
"eval"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
eval
,
UNKNOWN
,
1
,
0
,
false
,
false
),
"eval"
));
PyExc_RecursionErrorInst
=
new
(
RuntimeError
)
BoxedException
();
gc
::
registerPermanentRoot
(
PyExc_RecursionErrorInst
);
PyExc_MemoryErrorInst
=
new
(
MemoryError
)
BoxedException
();
gc
::
registerPermanentRoot
(
PyExc_MemoryErrorInst
);
}
}
}
}
src/runtime/capi.cpp
View file @
077fffc6
...
@@ -673,21 +673,24 @@ void checkAndThrowCAPIException() {
...
@@ -673,21 +673,24 @@ void checkAndThrowCAPIException() {
if
(
!
tb
)
if
(
!
tb
)
tb
=
None
;
tb
=
None
;
// Make sure to call PyErr_Clear() *before* normalizing the exception, since otherwise
// the normalization can think that it had raised an exception, resulting to a call
// to checkAndThrowCAPIException, and boom.
PyErr_Clear
();
// This is similar to PyErr_NormalizeException:
// This is similar to PyErr_NormalizeException:
if
(
!
isInstance
(
value
,
type
))
{
if
(
!
isInstance
(
value
,
type
))
{
if
(
value
->
cls
==
tuple_cls
)
{
if
(
value
->
cls
==
tuple_cls
)
{
value
=
runtimeCall
(
cur_thread_state
.
curexc_type
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
value
,
NULL
,
NULL
,
value
=
runtimeCall
(
type
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
value
,
NULL
,
NULL
,
NULL
,
NULL
);
NULL
,
NULL
);
}
else
if
(
value
==
None
)
{
}
else
if
(
value
==
None
)
{
value
=
runtimeCall
(
cur_thread_state
.
curexc_
type
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
value
=
runtimeCall
(
type
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
else
{
}
else
{
value
=
runtimeCall
(
cur_thread_state
.
curexc_
type
,
ArgPassSpec
(
1
),
value
,
NULL
,
NULL
,
NULL
,
NULL
);
value
=
runtimeCall
(
type
,
ArgPassSpec
(
1
),
value
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
}
}
RELEASE_ASSERT
(
value
->
cls
==
type
,
"unsupported"
);
RELEASE_ASSERT
(
value
->
cls
==
type
,
"unsupported"
);
PyErr_Clear
();
if
(
tb
!=
None
)
if
(
tb
!=
None
)
raiseRaw
(
ExcInfo
(
value
->
cls
,
value
,
tb
));
raiseRaw
(
ExcInfo
(
value
->
cls
,
value
,
tb
));
raiseExc
(
value
);
raiseExc
(
value
);
...
@@ -856,6 +859,11 @@ extern "C" PyObject* PyErr_Occurred() noexcept {
...
@@ -856,6 +859,11 @@ extern "C" PyObject* PyErr_Occurred() noexcept {
}
}
extern
"C"
int
PyErr_WarnEx
(
PyObject
*
category
,
const
char
*
text
,
Py_ssize_t
stacklevel
)
noexcept
{
extern
"C"
int
PyErr_WarnEx
(
PyObject
*
category
,
const
char
*
text
,
Py_ssize_t
stacklevel
)
noexcept
{
// These warnings are silenced by default:
// We should copy the real CPython code in here
if
(
category
==
PyExc_DeprecationWarning
)
return
0
;
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
}
}
...
...
src/runtime/dict.cpp
View file @
077fffc6
...
@@ -174,12 +174,7 @@ Box* dictGetitem(BoxedDict* self, Box* k) {
...
@@ -174,12 +174,7 @@ Box* dictGetitem(BoxedDict* self, Box* k) {
auto
it
=
self
->
d
.
find
(
k
);
auto
it
=
self
->
d
.
find
(
k
);
if
(
it
==
self
->
d
.
end
())
{
if
(
it
==
self
->
d
.
end
())
{
BoxedString
*
s
=
reprOrNull
(
k
);
raiseExcHelper
(
KeyError
,
k
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
}
Box
*
pos
=
self
->
d
[
k
];
Box
*
pos
=
self
->
d
[
k
];
...
@@ -306,12 +301,7 @@ Box* dictDelitem(BoxedDict* self, Box* k) {
...
@@ -306,12 +301,7 @@ Box* dictDelitem(BoxedDict* self, Box* k) {
auto
it
=
self
->
d
.
find
(
k
);
auto
it
=
self
->
d
.
find
(
k
);
if
(
it
==
self
->
d
.
end
())
{
if
(
it
==
self
->
d
.
end
())
{
BoxedString
*
s
=
reprOrNull
(
k
);
raiseExcHelper
(
KeyError
,
k
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
}
self
->
d
.
erase
(
it
);
self
->
d
.
erase
(
it
);
...
@@ -329,6 +319,18 @@ extern "C" int PyDict_DelItem(PyObject* op, PyObject* key) noexcept {
...
@@ -329,6 +319,18 @@ extern "C" int PyDict_DelItem(PyObject* op, PyObject* key) noexcept {
return
0
;
return
0
;
}
}
extern
"C"
int
PyDict_DelItemString
(
PyObject
*
v
,
const
char
*
key
)
noexcept
{
PyObject
*
kv
;
int
err
;
kv
=
PyString_FromString
(
key
);
if
(
kv
==
NULL
)
return
-
1
;
err
=
PyDict_DelItem
(
v
,
kv
);
Py_DECREF
(
kv
);
return
err
;
}
Box
*
dictPop
(
BoxedDict
*
self
,
Box
*
k
,
Box
*
d
)
{
Box
*
dictPop
(
BoxedDict
*
self
,
Box
*
k
,
Box
*
d
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
raiseExcHelper
(
TypeError
,
"descriptor 'pop' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
raiseExcHelper
(
TypeError
,
"descriptor 'pop' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
...
@@ -338,12 +340,7 @@ Box* dictPop(BoxedDict* self, Box* k, Box* d) {
...
@@ -338,12 +340,7 @@ Box* dictPop(BoxedDict* self, Box* k, Box* d) {
if
(
d
)
if
(
d
)
return
d
;
return
d
;
BoxedString
*
s
=
reprOrNull
(
k
);
raiseExcHelper
(
KeyError
,
k
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
}
Box
*
rtn
=
it
->
second
;
Box
*
rtn
=
it
->
second
;
...
...
src/runtime/import.cpp
View file @
077fffc6
...
@@ -261,6 +261,13 @@ static void ensure_fromlist(Box* module, Box* fromlist, const std::string& modul
...
@@ -261,6 +261,13 @@ static void ensure_fromlist(Box* module, Box* fromlist, const std::string& modul
}
}
}
}
extern
"C"
PyObject
*
PyImport_ImportModule
(
const
char
*
name
)
noexcept
{
if
(
strcmp
(
"__builtin__"
,
name
)
==
0
)
return
builtins_module
;
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
Box
*
import
(
int
level
,
Box
*
from_imports
,
const
std
::
string
*
module_name
)
{
extern
"C"
Box
*
import
(
int
level
,
Box
*
from_imports
,
const
std
::
string
*
module_name
)
{
RELEASE_ASSERT
(
level
==
-
1
||
level
==
0
,
"not implemented"
);
RELEASE_ASSERT
(
level
==
-
1
||
level
==
0
,
"not implemented"
);
...
...
src/runtime/int.cpp
View file @
077fffc6
...
@@ -45,7 +45,8 @@ extern "C" long PyInt_AsLong(PyObject* op) noexcept {
...
@@ -45,7 +45,8 @@ extern "C" long PyInt_AsLong(PyObject* op) noexcept {
if
(
op
->
cls
==
long_cls
)
if
(
op
->
cls
==
long_cls
)
return
PyLong_AsLong
(
op
);
return
PyLong_AsLong
(
op
);
Py_FatalError
(
"unimplemented"
);
PyErr_SetString
(
PyExc_TypeError
,
"an integer is required"
);
return
-
1
;
}
}
extern
"C"
Py_ssize_t
PyInt_AsSsize_t
(
PyObject
*
op
)
noexcept
{
extern
"C"
Py_ssize_t
PyInt_AsSsize_t
(
PyObject
*
op
)
noexcept
{
...
...
src/runtime/objmodel.cpp
View file @
077fffc6
...
@@ -208,7 +208,7 @@ extern "C" void assertFail(BoxedModule* inModule, Box* msg) {
...
@@ -208,7 +208,7 @@ extern "C" void assertFail(BoxedModule* inModule, Box* msg) {
BoxedString
*
tostr
=
str
(
msg
);
BoxedString
*
tostr
=
str
(
msg
);
raiseExcHelper
(
AssertionError
,
"%s"
,
tostr
->
s
.
c_str
());
raiseExcHelper
(
AssertionError
,
"%s"
,
tostr
->
s
.
c_str
());
}
else
{
}
else
{
raiseExcHelper
(
AssertionError
,
NULL
);
raiseExcHelper
(
AssertionError
,
""
);
}
}
}
}
...
...
src/runtime/objmodel.h
View file @
077fffc6
...
@@ -41,6 +41,7 @@ extern "C" Box* deopt(AST_expr* expr, Box* value);
...
@@ -41,6 +41,7 @@ extern "C" Box* deopt(AST_expr* expr, Box* value);
// helper function for raising from the runtime:
// helper function for raising from the runtime:
void
raiseExcHelper
(
BoxedClass
*
,
const
char
*
fmt
,
...)
__attribute__
((
__noreturn__
));
void
raiseExcHelper
(
BoxedClass
*
,
const
char
*
fmt
,
...)
__attribute__
((
__noreturn__
));
void
raiseExcHelper
(
BoxedClass
*
,
Box
*
arg
)
__attribute__
((
__noreturn__
));
BoxedModule
*
getCurrentModule
();
BoxedModule
*
getCurrentModule
();
...
...
src/runtime/set.cpp
View file @
077fffc6
...
@@ -200,12 +200,7 @@ Box* setRemove(BoxedSet* self, Box* v) {
...
@@ -200,12 +200,7 @@ Box* setRemove(BoxedSet* self, Box* v) {
auto
it
=
self
->
s
.
find
(
v
);
auto
it
=
self
->
s
.
find
(
v
);
if
(
it
==
self
->
s
.
end
())
{
if
(
it
==
self
->
s
.
end
())
{
BoxedString
*
s
=
reprOrNull
(
v
);
raiseExcHelper
(
KeyError
,
v
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
}
self
->
s
.
erase
(
it
);
self
->
s
.
erase
(
it
);
...
...
src/runtime/stacktrace.cpp
View file @
077fffc6
...
@@ -196,9 +196,7 @@ ExcInfo::ExcInfo(Box* type, Box* value, Box* traceback) : type(type), value(valu
...
@@ -196,9 +196,7 @@ ExcInfo::ExcInfo(Box* type, Box* value, Box* traceback) : type(type), value(valu
#endif
#endif
void
ExcInfo
::
printExcAndTraceback
()
const
{
void
ExcInfo
::
printExcAndTraceback
()
const
{
std
::
string
msg
=
formatException
(
value
);
PyErr_Display
(
type
,
value
,
traceback
);
printTraceback
(
traceback
);
fprintf
(
stderr
,
"%s
\n
"
,
msg
.
c_str
());
}
}
bool
ExcInfo
::
matches
(
BoxedClass
*
cls
)
const
{
bool
ExcInfo
::
matches
(
BoxedClass
*
cls
)
const
{
...
@@ -242,6 +240,11 @@ void raise3(Box* arg0, Box* arg1, Box* arg2) {
...
@@ -242,6 +240,11 @@ void raise3(Box* arg0, Box* arg1, Box* arg2) {
getTypeName
(
arg0
));
getTypeName
(
arg0
));
}
}
void
raiseExcHelper
(
BoxedClass
*
cls
,
Box
*
arg
)
{
Box
*
exc_obj
=
runtimeCall
(
cls
,
ArgPassSpec
(
1
),
arg
,
NULL
,
NULL
,
NULL
,
NULL
);
raiseExc
(
exc_obj
);
}
void
raiseExcHelper
(
BoxedClass
*
cls
,
const
char
*
msg
,
...)
{
void
raiseExcHelper
(
BoxedClass
*
cls
,
const
char
*
msg
,
...)
{
if
(
msg
!=
NULL
)
{
if
(
msg
!=
NULL
)
{
va_list
ap
;
va_list
ap
;
...
@@ -265,18 +268,4 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
...
@@ -265,18 +268,4 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
raiseExc
(
exc_obj
);
raiseExc
(
exc_obj
);
}
}
}
}
std
::
string
formatException
(
Box
*
b
)
{
std
::
string
name
=
getTypeName
(
b
);
BoxedString
*
r
=
strOrNull
(
b
);
if
(
!
r
)
return
name
;
assert
(
r
->
cls
==
str_cls
);
const
std
::
string
*
msg
=
&
r
->
s
;
if
(
msg
->
size
())
return
name
+
": "
+
*
msg
;
return
name
;
}
}
}
src/runtime/types.cpp
View file @
077fffc6
...
@@ -559,7 +559,7 @@ extern "C" Box* createUserClass(const std::string* name, Box* _bases, Box* _attr
...
@@ -559,7 +559,7 @@ extern "C" Box* createUserClass(const std::string* name, Box* _bases, Box* _attr
RELEASE_ASSERT
(
e
.
matches
(
BaseException
),
""
);
RELEASE_ASSERT
(
e
.
matches
(
BaseException
),
""
);
Box
*
msg
=
e
.
value
->
getattr
(
"message"
);
Box
*
msg
=
getattr
(
e
.
value
,
"message"
);
RELEASE_ASSERT
(
msg
,
""
);
RELEASE_ASSERT
(
msg
,
""
);
RELEASE_ASSERT
(
msg
->
cls
==
str_cls
,
""
);
RELEASE_ASSERT
(
msg
->
cls
==
str_cls
,
""
);
...
@@ -834,6 +834,40 @@ Box* typeRepr(BoxedClass* self) {
...
@@ -834,6 +834,40 @@ Box* typeRepr(BoxedClass* self) {
return
boxString
(
os
.
str
());
return
boxString
(
os
.
str
());
}
}
static
PyObject
*
typeModule
(
Box
*
_type
,
void
*
context
)
{
PyTypeObject
*
type
=
static_cast
<
PyTypeObject
*>
(
_type
);
PyObject
*
mod
;
const
char
*
s
;
if
(
type
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
)
{
mod
=
type
->
getattr
(
"__module__"
);
if
(
!
mod
)
raiseExcHelper
(
AttributeError
,
"__module__"
);
return
mod
;
}
else
{
s
=
strrchr
(
type
->
tp_name
,
'.'
);
if
(
s
!=
NULL
)
return
PyString_FromStringAndSize
(
type
->
tp_name
,
(
Py_ssize_t
)(
s
-
type
->
tp_name
));
return
PyString_FromString
(
"__builtin__"
);
}
}
static
void
typeSetModule
(
Box
*
_type
,
PyObject
*
value
,
void
*
context
)
{
PyTypeObject
*
type
=
static_cast
<
PyTypeObject
*>
(
_type
);
if
(
!
(
type
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
))
{
raiseExcHelper
(
TypeError
,
"can't set %s.__module__"
,
type
->
tp_name
);
}
if
(
!
value
)
{
raiseExcHelper
(
TypeError
,
"can't delete %s.__module__"
,
type
->
tp_name
);
}
PyType_Modified
(
type
);
type
->
setattr
(
"__module__"
,
value
,
NULL
);
}
Box
*
typeHash
(
BoxedClass
*
self
)
{
Box
*
typeHash
(
BoxedClass
*
self
)
{
assert
(
isSubclass
(
self
->
cls
,
type_cls
));
assert
(
isSubclass
(
self
->
cls
,
type_cls
));
...
@@ -1272,6 +1306,7 @@ void setupRuntime() {
...
@@ -1272,6 +1306,7 @@ void setupRuntime() {
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeNew
,
UNKNOWN
,
4
,
2
,
false
,
false
),
{
NULL
,
NULL
}));
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeNew
,
UNKNOWN
,
4
,
2
,
false
,
false
),
{
NULL
,
NULL
}));
type_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeRepr
,
STR
,
1
)));
type_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeRepr
,
STR
,
1
)));
type_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeHash
,
BOXED_INT
,
1
)));
type_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
typeHash
,
BOXED_INT
,
1
)));
type_cls
->
giveAttr
(
"__module__"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
typeModule
,
typeSetModule
,
NULL
));
type_cls
->
freeze
();
type_cls
->
freeze
();
none_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
noneRepr
,
STR
,
1
)));
none_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
noneRepr
,
STR
,
1
)));
...
@@ -1365,6 +1400,7 @@ void setupRuntime() {
...
@@ -1365,6 +1400,7 @@ void setupRuntime() {
setupSys
();
setupSys
();
setupBuiltins
();
setupBuiltins
();
_PyExc_Init
();
setupThread
();
setupThread
();
setupGC
();
setupGC
();
setupImport
();
setupImport
();
...
...
src/runtime/types.h
View file @
077fffc6
...
@@ -613,12 +613,29 @@ extern "C" void boxGCHandler(GCVisitor* v, Box* b);
...
@@ -613,12 +613,29 @@ extern "C" void boxGCHandler(GCVisitor* v, Box* b);
Box
*
objectNewNoArgs
(
BoxedClass
*
cls
);
Box
*
objectNewNoArgs
(
BoxedClass
*
cls
);
extern
"C"
BoxedClass
*
Exception
,
*
AssertionError
,
*
AttributeError
,
*
TypeError
,
*
NameError
,
*
KeyError
,
*
IndexError
,
*
IOError
,
*
OSError
,
*
ZeroDivisionError
,
*
ValueError
,
*
UnboundLocalError
,
*
RuntimeError
,
*
ImportError
,
*
StopIteration
,
*
GeneratorExit
,
*
SyntaxError
;
Box
*
makeAttrWrapper
(
Box
*
b
);
Box
*
makeAttrWrapper
(
Box
*
b
);
#define SystemError ((BoxedClass*)PyExc_SystemError)
#define StopIteration ((BoxedClass*)PyExc_StopIteration)
#define NameError ((BoxedClass*)PyExc_NameError)
#define UnboundLocalError ((BoxedClass*)PyExc_UnboundLocalError)
#define BaseException ((BoxedClass*)PyExc_BaseException)
#define TypeError ((BoxedClass*)PyExc_TypeError)
#define AssertionError ((BoxedClass*)PyExc_AssertionError)
#define ValueError ((BoxedClass*)PyExc_ValueError)
#define SystemExit ((BoxedClass*)PyExc_SystemExit)
#define SyntaxError ((BoxedClass*)PyExc_SyntaxError)
#define Exception ((BoxedClass*)PyExc_Exception)
#define AttributeError ((BoxedClass*)PyExc_AttributeError)
#define RuntimeError ((BoxedClass*)PyExc_RuntimeError)
#define ZeroDivisionError ((BoxedClass*)PyExc_ZeroDivisionError)
#define ImportError ((BoxedClass*)PyExc_ImportError)
#define IndexError ((BoxedClass*)PyExc_IndexError)
#define GeneratorExit ((BoxedClass*)PyExc_GeneratorExit)
#define IOError ((BoxedClass*)PyExc_IOError)
#define KeyError ((BoxedClass*)PyExc_KeyError)
#define OverflowError ((BoxedClass*)PyExc_OverflowError)
// Our default for tp_alloc:
// Our default for tp_alloc:
PyObject
*
PystonType_GenericAlloc
(
BoxedClass
*
cls
,
Py_ssize_t
nitems
)
noexcept
;
PyObject
*
PystonType_GenericAlloc
(
BoxedClass
*
cls
,
Py_ssize_t
nitems
)
noexcept
;
}
}
...
...
src/runtime/unicode.cpp
View file @
077fffc6
...
@@ -373,34 +373,6 @@ extern "C" Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch) noexcept {
...
@@ -373,34 +373,6 @@ extern "C" Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch) noexcept {
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
}
}
extern
"C"
int
PyUnicodeEncodeError_GetStart
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyUnicodeDecodeError_GetStart
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyUnicodeTranslateError_GetStart
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyUnicodeEncodeError_GetEnd
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyUnicodeDecodeError_GetEnd
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyUnicodeTranslateError_GetEnd
(
PyObject
*
,
Py_ssize_t
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
PyObject
*
PyUnicodeEncodeError_GetObject
(
PyObject
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
PyObject
*
_PyUnicode_DecodeUnicodeInternal
(
const
char
*
s
,
Py_ssize_t
size
,
const
char
*
errors
)
noexcept
{
extern
"C"
PyObject
*
_PyUnicode_DecodeUnicodeInternal
(
const
char
*
s
,
Py_ssize_t
size
,
const
char
*
errors
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
Py_FatalError
(
"unimplemented"
);
}
}
...
...
test/tests/exceptions_nonreprable.py
View file @
077fffc6
# expected: fail
# - exception printing
class
BadException
(
Exception
):
class
BadException
(
Exception
):
def
__str__
(
self
):
def
__str__
(
self
):
print
"str"
print
"str"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment