-
Notifications
You must be signed in to change notification settings - Fork 6
[WIP] On demand analyze for allocation #37
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include "memory_analysis.h" | ||
| __attribute__((malloc)) memAnalysisKlass* allocTest() { | ||
| return new memAnalysisKlass; | ||
| } | ||
|
|
||
| __attribute__((ownership_returns(malloc))) memAnalysisKlass* | ||
| allocTestReturns() { | ||
| return new memAnalysisKlass; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #ifndef MEMORY_ANALYSIS_H | ||
| #define MEMORY_ANALYSIS_H | ||
|
|
||
| #include <new> | ||
| #include <stdlib.h> | ||
|
|
||
| class memAnalysisKlass { | ||
| int val; | ||
| }; | ||
| __attribute__((malloc)) memAnalysisKlass* allocTest(); | ||
| __attribute__((ownership_returns(malloc))) memAnalysisKlass* allocTestReturns(); | ||
|
|
||
| inline memAnalysisKlass* allocNew() { return new memAnalysisKlass; } | ||
| inline memAnalysisKlass* allocNew2() { return new memAnalysisKlass; } | ||
| #endif // MEMORY_ANALYSIS_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 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.allocTest() | ||
| assert type(obj) == cppjit.gbl.memAnalysisKlass | ||
| assert obj.__python_owns__ | ||
|
|
||
| def test02_ownership_returns_attr(self): | ||
| import cppjit | ||
|
|
||
| obj = cppjit.gbl.allocTestReturns() | ||
| assert type(obj) == cppjit.gbl.memAnalysisKlass | ||
| assert obj.__python_owns__ | ||
|
|
||
| def test03_analyzer_new(self): | ||
| import cppjit | ||
|
|
||
| cppjit._backend.SetUseAllocAnalyzer(True) | ||
|
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. Please add a wrapper in |
||
| obj = cppjit.gbl.allocNew() | ||
| assert type(obj) == cppjit.gbl.memAnalysisKlass | ||
| assert obj.__python_owns__ | ||
|
|
||
| def test04_analyzer_new_default(self): | ||
| import cppjit | ||
|
|
||
| cppjit._backend.SetUseAllocAnalyzer(False) | ||
| obj = cppjit.gbl.allocNew2() | ||
| assert type(obj) == cppjit.gbl.memAnalysisKlass | ||
| assert not (obj.__python_owns__) | ||
|
Comment on lines
+44
to
+47
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 need a test for reusing existing results... i.e. already analyzed, but |
||
| 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.
Can the function names be a bit more descriptive? In the context of the test. Example:
AnalysisOnAllocNew&AnalysisOffAllocNew?