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-132775: Add _PyObject_GetXIDataWithFallback()#133482

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
Show file tree
Hide file tree
Changes fromall 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
25 changes: 23 additions & 2 deletionsInclude/internal/pycore_crossinterp.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,23 @@ PyAPI_FUNC(void) _PyXIData_Clear(PyInterpreterState *, _PyXIData_t *);

/* getting cross-interpreter data */

typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *);
typedef int xidata_fallback_t;
#define _PyXIDATA_XIDATA_ONLY (0)
#define _PyXIDATA_FULL_FALLBACK (1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe flags like 0b111?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I added these with the idea that there is conceptual room for other options and the actual values aren't so important. However, they don't need to be unioned, so I'm not sure there's much value in using another literal form.

neonene reacted with thumbs up emoji

// Technically, we don't need two different function types;
// we could go with just the fallback one. However, only container
// types like tuple need it, so always having the extra arg would be
// a bit unfortunate. It's also nice to be able to clearly distinguish
// between types that might call _PyObject_GetXIData() and those that won't.
//
typedef int (*xidatafunc)(PyThreadState *, PyObject *, _PyXIData_t *);
typedef int (*xidatafbfunc)(
PyThreadState *, PyObject *, xidata_fallback_t, _PyXIData_t *);
typedef struct {
xidatafunc basic;
xidatafbfunc fallback;
} _PyXIData_getdata_t;
Comment on lines +147 to +150
Copy link
Contributor

@neoneneneoneneMay 16, 2025
edited
Loading

Choose a reason for hiding this comment

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

Does the layout imply that it would accept two functions in the future? If exclusive, is there any reason why it cannot be a void pointer (or xidatafunc) with a flag? (The C compilers could verifyxidatafbfunc atREGISTER_FALLBACK().)

E: No change request from me as long as there are only two options.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, I tried both and went with this because I don't expect other options. This is internal API so I wasn't going to worry about it too much for now. That said, maybe it would be better to take the void * approach now. I'll think about it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm inclined to leave it the way it is, since I anticipate only those two options will be needed and it's nice to keep the signature explicit (instead ofvoid *).

neonene reacted with thumbs up emoji

PyAPI_FUNC(PyObject *) _PyXIData_GetNotShareableErrorType(PyThreadState *);
PyAPI_FUNC(void) _PyXIData_SetNotShareableError(PyThreadState *, const char *);
Expand All@@ -140,16 +156,21 @@ PyAPI_FUNC(void) _PyXIData_FormatNotShareableError(
const char *,
...);

PyAPI_FUNC(xidatafunc) _PyXIData_Lookup(
PyAPI_FUNC(_PyXIData_getdata_t) _PyXIData_Lookup(
PyThreadState *,
PyObject *);
PyAPI_FUNC(int) _PyObject_CheckXIData(
PyThreadState *,
PyObject *);

PyAPI_FUNC(int) _PyObject_GetXIDataNoFallback(
PyThreadState *,
PyObject *,
_PyXIData_t *);
PyAPI_FUNC(int) _PyObject_GetXIData(
PyThreadState *,
PyObject *,
xidata_fallback_t,
_PyXIData_t *);

// _PyObject_GetXIData() for bytes
Expand Down
4 changes: 2 additions & 2 deletionsInclude/internal/pycore_crossinterp_data_registry.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ typedef struct _xid_regitem {
/* This is NULL for builtin types. */
PyObject *weakref;
size_t refcount;
xidatafunc getdata;
_PyXIData_getdata_t getdata;
} _PyXIData_regitem_t;

typedef struct {
Expand All@@ -30,7 +30,7 @@ typedef struct {
PyAPI_FUNC(int) _PyXIData_RegisterClass(
PyThreadState *,
PyTypeObject *,
xidatafunc);
_PyXIData_getdata_t);
PyAPI_FUNC(int) _PyXIData_UnregisterClass(
PyThreadState *,
PyTypeObject *);
Expand Down
2 changes: 1 addition & 1 deletionLib/test/support/import_helper.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -438,5 +438,5 @@ def ensure_module_imported(name, *, clearnone=True):
if sys.modules.get(name) is not None:
mod = sys.modules[name]
else:
mod, _, _ =_force_import(name, False, True, clearnone)
mod, _, _ =_ensure_module(name, False, True, clearnone)
return mod
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp