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

gh-132775: Add _PyObject_GetXIDataWithFallback() by ericsnowcurrently · Pull Request #133482 · python/cpython · GitHub

/ cpython Public

gh-132775: Add _PyObject_GetXIDataWithFallback() - #133482

Merged
ericsnowcurrently merged 4 commits into
python:mainfrom
ericsnowcurrently:add-pyobject-getxidata-with-fallback
May 21, 2025
Merged

gh-132775: Add _PyObject_GetXIDataWithFallback()#133482
ericsnowcurrently merged 4 commits into
python:mainfrom
ericsnowcurrently:add-pyobject-getxidata-with-fallback

Conversation

ericsnowcurrently commented May 6, 2025
edited
Loading

Copy link
Copy Markdown
Member

Comment thread Python/crossinterp.c Outdated
Comment on lines +481 to +482
#ifdef Py_DEBUG
Py_UNREACHABLE();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The #ifdef looks like a typo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It's there to make sure we abort on debug builds, but we have a fallback for non-debug builds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd prefer an explicit Py_FatalError() then. I think I can see this usage only in crossinterp.c (here, L1673, L1700).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

My intention is to not crash under normal usage, which is what Py_FatalError() would do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ah, Py_FatalError() instead of Py_UNREACHABLE()? I'm okay with that. It really should be unreachable through.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's fair. I'll switch it to explicitly Py_FatalError().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks. This is off-topic, but would one of the coming PRs address #133107 (comment)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah, I'll be addressing that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

ericsnowcurrently force-pushed the add-pyobject-getxidata-with-fallback branch 2 times, most recently from 04308b9 to b9f1eea Compare May 13, 2025 00:08
ericsnowcurrently force-pushed the add-pyobject-getxidata-with-fallback branch from b9f1eea to 55ccaa0 Compare May 13, 2025 00:46
ericsnowcurrently marked this pull request as ready for review May 13, 2025 00:47
Comment thread Lib/test/test_crossinterp.py Outdated
Comment on lines +1342 to +1343
EXCEPTION,
OBJECT,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: indent. Also, cls is undefined at L726, 732:

assert not hasattr(mod, func.__name__), (cls, getattr(mod, func.__name__))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

Comment thread Lib/test/test_crossinterp.py Outdated
# Currently the "extra" attrs are not preserved
# (via __reduce__).
self.assertIs(type(exc1), type(exc2))
#self.assert_exc_equal(grouped1, grouped2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is this still intentionally commented out? The assertion passed for me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

Comment thread Lib/test/test_crossinterp.py Outdated
def assert_equal_or_equalish(self, obj, expected):
cls = type(expected)
if cls.__eq__ is not object.__eq__:
# assert cls not in (types.MethodType, types.BuiltinMethodType, types.MethodWrapperType), cls

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ditto. See also:

L757:

#        self.assert_roundtrip_equal(defs.TOP_FUNCTIONS)

L844, 997, 1463:

#            UnicodeError: (None, msg, None, None, None),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

Comment thread Python/crossinterp.c Outdated
Py_FatalError("unsupported xidata fallback option");
#endif
_PyErr_SetString(tstate, PyExc_SystemError,
"unsuppocted xidata fallback option");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: unsuppo"c"ted

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

Comment thread Python/crossinterp.c Outdated
}

int
_PyObject_GetXIDataWithFallback(PyThreadState *tstate,

neonene May 15, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could we replace the long name with _PyObject_GetXIData? I feel the existing _PyObject_GetXIData could be longer (e.g. _PyObject_GetXIDataNoFallback), as it is unpopular at all in newer PRs.

UPDATE: No, _PyObject_GetXIData should remain as-is.

neonene May 16, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure whether the fallback parameter is needed. Does this function support the following?

  • call getdata.basic() under the _PyXIDATA_FULL_FALLBACK case
  • call getdata.fallback() under the _PyXIDATA_XIDATA_ONLY case

UPDATE: Yes, they are necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I take back the questions in this topic. Sorry for the noise.

(I currently interpret getdata.fallback as getdata.(with)fallback that can pass an option to tuple's items, and WithFallback as _PyFunction_GetXIData and _PyPickle_GetXIData.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good point about the function name. I'll take a look.

As to the fallback parameter, it does not determine which function is called. The _PyXIData_getdata_t functions will be called for any of the fallback values. It's just a matter of if the fallback parameter is propagated to the getdata func.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've changed the name as suggested. Thanks for that!

Comment on lines +147 to +150
typedef struct {
xidatafunc basic;
xidatafbfunc fallback;
} _PyXIData_getdata_t;

neonene May 16, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 verify xidatafbfunc at REGISTER_FALLBACK().)

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 of void *).

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe flags like 0b111?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

ericsnowcurrently merged commit 88f8102 into python:main May 21, 2025

Copy link
Copy Markdown

Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 21, 2025
…-133482)

It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.  There's also room for other fallback modes if that later makes sense.
(cherry picked from commit 88f8102)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

bedevere-app Bot commented May 21, 2025

Copy link
Copy Markdown

GH-134418 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 21, 2025
ericsnowcurrently deleted the add-pyobject-getxidata-with-fallback branch May 21, 2025 14:02
ericsnowcurrently added a commit that referenced this pull request May 21, 2025
It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.
There's also room for other fallback modes if that later makes sense.

(cherry picked from commit 88f8102, AKA gh-133482)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
lkollar pushed a commit to lkollar/cpython that referenced this pull request May 26, 2025
…-133482)

It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.  There's also room for other fallback modes if that later makes sense.
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…-133482)

It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.  There's also room for other fallback modes if that later makes sense.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…-133482)

It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.  There's also room for other fallback modes if that later makes sense.
gostak-dd pushed a commit to gostak-dd/cpython that referenced this pull request Jun 2, 2026
…-133482)

It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`.  There's also room for other fallback modes if that later makes sense.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL