コード例 #1
0
ファイル: geom.py プロジェクト: prihit/we-care

# ### OGR_G ctypes function prototypes ###

# GeoJSON routines.
from_json = geom_output(lgdal.OGR_G_CreateGeometryFromJson, [c_char_p])
to_json = string_output(lgdal.OGR_G_ExportToJson, [c_void_p], str_result=True, decoding='ascii')
to_kml = string_output(lgdal.OGR_G_ExportToKML, [c_void_p, c_char_p], str_result=True, decoding='ascii')

# GetX, GetY, GetZ all return doubles.
getx = pnt_func(lgdal.OGR_G_GetX)
gety = pnt_func(lgdal.OGR_G_GetY)
getz = pnt_func(lgdal.OGR_G_GetZ)

# Geometry creation routines.
from_wkb = geom_output(lgdal.OGR_G_CreateFromWkb, [c_char_p, c_void_p, POINTER(c_void_p), c_int], offset=-2)
from_wkt = geom_output(lgdal.OGR_G_CreateFromWkt, [POINTER(c_char_p), c_void_p, POINTER(c_void_p)], offset=-1)
from_gml = geom_output(lgdal.OGR_G_CreateFromGML, [c_char_p])
create_geom = geom_output(lgdal.OGR_G_CreateGeometry, [c_int])
clone_geom = geom_output(lgdal.OGR_G_Clone, [c_void_p])
get_geom_ref = geom_output(lgdal.OGR_G_GetGeometryRef, [c_void_p, c_int])
get_boundary = geom_output(lgdal.OGR_G_GetBoundary, [c_void_p])
geom_convex_hull = geom_output(lgdal.OGR_G_ConvexHull, [c_void_p])
geom_diff = geom_output(lgdal.OGR_G_Difference, [c_void_p, c_void_p])
geom_intersection = geom_output(lgdal.OGR_G_Intersection, [c_void_p, c_void_p])
geom_sym_diff = geom_output(lgdal.OGR_G_SymmetricDifference, [c_void_p, c_void_p])
geom_union = geom_output(lgdal.OGR_G_Union, [c_void_p, c_void_p])

# Geometry modification routines.
add_geom = void_output(lgdal.OGR_G_AddGeometry, [c_void_p, c_void_p])
import_wkt = void_output(lgdal.OGR_G_ImportFromWkt, [c_void_p, POINTER(c_char_p)])
コード例 #2
0
def register_library(library):
    #
    # Construction & Destruction
    #
    library.serialboxMetainfoCreate.argtypes = None
    library.serialboxMetainfoCreate.restype = POINTER(MetainfoImpl)

    library.serialboxMetainfoCreateFromMetainfo.argtypes = [
        POINTER(MetainfoImpl)
    ]
    library.serialboxMetainfoCreateFromMetainfo.restype = POINTER(MetainfoImpl)

    library.serialboxMetainfoDestroy.argtypes = [POINTER(MetainfoImpl)]
    library.serialboxMetainfoDestroy.restype = None

    #
    # Utility
    #
    library.serialboxMetainfoGetSize.argtypes = [POINTER(MetainfoImpl)]
    library.serialboxMetainfoGetSize.restype = c_int

    library.serialboxMetainfoIsEmpty.argtypes = [POINTER(MetainfoImpl)]
    library.serialboxMetainfoIsEmpty.restype = c_int

    library.serialboxMetainfoClear.argtypes = [POINTER(MetainfoImpl)]
    library.serialboxMetainfoClear.restype = None

    library.serialboxMetainfoEqual.argtypes = [
        POINTER(MetainfoImpl), POINTER(MetainfoImpl)
    ]
    library.serialboxMetainfoEqual.restype = c_int

    library.serialboxMetainfoHasKey.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoHasKey.restype = c_int

    library.serialboxMetainfoGetTypeIDOfKey.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetTypeIDOfKey.restype = c_int

    library.serialboxMetainfoToString.argtypes = [POINTER(MetainfoImpl)]
    library.serialboxMetainfoToString.restype = c_char_p

    library.serialboxMetainfoCreateElementInfo.argtypes = [
        POINTER(MetainfoImpl)
    ]
    library.serialboxMetainfoCreateElementInfo.restype = POINTER(
        MetainfoElementInfoImpl)

    library.serialboxMetainfoDestroyElementInfo.argtypes = [
        POINTER(MetainfoElementInfoImpl)
    ]
    library.serialboxMetainfoDestroyElementInfo.restype = None

    library.serialboxMetainfoDeleteKey.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoDeleteKey.restype = c_int

    #
    # Arrays
    #
    library.serialboxArrayOfBooleanCreate.argtypes = [c_int]
    library.serialboxArrayOfBooleanCreate.restype = POINTER(ArrayOfBooleanImpl)

    library.serialboxArrayOfInt32Create.argtypes = [c_int]
    library.serialboxArrayOfInt32Create.restype = POINTER(ArrayOfInt32Impl)

    library.serialboxArrayOfInt64Create.argtypes = [c_int]
    library.serialboxArrayOfInt64Create.restype = POINTER(ArrayOfInt64Impl)

    library.serialboxArrayOfFloat32Create.argtypes = [c_int]
    library.serialboxArrayOfFloat32Create.restype = POINTER(ArrayOfFloat32Impl)

    library.serialboxArrayOfFloat64Create.argtypes = [c_int]
    library.serialboxArrayOfFloat64Create.restype = POINTER(ArrayOfFloat64Impl)

    library.serialboxArrayOfStringCreate.argtypes = [c_int]
    library.serialboxArrayOfStringCreate.restype = POINTER(ArrayOfStringImpl)

    library.serialboxArrayOfBooleanDestroy.argtypes = [
        POINTER(ArrayOfBooleanImpl)
    ]
    library.serialboxArrayOfBooleanDestroy.restype = None

    library.serialboxArrayOfInt32Destroy.argtypes = [POINTER(ArrayOfInt32Impl)]
    library.serialboxArrayOfInt32Destroy.restype = None

    library.serialboxArrayOfInt64Destroy.argtypes = [POINTER(ArrayOfInt64Impl)]
    library.serialboxArrayOfInt64Destroy.restype = None

    library.serialboxArrayOfFloat32Destroy.argtypes = [
        POINTER(ArrayOfFloat32Impl)
    ]
    library.serialboxArrayOfFloat32Destroy.restype = None

    library.serialboxArrayOfFloat64Destroy.argtypes = [
        POINTER(ArrayOfFloat64Impl)
    ]
    library.serialboxArrayOfFloat64Destroy.restype = None

    library.serialboxArrayOfStringDestroy.argtypes = [
        POINTER(ArrayOfStringImpl)
    ]
    library.serialboxArrayOfStringDestroy.restype = None

    #
    # Add meta-information
    #
    library.serialboxMetainfoAddBoolean.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_bool
    ]
    library.serialboxMetainfoAddBoolean.restype = c_int

    library.serialboxMetainfoAddInt32.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_int32
    ]
    library.serialboxMetainfoAddInt32.restype = c_int

    library.serialboxMetainfoAddInt64.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_int64
    ]
    library.serialboxMetainfoAddInt64.restype = c_int

    library.serialboxMetainfoAddFloat32.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_float
    ]
    library.serialboxMetainfoAddFloat32.restype = c_int

    library.serialboxMetainfoAddFloat64.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_double
    ]
    library.serialboxMetainfoAddFloat64.restype = c_int

    library.serialboxMetainfoAddString.argtypes = [
        POINTER(MetainfoImpl), c_char_p, c_char_p
    ]
    library.serialboxMetainfoAddString.restype = c_int

    library.serialboxMetainfoAddArrayOfBoolean.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfBooleanImpl)
    ]
    library.serialboxMetainfoAddArrayOfBoolean.restype = c_int

    library.serialboxMetainfoAddArrayOfInt32.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfInt32Impl)
    ]
    library.serialboxMetainfoAddArrayOfInt32.restype = c_int

    library.serialboxMetainfoAddArrayOfInt64.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfInt64Impl)
    ]
    library.serialboxMetainfoAddArrayOfInt64.restype = c_int

    library.serialboxMetainfoAddArrayOfFloat32.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfFloat32Impl)
    ]
    library.serialboxMetainfoAddArrayOfFloat32.restype = c_int

    library.serialboxMetainfoAddArrayOfFloat64.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfFloat64Impl)
    ]
    library.serialboxMetainfoAddArrayOfFloat64.restype = c_int

    library.serialboxMetainfoAddArrayOfString.argtypes = [
        POINTER(MetainfoImpl), c_char_p,
        POINTER(ArrayOfStringImpl)
    ]
    library.serialboxMetainfoAddArrayOfString.restype = c_int

    #
    # Query meta-information
    #
    library.serialboxMetainfoGetBoolean.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetBoolean.restype = c_int

    library.serialboxMetainfoGetInt32.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetInt32.restype = c_int32

    library.serialboxMetainfoGetInt64.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetInt64.restype = c_int64

    library.serialboxMetainfoGetFloat32.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetFloat32.restype = c_float

    library.serialboxMetainfoGetFloat64.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetFloat64.restype = c_double

    library.serialboxMetainfoGetString.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetString.restype = c_char_p

    library.serialboxMetainfoGetArrayOfBoolean.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfBoolean.restype = POINTER(
        ArrayOfBooleanImpl)

    library.serialboxMetainfoGetArrayOfInt32.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfInt32.restype = POINTER(
        ArrayOfInt32Impl)

    library.serialboxMetainfoGetArrayOfInt64.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfInt64.restype = POINTER(
        ArrayOfInt64Impl)

    library.serialboxMetainfoGetArrayOfFloat32.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfFloat32.restype = POINTER(
        ArrayOfFloat32Impl)

    library.serialboxMetainfoGetArrayOfFloat64.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfFloat64.restype = POINTER(
        ArrayOfFloat64Impl)

    library.serialboxMetainfoGetArrayOfString.argtypes = [
        POINTER(MetainfoImpl), c_char_p
    ]
    library.serialboxMetainfoGetArrayOfString.restype = POINTER(
        ArrayOfStringImpl)
コード例 #3
0
def parse_vector(s):
    status = c_int()
    val = rccall("R_ParseVector", c_void_p,
                 [c_void_p, c_int, POINTER(c_int), c_void_p], s, -1, status,
                 rcglobal("R_NilValue"))
    return val, status.value
コード例 #4
0
class ArrayOfBooleanImpl(Structure):
    """ Mapping of serialboxArrayOfBoolean_t """
    _fields_ = [("data", POINTER(c_int)), ("len", c_int)]
コード例 #5
0
class ArrayOfFloat64Impl(Structure):
    """ Mapping of serialboxArrayOfFloat64_t """
    _fields_ = [("data", POINTER(c_double)), ("len", c_int)]
コード例 #6
0
ファイル: bootstrap.py プロジェクト: arbor/vmcloak
        ('dmLogPixels', c_ushort),
        ('dmBitsPerPel', c_ushort),
        ('dmPelsWidth', c_uint),
        ('dmPelsHeight', c_uint),
        ('unused2', c_uint * 10),
    ]

class UNICODE_STRING(Structure):
    _fields_ = [
        ('Length', c_ushort),
        ('MaximumLength', c_ushort),
        ('Buffer', c_wchar_p),
    ]

EnumDisplaySettings = windll.user32.EnumDisplaySettingsA
EnumDisplaySettings.argtypes = c_char_p, c_uint, POINTER(_DevMode)

ChangeDisplaySettings = windll.user32.ChangeDisplaySettingsA
ChangeDisplaySettings.argtypes = POINTER(_DevMode), c_uint

NtRenameKey = windll.ntdll.NtRenameKey
NtRenameKey.argtypes = HANDLE, POINTER(UNICODE_STRING)

RegOpenKeyExW = windll.advapi32.RegOpenKeyExW
RegOpenKeyExW.argtypes = HANDLE, LPCWSTR, DWORD, ULONG, POINTER(HANDLE)
RegOpenKeyExW.restype = LONG

RegCloseKey = windll.advapi32.RegCloseKey
RegCloseKey.argtypes = HANDLE,

ENUM_CURRENT_SETTINGS = -1
コード例 #7
0
def to_gml3(OGRGeom):
    gml3_capi = string_output(lgdal.OGR_G_ExportToGMLEx,
                              [c_void_p, POINTER(c_char_p)],
                              str_result=True,
                              decoding='ascii')
    return gml3_capi(OGRGeom.ptr, byref(c_char_p('FORMAT=GML3'.encode())))
コード例 #8
0
else:
    PY3 = False

stdin = sys.stdin
stdout = sys.stdout
stderr = sys.stderr
argv = sys.argv

original_stderr = sys.stderr

if OSWIN32:
    from ctypes import WINFUNCTYPE, windll, POINTER
    from ctypes.wintypes import BOOL, HANDLE, DWORD, LPWSTR, LPCWSTR

try:
    ReadConsoleW = WINFUNCTYPE(BOOL, HANDLE, LPVOID, DWORD, POINTER(DWORD),
                               LPVOID)(("ReadConsoleW", windll.kernel32))
    WriteConsoleW = WINFUNCTYPE(BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD),
                                LPVOID)(("WriteConsoleW", windll.kernel32))
except NameError:
    ReadConsoleW = WriteConsoleW = None


class UnicodeInput(IOBase):
    """Unicode terminal input class."""
    def __init__(self, hConsole, name, bufsize=1024):
        """Initialize the input stream."""
        self._hConsole = hConsole
        self.bufsize = bufsize
        self.buffer = create_unicode_buffer(bufsize)
        self.name = name
コード例 #9
0
def get_unicode_console():
    """
    Get Unicode console objects.

    @return: stdin, stdout, stderr, argv
    @rtype: tuple
    """
    # Make Unicode console output work independently of the current code page.
    # This also fixes <http://bugs.python.org/issue1602>.
    # Credit to Michael Kaplan <http://blogs.msdn.com/b/michkap/archive/2010/04/07/9989346.aspx>
    # and TZOmegaTZIOY
    # <https://stackoverflow.com/questions/878972/windows-cmd-encoding-change-causes-python-crash/1432462#1432462>.

    global stdin, stdout, stderr, argv

    if not OSWIN32:
        return stdin, stdout, stderr, argv

    try:
        # <https://msdn.microsoft.com/en-us/library/ms683231(VS.85).aspx>
        # HANDLE WINAPI GetStdHandle(DWORD nStdHandle);
        # returns INVALID_HANDLE_VALUE, NULL, or a valid handle
        #
        # <https://msdn.microsoft.com/en-us/library/aa364960(VS.85).aspx>
        # DWORD WINAPI GetFileType(DWORD hFile);
        #
        # <https://msdn.microsoft.com/en-us/library/ms683167(VS.85).aspx>
        # BOOL WINAPI GetConsoleMode(HANDLE hConsole, LPDWORD lpMode);

        GetStdHandle = WINFUNCTYPE(HANDLE,
                                   DWORD)(("GetStdHandle", windll.kernel32))
        STD_INPUT_HANDLE = DWORD(-10)
        STD_OUTPUT_HANDLE = DWORD(-11)
        STD_ERROR_HANDLE = DWORD(-12)
        GetFileType = WINFUNCTYPE(DWORD,
                                  DWORD)(("GetFileType", windll.kernel32))
        FILE_TYPE_CHAR = 0x0002
        FILE_TYPE_REMOTE = 0x8000
        GetConsoleMode = (WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
            ("GetConsoleMode", windll.kernel32)))
        INVALID_HANDLE_VALUE = DWORD(-1).value

        def not_a_console(handle):
            """Return whether the handle is not to a console."""
            if handle == INVALID_HANDLE_VALUE or handle is None:
                return True
            return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR
                    or GetConsoleMode(handle, byref(DWORD())) == 0)

        old_stdin_fileno = old_fileno('in')
        old_stdout_fileno = old_fileno('out')
        old_stderr_fileno = old_fileno('err')

        STDIN_FILENO = 0
        STDOUT_FILENO = 1
        STDERR_FILENO = 2
        real_stdin = (old_stdin_fileno == STDIN_FILENO)
        real_stdout = (old_stdout_fileno == STDOUT_FILENO)
        real_stderr = (old_stderr_fileno == STDERR_FILENO)

        if real_stdin:
            hStdin = GetStdHandle(STD_INPUT_HANDLE)
            if not_a_console(hStdin):
                real_stdin = False

        if real_stdout:
            hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
            if not_a_console(hStdout):
                real_stdout = False

        if real_stderr:
            hStderr = GetStdHandle(STD_ERROR_HANDLE)
            if not_a_console(hStderr):
                real_stderr = False

        if real_stdout or real_stderr:
            if real_stdin:
                stdin = UnicodeInput(hStdin, name='<Unicode console stdin>')

            if real_stdout:
                stdout = UnicodeOutput(hStdout, sys.stdout, STDOUT_FILENO,
                                       '<Unicode console stdout>')
            else:
                stdout = UnicodeOutput(None, sys.stdout, old_stdout_fileno,
                                       '<Unicode redirected stdout>')

            if real_stderr:
                stderr = UnicodeOutput(hStderr, sys.stderr, STDERR_FILENO,
                                       '<Unicode console stderr>')
            else:
                stderr = UnicodeOutput(None, sys.stderr, old_stderr_fileno,
                                       '<Unicode redirected stderr>')
    except Exception as e:
        _complain("exception %r while fixing up sys.stdout and sys.stderr" %
                  (e, ))

    # While we're at it, let's unmangle the command-line arguments:

    # This works around <http://bugs.python.org/issue2128>.
    GetCommandLineW = WINFUNCTYPE(LPWSTR)(("GetCommandLineW", windll.kernel32))
    CommandLineToArgvW = (WINFUNCTYPE(POINTER(LPWSTR), LPCWSTR,
                                      POINTER(c_int))(("CommandLineToArgvW",
                                                       windll.shell32)))

    argc = c_int(0)
    argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))

    argv = [argv_unicode[i].encode('utf-8') for i in range(0, argc.value)]

    if not hasattr(sys, 'frozen'):
        # If this is an executable produced by py2exe or bbfreeze, then it will
        # have been invoked directly. Otherwise, unicode_argv[0] is the Python
        # interpreter, so skip that.
        argv = argv[1:]

        # Also skip option arguments to the Python interpreter.
        while len(argv) > 0:
            arg = argv[0]
            if not arg.startswith(b"-") or arg == u"-":
                break
            argv = argv[1:]
            if arg == u'-m':
                # sys.argv[0] should really be the absolute path of the module source,
                # but never mind
                break
            if arg == u'-c':
                argv[0] = u'-c'
                break

    if argv == []:
        argv = [u'']

    return stdin, stdout, stderr, argv
コード例 #10
0
from analysis import request_graph

# Define the C interface
patch_subset = cdll.LoadLibrary('./patch_subset/py/patch_subset_session.so')  # pylint: disable=invalid-name


class RECORD(Structure):
    _fields_ = [("request_size", c_uint32), ("response_size", c_uint32)]


new_session = patch_subset.PatchSubsetSession_new  # pylint: disable=invalid-name
new_session.restype = c_void_p
extend = patch_subset.PatchSubsetSession_extend  # pylint: disable=invalid-name
extend.restype = c_bool
get_font_bytes = patch_subset.PatchSubsetSession_get_font  # pylint: disable=invalid-name
get_font_bytes.restype = POINTER(c_ubyte)
get_requests = patch_subset.PatchSubsetSession_get_requests  # pylint: disable=invalid-name
get_requests.restype = POINTER(RECORD)

Record = collections.namedtuple("Record", ["request_size", "response_size"])
Config = collections.namedtuple("Config", [
    "remap_codepoints", "max_predicted_codepoints",
    "prediction_frequency_threshold"
])


def create_with_codepoint_remapping():
    return PatchSubsetMethod(Config(True, 0, 0.0))


def create_with_codepoint_prediction(max_predicted, threshold):
コード例 #11
0
            return str(self.sa_sin6)
        elif family == 18:  # AF_LINK
            return str(self.sa_sdl)
        else:
            print(family)
            raise NotImplementedError(
                    "address family %d not supported" % family
                    )


class ifaddrs(Structure):
    pass


ifaddrs._fields_ = [
    ('ifa_next',        POINTER(ifaddrs)),
    ('ifa_name',        c_char_p),
    ('ifa_flags',       c_uint),
    ('ifa_addr',        POINTER(sockaddr)),
    ('ifa_netmask',     POINTER(sockaddr)),
    ('ifa_dstaddr',     POINTER(sockaddr)),
    ('ifa_data',        c_void_p)
]

# Define constants for the most useful interface flags (from if.h).
IFF_UP = 0x0001
IFF_BROADCAST = 0x0002
IFF_LOOPBACK = 0x0008
IFF_POINTTOPOINT = 0x0010
IFF_RUNNING = 0x0040
if sys.platform == 'darwin' or 'bsd' in sys.platform:
コード例 #12
0
ファイル: types.py プロジェクト: RajatRasal/devito
 def _generate_unique_dtype(cls, pname, ptype, pfields):
     dtype = POINTER(type(pname, (ptype,), {'_fields_': pfields}))
     key = (pname, ptype, tuple(pfields))
     return cls._dtype_cache.setdefault(key, dtype)
コード例 #13
0
ファイル: pmcc.py プロジェクト: wuliming/pcp
 def get_vlist(self, vset, vlist_idx):
     """ Return the vlist[vlist_idx] of vset[vset_idx] """
     listptr = cast(vset.contents.vlist, POINTER(pmValue))
     return listptr[vlist_idx]
コード例 #14
0
from ctypes import c_double, c_int, POINTER, Structure, CDLL

_c_double_p = POINTER(c_double)

MAX_PATH_LENGTH = 100


class HybridAStarInitialConditions(Structure):
    _fields_ = [("x_start", c_double), ("y_start", c_double),
                ("yaw_start", c_double), ("x_end", c_double),
                ("y_end", c_double), ("yaw_end", c_double),
                ("o_llx", _c_double_p), ("o_lly", _c_double_p),
                ("o_urx", _c_double_p), ("o_ury", _c_double_p), ("no", c_int)]


class HybridAStarReturnValues(Structure):
    _fields_ = [("success", c_int), ("x_path", c_double * MAX_PATH_LENGTH),
                ("y_path", c_double * MAX_PATH_LENGTH),
                ("yaw_path", c_double * MAX_PATH_LENGTH)]


class HybridAStarHyperparameters(Structure):
    _fields_ = [
        ("step_size", c_double),
        ("max_iterations", c_int),
        ("completion_threshold", c_double),
        ("angle_completion_threshold", c_double),
        ("rad_step", c_double),
        ("rad_upper_range", c_double),
        ("rad_lower_range", c_double),
        ("obstacle_clearance", c_double),
コード例 #15
0
ファイル: linker.py プロジェクト: seth1002/llvmlite
from __future__ import print_function, absolute_import
from ctypes import c_int, c_char_p, POINTER
from . import ffi


def link_modules(dst, src):
    dst.verify()
    src.verify()
    with ffi.OutputString() as outerr:
        err = ffi.lib.LLVMPY_LinkModules(dst, src, outerr)
        # The underlying module was destroyed
        src.detach()
        if err:
            raise RuntimeError(str(outerr))


ffi.lib.LLVMPY_LinkModules.argtypes = [
    ffi.LLVMModuleRef,
    ffi.LLVMModuleRef,
    POINTER(c_char_p),
]

ffi.lib.LLVMPY_LinkModules.restype = c_int
コード例 #16
0
def register_library(library):
    """Register function prototypes with LLVM library instance."""

    # Object.h functions
    library.LLVMCreateObjectFile.argtypes = [MemoryBuffer]
    library.LLVMCreateObjectFile.restype = c_object_p

    library.LLVMDisposeObjectFile.argtypes = [ObjectFile]

    library.LLVMGetSections.argtypes = [ObjectFile]
    library.LLVMGetSections.restype = c_object_p

    library.LLVMDisposeSectionIterator.argtypes = [c_object_p]

    library.LLVMIsSectionIteratorAtEnd.argtypes = [ObjectFile, c_object_p]
    library.LLVMIsSectionIteratorAtEnd.restype = bool

    library.LLVMMoveToNextSection.argtypes = [c_object_p]

    library.LLVMMoveToContainingSection.argtypes = [c_object_p, c_object_p]

    library.LLVMGetSymbols.argtypes = [ObjectFile]
    library.LLVMGetSymbols.restype = c_object_p

    library.LLVMDisposeSymbolIterator.argtypes = [c_object_p]

    library.LLVMIsSymbolIteratorAtEnd.argtypes = [ObjectFile, c_object_p]
    library.LLVMIsSymbolIteratorAtEnd.restype = bool

    library.LLVMMoveToNextSymbol.argtypes = [c_object_p]

    library.LLVMGetSectionName.argtypes = [c_object_p]
    library.LLVMGetSectionName.restype = c_char_p

    library.LLVMGetSectionSize.argtypes = [c_object_p]
    library.LLVMGetSectionSize.restype = c_uint64

    library.LLVMGetSectionContents.argtypes = [c_object_p]
    # Can't use c_char_p here as it isn't a NUL-terminated string.
    library.LLVMGetSectionContents.restype = POINTER(c_char)

    library.LLVMGetSectionAddress.argtypes = [c_object_p]
    library.LLVMGetSectionAddress.restype = c_uint64

    library.LLVMGetSectionContainsSymbol.argtypes = [c_object_p, c_object_p]
    library.LLVMGetSectionContainsSymbol.restype = bool

    library.LLVMGetRelocations.argtypes = [c_object_p]
    library.LLVMGetRelocations.restype = c_object_p

    library.LLVMDisposeRelocationIterator.argtypes = [c_object_p]

    library.LLVMIsRelocationIteratorAtEnd.argtypes = [c_object_p, c_object_p]
    library.LLVMIsRelocationIteratorAtEnd.restype = bool

    library.LLVMMoveToNextRelocation.argtypes = [c_object_p]

    library.LLVMGetSymbolName.argtypes = [Symbol]
    library.LLVMGetSymbolName.restype = c_char_p

    library.LLVMGetSymbolAddress.argtypes = [Symbol]
    library.LLVMGetSymbolAddress.restype = c_uint64

    library.LLVMGetSymbolSize.argtypes = [Symbol]
    library.LLVMGetSymbolSize.restype = c_uint64

    library.LLVMGetRelocationOffset.argtypes = [c_object_p]
    library.LLVMGetRelocationOffset.restype = c_uint64

    library.LLVMGetRelocationSymbol.argtypes = [c_object_p]
    library.LLVMGetRelocationSymbol.restype = c_object_p

    library.LLVMGetRelocationType.argtypes = [c_object_p]
    library.LLVMGetRelocationType.restype = c_uint64

    library.LLVMGetRelocationTypeName.argtypes = [c_object_p]
    library.LLVMGetRelocationTypeName.restype = c_char_p

    library.LLVMGetRelocationValueString.argtypes = [c_object_p]
    library.LLVMGetRelocationValueString.restype = c_char_p
コード例 #17
0
# https://publicwiki.deltares.nl/display/~baart_f/2011/10/23/Calling+fortran+from+python
#

import numpy as np
from ctypes import (CDLL, POINTER, ARRAY, c_void_p, c_int, byref, c_double,
                    c_char, c_char_p, create_string_buffer)
from numpy.ctypeslib import ndpointer
import os

# dllpath = os.path.abspath("libtest.so") # or .dll or .so
# libtest = CDLL(dllpath)
libtest = CDLL('./libtest.so')

# Define some extra types
# pointer to a double
c_double_p = POINTER(c_double)
# pointer to a integer
c_int_p = POINTER(c_int)

shape2x2 = (2, 2)
# Pointer to a 2x2 double in fortran layout
c_double2x2_f = ndpointer(shape=shape2x2, dtype="double", flags="FORTRAN")
c_double2x2_c = ndpointer(shape=shape2x2, dtype="double", flags="C")
# Pointer to a pointer to a 10x10 double in fortran layout
c_double2x2_f_p = POINTER(c_double2x2_f)
c_double2x2_c_p = POINTER(c_double2x2_c)
shape3x2 = (3, 2)
shape2x3 = (2, 3)
# Pointer to a 2x3,3x2 double in fortran layout
c_double2x3_f = ndpointer(shape=shape2x3, dtype="double", flags="FORTRAN")
c_double3x2_f = ndpointer(shape=shape3x2, dtype="double", flags="FORTRAN")
コード例 #18
0
    libogg = ExternalLibrary.load(
        "ogg", tests=[lambda lib: hasattr(lib, "oggpack_writeinit")])
except ExternalLibraryError:
    pass
except:
    _print_exc()

if libogg:
    PYOGG_OGG_AVAIL = True
else:
    PYOGG_OGG_AVAIL = False

if PYOGG_OGG_AVAIL:

    # ctypes
    c_ubyte_p = POINTER(c_ubyte)
    c_uchar = c_ubyte
    c_uchar_p = c_ubyte_p
    c_float_p = POINTER(c_float)
    c_float_p_p = POINTER(c_float_p)
    c_float_p_p_p = POINTER(c_float_p_p)
    c_char_p_p = POINTER(c_char_p)
    c_int_p = POINTER(c_int)
    c_long_p = POINTER(c_long)

    # os_types
    ogg_int16_t = c_int16
    ogg_uint16_t = c_uint16
    ogg_int32_t = c_int32
    ogg_uint32_t = c_uint32
    ogg_int64_t = c_int64
コード例 #19
0
ファイル: win32.py プロジェクト: jpwroberts/colorama
                , self.dwCursorPosition.Y, self.dwCursorPosition.X
                , self.wAttributes
                , self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right
                , self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
            )

    _GetStdHandle = windll.kernel32.GetStdHandle
    _GetStdHandle.argtypes = [
        wintypes.DWORD,
    ]
    _GetStdHandle.restype = wintypes.HANDLE

    _GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
    _GetConsoleScreenBufferInfo.argtypes = [
        wintypes.HANDLE,
        POINTER(CONSOLE_SCREEN_BUFFER_INFO),
    ]
    _GetConsoleScreenBufferInfo.restype = wintypes.BOOL

    _SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
    _SetConsoleTextAttribute.argtypes = [
        wintypes.HANDLE,
        wintypes.WORD,
    ]
    _SetConsoleTextAttribute.restype = wintypes.BOOL

    _SetConsoleCursorPosition = windll.kernel32.SetConsoleCursorPosition
    _SetConsoleCursorPosition.argtypes = [
        wintypes.HANDLE,
        COORD,
    ]
