[Pythonmac-SIG] building universal binaries

Bob Ippolito bob at redivi.com
Fri Feb 3 22:29:34 CET 2006


On Feb 3, 2006, at 12:05 PM, Jeremy Kloth wrote:

> On Friday, February 03, 2006 12:51 PM, Bob Ippolito wrote:
>> Packages that do something with sys.byteorder at setup.py time are
>> probably going to be broken also... but I've never seen that either.
>
> Any package that wraps Expat will probably be using sys.byteorder  
> as Expat
> needs to know the byte order at compile time for its UTF-16  
> functionality.
> Packages that I know about are PyXML, cElementTree and 4Suite.

Ok, then they're all broken.  They need to use the C preprocessor,  
not setup.py, to determine byteorder.

Something like this (not yet tested) should work for cElementTree,  
for example:

=== cElementTree.c
==================================================================
--- cElementTree.c      (revision 54)
+++ cElementTree.c      (local)
@@ -33,6 +33,7 @@
   * 2005-08-11 fl  added runtime test for copy workaround (1.0.3)
   * 2005-12-13 fl  added expat_capi support (for xml.etree) (1.0.4)
   * 2005-12-16 fl  added support for non-standard encodings
+ * 2006-02-03 bi  determine endian from Python.h, not sys.byteorder
   *
   * Copyright (c) 1999-2005 by Secret Labs AB.  All rights reserved.
   * Copyright (c) 1999-2005 by Fredrik Lundh.
=== setup.py
==================================================================
--- setup.py    (revision 54)
+++ setup.py    (local)
@@ -49,10 +49,7 @@
              defines.append((feature_macro, "1"))
      defines.append(("XML_NS", "1"))
      defines.append(("XML_DTD", "1"))
-    if sys.byteorder == "little":
-        defines.append(("BYTEORDER", "1234"))
-    else:
-        defines.append(("BYTEORDER", "4321"))
+    defines.append(("HAVE_EXPAT_CONFIG_H", "1"))
      defines.append(("XML_CONTEXT_BYTES", "1024"))
=== expat_config.h
==================================================================
--- expat_config.h      (revision 54)
+++ expat_config.h      (local)
@@ -0,0 +1,9 @@
+#include "Python.h"
+#ifdef BYTEORDER
+#undef BYTEORDER
+#endif
+#ifdef WORDS_BIGENDIAN
+#define BYTEORDER 4321
+#else
+#define BYTEORDER 1234
+#endif


-bob



More information about the Pythonmac-SIG mailing list