[SOT][3.12] Eval frame compat for Python 3.12 - #61272
Merged
Merged
Conversation
SigureMo
reviewed
Jan 29, 2024
Comment on lines
+449
to
+450
| #if PY_VERSION_HEX >= 0x030c0000 | ||
| #else |
Member
There was a problem hiding this comment.
Suggested change
| #if PY_VERSION_HEX >= 0x030c0000 | |
| #else | |
| #if PY_VERSION_HEX < 0x030c0000 |
| Py_INCREF(func); | ||
| #if PY_VERSION_HEX < 0x030c0000 | ||
| #if PY_VERSION_HEX >= 0x030c0000 | ||
| Py_XINCREF(((PyFunctionObject *)frame->f_funcobj)->func_closure); |
Member
Author
There was a problem hiding this comment.
frame->f_funcobj 已经是 PyObject 类型了,或许可以直接写Py_XINCREF(frame->f_funcobj);
| #if PY_VERSION_HEX >= 0x030c0000 | ||
| Py_XINCREF(((PyFunctionObject *)frame->f_funcobj)->func_closure); | ||
| func->func_closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure; | ||
| _PyFrame_Initialize(shadow, func, NULL, code, 0); |
Member
Author
There was a problem hiding this comment.
在初始化 shadow 的时候,希望把所有 localsplus 初始化为 NULL ,所以他是0,_PyFrame_Initialize 会在函数内部根据 code->co_nlocalsplus 的大小逐个赋 NULL
SigureMo
previously approved these changes
Jan 29, 2024
| def gen_call_function(self, argc=0): | ||
| if sys.version_info >= (3, 11): | ||
| self._add_instr("PRECALL", arg=argc, argval=argc) | ||
| if sys.version_info == (3, 11): |
Member
There was a problem hiding this comment.
Suggested change
| if sys.version_info == (3, 11): | |
| if sys.version_info >= (3, 11) and sys.version_info < (3, 12): |
Python 3.11.6 (main, Oct 2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=11, micro=6, releaselevel='final', serial=0)
>>> sys.version_info == (3, 11)
False
>>> (3, 11) <= sys.version_info < (3, 12)
True
>>> sys.version_info >= (3, 11) and sys.version_info < (3, 12)
True
>>>
虽然 (3, 11) <= sys.version_info < (3, 12) 看起来更好些,但静态分析工具不支持这种 pattern
Comment on lines
+725
to
+746
| if sys.version_info >= (3, 12) and instr.arg & 1: | ||
| attr_name_var = ConstantVariable.wrap_literal( | ||
| attr_name, self._graph | ||
| ) | ||
| obj = self.stack.pop() | ||
|
|
||
| method = BuiltinVariable( | ||
| getattr, graph=self._graph, tracker=DanglingTracker() | ||
| )(obj, attr_name_var) | ||
|
|
||
| if isinstance(method, MethodVariable) and "__getattr__" not in dir( | ||
| method.bound_instance.get_py_type() | ||
| ): | ||
| # bound method or the class override the __getattr__ | ||
| # push the unbound method and the self | ||
| self.stack.push(method.fn) | ||
| self.stack.push(obj) | ||
| else: | ||
| # unbound method, push the dummy and the function | ||
| self.stack.push(NullVariable()) | ||
| self.stack.push(method) | ||
| return |
Member
There was a problem hiding this comment.
这是 LOAD_METHOD 是吧,可以看看怎么复用,比如抽出一个新的函数 load_method
Member
|
点错了,咋直接 approve 了 |
SigureMo
reviewed
Jan 29, 2024
| version_info.minor <= 8 or version_info.minor >= 13 | ||
| ): | ||
| # print("skip test_eval_frame, current only support 3.8 - 3.10") | ||
| # print("skip test_eval_frame, current only support 3.8 - 3.13") |
SigureMo
reviewed
Jan 29, 2024
| def test_eval_frame(self): | ||
| if version_info.major != 3 or ( | ||
| version_info.minor <= 8 or version_info.minor >= 12 | ||
| version_info.minor <= 8 or version_info.minor >= 13 |
Member
There was a problem hiding this comment.
原来写的 <= 8 不对吧?
统一用
if not (sys.version_info >= (3, 8) and sys.version_info < (3, 13)):
这种 pattern 吧
Closed
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR types
Others
PR changes
Others
Description
尝试适配 sot Python3.12 (还没在ci打开单测)