GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Extract common bytecode retrieval logic from `_PyFrame_GetBytecode` and `_PyFrame_SafeGetLasti` · Issue #142929 · python/cpython Open Labels interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior) DescriptionBoth static inline _Py_CODEUNIT * _PyFrame_GetBytecode(_PyInterpreterFrame *f) { #ifdef Py_GIL_DISABLED PyCodeObject *co = _PyFrame_GetCode(f); _PyCodeArray *tlbc = _PyCode_GetTLBCArray(co); assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size); return (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index]; #else return _PyCode_CODE(_PyFrame_GetCode(f)); #endif } static inline int _PyFrame_SafeGetLasti(struct _PyInterpreterFrame *f) { // Code based on _PyFrame_GetBytecode() but replace _PyFrame_GetCode() // with _PyFrame_SafeGetCode(). PyCodeObject *co = _PyFrame_SafeGetCode(f); if (co == NULL) { return -1; } _Py_CODEUNIT *bytecode; #ifdef Py_GIL_DISABLED _PyCodeArray *tlbc = _PyCode_GetTLBCArray(co); assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size); bytecode = (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index]; #else bytecode = _PyCode_CODE(co); #endif return (int)(f->instr_ptr - bytecode) * sizeof(_Py_CODEUNIT); } However, I think we should extract the bytecode retrieving logic into another helper, let's say, static inline _Py_CODEUNIT * _PyFrame_GetBytecodeFromCodeObject(_PyInterpreterFrame *f, PyCodeObject *co) { #ifdef Py_GIL_DISABLED _PyCodeArray *tlbc = _PyCode_GetTLBCArray(co); assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size); return (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index]; #else return _PyCode_CODE(co); #endif } So we can use that helper as: static inline _Py_CODEUNIT * _PyFrame_GetBytecode(_PyInterpreterFrame *f) { PyCodeObject *co = _PyFrame_GetCode(f); return _PyFrame_GetBytecodeFromCodeObject(f, co); } static inline int _PyFrame_SafeGetLasti(_PyInterpreterFrame *f) { PyCodeObject *co = _PyFrame_SafGetCode(f); if(co == NULL){ return -1; } _Py_CODEUNIT *bytecode = _PyFrame_GetBytecodeFromCodeObject(f, co); return (int)(f->insert_ptr - bytecode) * sizeof(_Py_CODEUNIT); } However, we can use different types of helpers such as inline helper with a function pointer or a macro wrapper. My point here is not about the implementation of the helper itself, but about extracting the bytecode retrieving logic into another helper regardless of the helper name and the method used to implement that helper. Activity
MetadataMetadataAssigneesLabelsinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior) ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |