CoreMIDI using objc_util questions
By the way - I've worked on my C preprocessor thing a little. It seems to handle nested macro functions well now. I've also added basic conditional blocks using
#endif. Once I've got
#includeworking I'll probably put it on GitHub so you can all admire this "beautiful" code.
If anyone has any ideas on how the C expressions in
#elifcould be parsed, let me know. If all else fails I might do some dumb string replacing and then use Python's
astmodule for parsing. The syntax is similar enough.
Looking through the
cffisource code, it seems that it does remove comments from source code, and even understands very basic
#defines. Quoting one of the error messages:
only supports one of the following syntax: #define %s ... (literally dot-dot-dot) #define %s NUMBER (with NUMBER an integer constant, decimal/hex/octal)
This is a feature of
pycparser. Originally I only looked at the
pycparsersource, which is why I thought that
cffirequired fully preprocessed source code.
CFFI is created by the Pypy core team. They hint at an unreleased CFFI v1.3 here.
@wradcliffe Apple provides downloads for Xcode outside the App Store as well, at https://developer.apple.com/downloads/, though you do need to sign in with your Apple ID. (The first time you do so you'll also need to accept the usual agreement that you're over 13, etc.) The Xcode download is in the usual OS X installation package format, which is not very straightforward to open. If you have some time and don't mind a bit of exploring, read on.
To get to the actual Xcode data, grab yourself a copy of our lord and savior 7-Zip. You'll need it.
The installation image's file structure looks roughly like this:
dmgdisk image, which is a format that 7-Zip supports. It contains...
- The main
pkginstallation package. Technically it is a
xararchive, which 7-Zip supports. It contains...
- A number of folders with a
pkgextension. Which one contains what you want might be visible based on the name. Each one contains...
- A few data files.
Payloadis the main data, compressed using
gzip. How convenient, 7-Zip supports that as well. It contains...
cpioarchive. You guessed it, 7-Zip can read that as well. It contains...
- The good stuff. This is where you'll find the actual Xcode files.
The location of the iOS include directory (inside the Xcode.app bundle) is
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include. I'm not sure what exactly that translates to in the installation image, since I got Xcode from the App Store, and don't have the Xcode image lying around atm. (It would be so much nicer if the header files were available online somewhere...)
@dgelessus - pycparser uses ply as its Lex Yacc tool and ply contains a preprocessor. Have a look:
I am not sure why cffi does not take better advantage of this. The author Armin Rigo talks about it in this stackoverflow thread:
"While it is possible to use the gcc -E approach and manually "trim" the result, it is not the recommended way to use CFFI. Instead, the cdef() code is usually made either incrementally (adding functions as needed) or in bulk from an edited copy of the .h file. The first approach works best when copying from man pages; the second approach is for the case where we want complete access to a single 3rd-party library.
In all cases, it is very likely that you need to edit the .h file anyway: the recommended approach is to use ffi.set_source(), and remove from the cdef() any declarations that are superfluous, replacing them with .... For example, the actual .h file may contain the declaration #define FOOBAR 42, but the value 42 should not be relied upon (e.g. it could change in the future), so the cdef() should rather receive #define FOOBAR ...."
@ccc - Armin Rigo is working on PyPy now and cffi and a lot of what is being done with cffi is about making it play better in PyPy. Lots of work being done to make cffi bindings run very fast in PyPy.
@omz ... has anyone asked about the possibility of a PyPythonista App?
I knew someone must have written a C preprocessor in Python already, guess I didn't look well enough. I'll need to see how well that could be used and extended.
I am aware that the iOS header files would need some editing to be useful. (Some things are also simply not necessary for use with
cffiand could be removed.)
@dgelessus - thanks for dmg details. I will verify your procedure and get the header files I need. It turns out that @JonB was correct and that there are quite a few headers available on the Apple Open Source site. They don't have many of the frameworks and the did not have CoreMIDI. Here is a pointer to CoreFoundation.
@dgelessus - I finally got around to downloading the dmg on my Windows laptop. I went with XCode 6.4 for now. Your description for using 7-Zip failed at step one. 7-Zip decompresses the dmg to several small files and one huge file with a ".hfs" extension. It can not unpack the ".hfs". Could this be version specific? I got around this by using HFSExplorer instead. It allows you to browse and extract from the dmg file directly. You can get a copy here:
Make sure that you're using the beta version of 7-Zip. The "stable" version lacks support for a number of uncommon archive formats.