progrium / darwinkit

Native Mac APIs for Go. Previously known as MacDriver
MIT License
4.99k stars 158 forks source link

Add types to mapType #149

Closed programmingkidx closed 1 year ago

programmingkidx commented 1 year ago

A lot of methods are skipped by the wrapper generation system because the type they return on not in the mapType() function. To increase the number of Objective-C methods that are wrapped this patch adds support for these types:

programmingkidx commented 1 year ago

I wasn't sure if I should include changes to generated files so I will include them here.

0001-more-types.patch

tmc commented 1 year ago

@programmingkidx instead of attaching a patch could you push a commit?

edit: doing so for you

programmingkidx commented 1 year ago

Is there anything else stopping this pull request from being merged?

progrium commented 1 year ago

@tmc look good?

programmingkidx commented 1 year ago

This is the error I see when I try to build a program with this commit in place:

macdriver/core/core_objc.gen.go:4960:2: x redeclared in this block
macdriver/core/core_objc.gen.go:4957:7: other declaration of x
macdriver/core/core_objc.gen.go:4966:10: cannot convert x (variable of type gen_NSObject) to type C.uint

I traced the issue to a method called ProvideImageDataBytesPerRowOrigin(). According to the documentation there is no method with this name. There is one called provideImageData:bytesPerRow:origin::size::userInfo:. I'm guessing this is a bug.

My first idea to fix this issue was to open the json file for NSObject and change the argument's name from x to x1. Problem is there is no json file.

I then did a grep search. It showed ProvideImageDataBytesPerRowOrigin to only be in the core/core_objc.gen.go file, so this means I am not sure where this method comes from.

@tmc Any idea where the ProvideImageDataBytesPerRowOrigin() method comes from?

programmingkidx commented 1 year ago

I found where ProvideImageDataBytesPerRowOrigin() comes from. It is from api/objectivec/nsobject.objc.json. I fixed the problem by changing the name of the receiver variable.

programmingkidx commented 1 year ago

The current problem with this pull request is with a method called preservationPriorityForTag:. This is the error I see:

macdriver/cocoa/cocoa_objc.gen.go:742:3: error: 'preservationPriorityForTag:' is unavailable: not available on macOS preservationPriorityForTag: tag];

This is an issue with the API_UNAVAILABLE() macro. MacDriver does not currently have a system in place to handle this situation.

progrium commented 1 year ago

Not sure how this issue fell out of the documented change proposed. Maybe that it opened up new methods to be supported that introduced these errors? Anyway, I made sure these types are supported in darwinkit, so I'm closing this PR. Thanks!