コード例 #20
0
ファイル: setupapi.py プロジェクト: rnestler/pyjoulescope
        ("device_path", WCHAR * 1),  # variable size character array
    ]

    def __init__(self):
        Structure.__init__(self)
        self.cb_size = sizeof(self)


# HDEVINFO SetupDiGetClassDevs(
#   _In_opt_ const GUID   *ClassGuid,
#   _In_opt_       PCTSTR Enumerator,
#   _In_opt_       HWND   hwndParent,
#   _In_           DWORD  Flags);
SetupDiGetClassDevs = _setupapi.SetupDiGetClassDevsW
SetupDiGetClassDevs.restype = HANDLE
SetupDiGetClassDevs.argtypes = [POINTER(GUID), c_wchar_p, HANDLE, DWORD]

# BOOL SetupDiEnumDeviceInterfaces(
#   _In_           HDEVINFO                  DeviceInfoSet,
#   _In_opt_       PSP_DEVINFO_DATA          DeviceInfoData,
#   _In_     const GUID                      *InterfaceClassGuid,
#   _In_           DWORD                     MemberIndex,
#   _Out_          PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
SetupDiEnumDeviceInterfaces = _setupapi.SetupDiEnumDeviceInterfaces
SetupDiEnumDeviceInterfaces.restype = BOOL
SetupDiEnumDeviceInterfaces.argtypes = [
    c_void_p,
    POINTER(SpDevinfoData),
    POINTER(GUID), DWORD,
    POINTER(SpDeviceInterfaceData)
]
コード例 #21
0
class MetainfoElementInfoImpl(Structure):
    """ Mapping of serialboxMetainfoElementInfo_t """
    _fields_ = [("keys", POINTER(c_char_p)), ("types", POINTER(c_int)),
                ("len", c_int)]
