FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-121617: Include <string.h> for Py_CLEAR() macro by vstinner · Pull Request #144666 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (2) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/c-api/intro.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ System includes
* ``<limits.h>``
* ``<math.h>``
* ``<stdarg.h>``
* ``<string.h>``
* ``<wchar.h>``
* ``<sys/types.h>`` (if present)

Expand All @@ -138,7 +139,6 @@ System includes
* ``<errno.h>``
* ``<stdio.h>``
* ``<stdlib.h>``
* ``<string.h>``

.. note::

Expand Down
4 changes: 2 additions & 2 deletions Include/Python.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#include <limits.h> // INT_MAX
#include <math.h> // HUGE_VAL
#include <stdarg.h> // va_list
#include <string.h> // memcpy()
#include <wchar.h> // wchar_t
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> // ssize_t
#endif

// <errno.h>, <stdio.h>, <stdlib.h> and <string.h> headers are no longer used
// <errno.h>, <stdio.h> and <stdlib.h> headers are no longer used
// by Python, but kept for the backward compatibility of existing third party C
// extensions. They are not included by limited C API version 3.11 and newer.
//
Expand All @@ -37,7 +38,6 @@
# include <errno.h> // errno
# include <stdio.h> // FILE*
# include <stdlib.h> // getenv()
# include <string.h> // memcpy()
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000
# include <ctype.h> // tolower()
Expand Down
7 changes: 5 additions & 2 deletions Include/pyport.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,11 @@ extern "C" {
//
// Example: _Py_TYPEOF(x) x_copy = (x);
//
// The macro is only defined if GCC or clang compiler is used.
#if defined(__GNUC__) || defined(__clang__)
// On C23, use typeof(). Otherwise, the macro is only defined
// if GCC or clang compiler is used.
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
# define _Py_TYPEOF(expr) typeof(expr)
#elif defined(__GNUC__) || defined(__clang__)
# define _Py_TYPEOF(expr) __typeof__(expr)
#endif

Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_cext/extension.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ _testcext_exec(
#endif
)
{
PyObject *result;
PyObject *result, *obj;

#ifdef __STDC_VERSION__
if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
Expand All @@ -98,6 +98,10 @@ _testcext_exec(
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);

// Test Py_CLEAR()
obj = NULL;
Py_CLEAR(obj);

return 0;
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``Python.h`` now also includes ``<string.h>`` in the limited C API version 3.11
and newer to fix the :c:macro:`Py_CLEAR` macro which uses ``memcpy()``. Patch
by Victor Stinner.
Loading

Back | FazBrowse Home | New Git URL