Re: Need some help creating/dealing with struct types

Ronald Oussoren <[email protected]> Thu, 20 Aug 2015 14:18:50 +0200
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
> On 19 Aug 2015, at 09:00, Robert Klep <[email protected]> wrote:
> 
> All,
> 
> My goal is to call [SFAuthorization authorizationWithFlags:rights:environment:] <https://developer.apple.com/library/prerelease/mac/documentation/Security/Reference/SecurityFoundationFramework/Classes/SFAuthorization_Class/index.html#//apple_ref/occ/clm/SFAuthorization/authorizationWithFlags:rights:environment:> from PyObjC. My main issue is with the `rights` argument, a pointer to AuthorizationRights <https://developer.apple.com/library/prerelease/mac/documentation/Security/Reference/authorization_ref/index.html#//apple_ref/swift/tdef/c:@T@AuthorizationRights>.

The rights argument is a pass by reference argument. The easiest way to use them is to tell this to PyObjC, something like:

   objc.registerMetadataForSelector(b’SFAuthorization’, b’authorizationWithFlags:rights:environment:’, {
      ‘arguments’: {
        3: { ‘type_modifier’: b’n’ },
        4: { ‘type_modifier’: b’n’ },
      }
   })

That said, AuthorizationRights is an alias for AuthorisationItemSet and that is a struct with an embedded pointer to a buffer and that’s something that PyObjC doesn’t really support at the moment.

Could you file a ticket at my bitbucket repository? I want to provide wrappers for all frameworks, but that takes a lot of time and a ticket helps me to prioritise.

Ronald

> 
> I initially found this issue: Add ctypes support <https://bitbucket.org/ronaldoussoren/pyobjc/issues/23/add-ctypes-support>, which uses ctypes to create AuthorizationRights. However, even though the issue was solved, I have no idea how to get it working (PyObjC 3.0.4 on OSX 10.10.4).
> 
> Specifically, I'm using this:
> 
> auth = SFAuthorization.authorizationWithFlags_rights_environment_(
>   19,
>   ctypes.pointer(authorization_rights),
>   None)
> 
> Which results in an error similar to the one mentioned in the issue:
> 
>   ValueError: depythonifying 'pointer', got 'LP_AuthorizationRights'
> 
> I also looked at objc.createStructType() <https://pythonhosted.org/pyobjc/metadata/manual.html#objc.createStructType> to use instead of ctypes, but got stuck on the `typestr` argument (I can't find any documentation on it; I assumed it might be similar to Objective-C method signatures, but those aren't very well documented either).
> 
> Any help would be greatly appreciated!
> 
> – robert
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Pyobjc-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev

------------------------------------------------------------------------------

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev