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
dde3f8ac
Commit
dde3f8ac
authored
Mar 02, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More ref fixes
parent
c02c4901
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
34 deletions
+63
-34
src/capi/object.cpp
src/capi/object.cpp
+1
-0
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+1
-0
src/codegen/irgen.cpp
src/codegen/irgen.cpp
+9
-4
src/runtime/descr.cpp
src/runtime/descr.cpp
+30
-28
src/runtime/dict.cpp
src/runtime/dict.cpp
+1
-1
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+7
-1
test/tests/custom_partial.py
test/tests/custom_partial.py
+14
-0
No files found.
src/capi/object.cpp
View file @
dde3f8ac
...
...
@@ -475,6 +475,7 @@ extern "C" PyObject* PyObject_Str(PyObject* v) noexcept {
}
extern
"C"
PyObject
*
PyObject_SelfIter
(
PyObject
*
obj
)
noexcept
{
Py_INCREF
(
obj
);
return
obj
;
}
...
...
src/codegen/compvars.cpp
View file @
dde3f8ac
...
...
@@ -505,6 +505,7 @@ public:
llvm
::
Value
*
ptr
=
emitter
.
getBuilder
()
->
CreateConstGEP1_32
(
unpacked
,
i
);
llvm
::
Value
*
val
=
emitter
.
getBuilder
()
->
CreateLoad
(
ptr
);
assert
(
val
->
getType
()
==
g
.
llvm_value_type_ptr
);
emitter
.
setType
(
val
,
RefType
::
OWNED
);
rtn
.
push_back
(
new
ConcreteCompilerVariable
(
UNKNOWN
,
val
));
}
...
...
src/codegen/irgen.cpp
View file @
dde3f8ac
...
...
@@ -601,6 +601,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// TODO might be more efficient to do post-call safepoints?
generator
->
doSafePoint
(
block
->
body
[
0
]);
}
else
if
(
entry_descriptor
&&
block
==
entry_descriptor
->
backedge
->
target
)
{
assert
(
0
&&
"check refcounting"
);
assert
(
block
->
predecessors
.
size
()
>
1
);
assert
(
osr_entry_block
);
assert
(
phis
);
...
...
@@ -618,8 +619,13 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("For %s, given %s, analyzed for %s\n", p.first.c_str(), p.second->debugName().c_str(),
// analyzed_type->debugName().c_str());
assert
(
0
&&
"check refcounting"
);
llvm
::
PHINode
*
phi
=
emitter
->
getBuilder
()
->
CreatePHI
(
analyzed_type
->
llvmType
(),
block
->
predecessors
.
size
()
+
1
,
p
.
first
.
s
());
if
(
analyzed_type
->
getBoxType
()
==
analyzed_type
)
{
assert
(
0
&&
"check refcounting"
);
irstate
->
getRefcounts
()
->
setType
(
phi
,
RefType
::
OWNED
);
}
ConcreteCompilerVariable
*
var
=
new
ConcreteCompilerVariable
(
analyzed_type
,
phi
);
generator
->
giveLocalSymbol
(
p
.
first
,
var
);
(
*
phis
)[
p
.
first
]
=
std
::
make_pair
(
analyzed_type
,
phi
);
...
...
@@ -657,7 +663,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
ConcreteCompilerType
*
type
=
getTypeAtBlockStart
(
types
,
s
,
block
);
llvm
::
PHINode
*
phi
=
emitter
->
getBuilder
()
->
CreatePHI
(
type
->
llvmType
(),
block
->
predecessors
.
size
(),
s
.
s
());
if
(
phi
->
getType
()
==
g
.
llvm_value_type_ptr
)
if
(
type
->
getBoxType
()
==
type
)
irstate
->
getRefcounts
()
->
setType
(
phi
,
RefType
::
OWNED
);
ConcreteCompilerVariable
*
var
=
new
ConcreteCompilerVariable
(
type
,
phi
);
generator
->
giveLocalSymbol
(
s
,
var
);
...
...
@@ -758,7 +764,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("block %d: adding phi for %s from pred %d\n", block->idx, name.c_str(), pred->idx);
llvm
::
PHINode
*
phi
=
emitter
->
getBuilder
()
->
CreatePHI
(
cv
->
getType
()
->
llvmType
(),
block
->
predecessors
.
size
(),
name
.
s
());
if
(
phi
->
getType
()
==
g
.
llvm_value_type_ptr
)
if
(
cv
->
getType
()
->
getBoxType
()
==
cv
->
getType
()
)
irstate
->
getRefcounts
()
->
setType
(
phi
,
RefType
::
OWNED
);
// emitter->getBuilder()->CreateCall(g.funcs.dump, phi);
ConcreteCompilerVariable
*
var
=
new
ConcreteCompilerVariable
(
cv
->
getType
(),
phi
);
...
...
@@ -864,8 +870,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
llvm_phi
->
addIncoming
(
v
->
getValue
(),
llvm_exit_blocks
[
b
->
predecessors
[
j
]]);
if
(
v
->
getType
()
->
getBoxType
()
==
v
->
getType
())
{
// llvm::outs() << *v->getValue() << " is getting consumed by phi " << *llvm_phi << '\n';
irstate
->
getRefcounts
()
->
setType
(
llvm_phi
,
RefType
::
OWNED
);
//llvm::outs() << *v->getValue() << " is getting consumed by phi " << *llvm_phi << '\n';
assert
(
llvm
::
isa
<
llvm
::
BranchInst
>
(
terminator
));
irstate
->
getRefcounts
()
->
refConsumed
(
v
->
getValue
(),
terminator
);
}
...
...
src/runtime/descr.cpp
View file @
dde3f8ac
...
...
@@ -28,13 +28,13 @@ static Box* memberGet(BoxedMemberDescriptor* self, Box* inst, Box* owner) {
RELEASE_ASSERT
(
self
->
cls
==
member_descriptor_cls
,
""
);
if
(
inst
==
None
)
return
self
;
return
incref
(
self
)
;
if
(
self
->
type
==
BoxedMemberDescriptor
::
OBJECT
)
{
Box
*
rtn
=
*
(
Box
**
)(((
char
*
)
inst
)
+
self
->
offset
);
if
(
!
rtn
)
rtn
=
None
;
return
rtn
;
return
incref
(
rtn
)
;
}
Py_FatalError
(
"unimplemented"
);
...
...
@@ -57,8 +57,10 @@ static void propertyDocCopy(BoxedProperty* prop, Box* fget) {
if
(
get_doc
)
{
if
(
prop
->
cls
==
property_cls
)
{
Py_XDECREF
(
prop
->
prop_doc
);
prop
->
prop_doc
=
get_doc
;
}
else
{
AUTO_DECREF
(
get_doc
);
/* If this is a property subclass, put __doc__
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
...
...
@@ -75,10 +77,10 @@ static Box* propertyInit(Box* _self, Box* fget, Box* fset, Box** args) {
Box
*
doc
=
args
[
1
];
BoxedProperty
*
self
=
static_cast
<
BoxedProperty
*>
(
_self
);
self
->
prop_get
=
fget
==
None
?
NULL
:
fget
;
self
->
prop_set
=
fset
==
None
?
NULL
:
fset
;
self
->
prop_del
=
fdel
==
None
?
NULL
:
fdel
;
self
->
prop_doc
=
doc
;
self
->
prop_get
=
fget
==
None
?
NULL
:
incref
(
fget
)
;
self
->
prop_set
=
fset
==
None
?
NULL
:
incref
(
fset
)
;
self
->
prop_del
=
fdel
==
None
?
NULL
:
incref
(
fdel
)
;
self
->
prop_doc
=
xincref
(
doc
)
;
self
->
getter_doc
=
false
;
/* if no docstring given and the getter has one, use that one */
...
...
@@ -94,7 +96,7 @@ static Box* propertyGet(Box* self, Box* obj, Box* type) {
BoxedProperty
*
prop
=
static_cast
<
BoxedProperty
*>
(
self
);
if
(
obj
==
NULL
||
obj
==
None
)
{
return
self
;
return
incref
(
self
)
;
}
if
(
prop
->
prop_get
==
NULL
)
{
...
...
@@ -124,7 +126,7 @@ static Box* propertySet(Box* self, Box* obj, Box* val) {
}
else
{
runtimeCall
(
func
,
ArgPassSpec
(
2
),
obj
,
val
,
NULL
,
NULL
,
NULL
);
}
return
None
;
return
incref
(
None
)
;
}
static
Box
*
propertyDel
(
Box
*
self
,
Box
*
obj
)
{
...
...
@@ -190,7 +192,7 @@ static Box* staticmethodInit(Box* _self, Box* f) {
BoxedStaticmethod
*
self
=
static_cast
<
BoxedStaticmethod
*>
(
_self
);
self
->
sm_callable
=
f
;
return
None
;
return
incref
(
None
)
;
}
static
Box
*
staticmethodGet
(
Box
*
self
,
Box
*
obj
,
Box
*
type
)
{
...
...
@@ -202,7 +204,7 @@ static Box* staticmethodGet(Box* self, Box* obj, Box* type) {
raiseExcHelper
(
RuntimeError
,
"uninitialized staticmethod object"
);
}
return
sm
->
sm_callable
;
return
incref
(
sm
->
sm_callable
)
;
}
extern
"C"
PyObject
*
PyClassMethod_New
(
PyObject
*
callable
)
noexcept
{
...
...
@@ -212,9 +214,9 @@ extern "C" PyObject* PyClassMethod_New(PyObject* callable) noexcept {
static
Box
*
classmethodInit
(
Box
*
_self
,
Box
*
f
)
{
RELEASE_ASSERT
(
isSubclass
(
_self
->
cls
,
classmethod_cls
),
""
);
BoxedClassmethod
*
self
=
static_cast
<
BoxedClassmethod
*>
(
_self
);
self
->
cm_callable
=
f
;
self
->
cm_callable
=
incref
(
f
)
;
return
None
;
return
incref
(
None
)
;
}
static
Box
*
classmethodGet
(
Box
*
self
,
Box
*
obj
,
Box
*
type
)
{
...
...
@@ -390,14 +392,6 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
RELEASE_ASSERT
(
0
,
"0x%x"
,
call_flags
);
}
if
(
!
rtn
)
throwCAPIException
();
if
(
rewrite_args
)
{
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
if
(
paramspec
.
totalReceived
()
>=
1
)
Py_DECREF
(
arg1
);
if
(
paramspec
.
totalReceived
()
>=
2
)
...
...
@@ -407,6 +401,14 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
for
(
int
i
=
0
;
i
<
paramspec
.
totalReceived
()
-
3
;
i
++
)
Py_DECREF
(
oargs
[
i
]);
if
(
!
rtn
)
throwCAPIException
();
if
(
rewrite_args
)
{
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
return
rtn
;
}
static
Box
*
methodGetName
(
Box
*
b
,
void
*
)
{
...
...
@@ -414,14 +416,14 @@ static Box* methodGetName(Box* b, void*) {
const
char
*
s
=
static_cast
<
BoxedMethodDescriptor
*>
(
b
)
->
method
->
ml_name
;
if
(
s
)
return
boxString
(
s
);
return
None
;
return
incref
(
None
)
;
}
static
Box
*
methodGetDoc
(
Box
*
b
,
void
*
)
{
assert
(
b
->
cls
==
method_cls
);
const
char
*
s
=
static_cast
<
BoxedMethodDescriptor
*>
(
b
)
->
method
->
ml_doc
;
if
(
s
)
return
boxString
(
s
);
return
None
;
return
incref
(
None
)
;
}
static
Box
*
methodRepr
(
Box
*
_o
)
{
...
...
@@ -445,7 +447,7 @@ Box* BoxedMethodDescriptor::descr_get(BoxedMethodDescriptor* self, Box* inst, Bo
Py_FatalError
(
"unimplemented"
);
if
(
inst
==
NULL
)
return
self
;
return
incref
(
self
)
;
else
return
boxInstanceMethod
(
inst
,
self
,
self
->
type
);
}
...
...
@@ -554,7 +556,7 @@ Box* BoxedWrapperDescriptor::descr_get(Box* _self, Box* inst, Box* owner) noexce
BoxedWrapperDescriptor
*
self
=
static_cast
<
BoxedWrapperDescriptor
*>
(
_self
);
if
(
inst
==
NULL
)
return
self
;
return
incref
(
self
)
;
if
(
!
isSubclass
(
inst
->
cls
,
self
->
type
))
{
PyErr_Format
(
TypeError
,
"Descriptor '' for '%s' objects doesn't apply to '%s' object"
,
...
...
@@ -690,8 +692,8 @@ Box* BoxedWrapperDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args,
break
;
}
checkAndThrowCAPIException
();
assert
(
rtn
&&
"should have set + thrown an exception!"
);
if
(
!
rtn
)
throwCAPIException
(
);
return
rtn
;
}
...
...
@@ -764,8 +766,8 @@ Box* BoxedWrapperObject::__call__(BoxedWrapperObject* self, Box* args, Box* kwds
RELEASE_ASSERT
(
0
,
"%d"
,
flags
);
}
checkAndThrowCAPIException
();
assert
(
rtn
&&
"should have set + thrown an exception!"
);
if
(
!
rtn
)
throwCAPIException
(
);
return
rtn
;
}
...
...
src/runtime/dict.cpp
View file @
dde3f8ac
...
...
@@ -96,7 +96,7 @@ Box* dictItems(BoxedDict* self) {
rtn
->
ensure
(
self
->
d
.
size
());
for
(
const
auto
&
p
:
*
self
)
{
BoxedTuple
*
t
=
BoxedTuple
::
create
({
p
.
first
,
p
.
second
});
listAppendInternal
(
rtn
,
t
);
listAppendInternal
Stolen
(
rtn
,
t
);
}
return
rtn
;
...
...
src/runtime/tuple.cpp
View file @
dde3f8ac
...
...
@@ -32,6 +32,7 @@ extern "C" Box* createTuple(int64_t nelts, Box** elts) {
}
Box
*
_tupleSlice
(
BoxedTuple
*
self
,
i64
start
,
i64
stop
,
i64
step
,
i64
length
)
{
assert
(
0
&&
"check refcounting"
);
i64
size
=
self
->
size
();
assert
(
step
!=
0
);
...
...
@@ -114,6 +115,7 @@ extern "C" int _PyTuple_Resize(PyObject** pv, Py_ssize_t newsize) noexcept {
}
int
BoxedTuple
::
Resize
(
BoxedTuple
**
pv
,
size_t
newsize
)
noexcept
{
assert
(
0
&&
"check refcounting"
);
assert
((
*
pv
)
->
cls
==
tuple_cls
);
BoxedTuple
*
t
=
static_cast
<
BoxedTuple
*>
(
*
pv
);
...
...
@@ -162,6 +164,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
if
(
!
PyTuple_Check
(
rhs
))
{
return
incref
(
NotImplemented
);
}
assert
(
0
&&
"check refcounting"
);
BoxedTuple
*
_rhs
=
static_cast
<
BoxedTuple
*>
(
rhs
);
...
...
@@ -172,6 +175,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
}
Box
*
tupleMulInt
(
BoxedTuple
*
self
,
int
n
)
{
assert
(
0
&&
"check refcounting"
);
int
s
=
self
->
size
();
if
(
n
<
0
)
...
...
@@ -199,7 +203,7 @@ Box* tupleMul(BoxedTuple* self, Box* rhs) {
throwCAPIException
();
return
tupleMulInt
(
self
,
n
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -386,6 +390,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
}
extern
"C"
int
PyTuple_SetItem
(
PyObject
*
op
,
Py_ssize_t
i
,
PyObject
*
newitem
)
noexcept
{
assert
(
0
&&
"check refcounting"
);
RELEASE_ASSERT
(
PyTuple_Check
(
op
),
""
);
BoxedTuple
*
t
=
static_cast
<
BoxedTuple
*>
(
op
);
...
...
@@ -398,6 +403,7 @@ extern "C" int PyTuple_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) no
}
extern
"C"
PyObject
*
PyTuple_Pack
(
Py_ssize_t
n
,
...)
noexcept
{
assert
(
0
&&
"check refcounting"
);
va_list
vargs
;
va_start
(
vargs
,
n
);
...
...
test/tests/custom_partial.py
0 → 100644
View file @
dde3f8ac
# import functools
# partial = functools.partial
def
partial
(
func
,
*
args
):
def
inner
(
*
a
,
**
kw
):
return
func
(
*
(
args
+
a
),
**
kw
)
return
inner
def
g
():
f
=
partial
(
lambda
*
args
:
args
,
1
,
23
)
print
f
(
"hello"
)
g
()
f
=
partial
(
lambda
*
args
:
args
,
1
,
23
)
print
f
(
"hello"
)
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