Problem with pyconfig.h in python36 which is already solved for python27

Stefan Metzmacher metze at samba.org
Sat Jan 26 11:08:11 UTC 2019


Hi,

in Samba we recently switched to use python3 by default. But this breaks
the build on FreeBSD (at least 11.1 and 12.0). In order to be most
portable, we have a policy in Samba to include <Python.h> as the
first header when creating python bindings. It means pyconfig.h and
various system headers are included before our own config.h.
A detailed way to reproduce this can be found at the end of this mail.

The problem is that pyconfig.h defines
_POSIX_C_SOURCE, __BSD_VISIBLE, _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED.

This seems to be fixed for python27 in this commit:
https://github.com/freebsd/freebsd-ports/commit/4b17dd9aeb9b28759551f38bf0f6b0edcac88607
which added lang/python27/files/patch-pr192365.

Could this be fixed for all python versions?

An alternative fix for this specific problem would be
defining __STDC_WANT_LIB_EXT1__ in pyconfig.h,
but I don't know the reason for lang/python27/files/patch-pr192365
and I guess it's better to have the same fix for all python versions.

Is this the correct channel to report this problem?

Thanks in advance!
metze

This is a standalone way to reproduce the problem:

$ cat memset_s.c
#include <Python.h>
#include <string.h>
int main(void)
{
        char array[5] = { 1, };
        memset_s(array, 5, 0, 5);
        return 0;
}

$ gcc -o memset_s.exe memset_s.c -I /usr/local/include/python2.7/

$ gcc -o memset_s.exe memset_s.c -I /usr/local/include/python3.6m/
memset_s.c: In function 'main':
memset_s.c:6:2: warning: implicit declaration of function 'memset_s';
did you mean 'memset'? [-Wimplicit-function-declaration]
  memset_s(array, 5, 0, 5);
  ^~~~~~~~
  memset

$ gcc -o memset_s.exe memset_s.c -I ./python3.6m/
$ diff -Npur /usr/local/include/python3.6m/ ./python3.6m/
diff -Npur /usr/local/include/python3.6m/pyconfig.h ./python3.6m/pyconfig.h
--- /usr/local/include/python3.6m/pyconfig.h    2019-01-10
02:17:29.000000000 +0100
+++ ./python3.6m/pyconfig.h     2019-01-25 23:14:09.425842000 +0100
@@ -1478,7 +1478,7 @@
 /* #undef _POSIX_1_SOURCE */

 /* Define to activate features from IEEE Stds 1003.1-2008 */
-#define _POSIX_C_SOURCE 200809L
+//#define _POSIX_C_SOURCE 200809L

 /* Define to 1 if you need to in order for `stat' and other things to
work. */
 /* #undef _POSIX_SOURCE */
@@ -1490,13 +1490,13 @@
 #define _REENTRANT 1

 /* Define to the level of X/Open that your system supports */
-#define _XOPEN_SOURCE 700
+//#define _XOPEN_SOURCE 700

 /* Define to activate Unix95-and-earlier features */
-#define _XOPEN_SOURCE_EXTENDED 1
+//#define _XOPEN_SOURCE_EXTENDED 1

 /* Define on FreeBSD to activate all library features */
-#define __BSD_VISIBLE 1
+//#define __BSD_VISIBLE 1

 /* Define to 1 if type `char' is unsigned and you are not using gcc.  */
 #ifndef __CHAR_UNSIGNED__



$ gcc -o memset_s.exe memset_s.c -I ./python3.6m.fix2/
$ diff -Npur /usr/local/include/python3.6m/ ./python3.6m.fix2/
diff -Npur /usr/local/include/python3.6m/pyconfig.h
./python3.6m.fix2/pyconfig.h
--- /usr/local/include/python3.6m/pyconfig.h    2019-01-10
02:17:29.000000000 +0100
+++ ./python3.6m.fix2/pyconfig.h        2019-01-25 23:43:59.350194000 +0100
@@ -1498,6 +1498,8 @@
 /* Define on FreeBSD to activate all library features */
 #define __BSD_VISIBLE 1

+#define __STDC_WANT_LIB_EXT1__ 1
+
 /* Define to 1 if type `char' is unsigned and you are not using gcc.  */
 #ifndef __CHAR_UNSIGNED__
 /* # undef __CHAR_UNSIGNED__ */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-python/attachments/20190126/3fb1d577/attachment.sig>


More information about the freebsd-python mailing list