Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-128629: Add Py_PACK_VERSION and Py_PACK_FULL_VERSION#128630

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 2 commits intopython:mainfromencukou:pack_version_wg
Jan 9, 2025

Conversation

encukou
Copy link
Member

@encukouencukou commentedJan 8, 2025
edited by github-actionsbot
Loading

@@ -0,0 +1,74 @@
/* Test version macros in the limited API */

#define Py_LIMITED_API 0x030E0000 // Added in 3.14
Copy link
Member

Choose a reason for hiding this comment

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

You need more complicated code for Free Threading, something like:

#include "pyconfig.h"  // Py_GIL_DISABLED#ifndef Py_GIL_DISABLED#  define Py_LIMITED_API 0x030e0000  // Added in 3.14#endif

encukou reacted with thumbs up emoji
result = _testlimitedcapi.pack_version(*args)
self.assertEqual(result, expected)

def test_pack_full_version_ctypes(self):
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of testing the API through ctypes? It should be the same as testing_testlimitedcapi, no?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It tests the exported function.
(Unlike most similar API, these are macros even in limited API. This tests the case of not using the C headers at all.)

Copy link
Member

Choose a reason for hiding this comment

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

The_testcapi module tests Py_INCREF() macroand function this way:

#defineTEST_REFCOUNT() \    do { \        PyObject *obj = PyList_New(0); \        if (obj == NULL) { \            return NULL; \        } \        assert(Py_REFCNT(obj) == 1); \        \/* test Py_NewRef() */ \PyObject*ref=Py_NewRef(obj); \assert(ref==obj); \assert(Py_REFCNT(obj)==2); \Py_DECREF(ref); \        \/* test Py_XNewRef() */ \PyObject*xref=Py_XNewRef(obj); \assert(xref==obj); \assert(Py_REFCNT(obj)==2); \Py_DECREF(xref); \        \assert(Py_XNewRef(NULL)==NULL); \        \Py_DECREF(obj); \Py_RETURN_NONE; \    }while (0)// Test Py_NewRef() and Py_XNewRef() macrosstaticPyObject*test_refcount_macros(PyObject*self,PyObject*Py_UNUSED(ignored)){TEST_REFCOUNT();}#undef Py_NewRef#undef Py_XNewRef// Test Py_NewRef() and Py_XNewRef() functions, after undefining macros.staticPyObject*test_refcount_funcs(PyObject*self,PyObject*Py_UNUSED(ignored)){TEST_REFCOUNT();}

Maybe you can do something similar to avoid ctypes.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The C tests do something similar, with#undef Py_PACK_FULL_VERSION.
(But if I had misspelled that#undef, the test would quietly be ineffective.)

Also, I don't particularly want to avoid ctypes :)

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1,4 +1,5 @@

#ifndef _Py_PATCHLEVEL_H
Copy link
Member

Choose a reason for hiding this comment

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

Why not just Py_PATCHLEVEL_H, as done in other header files?

Copy link
MemberAuthor

@encukouencukouJan 9, 2025
edited
Loading

Choose a reason for hiding this comment

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

Because I don't want to add this define to public API. It's a private detail, users don't need this; we should be able to, for example, merge this code into another header and removepatchlevel.h.

@encukou
Copy link
MemberAuthor

Thank you for the reviews!

@encukouencukou merged commit1439b81 intopython:mainJan 9, 2025
45 checks passed
@encukouencukou deleted the pack_version_wg branchJanuary 9, 2025 10:10
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner approved these changes

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@encukou@vstinner@erlend-aasland

[8]ページ先頭

©2009-2025 Movatter.jp