Skip to content

[memory-analysis] Added a field to CPPMethod to store memory-ownershi… - #35

Draft
keremsahn wants to merge 1 commit into
compiler-research:mainfrom
keremsahn:bool-is-alloc
Draft

[memory-analysis] Added a field to CPPMethod to store memory-ownershi…#35
keremsahn wants to merge 1 commit into
compiler-research:mainfrom
keremsahn:bool-is-alloc

Conversation

@keremsahn

@keremsahn keremsahn commented Aug 21, 2026

Copy link
Copy Markdown

When overload resolution happens and a suitable candidate found and called, HandleReturn helper is called for every case. In this function I call GetAllocBehaviour function for the first element of overload candidates (I followed design where IsCreator flag belongs to overload group, not unique for every PyCallable, but I think of changing it).

2 important notes: Enum order of AllocType is going to change in CppInterOp after open PRs are merged,
and IsAllocator returns bool in the current CppInterOp but this is also going to change after PRs get merged, that is why I keep AllocType in CPPMethod even though it is not useful now

@Vipul-Cariappa @aaronj0

…p information and this information effects kIsCreator flag of overload group , currently analyzer is not called, just attribute checker is called
Comment thread src/cpyrt/CPPMethod.cxx
//----------------------------------------------------------------------------
// FIXME: For now every allocation is assumed to be done with `new`
// will be fixed soon. Also the reason function returns an AllocType
// instead of bool, IsAllocator function from CppInterOp changed a little,

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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.

@Vipul-Cariappa
Vipul-Cariappa marked this pull request as draft August 23, 2026 04:52
@Vipul-Cariappa

Copy link
Copy Markdown
Collaborator

I am converting to draft for now. Once I am happy with the state of this PR, I will mark it "ready for review" for others.
Note: I may take some time to review it.
@keremsahn, hope that is fine with you.

Comment on lines +7 to +11
class memAnalysisKlass {
int val;
};
__attribute__((malloc)) memAnalysisKlass* allocTest();
__attribute__((ownership_returns(malloc))) memAnalysisKlass* allocTestReturns();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put everything in this file into a namespace; otherwise, the names may conflict with things that are JIT compiled or exist in other files.

@Vipul-Cariappa Vipul-Cariappa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments. LGTM, otherwise.


obj = cppjit.gbl.allocTestReturns()
assert type(obj) == cppjit.gbl.memAnalysisKlass
assert obj.__python_owns__

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need tests for

assert not obj.__python__owns__

Comment thread src/cpyrt/PyCallable.h
virtual PyObject* GetArgDefault(int /* iarg */, bool silent = true) = 0;
virtual bool IsConst() { return false; }
virtual cppjit::interop::AllocType GetAllocBehaviour() {
return cppjit::interop::AllocType::None;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return cppjit::interop::AllocType::None;
return cppjit::interop::AllocType::Unknown;

?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants