[pypy-commit] pypy ec-keepalive: Yet Another attempt to fix rpython_startup_code(), this time writing it

arigo pypy.commits at gmail.com
Mon Jan 4 13:51:12 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: ec-keepalive
Changeset: r81559:5a02efb1a226
Date: 2016-01-04 19:50 +0100
http://bitbucket.org/pypy/pypy/changeset/5a02efb1a226/

Log:	Yet Another attempt to fix rpython_startup_code(), this time writing
	it as plain C code (why wasn't it done this way already...)

diff --git a/rpython/rlib/entrypoint.py b/rpython/rlib/entrypoint.py
--- a/rpython/rlib/entrypoint.py
+++ b/rpython/rlib/entrypoint.py
@@ -1,4 +1,4 @@
-secondary_entrypoints = {}
+secondary_entrypoints = {"main": []}
 
 import py
 from rpython.rtyper.lltypesystem import lltype, rffi
@@ -109,17 +109,3 @@
                     "you.  Another difference is that entrypoint_highlevel() "
                     "returns the normal Python function, which can be safely "
                     "called from more Python code.")
-
-
-# the point of dance below is so the call to rpython_startup_code actually
-# does call asm_stack_bottom. It's here because there is no other good place.
-# This thing is imported by any target which has any API, so it'll get
-# registered
-
-RPython_StartupCode = rffi.llexternal('RPython_StartupCode', [], lltype.Void,
-                                      _nowrapper=True,
-                                      random_effects_on_gcobjs=True)
-
- at entrypoint_highlevel('main', [], c_name='rpython_startup_code')
-def rpython_startup_code():
-    RPython_StartupCode()
diff --git a/rpython/translator/c/src/entrypoint.c b/rpython/translator/c/src/entrypoint.c
--- a/rpython/translator/c/src/entrypoint.c
+++ b/rpython/translator/c/src/entrypoint.c
@@ -37,6 +37,24 @@
 # include <src/thread.h>
 #endif
 
+void rpython_startup_code(void)
+{
+#ifdef RPY_WITH_GIL
+    RPyGilAcquire();
+#endif
+#ifdef PYPY_USE_ASMGCC
+    pypy_g_rpython_rtyper_lltypesystem_rffi_StackCounter.sc_inst_stacks_counter++;
+#endif
+    pypy_asm_stack_bottom();
+    RPython_StartupCode();
+#ifdef PYPY_USE_ASMGCC
+    pypy_g_rpython_rtyper_lltypesystem_rffi_StackCounter.sc_inst_stacks_counter--;
+#endif
+#ifdef RPY_WITH_GIL
+    RPyGilRelease();
+#endif
+}
+
 
 RPY_EXTERN
 int pypy_main_function(int argc, char *argv[])
diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -96,6 +96,8 @@
                     continue
                 if name == 'pypy_debug_file':     # ok to export this one
                     continue
+                if name == 'rpython_startup_code':  # ok for this one too
+                    continue
                 if 'pypy' in name.lower() or 'rpy' in name.lower():
                     raise Exception("Unexpected exported name %r.  "
                         "What is likely missing is RPY_EXTERN before the "
diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py
--- a/rpython/translator/driver.py
+++ b/rpython/translator/driver.py
@@ -203,9 +203,8 @@
                 try:
                     points = secondary_entrypoints[key]
                 except KeyError:
-                    raise KeyError(
-                        "Entrypoints not found. I only know the keys %r." %
-                        (", ".join(secondary_entrypoints.keys()), ))
+                    raise KeyError("Entrypoint %r not found (not in %r)" %
+                                   (key, secondary_entrypoints.keys()))
                 self.secondary_entrypoints.extend(points)
 
         self.translator.driver_instrument_result = self.instrument_result


More information about the pypy-commit mailing list