-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-132775: Add _PyCode_VerifyStateless() #133221
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-132775: Add _PyCode_VerifyStateless() #133221
Conversation
Include/internal/pycore_code.h
Outdated
|
||
/* "Stateless" code is a function or code object which does not rely on | ||
* external state or internal state. It may rely on arguments and | ||
* builtins, but not globals or a closure. Thus it does not need to |
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.
* builtins, but not globals or a closure. Thus it does not need to | |
* builtins, but not globals or a closure. Thus it does not |
Include/internal/pycore_code.h
Outdated
* Stateless code that takes no arguments and doesn't return anything | ||
* may be treated like a script. | ||
* | ||
* Note that we can consider stateless code to be |
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.
* Note that we can consider stateless code to be | |
* We consider stateless code to be |
Objects/codeobject.c
Outdated
} | ||
// We may consider relaxing these if it becomes a problem. | ||
errmsg = _PyCode_CheckNoInternalState(co); | ||
if (errmsg != NULL) { |
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 convention is NULL means error and non-null is not error. I don't think it's a good idea to do the opposite here.
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 function cannot fail, but I see what you are saying. I'll change this.
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
} | ||
|
||
if (errmsg != NULL) { | ||
if (p_errmsg != NULL) { |
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.
If p_errmsg
can be NULL
, then the cases above need a check too, right?
"Stateless" code is a function or code object which does not rely on external state or internal state. It may rely on arguments and
builtins, but not globals or a closure. I've left a comment in pycore_code.h that provides more detail.
We also add
_PyFunction_VerifyStateless()
. The new functions will be used in several later changes that facilitate "sharing" functions and code objects between interpreters.