Skip to content

Building Python 3.11 fails to build on FreeBSD 12: static_assert() is not defined by <assert.h> #91782

@vstinner

Description

@vstinner

Python 3.11 no longer builds on FreeBSD 12 since the commit 7cdaf87 that I made yesterday.

My change: #91730

I checked with buildbots that Python still builds successfully on FreeBSD. It did on the two FreeBSD buildbot workers. Problem: one FreeBSD worker failed to download code with Git and the build was marked as successful :-(

Successful build+test on FreeBSD:

git failed on the second job!

fatal: bad object refs/heads/refs/pull/28569
error: https://github.com/python/cpython.git did not send all necessary objects
(...)
fatal: failed to run reflog
error: task 'gc' failed
program finished with exit code 1

And now Python fails to build on "AMD64 FreeBSD Non-Debug 3.x" which runs FreeBSD 12.3: https://buildbot.python.org/all/#/builders/172/builds/1911

test.pythoninfo:

os.uname: posix.uname_result(sysname='FreeBSD', nodename='123-RELEASE-p2-amd64-9e36', release='12.3-RELEASE-p1', version='FreeBSD 12.3-RELEASE-p1 GENERIC', machine='amd64')

The problem is that `/usr/include/sys/cdefs.hsets the ISO C standard to something older than-std=c11`` command line.

Reproducer, the 4 defines are copied from Python pyconfig.h:

#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700
#define _XOPEN_SOURCE_EXTENDED 1
#define __BSD_VISIBLE 1
#include <assert.h>

int main()
{
    static_assert(1 == 1, "ok");
    static_assert(1 == 0, "bug");
    return 0;
}
  • _XOPEN_SOURCE=700 sets _POSIX_C_SOURCE to 200809
  • _POSIX_C_SOURCE=200809 sets __ISO_C_VISIBLE to 1999
  • <assert.h> does not define static_assert() if __ISO_C_VISIBLE is less than 2011 which is the case here!

In <sys/cdefs.h>, I don't see any value of _XOPEN_SOURCE or _POSIX_C_SOURCE which could give a C standard higher than 2008. It seems like _XOPEN_SOURCE and _POSIX_C_SOURCE should not be defined to get ISO C11 (which defines static_assert()).

But the Python build system is complex, and I'm not comfortable to remove _XOPEN_SOURCE and _POSIX_C_SOURCE from pyconfig.h on all BSD platforms. I don't know if it would drop support for old FreeBSD version or if it would break other BSD variants like OpenBSD and NetBSD.


An alternative would be to use _Static_assert(). It should work, but I like static_assert() syntax, and we may use other C11 features
tomorrow.

Another alternative is to define static_assert() in Python if it's not defined... but I dislike working around issues with system headers :-(

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-freebsdtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions