-
Notifications
You must be signed in to change notification settings - Fork 6
[memory-analysis] Added a field to CPPMethod to store memory-ownershi… #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,9 @@ class PyCallable { | |||||
| virtual PyObject* GetCoVarNames() = 0; | ||||||
| virtual PyObject* GetArgDefault(int /* iarg */, bool silent = true) = 0; | ||||||
| virtual bool IsConst() { return false; } | ||||||
| virtual cppjit::interop::AllocType GetAllocBehaviour() { | ||||||
| return cppjit::interop::AllocType::None; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only class does not override GetAllocBehaviour is TPythonCallBack, and from my understanding this class is for some sort of python function, not C/C++, therefore I thought it would make sense to return None |
||||||
| } | ||||||
|
|
||||||
| virtual PyObject* GetScopeProxy() = 0; | ||||||
| virtual interop::TCppFuncAddr_t GetFunctionAddress() = 0; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include "memory_analysis.h" | ||
| __attribute__((malloc)) memory::memAnalysisKlass* memory::mallocAttr() { | ||
| return new memory::memAnalysisKlass; | ||
| } | ||
|
|
||
| __attribute__((ownership_returns(malloc))) memory::memAnalysisKlass* | ||
| memory::ownershipReturnsAttr() { | ||
| return new memory::memAnalysisKlass; | ||
| } | ||
|
|
||
| // Expected to not return ownership when analysis is off, and there is just | ||
| // attr-check | ||
| memory::memAnalysisKlass* memory::noAttr() { | ||
| return new memory::memAnalysisKlass; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #ifndef MEMORY_ANALYSIS_H | ||
| #define MEMORY_ANALYSIS_H | ||
|
|
||
| #include <new> | ||
| #include <stdlib.h> | ||
| namespace memory { | ||
|
|
||
| class memAnalysisKlass { | ||
| public: | ||
| int val; | ||
| }; | ||
| __attribute__((malloc)) memAnalysisKlass* mallocAttr(); | ||
| __attribute__((ownership_returns(malloc))) memAnalysisKlass* | ||
| ownershipReturnsAttr(); | ||
| memAnalysisKlass* noAttr(); | ||
|
|
||
| } // namespace memory | ||
|
|
||
| #endif // MEMORY_ANALYSIS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import py | ||
| from support import setup_make | ||
|
|
||
| currpath = py.path.local(__file__).dirpath() | ||
| test_dct = str(currpath.join("cpp/memory_analysisDict")) | ||
|
|
||
|
|
||
| def setup_module(mod): | ||
| setup_make("memory_analysis") | ||
|
|
||
|
|
||
| class TestMEMORYANALYSIS: | ||
| def setup_class(cls): | ||
| cls.test_dct = test_dct | ||
| import cppjit | ||
|
|
||
| cls.memory_analysis = cppjit.load_reflection_info(cls.test_dct) | ||
|
|
||
| def test01_malloc_attr(self): | ||
| import cppjit | ||
|
|
||
| obj = cppjit.gbl.memory.mallocAttr() | ||
| assert type(obj) == cppjit.gbl.memory.memAnalysisKlass | ||
| assert obj.__python_owns__ | ||
|
|
||
| def test02_ownership_returns_attr(self): | ||
| import cppjit | ||
|
|
||
| obj = cppjit.gbl.memory.ownershipReturnsAttr() | ||
| assert type(obj) == cppjit.gbl.memory.memAnalysisKlass | ||
| assert obj.__python_owns__ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need tests for assert not obj.__python__owns__ |
||
|
|
||
| def test03_no_attr(self): | ||
| import cppjit | ||
|
|
||
| obj = cppjit.gbl.memory.noAttr() | ||
| assert type(obj) == cppjit.gbl.memory.memAnalysisKlass | ||
| assert not obj.__python_owns__ | ||
| obj.__python_owns__ = True | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test these changes on top of your CppInterOp branches by updating the remote and ref here: https://github.com/compiler-research/cppjit/blob/main/CMakeLists.txt#L14-L15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes this PR depends on are already part of main in CppInterOp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant for changes that have not been merged yet (referred to in the FIXME comment on
IsAllocator). iiuc the API on the CppInterOp side will change pending some work being merged, so if you want to coverage test the cppjit patch, this could help