Commits

David Schneider committed a57b50c

add a helper method to translatorshell to get the compiled function from the compiled library and update the documentation

  • Participants
  • Parent commits 7a0d270

Comments (0)

Files changed (2)

File pypy/doc/getting-started-dev.rst

 only use low level types that are available in C (e.g. int). The compiled
 version is now in a ``.so`` library. You can run it say using ctypes:
 
-   >>> from ctypes import CDLL
-   >>> f = CDLL(lib)
+   >>> f = get_c_function(lib, snippet.is_perfect_number)
    >>> f(5)
    0
    >>> f(6)

File rpython/bin/translatorshell.py

     t.view()                           # graph + annotations under the mouse
 
     t.rtype()                          # use low level operations 
-    f = t.compile_c()                  # C compilation
+    lib = t.compile_c()                # C compilation as a library
+    f = get_c_function(lib, f)         # get the function out of the library
     assert f(arg) == func(arg)         # sanity check (for C)
-    
+
 
 Some functions are provided for the benefit of interactive testing.
 Try dir(snippet) for list of current snippets.
 
 import py
 
+
+def get_c_function(lib, f):
+    from ctypes import CDLL
+    name = f.__name__
+    return getattr(CDLL(lib.strpath), 'pypy_g_' + name)
+
+
 def setup_readline():
     import readline
     try: