den-run-ai / ctypesgen

Automatically exported from code.google.com/p/ctypesgen
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Wrap 'c' with ord() #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The c codes is like:

    #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
    #define DEFAULT_LANG            CHR('d','f','l','t')

The generated code:
    def CHR(ch1, ch2, ch3, ch4):
        return ((((ch1 << 24) | (ch2 << 16)) | (ch3 << 8)) | ch4)
    try:
        DEFAULT_LANG = (CHR ('d', 'f', 'l', 't'))
    except:
        pass

This of course doesn't work. If an ord() is used to surrounding characters, it 
will work ok.

        DEFAULT_LANG = (CHR (ord('d'), ord('f'), ord('l'), ord('t')))

Another way to solve this problem is to provide a mechanism to overrides 
generated code. Like user defined CHR() was used instead of autogen CHR():

    def _override_CHR(ch1, ch2, ch3, ch4):
        return ((((ord(ch1) << 24) | (ord(ch2) << 16)) | (ord(ch3) << 8)) | ord(ch4))

Original issue reported on code.google.com by mozbug...@gmail.com on 25 May 2011 at 9:31