pyclibrary.backends package

Submodules

pyclibrary.backends.ctypes module

Proxy to both CHeader and ctypes, allowing automatic type conversion and function calling based on C header definitions.

pyclibrary.backends.ctypes.make_mess(mess)[source]
class pyclibrary.backends.ctypes.CTypesCLibrary(lib, *args, **kwargs)[source]

Bases: pyclibrary.c_library.CLibrary

The CLibrary class is intended to automate much of the work in using ctypes by integrating header file definitions from CParser.

This class serves as a proxy to a ctypes object, adding a few features:
  • allows easy access to values defined via CParser

  • automatic type conversions for function calls using CParser function signatures

  • creates ctype classes based on type definitions from CParser

Initialize using a ctypes shared object and a CParser:

headers = CParser.winDefs() lib = CLibrary(windll.User32, headers)

There are 3 ways to access library elements:
lib(type, name):

type can be one of ‘values’, ‘functions’, ‘types’, ‘structs’, ‘unions’, or ‘enums’. Returns an object matching name. For values, the value from the headers is returned. For functions, a callable object is returned that handles automatic type conversion for arguments and return values. For structs, types, and enums, a ctypes class is returned matching the type specified.

lib.name:

searches in order through values, functions, types, structs, unions, and enums from header definitions and returns an object for the first match found. The object returned is the same as returned by lib(type, name). This is the preferred way to access elements from CLibrary, but may not work in some situations (for example, if a struct and variable share the same name).

lib[type]:

Accesses the header definitions directly, returns definition dictionaries based on the type requested. This is equivalent to headers.defs[type].

Parameters
  • lib – Library object.

  • headers (CParser) – CParser holding all the definitions.

  • prefix (unicode) – Prefix to remove from all definitions.

  • fix_case (bool) – Should name be converted from camelCase to python PEP8 compliants names.

Null = <object object>

Balise to use when a NULL pointer is needed

backend = 'ctypes'

Id of the backend

pyclibrary.backends.ctypes.init_clibrary(extra_types={})[source]
pyclibrary.backends.ctypes.identify_library(lib)[source]
pyclibrary.backends.ctypes.get_library_path(lib)[source]