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
0b1acea8
Commit
0b1acea8
authored
Feb 11, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on getting old-style classes working
parent
3874fd6c
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
184 additions
and
70 deletions
+184
-70
src/capi/modsupport.cpp
src/capi/modsupport.cpp
+2
-2
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+1
-1
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+1
-1
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+7
-3
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+4
-3
src/core/types.h
src/core/types.h
+3
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+1
-1
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+141
-26
src/runtime/classobj.h
src/runtime/classobj.h
+14
-21
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+2
-3
src/runtime/types.cpp
src/runtime/types.cpp
+8
-7
No files found.
src/capi/modsupport.cpp
View file @
0b1acea8
...
...
@@ -431,11 +431,11 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
return
module
;
}
extern
"C"
PyObject
*
PyModule_GetDict
(
PyObject
*
_m
)
noexcept
{
extern
"C"
PyObject
*
PyModule_GetDict
(
BORROWED
(
PyObject
*
)
_m
)
noexcept
{
BoxedModule
*
m
=
static_cast
<
BoxedModule
*>
(
_m
);
assert
(
m
->
cls
==
module_cls
);
return
m
->
getAttrWrapper
(
);
return
autoDecref
(
m
->
getAttrWrapper
()
);
}
extern
"C"
int
PyModule_AddObject
(
PyObject
*
_m
,
const
char
*
name
,
PyObject
*
value
)
noexcept
{
...
...
src/capi/typeobject.cpp
View file @
0b1acea8
...
...
@@ -3427,7 +3427,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
cls
->
giveAttrBorrowed
(
"__base__"
,
base
);
assert
(
cls
->
tp_dict
==
NULL
);
cls
->
tp_dict
=
incref
(
cls
->
getAttrWrapper
()
);
cls
->
tp_dict
=
cls
->
getAttrWrapper
(
);
assert
(
cls
->
tp_name
);
...
...
src/codegen/ast_interpreter.cpp
View file @
0b1acea8
...
...
@@ -184,7 +184,7 @@ public:
Box
*
getGlobals
()
{
assert
(
globals
);
return
globals
;
return
incref
(
globals
)
;
}
FunctionMetadata
*
getMD
()
{
return
md
;
}
...
...
src/codegen/irgen/hooks.cpp
View file @
0b1acea8
...
...
@@ -331,7 +331,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
static
BoxedString
*
builtins_str
=
getStaticString
(
"__builtins__"
);
if
(
!
bm
->
hasattr
(
builtins_str
))
bm
->
giveAttr
(
builtins_str
,
PyModule_GetDict
(
builtins_module
));
bm
->
giveAttr
(
incref
(
builtins_str
)
,
PyModule_GetDict
(
builtins_module
));
md
=
new
FunctionMetadata
(
0
,
false
,
false
,
std
::
move
(
si
));
}
...
...
@@ -565,16 +565,20 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
if
(
globals
)
{
// From CPython (they set it to be f->f_builtins):
Box
*
globals_dict
=
globals
;
Box
*
globals_dict
;
if
(
globals
->
cls
==
module_cls
)
globals_dict
=
globals
->
getAttrWrapper
();
else
globals_dict
=
incref
(
globals
);
AUTO_DECREF
(
globals_dict
);
auto
requested_builtins
=
PyDict_GetItemString
(
globals_dict
,
"__builtins__"
);
if
(
requested_builtins
==
NULL
)
PyDict_SetItemString
(
globals_dict
,
"__builtins__"
,
builtins_module
);
else
RELEASE_ASSERT
(
requested_builtins
==
builtins_module
||
requested_builtins
==
builtins_module
->
getAttrWrapper
(
),
||
requested_builtins
==
autoDecref
(
builtins_module
->
getAttrWrapper
()
),
"we don't support overriding __builtins__"
);
}
}
...
...
src/codegen/unwinding.cpp
View file @
0b1acea8
...
...
@@ -369,7 +369,7 @@ public:
auto
locations
=
findLocations
(
PASSED_GLOBALS_NAME
);
assert
(
locations
.
size
()
==
1
);
Box
*
r
=
(
Box
*
)
readLocation
(
locations
[
0
]);
return
r
;
return
incref
(
r
)
;
}
else
if
(
id
.
type
==
PythonFrameId
::
INTERPRETED
)
{
return
getGlobalsForInterpretedFrame
((
void
*
)
id
.
bp
);
}
...
...
@@ -381,8 +381,10 @@ public:
if
(
!
globals
)
return
NULL
;
if
(
PyModule_Check
(
globals
))
if
(
PyModule_Check
(
globals
))
{
AUTO_DECREF
(
globals
);
return
globals
->
getAttrWrapper
();
}
return
globals
;
}
...
...
@@ -785,7 +787,6 @@ Box* getGlobals() {
auto
it
=
getTopPythonFrame
();
if
(
!
it
)
return
NULL
;
RELEASE_ASSERT
(
0
,
"check refcounting"
);
return
it
->
getGlobals
();
}
...
...
src/core/types.h
View file @
0b1acea8
...
...
@@ -670,7 +670,7 @@ public:
Py_INCREF
(
val
);
giveAttr
(
internStringMortal
(
attr
),
val
);
}
void
giveAttr
(
BoxedString
*
attr
,
Box
*
val
);
void
giveAttr
(
STOLEN
(
BoxedString
*
)
attr
,
STOLEN
(
Box
*
)
val
);
void
clearAttrs
();
...
...
@@ -685,7 +685,8 @@ public:
void
delattr
(
BoxedString
*
attr
,
DelattrRewriteArgs
*
rewrite_args
);
// Only valid for hc-backed instances:
BORROWED
(
Box
*
)
getAttrWrapper
();
// Maybe this should return a borrowed reference?
Box
*
getAttrWrapper
();
Box
*
reprIC
();
BoxedString
*
reprICAsString
();
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
0b1acea8
...
...
@@ -1067,7 +1067,7 @@ public:
static
Box
*
__reduce__
(
Box
*
self
)
{
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
BaseException
),
""
);
BoxedException
*
exc
=
static_cast
<
BoxedException
*>
(
self
);
return
BoxedTuple
::
create
({
self
->
cls
,
EmptyTuple
,
self
->
getAttrWrapper
(
)
});
return
BoxedTuple
::
create
({
self
->
cls
,
EmptyTuple
,
autoDecref
(
self
->
getAttrWrapper
()
)
});
}
};
...
...
src/runtime/classobj.cpp
View file @
0b1acea8
This diff is collapsed.
Click to expand it.
src/runtime/classobj.h
View file @
0b1acea8
...
...
@@ -48,17 +48,14 @@ public:
Box
**
weakreflist
;
BoxedClassobj
(
BoxedString
*
name
,
BoxedTuple
*
bases
)
:
bases
(
bases
),
name
(
name
)
{}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
BoxedClassobj
(
BoxedString
*
name
,
BoxedTuple
*
bases
)
:
bases
(
bases
),
name
(
name
)
{
Py_INCREF
(
name
);
Py_INCREF
(
bases
);
}
static
void
dealloc
(
Box
*
b
)
noexcept
;
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
;
static
int
clear
(
Box
*
self
)
noexcept
;
};
class
BoxedInstance
:
public
Box
{
...
...
@@ -69,19 +66,15 @@ public:
Box
**
weakreflist
;
BoxedInstance
(
BoxedClassobj
*
inst_cls
)
:
inst_cls
(
inst_cls
)
{}
BoxedInstance
(
BoxedClassobj
*
inst_cls
)
:
inst_cls
(
inst_cls
)
{
Py_INCREF
(
inst_cls
);
}
DEFAULT_CLASS
(
instance_cls
);
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
void
dealloc
(
Box
*
b
)
noexcept
;
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
;
static
int
clear
(
Box
*
self
)
noexcept
;
};
Box
*
instance_getattro
(
Box
*
cls
,
Box
*
attr
)
noexcept
;
...
...
@@ -89,7 +82,7 @@ int instance_setattro(Box* cls, Box* attr, Box* value) noexcept;
class
GetattrRewriteArgs
;
template
<
ExceptionStyle
S
>
Box
*
instanceGetattroInternal
(
Box
*
self
,
Box
*
attr
,
GetattrRewriteArgs
*
rewrite_args
)
noexcept
(
S
==
CAPI
);
Box
*
instanceSetattroInternal
(
Box
*
self
,
Box
*
attr
,
Box
*
val
,
SetattrRewriteArgs
*
rewrite_args
);
void
instanceSetattroInternal
(
Box
*
self
,
STOLEN
(
Box
*
)
attr
,
Box
*
val
,
SetattrRewriteArgs
*
rewrite_args
);
}
#endif
src/runtime/objmodel.cpp
View file @
0b1acea8
...
...
@@ -779,7 +779,7 @@ BoxedClass* BoxedClass::create(BoxedClass* metaclass, BoxedClass* base, int attr
void
BoxedClass
::
finishInitialization
()
{
assert
(
!
this
->
tp_dict
);
this
->
tp_dict
=
incref
(
this
->
getAttrWrapper
()
);
this
->
tp_dict
=
this
->
getAttrWrapper
(
);
commonClassSetup
(
this
);
tp_flags
|=
Py_TPFLAGS_READY
;
...
...
@@ -992,7 +992,7 @@ BoxedDict* Box::getDict() {
}
assert
(
d
->
cls
==
dict_cls
);
return
d
;
return
incref
(
d
)
;
}
static
StatCounter
box_getattr_slowpath
(
"slowpath_box_getattr"
);
...
...
@@ -2838,7 +2838,6 @@ extern "C" void setattr(Box* obj, BoxedString* attr, STOLEN(Box*) attr_val) {
RewriterVar
*
r_setattr
;
if
(
tp_setattro
==
instance_setattro
)
{
assert
(
0
&&
"check refcounting"
);
if
(
rewriter
.
get
())
{
SetattrRewriteArgs
rewrite_args
(
rewriter
.
get
(),
rewriter
->
getArg
(
0
),
rewriter
->
getArg
(
2
));
instanceSetattroInternal
(
obj
,
attr
,
attr_val
,
&
rewrite_args
);
...
...
src/runtime/types.cpp
View file @
0b1acea8
...
...
@@ -1305,7 +1305,7 @@ Box* typeCall(Box* obj, BoxedTuple* vararg, BoxedDict* kwargs) {
static
Box
*
typeDict
(
Box
*
obj
,
void
*
context
)
{
if
(
obj
->
cls
->
instancesHaveHCAttrs
())
return
PyDictProxy_New
(
obj
->
getAttrWrapper
(
));
return
PyDictProxy_New
(
autoDecref
(
obj
->
getAttrWrapper
()
));
abort
();
}
...
...
@@ -1392,6 +1392,7 @@ extern "C" Box* createUserClass(BoxedString* name, Box* _bases, Box* _attr_dict)
metaclass
=
bases
->
elts
[
0
]
->
cls
;
}
else
{
Box
*
gl
=
getGlobalsDict
();
AUTO_DECREF
(
gl
);
metaclass
=
PyDict_GetItemString
(
gl
,
"__metaclass__"
);
if
(
!
metaclass
)
{
...
...
@@ -1411,8 +1412,10 @@ extern "C" Box* createUserClass(BoxedString* name, Box* _bases, Box* _attr_dict)
// But for classes created from Python, we don't have this extra untracked reference.
// Rather than fix up the plumbing for now, just reach into the other system and remove this
// class from the list.
if
(
isSubclass
(
r
->
cls
,
type_cls
))
{
RELEASE_ASSERT
(
classes
.
back
()
==
r
,
""
);
classes
.
pop_back
();
}
return
r
;
}
catch
(
ExcInfo
e
)
{
...
...
@@ -2559,7 +2562,7 @@ Box* Box::getAttrWrapper() {
HiddenClass
*
hcls
=
attrs
->
hcls
;
if
(
hcls
->
type
==
HiddenClass
::
DICT_BACKED
)
{
return
attrs
->
attr_list
->
attrs
[
0
]
;
return
incref
(
attrs
->
attr_list
->
attrs
[
0
])
;
}
int
offset
=
hcls
->
getAttrwrapperOffset
();
...
...
@@ -2569,17 +2572,15 @@ Box* Box::getAttrWrapper() {
auto
new_hcls
=
hcls
->
getAttrwrapperChild
();
appendNewHCAttr
(
aw
,
NULL
);
attrs
->
hcls
=
new_hcls
;
Py_DECREF
(
aw
);
return
aw
;
}
else
{
assert
(
hcls
->
type
==
HiddenClass
::
SINGLETON
);
appendNewHCAttr
(
aw
,
NULL
);
hcls
->
appendAttrwrapper
();
Py_DECREF
(
aw
);
return
aw
;
}
}
return
attrs
->
attr_list
->
attrs
[
offset
]
;
return
incref
(
attrs
->
attr_list
->
attrs
[
offset
])
;
}
extern
"C"
PyObject
*
PyObject_GetAttrWrapper
(
PyObject
*
obj
)
noexcept
{
...
...
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