[Pyobjc-dev] Re: NSAnyEventMask as unsigned?
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-10-29 18:09:52
|
On Oct 29, 2003, at 12:51 PM, Ronald Oussoren wrote: > On 29 okt 2003, at 18:39, Bob Ippolito wrote: > >> On Oct 29, 2003, at 12:28 PM, Ronald Oussoren wrote: >> >>> Why is it a problem that NSAnyEventMask is -1? It is also -1 in ObjC >>> and therefore I suppose the conversion from Python to ObjC for >>> ``unsigned int`` values is too strict and doesn't accept -1 as a >>> valid value. >> >> It is 0xffffffffU in ObjC -- the fact that it has the same binary >> representation as the signed -1 is just a side effect. The >> conversion from Python to ObjC is indeed too strict for this kind of >> conversion, but rightly so, if you agree with the direction that >> Python itself is moving. For example, in Python 2.4, 0xffffffff >> without the L qualifier will become 0xffffffffL, instead of the >> current -1. > > You read the header file :-). The 'U' is bogus, it is inside an enum > definition and enums are signed integers. The following program should > make this clear: > > #include <stdio.h> > #import <AppKit/AppKit.h> > > int main(void) > { > printf("%s\n", @encode(__typeof__(NSAnyEventMask))); > return 0; > } > > This prints 'i', which is the type-code for 'int'. > > I don't like the hand-coded list, and therefore tried to be smart by > adding the type encoding for constants to the inttable structure which > didn't work because of the signedness of enums :-(. I'll update the > CodeGenerator scripts to detect '*Mask' as unsigned integers instead > of plain integers. Ah yes, you are of course correct. I'm not (yet) very familiar with the ObjC facilities for typing. However, the real problem is that Python really sucks at integers (from a bit twiddling / talking to C perspective).. it's handling of them diverges more and more from the C way of doing it after every release. In these cases, what you have is not even an "integer" in the intuitive sense, it's an integer length bit vector.. it's C's fault that it can't express this otherwise (not that Python has a built-in type that's any better at this). In any case, because this is Python, any sort of bit flag or mask really needs to treated as if it were unsigned or else bad things start happening and warnings get thrown all over the place (or probably break in 2.4). It would be awesome if you could write up some quick documentation as to how to run the code generators and how to make them respect manual overrides (for signatures, at least). I took a quick look at them, but I didn't quite get it. -bob |