Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restructure according to 3.11 migration guidelines
  • Loading branch information
matthiasdiener committed Jan 31, 2023
commit 48cd91137e4f90cee10084f61748e71878e0bba6
20 changes: 15 additions & 5 deletions src/_vmprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ write_all_code_objects(PyObject *module, PyObject * seen_code_ids)
}


#if PY_VERSION_HEX < 0x030900B1 /* < 3.9 */
static inline PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
{
Py_XINCREF(tstate->frame);
return tstate->frame;
}
#endif



static PyObject *
sample_stack_now(PyObject *module, PyObject * args)
Expand Down Expand Up @@ -298,11 +307,12 @@ sample_stack_now(PyObject *module, PyObject * args)
vmprof_ignore_signals(0);
return NULL;
}
#if PY_VERSION_HEX >= 0x030b00f0 /* >= 3.11 */
entry_count = vmp_walk_and_record_stack(tstate->cframe, m, SINGLE_BUF_SIZE/sizeof(void*)-1, (int)skip, 0);
#else
entry_count = vmp_walk_and_record_stack(tstate->frame, m, SINGLE_BUF_SIZE/sizeof(void*)-1, (int)skip, 0);
#endif

PyFrameObject* frame = PyThreadState_GetFrame(tstate);
entry_count = vmp_walk_and_record_stack(frame, m, SINGLE_BUF_SIZE/sizeof(void*)-1, (int)skip, 0);

Py_XDECREF(frame);


for (i = 0; i < entry_count; i++) {
routine_ip = m[i];
Expand Down
7 changes: 3 additions & 4 deletions src/vmp_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ static PY_STACK_FRAME_T * _write_python_stack_entry(PY_STACK_FRAME_T * frame, vo
result[*depth] = (void*) (int64_t) PyFrame_GetLineNumber(frame);
*depth = *depth + 1;
}
#if PY_VERSION_HEX >= 0x030b00f0 /* >= 3.11 */
if (!_PyFrame_IsIncomplete(frame))
#endif
result[*depth] = (void*)CODE_ADDR_TO_UID(FRAME_CODE(frame));
PyCodeObject* frame_code = FRAME_CODE(frame);
result[*depth] = (void*)CODE_ADDR_TO_UID(frame_code);
Py_DECREF(frame_code);
*depth = *depth + 1;
#else

Expand Down
14 changes: 9 additions & 5 deletions src/vmprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ int IS_VMPROF_EVAL(void * ptr);
#define PY_THREAD_STATE_T PyThreadState
#define FRAME_STEP(f) f->f_back

#if PY_VERSION_HEX >= 0x030b00f0 /* >= 3.11 */
#define FRAME_CODE(f) f->f_frame->f_code
#else
#define FRAME_CODE(f) f->f_code
#endif // PY_VERSION_HEX >= 0x030b00f0
#if PY_VERSION_HEX < 0x030900B1
static inline PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
{
Py_INCREF(frame->f_code);
return frame->f_code;
}
#endif

#define FRAME_CODE(f) PyFrame_GetCode(f)

#if CPYTHON_HAS_FRAME_EVALUATION
#define IS_VMPROF_EVAL(PTR) PTR == (void*)_PyEval_EvalFrameDefault
Expand Down
21 changes: 15 additions & 6 deletions src/vmprof_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,14 @@ int vmprof_register_virtual_function(char *code_name, intptr_t code_uid,
return 0;
}

#if PY_VERSION_HEX < 0x030900B1 /* < 3.9 */
static inline PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
{
Py_XINCREF(tstate->frame);
return tstate->frame;
}
#endif

int get_stack_trace(PY_THREAD_STATE_T * current, void** result, int max_depth, intptr_t pc)
{
PY_STACK_FRAME_T * frame;
Expand All @@ -488,17 +496,18 @@ int get_stack_trace(PY_THREAD_STATE_T * current, void** result, int max_depth, i
#endif
return 0;
}
#if PY_VERSION_HEX >= 0x030b00f0 /* >= 3.11 */
frame = current->cframe;
#else
frame = current->frame;
#endif
frame = PyThreadState_GetFrame(current);
#endif
if (frame == NULL) {
#if DEBUG
fprintf(stderr, "WARNING: get_stack_trace, frame is NULL\n");
#endif
return 0;
}
return vmp_walk_and_record_stack(frame, result, max_depth, 1, pc);

int res = vmp_walk_and_record_stack(frame, result, max_depth, 1, pc);

Py_XDECREF(frame);

return res;
}