[pypy-commit] pypy remove-PYPY_NOT_MAIN_FILE: Always generate separate header files, even for "one_source_file" builds.
amauryfa
noreply at buildbot.pypy.org
Tue Oct 2 16:37:46 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57724:33ac21ea061d
Date: 2012-10-02 14:50 +0200
http://bitbucket.org/pypy/pypy/changeset/33ac21ea061d/
Log: Always generate separate header files, even for "one_source_file"
builds. This allows int.c to be compiled separately.
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
@@ -749,15 +749,11 @@
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):
@@ -780,11 +776,11 @@
#
# 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)
#
@@ -919,6 +915,7 @@
srcdir / 'asm.c',
srcdir / 'instrument.c',
srcdir / 'll_strtod.c',
+ srcdir / 'int.c',
]
if _CYGWIN:
files.append(srcdir / 'cygwin_wait.c')
diff --git a/pypy/translator/c/src/int.c b/pypy/translator/c/src/int.c
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/int.c
@@ -0,0 +1,45 @@
+#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;
+ }
+}
+
diff --git a/pypy/translator/c/src/int.h b/pypy/translator/c/src/int.h
--- a/pypy/translator/c/src/int.h
+++ b/pypy/translator/c/src/int.h
@@ -1,11 +1,8 @@
+/************************************************************/
+/*** C header subsection: operations between ints ***/
-/************************************************************/
- /*** C header subsection: operations between ints ***/
-
-/*** unary operations ***/
-
-/************ win64 support:
+/* Note for win64:
'Signed' must be defined as
@@ -18,6 +15,8 @@
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)
@@ -237,56 +236,9 @@
#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
More information about the pypy-commit
mailing list