]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Tools/bgen/bgen/macsupport.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / bgen / bgen / macsupport.py
CommitLineData
4710c53d 1"""\\r
2Augment the "bgen" package with definitions that are useful on the Apple Macintosh.\r
3\r
4Intended usage is "from macsupport import *" -- this implies all bgen's goodies.\r
5"""\r
6\r
7\r
8# Import everything from bgen (for ourselves as well as for re-export)\r
9from bgen import *\r
10\r
11\r
12# Simple types\r
13Boolean = Type("Boolean", "b")\r
14SignedByte = Type("SignedByte", "b")\r
15Size = Type("Size", "l")\r
16Style = Type("Style", "b")\r
17StyleParameter = Type("StyleParameter", "h")\r
18CharParameter = Type("CharParameter", "h")\r
19TextEncoding = Type("TextEncoding", "l")\r
20ByteCount = Type("ByteCount", "l")\r
21Duration = Type("Duration", "l")\r
22ByteOffset = Type("ByteOffset", "l")\r
23OptionBits = Type("OptionBits", "l")\r
24ItemCount = Type("ItemCount", "l")\r
25PBVersion = Type("PBVersion", "l")\r
26ScriptCode = Type("ScriptCode", "h")\r
27LangCode = Type("LangCode", "h")\r
28RegionCode = Type("RegionCode", "h")\r
29\r
30UInt8 = Type("UInt8", "b")\r
31SInt8 = Type("SInt8", "b")\r
32UInt16 = Type("UInt16", "H")\r
33SInt16 = Type("SInt16", "h")\r
34UInt32 = Type("UInt32", "l")\r
35SInt32 = Type("SInt32", "l")\r
36Float32 = Type("Float32", "f")\r
37\r
38wide = OpaqueByValueType("wide", "PyMac_Buildwide", "PyMac_Getwide")\r
39wide_ptr = OpaqueType("wide", "PyMac_Buildwide", "PyMac_Getwide")\r
40\r
41# Pascal strings\r
42ConstStr255Param = OpaqueArrayType("Str255", "PyMac_BuildStr255", "PyMac_GetStr255")\r
43Str255 = OpaqueArrayType("Str255", "PyMac_BuildStr255", "PyMac_GetStr255")\r
44StringPtr = OpaqueByValueType("StringPtr", "PyMac_BuildStr255", "PyMac_GetStr255")\r
45ConstStringPtr = StringPtr\r
46\r
47# File System Specifications\r
48FSSpec_ptr = OpaqueType("FSSpec", "PyMac_BuildFSSpec", "PyMac_GetFSSpec")\r
49FSSpec = OpaqueByValueStructType("FSSpec", "PyMac_BuildFSSpec", "PyMac_GetFSSpec")\r
50FSRef_ptr = OpaqueType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef")\r
51FSRef = OpaqueByValueStructType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef")\r
52\r
53# OSType and ResType: 4-byte character strings\r
54def OSTypeType(typename):\r
55 return OpaqueByValueType(typename, "PyMac_BuildOSType", "PyMac_GetOSType")\r
56OSType = OSTypeType("OSType")\r
57ResType = OSTypeType("ResType")\r
58FourCharCode = OSTypeType("FourCharCode")\r
59\r
60# Version numbers\r
61NumVersion = OpaqueByValueType("NumVersion", "PyMac_BuildNumVersion", "BUG")\r
62\r
63# Handles (always resources in our case)\r
64Handle = OpaqueByValueType("Handle", "ResObj")\r
65MenuHandle = OpaqueByValueType("MenuHandle", "MenuObj")\r
66MenuRef = MenuHandle\r
67ControlHandle = OpaqueByValueType("ControlHandle", "CtlObj")\r
68ControlRef = ControlHandle\r
69\r
70# Windows and Dialogs\r
71WindowPtr = OpaqueByValueType("WindowPtr", "WinObj")\r
72WindowRef = WindowPtr\r
73DialogPtr = OpaqueByValueType("DialogPtr", "DlgObj")\r
74DialogRef = DialogPtr\r
75ExistingWindowPtr = OpaqueByValueType("WindowPtr", "WinObj_WhichWindow", "BUG")\r
76ExistingDialogPtr = OpaqueByValueType("DialogPtr", "DlgObj_WhichDialog", "BUG")\r
77\r
78# NULL pointer passed in as optional storage -- not present in Python version\r
79NullStorage = FakeType("(void *)0")\r
80\r
81# More standard datatypes\r
82Fixed = OpaqueByValueType("Fixed", "PyMac_BuildFixed", "PyMac_GetFixed")\r
83\r
84# Quickdraw data types\r
85Rect = Rect_ptr = OpaqueType("Rect", "PyMac_BuildRect", "PyMac_GetRect")\r
86Point = OpaqueByValueType("Point", "PyMac_BuildPoint", "PyMac_GetPoint")\r
87Point_ptr = OpaqueType("Point", "PyMac_BuildPoint", "PyMac_GetPoint")\r
88\r
89# Event records\r
90EventRecord = OpaqueType("EventRecord", "PyMac_BuildEventRecord", "PyMac_GetEventRecord")\r
91EventRecord_ptr = EventRecord\r
92\r
93# CoreFoundation datatypes\r
94CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj")\r
95CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")\r
96CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")\r
97CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")\r
98CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")\r
99CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj")\r
100CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj")\r
101CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")\r
102OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")\r
103\r
104# OSErr is special because it is turned into an exception\r
105# (Could do this with less code using a variant of mkvalue("O&")?)\r
106class OSErrType(Type):\r
107 def errorCheck(self, name):\r
108 Output("if (%s != noErr) return PyMac_Error(%s);", name, name)\r
109 self.used = 1\r
110OSErr = OSErrType("OSErr", 'h')\r
111OSStatus = OSErrType("OSStatus", 'l')\r
112\r
113\r
114# Various buffer types\r
115\r
116InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len)\r
117UcharInBuffer = VarInputBufferType('unsigned char', 'long', 'l') # (buf, len)\r
118OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len)\r
119\r
120InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len)\r
121VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len)\r
122\r
123OutBuffer = HeapOutputBufferType('char', 'long', 'l') # (buf, len)\r
124VarOutBuffer = VarHeapOutputBufferType('char', 'long', 'l') # (buf, &len)\r
125VarVarOutBuffer = VarVarHeapOutputBufferType('char', 'long', 'l') # (buf, len, &len)\r
126\r
127# Unicode arguments sometimes have reversed len, buffer (don't understand why Apple did this...)\r
128class VarUnicodeInputBufferType(VarInputBufferType):\r
129\r
130 def getargsFormat(self):\r
131 return "u#"\r
132\r
133class VarUnicodeReverseInputBufferType(ReverseInputBufferMixin, VarUnicodeInputBufferType):\r
134 pass\r
135\r
136UnicodeInBuffer = VarUnicodeInputBufferType('UniChar', 'UniCharCount', 'l')\r
137UnicodeReverseInBuffer = VarUnicodeReverseInputBufferType('UniChar', 'UniCharCount', 'l')\r
138UniChar_ptr = InputOnlyType("UniCharPtr", "u")\r
139\r
140\r
141# Predefine various pieces of program text to be passed to Module() later:\r
142\r
143# Stuff added immediately after the system include files\r
144includestuff = """\r
145#include "pymactoolbox.h"\r
146\r
147/* Macro to test whether a weak-loaded CFM function exists */\r
148#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\\\r
149 PyErr_SetString(PyExc_NotImplementedError, \\\r
150 "Not available in this shared library/OS version"); \\\r
151 return NULL; \\\r
152 }} while(0)\r
153\r
154"""\r
155\r
156# Stuff added just before the module's init function\r
157finalstuff = """\r
158"""\r
159\r
160# Stuff added inside the module's init function\r
161initstuff = """\r
162"""\r
163\r
164\r
165# Generator classes with a twist -- if the function returns OSErr,\r
166# its mode is manipulated so that it turns into an exception or disappears\r
167# (and its name is changed to _err, for documentation purposes).\r
168# This requires that the OSErr type (defined above) has a non-trivial\r
169# errorCheck method.\r
170class OSErrMixIn:\r
171 "Mix-in class to treat OSErr/OSStatus return values special"\r
172 def makereturnvar(self):\r
173 if self.returntype.__class__ == OSErrType:\r
174 return Variable(self.returntype, "_err", ErrorMode)\r
175 else:\r
176 return Variable(self.returntype, "_rv", OutMode)\r
177\r
178class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass\r
179class OSErrMethodGenerator(OSErrMixIn, MethodGenerator): pass\r
180\r
181class WeakLinkMixIn:\r
182 "Mix-in to test the function actually exists (!= NULL) before calling"\r
183\r
184 def precheck(self):\r
185 Output('#ifndef %s', self.name)\r
186 Output('PyMac_PRECHECK(%s);', self.name)\r
187 Output('#endif')\r
188\r
189class WeakLinkFunctionGenerator(WeakLinkMixIn, FunctionGenerator): pass\r
190class WeakLinkMethodGenerator(WeakLinkMixIn, MethodGenerator): pass\r
191class OSErrWeakLinkFunctionGenerator(OSErrMixIn, WeakLinkMixIn, FunctionGenerator): pass\r
192class OSErrWeakLinkMethodGenerator(OSErrMixIn, WeakLinkMixIn, MethodGenerator): pass\r
193\r
194class MacModule(Module):\r
195 "Subclass which gets the exception initializer from macglue.c"\r
196 def exceptionInitializer(self):\r
197 return "PyMac_GetOSErrException()"\r