By reading modules in pypy/module, finally we found out the workaround method.
For most of modules in 'pypy/module', their interp code could not be imported or used by other module's app code. But there is special module '__pypy__', it exposed several interp functions, and those code are used by other module's app code. E.g. __builtin__/app_functional.py used resizelist_hint and newlist_hint from __pypy__ module. But these two functions are actually defined as interp code in ‘__pypy__' module. The workaround solution is simple: add one more interface in __pypy__ module's __init__.py and point to the interp file in the module that would expose. E.g. if we would like to use function from fcntl/interp_fcntl.py, add below lines: import pypy.module.fcntl.interp_fcntl interpleveldefs = { ... 'xxx' : 'pypy.module.interpfcntl.xxx'} And then the function is visible to app code of the module by: from __pypy__ import xxx And finally, here comes the question why __pypy__ module is special to be capable to expose interp code? For a quick glance, we observed some extra code in its __init__.py, which were not seen from other modules: PYC_MAGIC = get_pyc_magic(self.space) self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC) Are the above code do the magic thing to expose interp code? On Sun, Jun 7, 2015 at 3:47 PM, Armin Rigo <ar...@tunes.org> wrote: > Hi Yicong, > > On 7 June 2015 at 09:33, Yicong Huang <hengha....@gmail.com> wrote: > > In this case, any alternative methods? > > I really think you need to look at some other directories > "pypy/module/*/" and use the same style. I'm still unsure what you're > trying to do, so I can't answer you more precisely. Most probably, it > is similar to other existing modules. If it is too different from all > of them, then you might be using entirely the wrong approach... > > > A bientôt, > > Armin. >
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev