]> granicus.if.org Git - python/commitdiff
Fix issue 4884, preventing a crash in the socket code when python is compiled
authorJeffrey Yasskin <jyasskin@gmail.com>
Fri, 9 Jan 2009 16:47:07 +0000 (16:47 +0000)
committerJeffrey Yasskin <jyasskin@gmail.com>
Fri, 9 Jan 2009 16:47:07 +0000 (16:47 +0000)
with llvm-gcc and run with a glibc <2.10.

Include/pyport.h
Modules/socketmodule.c

index 15c8644f5671b6595ff0b3d38338afb0af6417c3..54411f25972447e1151206c6136e19155b1700b0 100644 (file)
@@ -709,6 +709,15 @@ typedef    struct fd_set {
 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
 #endif
 
+/*
+ * Specify alignment on compilers that support it.
+ */
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define Py_ALIGNED(x) __attribute__((aligned(x)))
+#else
+#define Py_ALIGNED(x)
+#endif
+
 /* Eliminate end-of-loop code not reached warnings from SunPro C
  * when using do{...}while(0) macros
  */
index deff28a1be9a13b255ec3f49af60c614cbb75a6c..c1e3cfe175d82d3e041df46abf5e614a49b96710 100644 (file)
@@ -3334,7 +3334,11 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
 #ifdef HAVE_GETHOSTBYNAME_R_3_ARG
        struct hostent_data data;
 #else
-       char buf[16384];
+       /* glibcs up to 2.10 assume that the buf argument to
+          gethostbyaddr_r is 8-byte aligned, which at least llvm-gcc
+          does not ensure. The attribute below instructs the compiler
+          to maintain this alignment. */
+       char buf[16384] Py_ALIGNED(8);
        int buf_len = (sizeof buf) - 1;
        int errnop;
 #endif