Lisp HUG Maillist Archive

emun values defined in Mac OS headers

I am trying to access constant values defined in enum statements. 
This should be easy to do but I cannot figure this one out.

The following code segment is taken out of the file AEDataModel.h

enum {
  typeAEList                    = 'list',
  typeAERecord                  = 'reco',
  typeAppleEvent                = 'aevt',
  ... };

The problem seems that in these C statements, the enum type is not specified so that the functions enum-value-symbol or enum-symbol-value are useless. 
A desparte trial to define these as foreign variables does not work either, leading to an unresolved external function error as if the module was not registered.

(fli:register-module :AE
                     :real-name (namestring (truename "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE"))
                     :connection-style :immediate)

(fli:define-foreign-variable (typeAppleEvent "typeAppleEvent")
  :module :AE
  :accessor :constant)

CL-USER 27 > (typeAppleEvent)

Error: Foreign function TYPEAPPLEEVENT trying to call to unresolved external function "typeAppleEvent".
  1 (abort) Return to level 0.
  2 Return to top loop level 0.


Thanks

Bruno

Re: emun values defined in Mac OS headers

On Friday 11 April 2008 8:52:24 am Bruno Emond wrote:
> I am trying to access constant values defined in enum statements.
> This should be easy to do but I cannot figure this one out.
>
> The following code segment is taken out of the file AEDataModel.h
>
> enum {
>    typeAEList                    = 'list',
>    typeAERecord                  = 'reco',
>    typeAppleEvent                = 'aevt',
>    ... };

Enums are ints.

The dirty syntax 'list' is an int.  Note the single-quotes, denoting that the 
item contains characters (bytes).

So 'list' is 0x6c697374.  (Hmm, check the endian-ness).

The enum declaration is the same as writing a bunch of #defines, e.g.

#define typeAEList 0x6c697374
...

As far as I can tell, the foreign parser (on LWL), does not accept the 
syntax 'list' when parsing an enum.

From the rest of your email, it appears that you might be expecting to find 
the constants in the compiled object file in mac-os.  Enums, like #defines, 
are 'compiled away' - their values are simply substituted by the C compiler 
at compile time.

You cannot find these constants by name in the C module.

You need to create a .h file and run it through the foreign parser to create a 
lisp file so that lisp can know what the final values are.  Or create the 
lisp constants by hand - this might be the simplest option, since you have to 
convert the constants manually anyway (due to the dirty syntax).  Or, if 
you're feeling exceptionally lazy (or there are 1000's of these things), you 
could whip up a C program that printf's the name and value (as numbers) of 
each of the enums, then edit this file to be in lisp synax.

hth
pt


Updated at: 2020-12-10 08:43 UTC