Skip to content
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

Improve PointerHandler #8

Closed
wants to merge 1 commit into from
Closed

Conversation

byehack
Copy link
Contributor

@byehack byehack commented Mar 15, 2023

Partially _fixes #4 (comment)

@byehack byehack marked this pull request as draft March 15, 2023 22:47
@@ -86,6 +86,9 @@ def from_param(self, obj):
if isinstance(obj, str):
if issubclass(self.pointer_type, (POINTER(Int16), POINTER(UInt16))):
return obj
elif isinstance(obj, int):
if issubclass(self.pointer_type, (POINTER(Int32), POINTER(UInt32))):
return byref(self.pointer_type._type_(obj))
Copy link
Owner

Choose a reason for hiding this comment

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

I suppose it is impossible to pass python's int by reference. obj can not be changed by function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when we are passing python class as argument instead of ctypes classes, we don't care about the object reference.
This is creating reference to move the final value correctly to that function. (auto push the integer to type of argument then assign to its reference)
But if you have better idea, I'll be happy to know.

Copy link
Owner

Choose a reason for hiding this comment

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

If you aim to pass int value and don't aim to receive result value, I have nothing else to say.

@ynkdir
Copy link
Owner

ynkdir commented Mar 18, 2023

Is this ready to merge?

@byehack
Copy link
Contributor Author

byehack commented Mar 18, 2023

Hi @ynkdir ,
before anything, I think the whole of PointerHandler won't be cover the most of functions. it just does great job for few of them.
btw it is currently implemented, we should create a mapping python types and c-types that supported.
for example, in this PR we could add another condition for support convert int to Int16, UInt16, Int64 and UInt64 too.
maybe the better way is using a dictionary that these types correctly mapped.

@ynkdir
Copy link
Owner

ynkdir commented Mar 19, 2023

I will commit some changes before you complete it.
It supports assigning to structure member with type casting and it conflicts with this pull request.

@byehack
Copy link
Contributor Author

byehack commented Mar 19, 2023

c723275 seems reasonable. I didn't test yet but seems works.
I'm going to close this PR as we don't need it anymore.

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