Skip to content

Fixed MemberFunction not returning the correct return type.#396

Merged
jordanbriere merged 3 commits into
Source-Python-Dev-Team:masterfrom
CookStar:fix_member_function
May 21, 2021
Merged

Fixed MemberFunction not returning the correct return type.#396
jordanbriere merged 3 commits into
Source-Python-Dev-Team:masterfrom
CookStar:fix_member_function

Conversation

@CookStar

Copy link
Copy Markdown
Contributor

If the Function has a converter, then the MemberFunction must also have a correct converter.

@jordanbriere

Copy link
Copy Markdown
Contributor

If the Function has a converter, then the MemberFunction must also have a correct converter.

Thank you! This is a regression that was introduced when removing the copy constructor of the Function class to prevent reference/leak issues with its convention. Now that all (most?) convention issues have been addressed perhaps we could look into adding it back instead?

@CookStar

Copy link
Copy Markdown
Contributor Author

Now that all (most?) convention issues have been addressed perhaps we could look into adding it back instead?

Indeed, I don't think there will be any problems, either.
Restored the copy constructor.

One question: In this part added by 6d26bca, why does it check m_pCallingConvention by dynamic_cast and not just by comparing with CONV_CUSTOM?

else if (m_eCallingConvention != CONV_CUSTOM && !dynamic_cast<ICallingConventionWrapper *>(m_pCallingConvention))
m_pCallingConvention->m_bHooked = false;

If m_eCallingConvention isn't CONV_CUSTOM, I suppose there's no need to check further, is there?

// DynamicHooks calling convention (built-in and custom)
ICallingConvention* m_pCallingConvention;
bool m_bAllocatedCallingConvention;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed m_bAllocatedCallingConvention, which was forgotten.

@jordanbriere jordanbriere left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One question: In this part added by 6d26bca, why does it check m_pCallingConvention by dynamic_cast and not just by comparing with CONV_CUSTOM?

It was added as extra security as mentioned into #344 (comment). However, feel free to remove it. Chances are that whole thing will collapse anyway if they are independently mutated. 😄

{
m_pCallingConvention = obj.m_pCallingConvention;
m_oCallingConvention = obj.m_oCallingConvention;
Py_INCREF(m_oCallingConvention.ptr());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't tested, only hovered the changes, but is that necessary? I guess this is an additional reference reserved for DynamicHooks and it will be taken care of as well when the copy gets destroyed?

@CookStar CookStar Aug 25, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This process is necessary to prevent the destructor from freeing up the memory, but it seems to cause a memory leak when the function is hooked related to another bug.

Details will be provided in a new pull request.

@jordanbriere

Copy link
Copy Markdown
Contributor

Had a chance to run some tests just now and it passed everything I threw at it. Well done!

@jordanbriere jordanbriere merged commit 08635a3 into Source-Python-Dev-Team:master May 21, 2021
@CookStar

Copy link
Copy Markdown
Contributor Author

I have been unable to access github for a long time, so I apologize for the delay in replying.

It was added as extra security as mentioned into #344 (comment). However, feel free to remove it. Chances are that whole thing will collapse anyway if they are independently mutated. 😄

Indeed, you were right, it totally dropped from my memory.

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.

2 participants