Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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
gh-132775: Add _PyObject_GetXIDataWithFallback()#133482
Conversation
e72c2af
tocf17342
ComparePython/crossinterp.c Outdated
#ifdef Py_DEBUG | ||
Py_UNREACHABLE(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The#ifdef
looks like a typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It's there to make sure we abort on debug builds, but we have a fallback for non-debug builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd prefer an explicitPy_FatalError()
then. I think I can see this usage only incrossinterp.c
(here, L1673, L1700).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
My intention is to not crash under normal usage, which is whatPy_FatalError()
would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ah,Py_FatalError()
instead ofPy_UNREACHABLE()
? I'm okay with that. It really should be unreachable through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That's fair. I'll switch it to explicitlyPy_FatalError()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks. This is off-topic, but would one of the coming PRs address#133107 (comment)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, I'll be addressing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
04308b9
tob9f1eea
Compareb9f1eea
to55ccaa0
CompareLib/test/test_crossinterp.py Outdated
EXCEPTION, | ||
OBJECT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
nit: indent. Also,cls
is undefined at L726, 732:
assertnothasattr(mod,func.__name__), (cls,getattr(mod,func.__name__))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is this still intentionally commented out? The assertion passed for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ditto. See also:
L757:
# self.assert_roundtrip_equal(defs.TOP_FUNCTIONS)
L844, 997, 1463:
# UnicodeError: (None, msg, None, None, None),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
Python/crossinterp.c Outdated
Py_FatalError("unsupported xidata fallback option"); | ||
#endif | ||
_PyErr_SetString(tstate,PyExc_SystemError, | ||
"unsuppocted xidata fallback option"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
nit: unsuppo"c"ted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
Python/crossinterp.c Outdated
} | ||
int | ||
_PyObject_GetXIDataWithFallback(PyThreadState*tstate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure whether thefallback
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I take back the questions in this topic. Sorry for the noise.
(I currently interpretgetdata.fallback
asgetdata.(with)fallback
that can pass an option to tuple's items, andWithFallback
as_PyFunction_GetXIData
and_PyPickle_GetXIData
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've changed the name as suggested. Thanks for that!
typedef struct { | ||
xidatafunc basic; | ||
xidatafbfunc fallback; | ||
} _PyXIData_getdata_t; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 *
).
typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *); | ||
typedef int xidata_fallback_t; | ||
#define _PyXIDATA_XIDATA_ONLY (0) | ||
#define _PyXIDATA_FULL_FALLBACK (1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe flags like 0b111?
There was a problem hiding this comment.
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.
88f8102
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
GH-134418 is a backport of this pull request to the3.14 branch. |
Uh oh!
There was an error while loading.Please reload this page.