Lisp HUG Maillist Archive

define carbon constant in lisp

I'm trying to use carbon's OpenMovieFile function  (i guess its really a
quicktime function) from lispworks using the FLI.  I ran into a problem
though, the last argument to the file is a constant that I am not sure how
to represent in lisp (for the fli:define-foreign-function)

http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESII/openmoviefile.htm#//apple_ref/c/func/OpenMovieFile


I tried to create the appropriate SInt8 type (which is a signed char) to
represent it, but still couldn't find a way to pass it fsRdPerm (0x100)
without it erroring out.  It either errors with a bus error when I pass it
a value of 1, or cannot convert it to the foreign type error when I try
other things.

The enum which defines the constants, including fsRdPerm, is not typed, so
I am not sure how I could use the define-c-enum either, if this were even
to be the appropriate action.

http://developer.apple.com/documentation/Carbon/Reference/File_Manager/file_manager/constant_23.html#//apple_ref/c/econst/fsRdPerm


Does anyone know how I could define the fsRdPerm constant in order to use
the OpenMovieFile? 

Thank you for any help.


Stefano B.

PS - Thank you Dave Fox for the very helpful analysis of my other Carbon
problem.


Here are some definitions that I use:

(fli:define-foreign-function (openmoviefile "OpenMovieFile" :source)
    ((filespec (:pointer fsspec))
     (resrefnum :short)
     (permission sint8))   
  :result-type :int
  :language :c)

(fli:define-c-typedef (sint8 (:foreign-name "SInt8")) 
  (:signed :char))




Re: define carbon constant in lisp

Stefano,

On Jun 8, 2004, at 1:15 PM, Stefano R Bonissone wrote:

> I'm trying to use carbon's OpenMovieFile function  (i guess its really  
> a
> quicktime function) from lispworks using the FLI.  I ran into a problem
> though, the last argument to the file is a constant that I am not sure  
> how
> to represent in lisp (for the fli:define-foreign-function)
>
> http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESII/ 
> openmoviefile.htm#//apple_ref/c/func/OpenMovieFile
>
>
> I tried to create the appropriate SInt8 type (which is a signed char)  
> to
> represent it, but still couldn't find a way to pass it fsRdPerm (0x100)
> without it erroring out.  It either errors with a bus error when I  
> pass it
> a value of 1, or cannot convert it to the foreign type error when I try
> other things.

Did you try declaring the parameter as (permission :byte) and using one  
of the values below? Seems like it should work.

(defconstant $fsCurPerm #x0)                    ;   open access  
permissions in ioPermssn
(defconstant $fsRdPerm #x1)
(defconstant $fsWrPerm #x2)
(defconstant $fsRdWrPerm #x3)
(defconstant $fsRdWrShPerm #x4)
(defconstant $fsRdDenyPerm #x10)                ;   for use with  
OpenDeny and OpenRFDeny
(defconstant $fsWrDenyPerm #x20)                ;   for use with  
OpenDeny and OpenRFDeny


Best,

John DeSoi, Ph.D.


Re: define carbon constant in lisp

On Tuesday 08 June 2004 01:15 pm, Stefano R Bonissone wrote:
....
> I tried to create the appropriate SInt8 type (which is a signed char) to
> represent it, but still couldn't find a way to pass it fsRdPerm (0x100)

The 0x100 is a typo, right?  The man page says that fsRdPerm is 0x01.

Signed char means a value between -128 and +127.  0x100 is +256.

> without it erroring out.  It either errors with a bus error when I pass it
> a value of 1, or cannot convert it to the foreign type error when I try
> other things.

Bus error often means that the code is accessing incorrectly aligned data.  
Many C compilers stretch parameters to be the same size as an address (void*) 
before pushing them onto the stack.  Some operating systems (e.g. Windows) 
also impose non-C parameter conventions.  If you know what the Carbon C 
compiler does, you could guess how to lie to the fli (see below).

C is a sloppy language with sloppy "strong" typing added to it as an 
afterthought.  If you want to work around your problem - until davef responds 
with more accuracy than I - just lie to the fli.  Try telling it that 
"permission" is a :byte, or a :short, or a :long and see which one works.

> The enum which defines the constants, including fsRdPerm, is not typed, so

No, it is typed - by some sort of (obscure) default.  You probably have to 
poke around the C standard to see how enums are defined to be typed when a 
type is not explicitly specified by the programmer (e.g. is the compiler 
allowed to compress the enum to fit into the smallest number of byte-aligned 
bits, or, does it default to "int" like many other things in C do?).

pt


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