Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

PyCG can't support the analysis of function pointers in a call graph. #68

Closed
enderdzz opened this issue Aug 9, 2023 · 1 comment
Closed

Comments

@enderdzz
Copy link

enderdzz commented Aug 9, 2023

Hi,

It's a great project. But I've encountered an issue where PyCG cannot handle function pointers in the code.

Here's an example:

# pycg_test.py
def test1():
    print("test1")

class Foo():
    def __init__(self, name=None, fp=None):
        self.name = name
        self._handler = fp or test1

    def test2(self):
        self._handler()

c = Foo()
c.test2()

The minimum expected result for test2 should be: "pycg_test.Foo.test2": ["pycg_test.Foo._handler"]. If higher requirements are needed, it should extend to the following fp and test1, i.e., "pycg_test.Foo.test2": ["pycg_test.Foo._handler", "pycg_test.test1"].

However, the current output from PyCG is insufficient:

$ pycg pycg_test.py
{"pycg_test": ["pycg_test.Foo.__init__", "pycg_test.Foo.test2"], "pycg_test.test1": ["<builtin>.print"], "<builtin>.print": [], "pycg_test.Foo.__init__": [], "pycg_test.Foo.test2": []}

I want to ask if there's any solution available. I'm also willing to provide a PR. Thank you!

@vitsalis
Copy link
Owner

Closing due to archival of repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants