@@ -165,6 +165,9 @@ def __init__(self):
165165 # Stores function typedefs
166166 self .function_typedefs = {}
167167
168+ # Storage for custom calling conventions
169+ self .custom_conventions = {}
170+
168171 def __call__ (self , name , bases , cls_dict ):
169172 """Create and registers a new class."""
170173 # Set the manager attribute. This is required, so CustomType.__init__
@@ -183,6 +186,41 @@ def __call__(self, name, bases, cls_dict):
183186 self [name ] = cls
184187 return cls
185188
189+ def custom_calling_convention (self , cls ):
190+ """Register a custom calling convention class by its name.
191+
192+ Example:
193+
194+ .. code:: python
195+
196+ @manager.custom_calling_convention
197+ class MyCustomCallingConvention(CallingConvention):
198+ pass
199+
200+ # Equals to...
201+ class MyCustomCallingConvention(CallingConvention):
202+ pass
203+
204+ manager.register_convention(
205+ 'MyCustomCallingConvention',
206+ MyCustomCallingConvention)
207+ """
208+ self .register_convention (cls .__name__ , cls )
209+
210+ def register_convention (self , name , convention ):
211+ """Register a custom calling convention.
212+
213+ :param str name:
214+ Name of the custom calling convention.
215+ :param CallingConvention convention:
216+ The custom calling convention.
217+ """
218+ self .custom_conventions [name ] = convention
219+
220+ def unregister_convention (self , name ):
221+ """Unregister a custom calling convention."""
222+ self .custom_conventions .pop (name , None )
223+
186224 def register_converter (self , name , obj ):
187225 """Register a callable object as a converter.
188226
@@ -262,15 +300,16 @@ def create_pipe_from_dict(self, raw_data):
262300 """Create a pipe from a dictionary."""
263301 # Prepare functions
264302 funcs = parse_data (
303+ self ,
265304 raw_data ,
266305 (
267- (Key .BINARY , str , NO_DEFAULT ),
306+ (Key .BINARY , Key . as_str , NO_DEFAULT ),
268307 (Key .IDENTIFIER , Key .as_identifier , NO_DEFAULT ),
269308 (Key .ARGS , Key .as_args_tuple , ()),
270309 (Key .RETURN_TYPE , Key .as_return_type , DataType .VOID ),
271310 (Key .CONVENTION , Key .as_convention , Convention .CDECL ),
272311 (Key .SRV_CHECK , Key .as_bool , True ),
273- (Key .DOC , str , None )
312+ (Key .DOC , Key . as_str , None )
274313 )
275314 )
276315
@@ -308,14 +347,15 @@ def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
308347 """Create and registers a new type from a dictionary."""
309348 # Prepare general type information
310349 data = tuple (parse_data (
350+ self ,
311351 # Discard all subkeys and add the new dict to a another dict to
312352 # make it work with parse_data(). Okay, this can be improved...
313353 {0 : dict ((k , v ) for k , v in raw_data .items () if not isinstance (
314354 v , dict ))},
315355 (
316- (Key .BINARY , str , CustomType ._binary ),
356+ (Key .BINARY , Key . as_str , CustomType ._binary ),
317357 (Key .SRV_CHECK , Key .as_bool , CustomType ._srv_check ),
318- (Key .SIZE , int , CustomType ._size )
358+ (Key .SIZE , Key . as_int , CustomType ._size )
319359 )
320360 ))[0 ][1 ]
321361
@@ -324,11 +364,12 @@ def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
324364 # Prepare pointer and instance attributes
325365 for method in (self .instance_attribute , self .pointer_attribute ):
326366 attributes = parse_data (
367+ self ,
327368 raw_data .get (method .__name__ , {}),
328369 (
329370 (Key .TYPE_NAME , Key .as_attribute_type , NO_DEFAULT ),
330- (Key .OFFSET , int , NO_DEFAULT ),
331- (Key .DOC , str , None )
371+ (Key .OFFSET , Key . as_int , NO_DEFAULT ),
372+ (Key .DOC , Key . as_str , None )
332373 )
333374 )
334375
@@ -343,12 +384,13 @@ def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
343384 self .static_pointer_array ,
344385 self .dynamic_pointer_array ):
345386 arrays = parse_data (
387+ self ,
346388 raw_data .get (method .__name__ , {}),
347389 (
348390 (Key .TYPE_NAME , Key .as_attribute_type , NO_DEFAULT ),
349- (Key .OFFSET , int , NO_DEFAULT ),
350- (Key .LENGTH , int , None ),
351- (Key .DOC , str , None )
391+ (Key .OFFSET , Key . as_int , NO_DEFAULT ),
392+ (Key .LENGTH , Key . as_int , None ),
393+ (Key .DOC , Key . as_str , None )
352394 )
353395 )
354396
@@ -358,13 +400,14 @@ def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
358400
359401 # Prepare virtual functions
360402 vfuncs = parse_data (
403+ self ,
361404 raw_data .get ('virtual_function' , {}),
362405 (
363- (Key .OFFSET , int , NO_DEFAULT ),
406+ (Key .OFFSET , Key . as_int , NO_DEFAULT ),
364407 (Key .ARGS , Key .as_args_tuple , ()),
365408 (Key .RETURN_TYPE , Key .as_return_type , DataType .VOID ),
366409 (Key .CONVENTION , Key .as_convention , Convention .THISCALL ),
367- (Key .DOC , str , None )
410+ (Key .DOC , Key . as_str , None )
368411 )
369412 )
370413
@@ -374,13 +417,14 @@ def create_type_from_dict(self, type_name, raw_data, bases=(CustomType,)):
374417
375418 # Prepare functions
376419 funcs = parse_data (
420+ self ,
377421 raw_data .get ('function' , {}),
378422 (
379423 (Key .IDENTIFIER , Key .as_identifier , NO_DEFAULT ),
380424 (Key .ARGS , Key .as_args_tuple , ()),
381425 (Key .RETURN_TYPE , Key .as_return_type , DataType .VOID ),
382426 (Key .CONVENTION , Key .as_convention , Convention .THISCALL ),
383- (Key .DOC , str , None )
427+ (Key .DOC , Key . as_str , None )
384428 )
385429 )
386430
@@ -657,12 +701,13 @@ def create_function_typedefs_from_file(self, f):
657701
658702 # Prepare typedefs
659703 typedefs = parse_data (
704+ self ,
660705 raw_data ,
661706 (
662707 (Key .ARGS , Key .as_args_tuple , ()),
663708 (Key .RETURN_TYPE , Key .as_return_type , DataType .VOID ),
664709 (Key .CONVENTION , Key .as_convention , Convention .CDECL ),
665- (Key .DOC , str , None )
710+ (Key .DOC , Key . as_str , None )
666711 )
667712 )
668713
@@ -694,12 +739,13 @@ def create_global_pointers_from_file(self, f):
694739 """Create global pointers from a file."""
695740 # Parse pointer data
696741 pointers = parse_data (
742+ self ,
697743 ConfigObj (f , file_error = True ),
698744 (
699- (Key .BINARY , str , NO_DEFAULT ),
745+ (Key .BINARY , Key . as_str , NO_DEFAULT ),
700746 (Key .IDENTIFIER , Key .as_identifier , NO_DEFAULT ),
701- (Key .OFFSET , int , 0 ),
702- (Key .LEVEL , int , 0 ),
747+ (Key .OFFSET , Key . as_int , 0 ),
748+ (Key .LEVEL , Key . as_int , 0 ),
703749 (Key .SRV_CHECK , Key .as_bool , True ),
704750 )
705751 )
0 commit comments