Skip to content

Commit

Permalink
Fix the bug that fails to trigger the event when ccall has an arg tha…
Browse files Browse the repository at this point in the history
…t's a method (#553)
  • Loading branch information
gaogaotiantian authored Feb 4, 2025
1 parent 7cbc8ae commit 25e2b5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/viztracer/modules/snaptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg)
if (PyCFunction_Check(meth)) {
return (PyObject*)((PyCFunctionObject*)meth);
}
} else if (Py_TYPE(callable) == &PyMethod_Type) {
PyObject* func = PyMethod_GET_FUNCTION(callable);
if (func && PyCFunction_Check(func)) {
Py_INCREF(func);
return func;
}
}
return NULL;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import signal
import sys
import tempfile
import textwrap
import unittest

import viztracer
Expand Down Expand Up @@ -332,6 +333,21 @@ def call_self(n):
expected_entries=6)


class TestIssue552(CmdlineTmpl):
def test_issue552(self):
script = textwrap.dedent("""
from viztracer import VizTracer
class A:
f = classmethod(repr)
with VizTracer():
A().f()
""")

self.template([sys.executable, "cmdline_test.py"], script=script,
expected_output_file="result.json",
expected_entries=1)


file_timestamp_disorder = """
def g():
pass
Expand Down

0 comments on commit 25e2b5c

Please sign in to comment.