Commits

Amaury Forgeot d'Arc committed 33ac21e

Always generate separate header files, even for "one_source_file" builds.
This allows int.c to be compiled separately.

  • Participants
  • Parent commits ea51e86
  • Branches remove-PYPY_NOT_MAIN_FILE

Comments (0)

Files changed (3)

pypy/translator/c/genc.py

                 yield self.uniquecname(basecname), subiter()
 
     @contextlib.contextmanager
-    def write_on_maybe_included_file(self, f, name):
-        if self.one_source_file:
-            print >> f
-            yield f
-        else:
-            fi = self.makefile(name)
-            print >> f, '#include "%s"' % name
-            yield fi
-            fi.close()
+    def write_on_included_file(self, f, name):
+        fi = self.makefile(name)
+        print >> f, '#include "%s"' % name
+        yield fi
+        fi.close()
 
     @contextlib.contextmanager
     def write_on_maybe_separate_source(self, f, name):
         #
         # All declarations
         #
-        with self.write_on_maybe_included_file(f, 'structdef.h') as fi:
+        with self.write_on_included_file(f, 'structdef.h') as fi:
             gen_structdef(fi, self.database)
-        with self.write_on_maybe_included_file(f, 'forwarddecl.h') as fi:
+        with self.write_on_included_file(f, 'forwarddecl.h') as fi:
             gen_forwarddecl(fi, self.database)
-        with self.write_on_maybe_included_file(f, 'preimpl.h') as fi:
+        with self.write_on_included_file(f, 'preimpl.h') as fi:
             gen_preimpl(fi, self.database)
 
         #
         srcdir / 'asm.c',
         srcdir / 'instrument.c',
         srcdir / 'll_strtod.c',
+        srcdir / 'int.c',
     ]
     if _CYGWIN:
         files.append(srcdir / 'cygwin_wait.c')

pypy/translator/c/src/int.c

+#include "common_header.h"
+#include "structdef.h"
+#include "forwarddecl.h"
+#include "preimpl.h"
+#include <src/int.h>
+#include <src/support.h>
+#include <src/exception.h>
+
+/* adjusted from intobject.c, Python 2.3.3 */
+
+long long op_llong_mul_ovf(long long a, long long b)
+{
+    double doubled_longprod;	/* (double)longprod */
+    double doubleprod;		/* (double)a * (double)b */
+    long long longprod;
+
+    longprod = a * b;
+    doubleprod = (double)a * (double)b;
+    doubled_longprod = (double)longprod;
+
+    /* Fast path for normal case:  small multiplicands, and no info
+       is lost in either method. */
+    if (doubled_longprod == doubleprod)
+	return longprod;
+
+    /* Somebody somewhere lost info.  Close enough, or way off?  Note
+       that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
+       The difference either is or isn't significant compared to the
+       true value (of which doubleprod is a good approximation).
+    */
+    {
+	const double diff = doubled_longprod - doubleprod;
+	const double absdiff = diff >= 0.0 ? diff : -diff;
+	const double absprod = doubleprod >= 0.0 ? doubleprod :
+	    -doubleprod;
+	/* absdiff/absprod <= 1/32 iff
+	   32 * absdiff <= absprod -- 5 good bits is "close enough" */
+	if (32.0 * absdiff <= absprod)
+	    return longprod;
+
+	FAIL_OVF("integer multiplication");
+	return -1;
+    }
+}
+

pypy/translator/c/src/int.h

+/************************************************************/
+/***  C header subsection: operations between ints        ***/
 
-/************************************************************/
- /***  C header subsection: operations between ints        ***/
 
-
-/*** unary operations ***/
-
-/************ win64 support:
+/* Note for win64:
 
    'Signed' must be defined as
 
        LONG_MIN         in all other cases
  */
 
+/*** unary operations ***/
+
 #define OP_INT_IS_TRUE(x,r)   r = ((x) != 0)
 #define OP_INT_INVERT(x,r)    r = ~(x)
 #define OP_INT_NEG(x,r)       r = -(x)
 
 #define OP_BOOL_NOT(x, r) r = !(x)
 
-/* _________________ certain implementations __________________ */
-
-/* adjusted from intobject.c, Python 2.3.3 */
-
-/* prototypes */
-
 long long op_llong_mul_ovf(long long a, long long b);
 
-/* implementations */
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-
-long long op_llong_mul_ovf(long long a, long long b)
-{
-	double doubled_longprod;	/* (double)longprod */
-	double doubleprod;		/* (double)a * (double)b */
-	long long longprod;
-
-	longprod = a * b;
-	doubleprod = (double)a * (double)b;
-	doubled_longprod = (double)longprod;
-
-	/* Fast path for normal case:  small multiplicands, and no info
-	   is lost in either method. */
-	if (doubled_longprod == doubleprod)
-		return longprod;
-
-	/* Somebody somewhere lost info.  Close enough, or way off?  Note
-	   that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
-	   The difference either is or isn't significant compared to the
-	   true value (of which doubleprod is a good approximation).
-	*/
-	{
-		const double diff = doubled_longprod - doubleprod;
-		const double absdiff = diff >= 0.0 ? diff : -diff;
-		const double absprod = doubleprod >= 0.0 ? doubleprod :
-							  -doubleprod;
-		/* absdiff/absprod <= 1/32 iff
-		   32 * absdiff <= absprod -- 5 good bits is "close enough" */
-		if (32.0 * absdiff <= absprod)
-			return longprod;
-
-		FAIL_OVF("integer multiplication");
-		return -1;
-	}
-}
-
-#endif /* PYPY_MAIN_IMPLEMENTATION_FILE */
-
-/* implementations */
+/* The definitions above can be used with various types */ 
 
 #define OP_UINT_IS_TRUE OP_INT_IS_TRUE
 #define OP_UINT_INVERT OP_INT_INVERT