コード例 #22
0
ファイル: ansiterm.py プロジェクト: zxc524580210/audacity
import sys,os
try:
	if not(sys.stderr.isatty()and sys.stdout.isatty()):
		raise ValueError('not a tty')
	from ctypes import Structure,windll,c_short,c_ushort,c_ulong,c_int,byref,POINTER,c_long,c_wchar
	class COORD(Structure):
		_fields_=[("X",c_short),("Y",c_short)]
	class SMALL_RECT(Structure):
		_fields_=[("Left",c_short),("Top",c_short),("Right",c_short),("Bottom",c_short)]
	class CONSOLE_SCREEN_BUFFER_INFO(Structure):
		_fields_=[("Size",COORD),("CursorPosition",COORD),("Attributes",c_short),("Window",SMALL_RECT),("MaximumWindowSize",COORD)]
	class CONSOLE_CURSOR_INFO(Structure):
		_fields_=[('dwSize',c_ulong),('bVisible',c_int)]
	windll.kernel32.GetStdHandle.argtypes=[c_ulong]
	windll.kernel32.GetStdHandle.restype=c_ulong
	windll.kernel32.GetConsoleScreenBufferInfo.argtypes=[c_ulong,POINTER(CONSOLE_SCREEN_BUFFER_INFO)]
	windll.kernel32.GetConsoleScreenBufferInfo.restype=c_long
	windll.kernel32.SetConsoleTextAttribute.argtypes=[c_ulong,c_ushort]
	windll.kernel32.SetConsoleTextAttribute.restype=c_long
	windll.kernel32.FillConsoleOutputCharacterW.argtypes=[c_ulong,c_wchar,c_ulong,POINTER(COORD),POINTER(c_ulong)]
	windll.kernel32.FillConsoleOutputCharacterW.restype=c_long
	windll.kernel32.FillConsoleOutputAttribute.argtypes=[c_ulong,c_ushort,c_ulong,POINTER(COORD),POINTER(c_ulong)]
	windll.kernel32.FillConsoleOutputAttribute.restype=c_long
	windll.kernel32.SetConsoleCursorPosition.argtypes=[c_ulong,POINTER(COORD)]
	windll.kernel32.SetConsoleCursorPosition.restype=c_long
	windll.kernel32.SetConsoleCursorInfo.argtypes=[c_ulong,POINTER(CONSOLE_CURSOR_INFO)]
	windll.kernel32.SetConsoleCursorInfo.restype=c_long
	sbinfo=CONSOLE_SCREEN_BUFFER_INFO()
	csinfo=CONSOLE_CURSOR_INFO()
	hconsole=windll.kernel32.GetStdHandle(-11)
	windll.kernel32.GetConsoleScreenBufferInfo(hconsole,byref(sbinfo))
コード例 #23
0
class ArrayOfFloat32Impl(Structure):
    """ Mapping of serialboxArrayOfFloat32_t """
    _fields_ = [("data", POINTER(c_float)), ("len", c_int)]
コード例 #24
0
ファイル: threading.py プロジェクト: yuemingl/ode-python-1
# -*- coding: utf-8 -*-

from ctypes import Structure
from ctypes import POINTER
from ctypes import CFUNCTYPE
from ctypes import c_int32
from ctypes import c_uint32
from ctypes import c_char
from ctypes import c_void_p
from ctypes import c_uint64

class dxThreadingImplementation(Structure):
    pass

dThreadingImplementationID = POINTER(dxThreadingImplementation)

dmutexindex_t = c_uint32

class dxMutexGroup(Structure):
    pass

dMutexGroupID = POINTER(dxMutexGroup)

dMutexGroupAllocFunction = CFUNCTYPE(dMutexGroupID, dThreadingImplementationID, dmutexindex_t, POINTER(POINTER(c_char)))
dMutexGroupFreeFunction = CFUNCTYPE(None, dThreadingImplementationID, dMutexGroupID)
dMutexGroupMutexLockFunction = CFUNCTYPE(None, dThreadingImplementationID, dMutexGroupID, dmutexindex_t)
dMutexGroupMutexUnlockFunction = CFUNCTYPE(None, dThreadingImplementationID, dMutexGroupID, dmutexindex_t)

class dxCallReleasee(Structure):
    pass
コード例 #25
0
class ArrayOfStringImpl(Structure):
    """ Mapping of serialboxArrayOfString_t """
    _fields_ = [("data", POINTER(c_char_p)), ("len", c_int)]
コード例 #26
0
class CGrammarError(Structure):
    _fields_ = [("errorCode", c_int), ("errorLevel", c_int),
                ("errorDescription", c_char_p), ("startPos", c_size_t),
                ("errorLen", c_size_t), ("suggestions", POINTER(c_char_p))]


