GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.13] gh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (… · python/cpython@a4ab2c1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Include
    • object.h
  • Lib/test
    • test_cext
      • extension.c
    • test_cppext
      • extension.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Include/object.h‎

Copy file name to clipboardExpand all lines: Include/object.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
10061006
do { \
10071007
_Py_TYPEOF(op)* _tmp_op_ptr = &(op); \
10081008
_Py_TYPEOF(op) _tmp_old_op = (*_tmp_op_ptr); \
1009-
if (_tmp_old_op != NULL) { \
1009+
if (_tmp_old_op != _Py_NULL) { \
10101010
*_tmp_op_ptr = _Py_NULL; \
10111011
Py_DECREF(_tmp_old_op); \
10121012
} \
@@ -1016,7 +1016,7 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
10161016
do { \
10171017
PyObject **_tmp_op_ptr = _Py_CAST(PyObject**, &(op)); \
10181018
PyObject *_tmp_old_op = (*_tmp_op_ptr); \
1019-
if (_tmp_old_op != NULL) { \
1019+
if (_tmp_old_op != _Py_NULL) { \
10201020
PyObject *_null_ptr = _Py_NULL; \
10211021
memcpy(_tmp_op_ptr, &_null_ptr, sizeof(PyObject*)); \
10221022
Py_DECREF(_tmp_old_op); \
Collapse file

‎Lib/test/test_cext/extension.c‎

Copy file name to clipboardExpand all lines: Lib/test/test_cext/extension.c
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ _testcext_exec(
4545
#endif
4646
)
4747
{
48+
PyObject *obj;
49+
4850
#ifdef __STDC_VERSION__
4951
if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
5052
return -1;
@@ -55,6 +57,22 @@ _testcext_exec(
5557
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
5658
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);
5759

60+
// Test Py_CLEAR(): use typeof()/__typeof__() if available, or memcpy()
61+
obj = Py_None;
62+
Py_CLEAR(obj);
63+
assert(obj == NULL);
64+
65+
#ifndef Py_LIMITED_API
66+
// Test Py_SETREF(): use typeof()/__typeof__() if available, or memcpy()
67+
obj = Py_None;
68+
Py_SETREF(obj, NULL);
69+
assert(obj == NULL);
70+
71+
// Test that Py_BEGIN_CRITICAL_SECTION is available
72+
Py_BEGIN_CRITICAL_SECTION(module);
73+
Py_END_CRITICAL_SECTION();
74+
#endif
75+
5876
return 0;
5977
}
6078

Collapse file

‎Lib/test/test_cppext/extension.cpp‎

Copy file name to clipboardExpand all lines: Lib/test/test_cppext/extension.cpp
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,22 @@ _testcppext_exec(PyObject *module)
238238
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
239239
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);
240240

241+
// Test Py_CLEAR(): use typeof()/__typeof__() if available, or memcpy()
242+
PyObject *obj = Py_None;
243+
Py_CLEAR(obj);
244+
assert(obj == _Py_NULL);
245+
246+
#ifndef Py_LIMITED_API
247+
// Test Py_SETREF(): use typeof()/__typeof__() if available, or memcpy()
248+
obj = Py_None;
249+
Py_SETREF(obj, _Py_NULL);
250+
assert(obj == _Py_NULL);
251+
252+
// Test that Py_BEGIN_CRITICAL_SECTION is available
253+
Py_BEGIN_CRITICAL_SECTION(module);
254+
Py_END_CRITICAL_SECTION();
255+
#endif
256+
241257
return 0;
242258
}
243259

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.