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
Boxiang Sun
cython
Commits
52419f66
Commit
52419f66
authored
Sep 21, 2017
by
Ronan Lamy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a PyPy-compatible definition of getrefcount()
parent
1bb93db2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
tests/run/test_coroutines_pep492.pyx
tests/run/test_coroutines_pep492.pyx
+20
-10
No files found.
tests/run/test_coroutines_pep492.pyx
View file @
52419f66
...
@@ -54,6 +54,16 @@ except ImportError:
...
@@ -54,6 +54,16 @@ except ImportError:
def
__call__
(
self
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
self
.
_GeneratorWrapper
(
self
.
_gen
(
*
args
,
**
kwargs
))
return
self
.
_GeneratorWrapper
(
self
.
_gen
(
*
args
,
**
kwargs
))
try
:
from
sys
import
getrefcount
except
ImportError
:
from
cpython.ref
cimport
PyObject
def
getrefcount
(
obj
):
gc
.
collect
()
# PyPy needs to execute a bytecode to run the finalizers
exec
(
''
,
{},
{})
return
(
<
PyObject
*>
obj
).
ob_refcnt
# compiled exec()
# compiled exec()
def
exec
(
code_string
,
l
,
g
):
def
exec
(
code_string
,
l
,
g
):
...
@@ -1867,7 +1877,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1867,7 +1877,7 @@ class CoroutineTest(unittest.TestCase):
def
test_for_2
(
self
):
def
test_for_2
(
self
):
tup
=
(
1
,
2
,
3
)
tup
=
(
1
,
2
,
3
)
refs_before
=
sys
.
getrefcount
(
tup
)
refs_before
=
getrefcount
(
tup
)
async
def
foo
():
async
def
foo
():
async
for
i
in
tup
:
async
for
i
in
tup
:
...
@@ -1878,7 +1888,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1878,7 +1888,7 @@ class CoroutineTest(unittest.TestCase):
run_async
(
foo
())
run_async
(
foo
())
self
.
assertEqual
(
sys
.
getrefcount
(
tup
),
refs_before
)
self
.
assertEqual
(
getrefcount
(
tup
),
refs_before
)
def
test_for_3
(
self
):
def
test_for_3
(
self
):
class
I
(
object
):
class
I
(
object
):
...
@@ -1886,7 +1896,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1886,7 +1896,7 @@ class CoroutineTest(unittest.TestCase):
return
self
return
self
aiter
=
I
()
aiter
=
I
()
refs_before
=
sys
.
getrefcount
(
aiter
)
refs_before
=
getrefcount
(
aiter
)
async
def
foo
():
async
def
foo
():
async
for
i
in
aiter
:
async
for
i
in
aiter
:
...
@@ -1898,7 +1908,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1898,7 +1908,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo())
run_async(foo())
self.assertEqual(
sys.
getrefcount(aiter), refs_before)
self.assertEqual(getrefcount(aiter), refs_before)
def test_for_4(self):
def test_for_4(self):
class I(object):
class I(object):
...
@@ -1909,7 +1919,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1909,7 +1919,7 @@ class CoroutineTest(unittest.TestCase):
return ()
return ()
aiter = I()
aiter = I()
refs_before =
sys.
getrefcount(aiter)
refs_before = getrefcount(aiter)
async def foo():
async def foo():
async for i in aiter:
async for i in aiter:
...
@@ -1921,7 +1931,7 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1921,7 +1931,7 @@ class CoroutineTest(unittest.TestCase):
run_async(foo())
run_async(foo())
self.assertEqual(
sys.
getrefcount(aiter), refs_before)
self.assertEqual(getrefcount(aiter), refs_before)
def test_for_5(self):
def test_for_5(self):
class I(object):
class I(object):
...
@@ -1971,8 +1981,8 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1971,8 +1981,8 @@ class CoroutineTest(unittest.TestCase):
manager = Manager()
manager = Manager()
iterable = Iterable()
iterable = Iterable()
mrefs_before =
sys.
getrefcount(manager)
mrefs_before = getrefcount(manager)
irefs_before =
sys.
getrefcount(iterable)
irefs_before = getrefcount(iterable)
async def main():
async def main():
nonlocal I
nonlocal I
...
@@ -1985,8 +1995,8 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1985,8 +1995,8 @@ class CoroutineTest(unittest.TestCase):
run_async(main())
run_async(main())
self.assertEqual(I, 111011)
self.assertEqual(I, 111011)
self.assertEqual(
sys.
getrefcount(manager), mrefs_before)
self.assertEqual(getrefcount(manager), mrefs_before)
self.assertEqual(
sys.
getrefcount(iterable), irefs_before)
self.assertEqual(getrefcount(iterable), irefs_before)
##############
##############
...
...
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