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
0230bff6
Commit
0230bff6
authored
May 12, 2015
by
Chris Toshok
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #496 from undingen/weakref_proxy
Add support for weakref.proxy
parents
12abc42b
1be43d90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
9 deletions
+68
-9
from_cpython/Objects/weakrefobject.c
from_cpython/Objects/weakrefobject.c
+7
-7
src/capi/object.cpp
src/capi/object.cpp
+22
-2
test/tests/weakref_proxy.py
test/tests/weakref_proxy.py
+39
-0
No files found.
from_cpython/Objects/weakrefobject.c
View file @
0230bff6
...
...
@@ -35,7 +35,9 @@ new_weakref(PyObject *ob, PyObject *callback)
{
PyWeakReference
*
result
;
result
=
PyObject_GC_New
(
PyWeakReference
,
&
_PyWeakref_RefType
);
// Pyston change: We can't use PyObject_GC_New because it will conservatively scan the memory.
// result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType);
result
=
(
PyWeakReference
*
)
_PyWeakref_RefType
.
tp_alloc
(
&
_PyWeakref_RefType
,
0
);
if
(
result
)
{
init_weakref
(
result
,
ob
,
callback
);
PyObject_GC_Track
(
result
);
...
...
@@ -706,9 +708,8 @@ _PyWeakref_ProxyType = {
0
,
/* tp_hash */
0
,
/* tp_call */
proxy_str
,
/* tp_str */
// Pyston change:
0
,
//proxy_getattr, /* tp_getattro */
0
,
//(setattrofunc)proxy_setattr, /* tp_setattro */
proxy_getattr
,
/* tp_getattro */
(
setattrofunc
)
proxy_setattr
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
|
Py_TPFLAGS_CHECKTYPES
,
/* tp_flags */
...
...
@@ -744,9 +745,8 @@ _PyWeakref_CallableProxyType = {
0
,
/* tp_hash */
proxy_call
,
/* tp_call */
proxy_str
,
/* tp_str */
// Pyston change:
0
,
//proxy_getattr, /* tp_getattro */
0
,
//(setattrofunc)proxy_setattr, /* tp_setattro */
proxy_getattr
,
/* tp_getattro */
(
setattrofunc
)
proxy_setattr
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
|
Py_TPFLAGS_CHECKTYPES
,
/* tp_flags */
...
...
src/capi/object.cpp
View file @
0230bff6
...
...
@@ -431,8 +431,28 @@ extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject*
return
0
;
}
extern
"C"
int
PyObject_SetAttr
(
PyObject
*
v
,
PyObject
*
name
,
PyObject
*
value
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
extern
"C"
int
PyObject_SetAttr
(
PyObject
*
obj
,
PyObject
*
name
,
PyObject
*
value
)
noexcept
{
if
(
!
PyString_Check
(
name
))
{
if
(
PyUnicode_Check
(
name
))
{
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
if
(
name
==
NULL
)
return
-
1
;
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"attribute name must be string, not '%.200s'"
,
Py_TYPE
(
name
)
->
tp_name
);
return
-
1
;
}
}
try
{
if
(
value
==
NULL
)
delattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
s
.
data
());
else
setattr
(
obj
,
static_cast
<
BoxedString
*>
(
name
)
->
s
.
data
(),
value
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
-
1
;
}
return
0
;
}
extern
"C"
int
PyObject_SetAttrString
(
PyObject
*
v
,
const
char
*
name
,
PyObject
*
w
)
noexcept
{
...
...
test/tests/weakref_proxy.py
0 → 100644
View file @
0230bff6
import
weakref
import
gc
class
C
(
object
):
def
foo
(
self
):
print
"inside foo()"
def
fact
(
n
):
if
n
<=
1
:
return
n
return
n
*
fact
(
n
-
1
)
def
getWR
():
c
=
C
()
wr
=
weakref
.
proxy
(
c
)
wr
.
attr
=
"test attr"
print
wr
.
attr
,
c
.
attr
wr
.
foo
()
del
c
return
wr
wr
=
getWR
()
fact
(
100
)
# try to clear some memory
gc
.
collect
()
try
:
wr
.
foo
()
except
ReferenceError
as
e
:
print
e
try
:
print
wr
.
attr
except
ReferenceError
as
e
:
print
e
try
:
wr
.
attr
=
"val2"
except
ReferenceError
as
e
:
print
e
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