Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
079d698d
Commit
079d698d
authored
Apr 02, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid using sys.getrefcount() where possible (PyPy doesn't have it)
parent
4cda4f13
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
tests/run/exceptionrefcount.pyx
tests/run/exceptionrefcount.pyx
+9
-5
tests/run/refcount_in_meth.pyx
tests/run/refcount_in_meth.pyx
+8
-5
No files found.
tests/run/exceptionrefcount.pyx
View file @
079d698d
__doc__
=
u"""
__doc__
=
u"""
>>> class SampleException(Exception): pass
>>> class SampleException(Exception): pass
>>> import sys
>>> def assert_refcount(rc1, rc2, func):
>>> def assert_refcount(rc1, rc2, func):
... # test ref-counts, but allow a bit of freedom
... # test ref-counts, but allow a bit of freedom
...
@@ -8,17 +7,17 @@ __doc__ = u"""
...
@@ -8,17 +7,17 @@ __doc__ = u"""
... func.__name__, rc1, rc2)
... func.__name__, rc1, rc2)
>>> def run_test(repeat, test_func):
>>> def run_test(repeat, test_func):
... initial_refcount =
sys.get
refcount(SampleException)
... initial_refcount =
get_
refcount(SampleException)
... for i in range(repeat):
... for i in range(repeat):
... try: raise SampleException
... try: raise SampleException
... except:
... except:
... refcount1 =
sys.get
refcount(SampleException)
... refcount1 =
get_
refcount(SampleException)
... test_func()
... test_func()
... refcount2 =
sys.get
refcount(SampleException)
... refcount2 =
get_
refcount(SampleException)
...
...
... assert_refcount(refcount1, refcount2, test_func)
... assert_refcount(refcount1, refcount2, test_func)
... assert_refcount(initial_refcount, refcount2, test_func)
... assert_refcount(initial_refcount, refcount2, test_func)
... refcount3 =
sys.get
refcount(SampleException)
... refcount3 =
get_
refcount(SampleException)
... assert_refcount(refcount1, refcount3, test_func)
... assert_refcount(refcount1, refcount3, test_func)
... assert_refcount(initial_refcount, refcount3, test_func)
... assert_refcount(initial_refcount, refcount3, test_func)
...
@@ -28,6 +27,11 @@ __doc__ = u"""
...
@@ -28,6 +27,11 @@ __doc__ = u"""
>>> run_test(50, test_finally)
>>> run_test(50, test_finally)
"""
"""
from
cpython.ref
cimport
PyObject
def
get_refcount
(
obj
):
return
(
<
PyObject
*>
obj
).
ob_refcnt
def
test_no_exception
():
def
test_no_exception
():
try
:
try
:
a
=
1
+
1
a
=
1
+
1
...
...
tests/run/refcount_in_meth.pyx
View file @
079d698d
...
@@ -12,7 +12,10 @@ True
...
@@ -12,7 +12,10 @@ True
True
True
"""
"""
import
sys
from
cpython.ref
cimport
PyObject
def
get_refcount
(
obj
):
return
(
<
PyObject
*>
obj
).
ob_refcnt
cdef
class
RefCountInMeth
(
object
):
cdef
class
RefCountInMeth
(
object
):
cdef
double
value
cdef
double
value
...
@@ -32,27 +35,27 @@ cdef class RefCountInMeth(object):
...
@@ -32,27 +35,27 @@ cdef class RefCountInMeth(object):
cdef
int
c_meth
(
self
):
cdef
int
c_meth
(
self
):
cdef
int
v
cdef
int
v
v
=
sys
.
get
refcount
(
self
)
v
=
get_
refcount
(
self
)
return
v
return
v
cdef
int
c_meth_if
(
self
):
cdef
int
c_meth_if
(
self
):
cdef
int
v
cdef
int
v
if
5
>
6
:
if
5
>
6
:
v
=
7
v
=
7
v
=
sys
.
get
refcount
(
self
)
v
=
get_
refcount
(
self
)
return
v
return
v
def
chk_meth
(
self
):
def
chk_meth
(
self
):
cdef
int
a
,
b
cdef
int
a
,
b
a
=
sys
.
get
refcount
(
self
)
a
=
get_
refcount
(
self
)
b
=
self
.
c_meth
()
b
=
self
.
c_meth
()
return
a
==
b
return
a
==
b
def
chk_meth_if
(
self
):
def
chk_meth_if
(
self
):
cdef
int
a
,
b
cdef
int
a
,
b
a
=
sys
.
get
refcount
(
self
)
a
=
get_
refcount
(
self
)
b
=
self
.
c_meth_if
()
b
=
self
.
c_meth_if
()
return
a
==
b
return
a
==
b
...
...
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