Re: [Pyobjc-dev] NSRunAlertPanel signature?
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-08-20 06:34:19
|
On Wednesday, 20 August, 2003, at 02:06, Bob Ippolito wrote: > > On Tuesday, Aug 19, 2003, at 15:16 America/New_York, Zachery Bir wrote: > >> In the AppKit docs, it spells the method NSRunAlertPanel like this: >> >> int NSRunAlertPanel(NSString *title, NSString *msg, NSString >> *defaultButton, NSString *alternateButton, NSString *otherButton, >> ...) >> >> I assumed that the ellipsis in argument list meant the additional >> buttons were unbounded. However, PyObjC complains when more than 5 >> parameters are passed. UI issues aside, is one or the other >> (signature or implementation) incorrect? > > ellipsis at the end of a C function prototype means that it's one of > those nasty magical C functions that take a variable number of > arguments (arglist_t, va_args, or whatever). Key offenders would be > stuff like printf and NSLog. > > If you pop open Scripts/CodeGenerators/cocoa_generator.py in the > PyObjC source and search for NSRunAlertPanel, you'll see that the > current code generator ignores the fact that NSRunAlertPanel can take > a variable number of arguments. > > So basically, the current code generator isn't smart enough to do > anything useful for a few kinds of "complex functions", so you'll have > to live with a non-varargs version of NSRunAlertPanel until someone > writes a smarter code generator (IIRC, the libffi code for this > madness isn't trivial, and the python bridge would be NO fun.. but I > think ctypes might have support for it) and you upgrade to whatever > version of PyObjC that may be. The main problem with varargs functions is that there is no easy way to detect which amount and type of arguments the function want to see. The only way to do that is to reimplement the code that walks through the vararg list, and there's lots of different, non-trivial, ways to do that. For the NSRun.*Panel functions you'd have to parse the message and interpret the %X arguments. My current strategy is to ignore varargs functions unless that would remove functionality. For the NSRun.*Panel functions we can savely ignore the additional arguments, and use the printf operator in python. BTW. libffi explicitly states that it doesn't support varargs function. It happens to work on the PPC because argument passing for varargs functions is simular enough to that of normal functions. Ronald |