[pypy-commit] pypy default: (bivab, arigo)

arigo noreply at buildbot.pypy.org
Mon Jun 6 18:57:42 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r44760:6e9d3f5647bb
Date: 2011-06-06 18:57 +0200
http://bitbucket.org/pypy/pypy/changeset/6e9d3f5647bb/

Log:	(bivab, arigo)

	Found here that using memcpy() is the recommend way; that makes
	sense. http://blog.llvm.org/2011/05/what-every-c-programmer-should-
	know.html

diff --git a/pypy/rlib/longlong2float.py b/pypy/rlib/longlong2float.py
--- a/pypy/rlib/longlong2float.py
+++ b/pypy/rlib/longlong2float.py
@@ -30,25 +30,16 @@
     return llval
 
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
-eci = ExternalCompilationInfo(post_include_bits=["""
+eci = ExternalCompilationInfo(includes=['string.h'],
+                              post_include_bits=["""
 static double pypy__longlong2float(long long x) {
-    int i;
     double dd;
-    char *p = (char*)&x;
-    char *d = (char*)&dd;
-    for(i = 0; i < 8; i++) {
-        d[i] = p[i];
-    }
+    memcpy(&dd, &x, 8);
     return dd;
 }
 static long long pypy__float2longlong(double x) {
-    int i;
     long long ll;
-    char *p = (char*)&x;
-    char *l = (char*)&ll;
-    for(i = 0; i < 8; i++) {
-        l[i] = p[i];
-    }
+    memcpy(&ll, &x, 8);
     return ll;
 }
 """])


More information about the pypy-commit mailing list