Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT: Minor cleanup to F2PY #20884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions numpy/core/include/numpy/npy_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#define NPY_OS_CYGWIN
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#define NPY_OS_WIN32
#elif defined(_WIN64) || defined(__WIN64__) || defined(WIN64)
#define NPY_OS_WIN64
#elif defined(__MINGW32__) || defined(__MINGW64__)
#define NPY_OS_MINGW
#elif defined(__APPLE__)
#define NPY_OS_DARWIN
#else
Expand Down
10 changes: 4 additions & 6 deletions numpy/f2py/cfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
includes0['string.h'] = '#include <string.h>'
includes0['setjmp.h'] = '#include <setjmp.h>'

includes['Python.h'] = '#include <Python.h>'
needs['arrayobject.h'] = ['Python.h']
includes['arrayobject.h'] = '''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
#include "arrayobject.h"'''

Expand All @@ -66,15 +64,15 @@
typedefs['unsigned_long'] = 'typedef unsigned long unsigned_long;'
typedefs['signed_char'] = 'typedef signed char signed_char;'
typedefs['long_long'] = """\
#ifdef _WIN32
#if defined(NPY_OS_WIN32)
typedef __int64 long_long;
#else
typedef long long long_long;
typedef unsigned long long unsigned_long_long;
#endif
"""
typedefs['unsigned_long_long'] = """\
#ifdef _WIN32
#if defined(NPY_OS_WIN32)
typedef __uint64 long_long;
#else
typedef unsigned long long unsigned_long_long;
Expand Down Expand Up @@ -574,13 +572,13 @@
#ifndef F2PY_THREAD_LOCAL_DECL
#if defined(_MSC_VER)
#define F2PY_THREAD_LOCAL_DECL __declspec(thread)
#elif defined(__MINGW32__) || defined(__MINGW64__)
#elif defined(NPY_OS_MINGW)
#define F2PY_THREAD_LOCAL_DECL __thread
#elif defined(__STDC_VERSION__) \\
&& (__STDC_VERSION__ >= 201112L) \\
&& !defined(__STDC_NO_THREADS__) \\
&& (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12)) \\
&& !defined(__OpenBSD__)
&& !defined(NPY_OS_OPENBSD)
/* __STDC_NO_THREADS__ was first defined in a maintenance release of glibc 2.12,
see https://lists.gnu.org/archive/html/commit-hurd/2012-07/msg00180.html,
so `!defined(__STDC_NO_THREADS__)` may give false positive for the existence
Expand Down
4 changes: 4 additions & 0 deletions numpy/f2py/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */

/* Unconditionally included */
#include <Python.h>
#include <numpy/npy_os.h>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically npy_os.h should only be included if long_long or unsigned_long_long or threading is required.

Copy link
Member Author

@HaoZeke HaoZeke Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option which would also provide quite a bit of clean up is to use #include <numpy/npy_common.h> (which defines, among other things, Python.h and npy_os.h) and remove the typedefs used by F2PY for say, complex numbers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In keeping with the original "minor cleanup" spirit of this PR, we will only use npy_os.h here and defer the larger cleanup w.r.t. npy_common.h to #21161.


""" + gentitle("See f2py2e/cfuncs.py: includes") + """
#includes#
#includes0#
Expand Down