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
ead008eb
Commit
ead008eb
authored
Nov 12, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get through some weakref
parent
b363d7a0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
14 deletions
+35
-14
from_cpython/Include/object.h
from_cpython/Include/object.h
+4
-0
src/capi/modsupport.cpp
src/capi/modsupport.cpp
+2
-2
src/core/types.h
src/core/types.h
+1
-1
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+4
-1
src/runtime/dict.cpp
src/runtime/dict.cpp
+4
-1
src/runtime/types.cpp
src/runtime/types.cpp
+19
-9
src/runtime/types.h
src/runtime/types.h
+1
-0
No files found.
from_cpython/Include/object.h
View file @
ead008eb
...
...
@@ -7,6 +7,10 @@ extern "C" {
#endif
// Pyston addition: refcounting annotations:
#define BORROWED(T) T
#define STOLEN(T) T
/* Object and type object interface */
/*
...
...
src/capi/modsupport.cpp
View file @
ead008eb
...
...
@@ -417,13 +417,13 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
}
}
BoxedModule
*
module
=
createModule
(
boxString
(
name
),
NULL
,
doc
);
BoxedModule
*
module
=
createModule
(
autoDecref
(
boxString
(
name
)
),
NULL
,
doc
);
// Pass self as is, even if NULL we are not allowed to change it to None
Box
*
passthrough
=
static_cast
<
Box
*>
(
self
);
while
(
methods
&&
methods
->
ml_name
)
{
module
->
giveAttr
(
methods
->
ml_name
,
new
BoxedCApiFunction
(
methods
,
passthrough
,
boxString
(
name
)));
module
->
giveAttr
(
methods
->
ml_name
,
new
BoxedCApiFunction
(
methods
,
passthrough
,
autoDecref
(
boxString
(
name
)
)));
methods
++
;
}
...
...
src/core/types.h
View file @
ead008eb
...
...
@@ -834,7 +834,7 @@ class BoxedClass;
// TODO these shouldn't be here
void
setupRuntime
();
Box
*
createAndRunModule
(
BoxedString
*
name
,
const
std
::
string
&
fn
);
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
=
NULL
,
const
char
*
doc
=
NULL
);
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
=
NULL
,
const
char
*
doc
=
NULL
)
noexcept
;
Box
*
moduleInit
(
BoxedModule
*
self
,
Box
*
name
,
Box
*
doc
=
NULL
);
// TODO where to put this
...
...
src/runtime/builtin_modules/sys.cpp
View file @
ead008eb
...
...
@@ -646,7 +646,10 @@ void setupSys() {
gc
::
registerPermanentRoot
(
sys_modules_dict
);
// This is ok to call here because we've already created the sys_modules_dict
sys_module
=
createModule
(
boxString
(
"sys"
));
sys_module
=
createModule
(
autoDecref
(
boxString
(
"sys"
)));
// sys_module is what holds on to all of the other modules:
Py_INCREF
(
sys_module
);
constants
.
push_back
(
sys_module
);
sys_module
->
giveAttrBorrowed
(
"modules"
,
sys_modules_dict
);
...
...
src/runtime/dict.cpp
View file @
ead008eb
...
...
@@ -785,6 +785,10 @@ static Box* dict_repr(PyObject* self) noexcept {
void
BoxedDict
::
dealloc
(
Box
*
b
)
noexcept
{
assert
(
PyDict_Check
(
b
));
for
(
auto
p
:
*
static_cast
<
BoxedDict
*>
(
b
))
{
Py_DECREF
(
p
.
first
);
Py_DECREF
(
p
.
second
);
}
static_cast
<
BoxedDict
*>
(
b
)
->
d
.
freeAllMemory
();
}
...
...
@@ -807,7 +811,6 @@ void setupDict() {
dict_iterator_cls
->
instances_are_nonzero
=
dict_keys_cls
->
instances_are_nonzero
=
dict_values_cls
->
instances_are_nonzero
=
dict_items_cls
->
instances_are_nonzero
=
true
;
dict_cls
->
tp_dealloc
=
&
BoxedDict
::
dealloc
;
dict_cls
->
has_safe_tp_dealloc
=
true
;
dict_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
dictLen
,
BOXED_INT
,
1
)));
...
...
src/runtime/types.cpp
View file @
ead008eb
...
...
@@ -2238,14 +2238,14 @@ Box* moduleInit(BoxedModule* self, Box* name, Box* doc) {
if
(
attrs
->
hcls
->
attributeArraySize
()
==
0
)
{
attrs
->
hcls
=
HiddenClass
::
makeSingleton
();
self
->
giveAttr
(
"__name__"
,
name
);
self
->
giveAttr
(
"__doc__"
,
doc
);
self
->
giveAttr
Borrowed
(
"__name__"
,
name
);
self
->
giveAttr
Borrowed
(
"__doc__"
,
doc
);
}
else
{
self
->
setattr
(
internStringMortal
(
"__name__"
),
name
,
NULL
);
self
->
setattr
(
internStringMortal
(
"__doc__"
),
doc
,
NULL
);
self
->
setattr
(
autoDecref
(
internStringMortal
(
"__name__"
)
),
name
,
NULL
);
self
->
setattr
(
autoDecref
(
internStringMortal
(
"__doc__"
)
),
doc
,
NULL
);
}
return
None
;
Py_RETURN_NONE
;
}
Box
*
moduleRepr
(
BoxedModule
*
m
)
{
...
...
@@ -3673,6 +3673,11 @@ done:
Py_TRASHCAN_SAFE_END
(
op
)
}
void
BoxedModule
::
dealloc
(
Box
*
b
)
noexcept
{
BoxedModule
*
self
=
static_cast
<
BoxedModule
*>
(
b
);
self
->
clearAttrs
();
}
#ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS()
...
...
@@ -3764,6 +3769,7 @@ void setupRuntime() {
BoxedClass
(
object_cls
,
&
AttrWrapper
::
gcHandler
,
0
,
0
,
sizeof
(
AttrWrapper
),
false
,
"attrwrapper"
);
dict_cls
=
new
(
0
)
BoxedClass
(
object_cls
,
&
BoxedDict
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedDict
),
false
,
"dict"
);
dict_cls
->
tp_flags
|=
Py_TPFLAGS_DICT_SUBCLASS
;
dict_cls
->
tp_dealloc
=
BoxedDict
::
dealloc
;
file_cls
=
new
(
0
)
BoxedClass
(
object_cls
,
&
BoxedFile
::
gcHandler
,
0
,
offsetof
(
BoxedFile
,
weakreflist
),
sizeof
(
BoxedFile
),
false
,
"file"
);
file_cls
->
tp_dealloc
=
file_dealloc
;
...
...
@@ -3785,6 +3791,7 @@ void setupRuntime() {
module_cls
=
new
(
0
)
BoxedClass
(
object_cls
,
&
BoxedModule
::
gcHandler
,
offsetof
(
BoxedModule
,
attrs
),
0
,
sizeof
(
BoxedModule
),
false
,
"module"
);
module_cls
->
tp_dealloc
=
BoxedModule
::
dealloc
;
member_descriptor_cls
=
new
(
0
)
BoxedClass
(
object_cls
,
NULL
,
0
,
0
,
sizeof
(
BoxedMemberDescriptor
),
false
,
"member_descriptor"
);
capifunc_cls
=
new
(
0
)
...
...
@@ -4252,7 +4259,7 @@ void setupRuntime() {
TRACK_ALLOCATIONS
=
true
;
}
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
,
const
char
*
doc
)
{
BoxedModule
*
createModule
(
BoxedString
*
name
,
const
char
*
fn
,
const
char
*
doc
)
noexcept
{
assert
((
!
fn
||
strlen
(
fn
))
&&
"probably wanted to set the fn to <stdin>?"
);
BoxedDict
*
d
=
getSysModulesDict
();
...
...
@@ -4265,13 +4272,16 @@ BoxedModule* createModule(BoxedString* name, const char* fn, const char* doc) {
}
BoxedModule
*
module
=
new
BoxedModule
();
moduleInit
(
module
,
name
,
boxString
(
doc
?
doc
:
""
));
autoDecref
(
moduleInit
(
module
,
name
,
autoDecref
(
boxString
(
doc
?
doc
:
""
))));
if
(
fn
)
module
->
giveAttr
(
"__file__"
,
boxString
(
fn
));
d
->
d
[
name
]
=
module
;
Py_XDECREF
(
existing
);
d
->
d
[
incref
(
name
)]
=
module
;
if
(
name
->
s
()
==
"__main__"
)
module
->
giveAttr
(
"__builtins__"
,
builtins_module
);
module
->
giveAttr
Borrowed
(
"__builtins__"
,
builtins_module
);
return
module
;
}
...
...
src/runtime/types.h
View file @
ead008eb
...
...
@@ -924,6 +924,7 @@ public:
Box
*
getLongConstant
(
llvm
::
StringRef
s
);
static
void
gcHandler
(
GCVisitor
*
v
,
Box
*
self
);
static
void
dealloc
(
Box
*
b
)
noexcept
;
private:
ContiguousMap
<
llvm
::
StringRef
,
BoxedString
*
,
llvm
::
StringMap
<
int
>>
str_constants
;
...
...
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