Hi Armin,

For the RPython module I added, I had added and passed test_ztranslation.py, and sucessfully built libpypy-c.so.
And in pypy console, it worked correctly. 
The problem happened when I tried to use this RPython module for the existed RPython module in pypy/module.
The test I failed was test_ztranslation.py. It reported the error: 
...
 else:
                    if hasattr(pyobj, '__call__'):
                        msg = "object with a __call__ is not RPython"
                    else:
                        msg = "unexpected prebuilt constant"
>                   raise Exception("%s: %r" % (msg, pyobj)
E             Exception: object with a __call__ is not RPython: <built-in function testFunc>

The corresponding line is where I used my RPython module:
myModule.testFunc()

---------------------------------------------------------------------

And here are my thoughts why I need to use RPython module:

I tried to implement a special lightweight sandbox or critical section to block certain builtin function.
One user scenario might look like this:

criticalSection.start()
criticalSection.block('select.epoll')
...some code in critical section...
criticcalSection.exit()

Different from "usual sandbox", we would like to only block some customized builtin functions for a segment of the code.

To achieve this purpose, here are my plans:
1. Write a builtin RPython module 'criticalsection', because I thought only builtin RPython module could be used for existed builtin RPython module
2. For the list of builtin functions that we might block, add the code in the begining of those functions, e.g.

def epoll:
    if criticalsection.isInCriticalSection() and criticalsection.block('select.epoll')
         return None
    ... the original code...


On Thu, May 28, 2015 at 9:57 PM, Armin Rigo <arigo@tunes.org> wrote:
Hi Yicong,

If you really want to add an RPython module in PyPy, you should follow
closely the example of another module.  The first step is to add tests
that run untranslated.  Your module must be correct and tested
*before* you attempt to translate it.  Being correct RPython is not
the first concern, as long as you follow the general guidelines shown
by the other existing module.

The last test to add (after all other tests) is a
"test_ztranslation.py", which tests that your module is correct
RPython code.  We can discuss specific RPython issues you'd have at
this point.

If you only want to learn RPython, you could also try to write a small
interpreter for a custom language.  This is the path that other people
take, and it allows them to choose which approach they prefer, e.g. if
they don't care about untranslated tests.  However, if you're working
with PyPy, then you have to follow the rules and write tests,
otherwise you're unlikely to get much help from any of us.

(Also, it would help us get some motivation if you could successfully
explain why you need an RPython module instead of, say, using CFFI.)


A bientôt,

Armin.