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
ee25dc67
Commit
ee25dc67
authored
May 27, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PyErr_GetExcInfo, make __builtins__ more similar to cpython
parent
925c13d5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
48 additions
and
10 deletions
+48
-10
from_cpython/Include/pyerrors.h
from_cpython/Include/pyerrors.h
+4
-0
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+2
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+27
-2
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+0
-8
src/runtime/types.cpp
src/runtime/types.cpp
+2
-0
test/tests/builtins.py
test/tests/builtins.py
+2
-0
test/tests/builtins_getitem.py
test/tests/builtins_getitem.py
+8
-0
test/tests/exec_in_test.py
test/tests/exec_in_test.py
+3
-0
No files found.
from_cpython/Include/pyerrors.h
View file @
ee25dc67
...
...
@@ -83,6 +83,10 @@ PyAPI_FUNC(void) PyErr_Clear(void) PYSTON_NOEXCEPT;
PyAPI_FUNC
(
void
)
PyErr_Fetch
(
PyObject
**
,
PyObject
**
,
PyObject
**
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
void
)
PyErr_Restore
(
PyObject
*
,
PyObject
*
,
PyObject
*
)
PYSTON_NOEXCEPT
;
// Pyton change: This functions are normally only available in CPython >= 3.3 and PyPy but Cython can use them.
PyAPI_FUNC
(
void
)
PyErr_GetExcInfo
(
PyObject
**
ptype
,
PyObject
**
pvalue
,
PyObject
**
ptraceback
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
void
)
PyErr_SetExcInfo
(
PyObject
*
type
,
PyObject
*
value
,
PyObject
*
traceback
)
PYSTON_NOEXCEPT
;
#ifdef Py_DEBUG
#define _PyErr_OCCURRED() PyErr_Occurred()
#else
...
...
src/codegen/irgen/hooks.cpp
View file @
ee25dc67
...
...
@@ -313,6 +313,8 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
std
::
unique_ptr
<
SourceInfo
>
si
(
new
SourceInfo
(
bm
,
scoping
,
m
,
m
->
body
,
fn
));
bm
->
setattr
(
"__doc__"
,
si
->
getDocString
(),
NULL
);
if
(
!
bm
->
hasattr
(
"__builtins__"
))
bm
->
giveAttr
(
"__builtins__"
,
PyModule_GetDict
(
builtins_module
));
CLFunction
*
cl_f
=
new
CLFunction
(
0
,
0
,
false
,
false
,
std
::
move
(
si
));
...
...
src/runtime/capi.cpp
View file @
ee25dc67
...
...
@@ -24,6 +24,7 @@
#include "llvm/Support/Path.h"
#include "capi/types.h"
#include "codegen/unwinding.h"
#include "core/threading.h"
#include "core/types.h"
#include "runtime/classobj.h"
...
...
@@ -233,8 +234,14 @@ done:
extern
"C"
PyObject
*
PyObject_GetAttr
(
PyObject
*
o
,
PyObject
*
attr_name
)
noexcept
{
if
(
!
isSubclass
(
attr_name
->
cls
,
str_cls
))
{
PyErr_Format
(
PyExc_TypeError
,
"attribute name must be string, not '%.200s'"
,
Py_TYPE
(
attr_name
)
->
tp_name
);
return
NULL
;
if
(
PyUnicode_Check
(
attr_name
))
{
attr_name
=
_PyUnicode_AsDefaultEncodedString
(
attr_name
,
NULL
);
if
(
attr_name
==
NULL
)
return
NULL
;
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"attribute name must be string, not '%.200s'"
,
Py_TYPE
(
attr_name
)
->
tp_name
);
return
NULL
;
}
}
try
{
...
...
@@ -958,6 +965,20 @@ extern "C" void PyErr_Clear() noexcept {
PyErr_Restore
(
NULL
,
NULL
,
NULL
);
}
extern
"C"
void
PyErr_GetExcInfo
(
PyObject
**
ptype
,
PyObject
**
pvalue
,
PyObject
**
ptraceback
)
noexcept
{
ExcInfo
*
exc
=
getFrameExcInfo
();
*
ptype
=
exc
->
type
;
*
pvalue
=
exc
->
value
;
*
ptraceback
=
exc
->
traceback
;
}
extern
"C"
void
PyErr_SetExcInfo
(
PyObject
*
type
,
PyObject
*
value
,
PyObject
*
traceback
)
noexcept
{
ExcInfo
*
exc
=
getFrameExcInfo
();
exc
->
type
=
type
;
exc
->
value
=
value
;
exc
->
traceback
=
traceback
;
}
extern
"C"
void
PyErr_SetString
(
PyObject
*
exception
,
const
char
*
string
)
noexcept
{
PyErr_SetObject
(
exception
,
boxStrConstant
(
string
));
}
...
...
@@ -1694,6 +1715,10 @@ extern "C" void _Py_FatalError(const char* fmt, const char* function, const char
abort
();
}
extern
"C"
PyObject
*
PyClassMethod_New
(
PyObject
*
callable
)
noexcept
{
return
new
BoxedClassmethod
(
callable
);
}
void
setupCAPI
()
{
capifunc_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedCApiFunction
::
__repr__
,
UNKNOWN
,
1
)));
...
...
src/runtime/objmodel.cpp
View file @
ee25dc67
...
...
@@ -4815,14 +4815,6 @@ extern "C" Box* getGlobal(Box* globals, const std::string* name) {
static
StatCounter
stat_builtins
(
"getglobal_builtins"
);
stat_builtins
.
log
();
if
((
*
name
)
==
"__builtins__"
)
{
if
(
rewriter
.
get
())
{
RewriterVar
*
r_rtn
=
rewriter
->
loadConst
((
intptr_t
)
builtins_module
,
rewriter
->
getReturnDestination
());
rewriter
->
commitReturning
(
r_rtn
);
}
return
builtins_module
;
}
Box
*
rtn
;
if
(
rewriter
.
get
())
{
RewriterVar
*
builtins
=
rewriter
->
loadConst
((
intptr_t
)
builtins_module
,
Location
::
any
());
...
...
src/runtime/types.cpp
View file @
ee25dc67
...
...
@@ -2803,6 +2803,8 @@ BoxedModule* createModule(const std::string& name, const char* fn, const char* d
module
->
giveAttr
(
"__file__"
,
boxString
(
fn
));
d
->
d
[
b_name
]
=
module
;
if
(
name
==
"__main__"
)
module
->
giveAttr
(
"__builtins__"
,
builtins_module
);
return
module
;
}
...
...
test/tests/builtins.py
View file @
ee25dc67
...
...
@@ -12,6 +12,8 @@ print __builtins__
__builtins__
=
2
print
__builtins__
import
builtins_getitem
print
all
([]),
all
([
True
]),
all
([
False
]),
all
([
None
]),
all
([
True
,
False
,
None
])
print
any
([]),
any
([
True
]),
any
([
False
]),
any
([
None
]),
any
([
True
,
False
,
None
])
...
...
test/tests/builtins_getitem.py
0 → 100644
View file @
ee25dc67
# this file get's also included by the builtins.py to test that __builtins__ becomes a dict when getting imported
try
:
import
types
print
type
(
__builtins__
)
==
types
.
ModuleType
__builtins__
[
"all"
]
print
"No exception"
except
TypeError
as
e
:
print
e
test/tests/exec_in_test.py
View file @
ee25dc67
...
...
@@ -178,3 +178,6 @@ print z
"""
exec
s
in
import_target
.
__dict__
,
{}
exec
s
in
globals
(),
{}
exec
"import builtins_getitem"
exec
"import builtins_getitem"
in
{},
{}
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