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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
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
Hide 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"""
>>> class SampleException(Exception): pass
>>> import sys
>>> def assert_refcount(rc1, rc2, func):
... # test ref-counts, but allow a bit of freedom
...
...
@@ -8,17 +7,17 @@ __doc__ = u"""
... func.__name__, rc1, rc2)
>>> def run_test(repeat, test_func):
... initial_refcount =
sys.get
refcount(SampleException)
... initial_refcount =
get_
refcount(SampleException)
... for i in range(repeat):
... try: raise SampleException
... except:
... refcount1 =
sys.get
refcount(SampleException)
... refcount1 =
get_
refcount(SampleException)
... test_func()
... refcount2 =
sys.get
refcount(SampleException)
... refcount2 =
get_
refcount(SampleException)
...
... assert_refcount(refcount1, 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(initial_refcount, refcount3, test_func)
...
...
@@ -28,6 +27,11 @@ __doc__ = u"""
>>> run_test(50, test_finally)
"""
from
cpython.ref
cimport
PyObject
def
get_refcount
(
obj
):
return
(
<
PyObject
*>
obj
).
ob_refcnt
def
test_no_exception
():
try
:
a
=
1
+
1
...
...
tests/run/refcount_in_meth.pyx
View file @
079d698d
...
...
@@ -12,7 +12,10 @@ True
True
"""
import
sys
from
cpython.ref
cimport
PyObject
def
get_refcount
(
obj
):
return
(
<
PyObject
*>
obj
).
ob_refcnt
cdef
class
RefCountInMeth
(
object
):
cdef
double
value
...
...
@@ -32,27 +35,27 @@ cdef class RefCountInMeth(object):
cdef
int
c_meth
(
self
):
cdef
int
v
v
=
sys
.
get
refcount
(
self
)
v
=
get_
refcount
(
self
)
return
v
cdef
int
c_meth_if
(
self
):
cdef
int
v
if
5
>
6
:
v
=
7
v
=
sys
.
get
refcount
(
self
)
v
=
get_
refcount
(
self
)
return
v
def
chk_meth
(
self
):
cdef
int
a
,
b
a
=
sys
.
get
refcount
(
self
)
a
=
get_
refcount
(
self
)
b
=
self
.
c_meth
()
return
a
==
b
def
chk_meth_if
(
self
):
cdef
int
a
,
b
a
=
sys
.
get
refcount
(
self
)
a
=
get_
refcount
(
self
)
b
=
self
.
c_meth_if
()
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