gh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL by vstinner · Pull Request #157067 · python/cpython · GitHub
Skip to content
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
2 changes: 1 addition & 1 deletion Include/refcount.h
12 changes: 10 additions & 2 deletions Lib/test/test_cext/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ _testcext_exec(PyObject *module)
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);

// Test Py_CLEAR()
obj = NULL;
// Test Py_CLEAR(): use typeof()/__typeof__() if available, or memcpy()
obj = Py_None;
Py_CLEAR(obj);
assert(obj == NULL);

#ifndef Py_LIMITED_API
// Test Py_SETREF(): use typeof()/__typeof__() if available, or memcpy()
obj = Py_None;
Py_SETREF(obj, NULL);
assert(obj == NULL);
#endif

// Test that Py_BEGIN_CRITICAL_SECTION is available
Py_BEGIN_CRITICAL_SECTION(module);
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_cppext/extension.cpp
Loading