Author: Ronan Lamy <[email protected]>
Branch: cpyext-leakchecking
Changeset: r92004:ee6ee454da80
Date: 2017-07-31 21:50 +0100
http://bitbucket.org/pypy/pypy/changeset/ee6ee454da80/
Log: Create builtin pyobjs early for interp-level tests as well
diff --git a/pypy/module/cpyext/test/test_api.py
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -6,7 +6,8 @@
from pypy.module.cpyext.api import (
slot_function, cpython_api, copy_header_files, INTERPLEVEL_API,
Py_ssize_t, Py_ssize_tP, PyObject, cts)
-from pypy.module.cpyext.test.test_cpyext import freeze_refcnts,
LeakCheckingTest
+from pypy.module.cpyext.test.test_cpyext import (
+ freeze_refcnts, LeakCheckingTest)
from pypy.interpreter.error import OperationError
from rpython.rlib import rawrefcount
import os
@@ -32,6 +33,7 @@
space.call_function(space.getattr(space.sys.get("stdout"),
space.wrap("write")),
space.wrap(""))
+ cls.preload_builtins(space)
class CAPI:
def __getattr__(self, name):
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -76,6 +76,23 @@
def freeze_refcnts(self):
rawrefcount._dont_free_any_more()
+def preload(space, name):
+ from pypy.module.cpyext.pyobject import make_ref
+ if '.' not in name:
+ w_obj = space.builtin.getdictvalue(space, name)
+ else:
+ module, localname = name.rsplit('.', 1)
+ code = "(): import {module}; return {module}.{localname}"
+ code = code.format(**locals())
+ w_obj = space.appexec([], code)
+ make_ref(space, w_obj)
+
+def preload_expr(space, expr):
+ from pypy.module.cpyext.pyobject import make_ref
+ code = "(): return {}".format(expr)
+ w_obj = space.appexec([], code)
+ make_ref(space, w_obj)
+
def is_interned_string(space, w_obj):
try:
s = space.str_w(w_obj)
@@ -118,6 +135,24 @@
'micronumpy', 'mmap'
])
+ @classmethod
+ def preload_builtins(cls, space):
+ """
+ Eagerly create pyobjs for various builtins so they don't look like
+ leaks.
+ """
+ space.getbuiltinmodule("cpyext")
+ # 'import os' to warm up reference counts
+ w_import = space.builtin.getdictvalue(space, '__import__')
+ space.call_function(w_import, space.wrap("os"))
+ for name in [
+ 'buffer', 'mmap.mmap',
+ 'types.FunctionType', 'types.CodeType',
+ 'types.TracebackType', 'types.FrameType']:
+ preload(space, name)
+ for expr in ['type(str.join)']:
+ preload_expr(space, expr)
+
def cleanup(self):
self.space.getexecutioncontext().cleanup_cpyext_state()
rawrefcount._collect()
@@ -178,23 +213,6 @@
def debug_collect(space):
rawrefcount._collect()
-def preload(space, name):
- from pypy.module.cpyext.pyobject import make_ref
- if '.' not in name:
- w_obj = space.builtin.getdictvalue(space, name)
- else:
- module, localname = name.rsplit('.', 1)
- code = "(): import {module}; return {module}.{localname}"
- code = code.format(**locals())
- w_obj = space.appexec([], code)
- make_ref(space, w_obj)
-
-def preload_expr(space, expr):
- from pypy.module.cpyext.pyobject import make_ref
- code = "(): return {}".format(expr)
- w_obj = space.appexec([], code)
- make_ref(space, w_obj)
-
class AppTestCpythonExtensionBase(LeakCheckingTest):
@@ -205,20 +223,8 @@
cls.w_runappdirect = space.wrap(cls.runappdirect)
if not cls.runappdirect:
cls.sys_info = get_cpyext_info(space)
- space.getbuiltinmodule("cpyext")
- # 'import os' to warm up reference counts
- w_import = space.builtin.getdictvalue(space, '__import__')
- space.call_function(w_import, space.wrap("os"))
- for name in [
- 'buffer', 'mmap.mmap',
- 'types.FunctionType', 'types.CodeType',
- 'types.TracebackType', 'types.FrameType']:
- preload(space, name)
- for expr in ['type(str.join)']:
- preload_expr(space, expr)
- #state = cls.space.fromcache(RefcountState) ZZZ
- #state.non_heaptypes_w[:] = []
cls.w_debug_collect = space.wrap(interp2app(debug_collect))
+ cls.preload_builtins(space)
else:
def w_import_module(self, name, init=None, body='', filename=None,
include_dirs=None, PY_SSIZE_T_CLEAN=False):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit