[pypy-commit] pypy default: - fix the mismatch between "int" and "long" return types for

arigo noreply at buildbot.pypy.org
Wed Jan 14 21:17:13 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r75335:b9d53b23c50b
Date: 2015-01-14 21:17 +0100
http://bitbucket.org/pypy/pypy/changeset/b9d53b23c50b/

Log:	- fix the mismatch between "int" and "long" return types for
	pypy_setup_home()

	- fix the docs to say that calling pypy_setup_home() is not
	optional (we get a segfault if we don't call it)

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -30,12 +30,10 @@
 
    Initialize threads. Only need to be called if there are any threads involved
 
-.. function:: long pypy_setup_home(char* home, int verbose);
+.. function:: int pypy_setup_home(char* home, int verbose);
 
    This function searches the PyPy standard library starting from the given
-   "PyPy home directory".  It is not strictly necessary to execute it before
-   running Python code, but without it you will not be able to import any
-   non-builtin module from the standard library.  The arguments are:
+   "PyPy home directory".  The arguments are:
 
    * ``home``: NULL terminated path to an executable inside the pypy directory
      (can be a .so name, can be made up)
@@ -84,17 +82,22 @@
 
     const char source[] = "print 'hello from pypy'";
 
-    int main()
+    int main(void)
     {
-      int res;
+        int res;
 
-      rpython_startup_code();
-      // pypy_setup_home() is not needed in this trivial example
-      res = pypy_execute_source((char*)source);
-      if (res) {
-        printf("Error calling pypy_execute_source!\n");
-      }
-      return res;
+        rpython_startup_code();
+        res = pypy_setup_home("/opt/pypy/bin/libpypy-c.so", 1);
+        if (res) {
+            printf("Error setting pypy home!\n");
+            return 1;
+        }
+
+        res = pypy_execute_source((char*)source);
+        if (res) {
+            printf("Error calling pypy_execute_source!\n");
+        }
+        return res;
     }
 
 If we save it as ``x.c`` now, compile it and run it (on linux) with::
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -101,7 +101,7 @@
         if space.is_none(w_path):
             if verbose:
                 debug("Failed to find library based on pypy_find_stdlib")
-            return 1
+            return rffi.cast(rffi.INT, 1)
         space.startup()
         space.call_function(w_pathsetter, w_path)
         # import site
@@ -109,13 +109,13 @@
             import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
                                     space.wrap('__import__'))
             space.call_function(import_, space.wrap('site'))
-            return 0
+            return rffi.cast(rffi.INT, 0)
         except OperationError, e:
             if verbose:
                 debug("OperationError:")
                 debug(" operror-type: " + e.w_type.getname(space))
                 debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
-            return -1
+            return rffi.cast(rffi.INT, -1)
 
     @entrypoint('main', [rffi.CCHARP], c_name='pypy_execute_source')
     def pypy_execute_source(ll_source):


More information about the pypy-commit mailing list