voikko = Voikko()
voikko.lib.voikko_set_string_option.argtypes = [c_int, c_int, c_char_p]
voikko.lib.voikko_set_string_option.restype = c_int

voikko.lib.voikko_spell_cstr.argtypes = [c_int, c_char_p]
voikko.lib.voikko_spell_cstr.restype = c_int

voikko.lib.voikko_suggest_cstr.argtypes = [c_int, c_char_p]
voikko.lib.voikko_suggest_cstr.restype = POINTER(c_char_p)

voikko.lib.voikko_hyphenate_cstr.argtypes = [c_int, c_char_p]
voikko.lib.voikko_hyphenate_cstr.restype = POINTER(c_char)

voikko.lib.voikko_next_token_cstr.argtypes = [
    c_int, c_char_p, c_size_t, POINTER(c_size_t)
]
voikko.lib.voikko_next_token_cstr.restype = c_int

voikko.lib.voikko_next_sentence_start_ucs4.argtypes = [
    c_int, c_wchar_p, c_size_t, POINTER(c_size_t)
]
voikko.lib.voikko_next_sentence_start_ucs4.restype = c_int

voikko.lib.voikko_next_sentence_start_cstr.argtypes = [
コード例 #27
0
    def getdirinfo(path):
        import ctypes
        from ctypes import c_void_p, c_wchar_p, Structure, WinError, POINTER
        from ctypes.wintypes import DWORD, HANDLE, BOOL

        # NOTE: use this flag to open symlink itself and not the target
        # See https://docs.microsoft.com/en-us/windows/desktop/api/
        # fileapi/nf-fileapi-createfilew#symbolic-link-behavior
        FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000

        FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
        FILE_SHARE_READ = 0x00000001
        OPEN_EXISTING = 3

        class FILETIME(Structure):
            _fields_ = [("dwLowDateTime", DWORD), ("dwHighDateTime", DWORD)]

        class BY_HANDLE_FILE_INFORMATION(Structure):
            _fields_ = [
                ("dwFileAttributes", DWORD),
                ("ftCreationTime", FILETIME),
                ("ftLastAccessTime", FILETIME),
                ("ftLastWriteTime", FILETIME),
                ("dwVolumeSerialNumber", DWORD),
                ("nFileSizeHigh", DWORD),
                ("nFileSizeLow", DWORD),
                ("nNumberOfLinks", DWORD),
                ("nFileIndexHigh", DWORD),
                ("nFileIndexLow", DWORD),
            ]

        flags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT

        func = ctypes.windll.kernel32.CreateFileW
        func.argtypes = [
            c_wchar_p,
            DWORD,
            DWORD,
            c_void_p,
            DWORD,
            DWORD,
            HANDLE,
        ]
        func.restype = HANDLE

        hfile = func(path, 0, FILE_SHARE_READ, None, OPEN_EXISTING, flags,
                     None)
        if hfile is None:
            raise WinError()

        func = ctypes.windll.kernel32.GetFileInformationByHandle
        func.argtypes = [HANDLE, POINTER(BY_HANDLE_FILE_INFORMATION)]
        func.restype = BOOL

        info = BY_HANDLE_FILE_INFORMATION()
        rv = func(hfile, info)

        func = ctypes.windll.kernel32.CloseHandle
        func.argtypes = [HANDLE]
        func.restype = BOOL

        func(hfile)

        if rv == 0:
            raise WinError()

        return info
コード例 #28
0
class CGrammarError(Structure):
    _fields_ = [("errorCode", c_int), ("errorLevel", c_int),
                ("errorDescription", c_char_p), ("startPos", c_size_t),
                ("errorLen", c_size_t), ("suggestions", POINTER(c_char_p))]
コード例 #29
0
swresample = pyglet.lib.load_library('swresample',
                                     win32=('swresample-4', 'swresample-3'),
                                     darwin=('swresample.4', 'swresample.3'))

swresample.swresample_version.restype = c_int

compat.set_version('swresample', swresample.swresample_version() >> 16)

SWR_CH_MAX = 32


class SwrContext(Structure):
    pass


swresample.swr_alloc_set_opts.restype = POINTER(SwrContext)
swresample.swr_alloc_set_opts.argtypes = [
    POINTER(SwrContext), c_int64, c_int, c_int, c_int64, c_int, c_int, c_int,
    c_void_p
]
swresample.swr_init.restype = c_int
swresample.swr_init.argtypes = [POINTER(SwrContext)]
swresample.swr_free.argtypes = [POINTER(POINTER(SwrContext))]
swresample.swr_convert.restype = c_int
swresample.swr_convert.argtypes = [
    POINTER(SwrContext),
    POINTER(c_uint8) * SWR_CH_MAX, c_int,
    POINTER(POINTER(c_uint8)), c_int
]
swresample.swr_set_compensation.restype = c_int
swresample.swr_set_compensation.argtypes = [POINTER(SwrContext), c_int, c_int]
コード例 #30
0
ファイル: glfw.py プロジェクト: mkvenkit/pp2e
def glfwGetJoystickButtons(joy):
    count = c_int(0)
    _glfw.glfwGetJoystickButtons.restype = POINTER(c_int)
    c_buttons = _glfw.glfwGetJoystickButtons(joy, byref(count))
    buttons = [c_buttons[i].value for i in range(count)]
    return buttons