Author: Amaury Forgeot d'Arc <[email protected]>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57733:3387ffeb70aa
Date: 2012-10-02 16:23 +0200
http://bitbucket.org/pypy/pypy/changeset/3387ffeb70aa/
Log: Split main.h: interface and implementation.
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -907,6 +907,7 @@
def add_extra_files(eci):
srcdir = py.path.local(autopath.pypydir).join('translator', 'c', 'src')
files = [
+ srcdir / 'main.c',
srcdir / 'allocator.c',
srcdir / 'mem.c',
srcdir / 'exception.c',
diff --git a/pypy/translator/c/src/main.c b/pypy/translator/c/src/main.c
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/main.c
@@ -0,0 +1,79 @@
+#include "common_header.h"
+#ifdef PYPY_STANDALONE
+#include "structdef.h"
+#include "forwarddecl.h"
+#include "preimpl.h"
+#include <src/main.h>
+#include <src/commondefs.h>
+#include <src/mem.h>
+#include <src/instrument.h>
+#include <src/rtyper.h>
+#include <src/exception.h>
+#include <src/debug_traceback.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef __GNUC__
+/* Hack to prevent this function from being inlined. Helps asmgcc
+ because the main() function has often a different prologue/epilogue. */
+int pypy_main_function(int argc, char *argv[]) __attribute__((__noinline__));
+#endif
+
+int pypy_main_function(int argc, char *argv[])
+{
+ char *errmsg;
+ int i, exitcode;
+ RPyListOfString *list;
+
+ pypy_asm_stack_bottom();
+#ifdef PYPY_X86_CHECK_SSE2_DEFINED
+ pypy_x86_check_sse2();
+#endif
+ instrument_setup();
+
+#ifndef MS_WINDOWS
+ /* this message does no longer apply to win64 :-) */
+ if (sizeof(void*) != SIZEOF_LONG) {
+ errmsg = "only support platforms where sizeof(void*) == sizeof(long),"
+ " for now";
+ goto error;
+ }
+#endif
+
+ errmsg = RPython_StartupCode();
+ if (errmsg) goto error;
+
+ list = _RPyListOfString_New(argc);
+ if (RPyExceptionOccurred()) goto memory_out;
+ for (i=0; i<argc; i++) {
+ RPyString *s = RPyString_FromString(argv[i]);
+ if (RPyExceptionOccurred()) goto memory_out;
+ _RPyListOfString_SetItem(list, i, s);
+ }
+
+ exitcode = STANDALONE_ENTRY_POINT(list);
+
+ pypy_debug_alloc_results();
+
+ if (RPyExceptionOccurred()) {
+ /* print the RPython traceback */
+ pypy_debug_catch_fatal_exception();
+ }
+
+ return exitcode;
+
+ memory_out:
+ errmsg = "out of memory";
+ error:
+ fprintf(stderr, "Fatal error during initialization: %s\n", errmsg);
+ abort();
+ return 1;
+}
+
+int PYPY_MAIN_FUNCTION(int argc, char *argv[])
+{
+ return pypy_main_function(argc, argv);
+}
+
+#endif /* PYPY_STANDALONE */
diff --git a/pypy/translator/c/src/main.h b/pypy/translator/c/src/main.h
--- a/pypy/translator/c/src/main.h
+++ b/pypy/translator/c/src/main.h
@@ -1,84 +1,13 @@
+#ifdef PYPY_STANDALONE
#ifndef STANDALONE_ENTRY_POINT
# define STANDALONE_ENTRY_POINT PYPY_STANDALONE
#endif
-char *RPython_StartupCode(void); /* forward */
-
-
-/* prototypes */
-
-int main(int argc, char *argv[]);
-
-
-/* implementations */
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-
#ifndef PYPY_MAIN_FUNCTION
#define PYPY_MAIN_FUNCTION main
#endif
-#ifdef __GNUC__
-/* Hack to prevent this function from being inlined. Helps asmgcc
- because the main() function has often a different prologue/epilogue. */
-int pypy_main_function(int argc, char *argv[]) __attribute__((__noinline__));
-#endif
-
-int pypy_main_function(int argc, char *argv[])
-{
- char *errmsg;
- int i, exitcode;
- RPyListOfString *list;
-
- pypy_asm_stack_bottom();
-#ifdef PYPY_X86_CHECK_SSE2_DEFINED
- pypy_x86_check_sse2();
-#endif
- instrument_setup();
-
-#ifndef MS_WINDOWS
- /* this message does no longer apply to win64 :-) */
- if (sizeof(void*) != SIZEOF_LONG) {
- errmsg = "only support platforms where sizeof(void*) == sizeof(long),"
- " for now";
- goto error;
- }
-#endif
-
- errmsg = RPython_StartupCode();
- if (errmsg) goto error;
-
- list = _RPyListOfString_New(argc);
- if (RPyExceptionOccurred()) goto memory_out;
- for (i=0; i<argc; i++) {
- RPyString *s = RPyString_FromString(argv[i]);
- if (RPyExceptionOccurred()) goto memory_out;
- _RPyListOfString_SetItem(list, i, s);
- }
-
- exitcode = STANDALONE_ENTRY_POINT(list);
-
- pypy_debug_alloc_results();
-
- if (RPyExceptionOccurred()) {
- /* print the RPython traceback */
- pypy_debug_catch_fatal_exception();
- }
-
- return exitcode;
-
- memory_out:
- errmsg = "out of memory";
- error:
- fprintf(stderr, "Fatal error during initialization: %s\n", errmsg);
- abort();
- return 1;
-}
-
-int PYPY_MAIN_FUNCTION(int argc, char *argv[])
-{
- return pypy_main_function(argc, argv);
-}
-
-#endif /* PYPY_MAIN_IMPLEMENTATION_FILE */
+char *RPython_StartupCode(void);
+int PYPY_MAIN_FUNCTION(int argc, char *argv[]);
+#endif /* PYPY_STANDALONE */
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit