Commits

Lenard Lindstrom committed ab15304

Move new buffer support determination to setup.py

Allow the ENABLE_NEWBUF C macro to be set in the compiler shell command. This
allows the decision to enable new buffer protocol support to be made in the
build chain, particularly setup.py. Now new buffer protocol support and the
deletion of src/newbuffer.c are controlled by the same piece of code.

Comments (0)

Files changed (2)

             extensions.append(e)
     del tmp_extensions
 
-#python2.5 and lower: remove new buffer testing framework
-if sys.version_info < (2, 6, 0):
+#decide whether or not to enable new buffer protocol support
+enable_newbuf = False
+if sys.version_info >= (2, 6, 0):
+    try:
+        sys.pypy_version_info
+    except AttributeError:
+        enable_newbuf = True
+
+if enable_newbuf:
+    enable_newbuf_value = '1'
+else:
+    enable_newbuf_value = '0'
+for e in extensions:
+    e.define_macros.append(('ENABLE_NEWBUF', enable_newbuf_value))
+
+#if new buffer protocol support is disabled then remove the testing framework
+if not enable_newbuf:
     posn = None
     for i, e in enumerate(extensions):
         if e.name == 'newbuffer':
 
 #define HAVE_OLD_BUFPROTO PY2
 
+#if !defined(PG_ENABLE_OLDBUF)  /* allow for command line override */
 #if HAVE_OLD_BUFPROTO
 #define PG_ENABLE_OLDBUF 1
 #else
 #define PG_ENABLE_OLDBUF 0
 #endif
+#endif
 
 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
 #endif
 
 /* Support new buffer protocol? */
+#if !defined(PG_ENABLE_NEWBUF)  /* allow for command line override */
 #if HAVE_NEW_BUFPROTO && !defined(PYPY_VERSION)
 #define PG_ENABLE_NEWBUF 1
 #else
 #define PG_ENABLE_NEWBUF 0
 #endif
+#endif
 
 #endif /* #if !defined(PGCOMPAT_H) */