1import os
2from ctypes import *
3from ctypes.util import find_library
4
5isl_dyld_library_path = os.environ.get('ISL_DYLD_LIBRARY_PATH')
6if isl_dyld_library_path != None:
7    os.environ['DYLD_LIBRARY_PATH'] =  isl_dyld_library_path
8try:
9    isl = cdll.LoadLibrary(isl_dlname)
10except:
11    isl = cdll.LoadLibrary(find_library("isl"))
12libc = cdll.LoadLibrary(find_library("c"))
13
14class Error(Exception):
15    pass
16
17class Context:
18    defaultInstance = None
19
20    def __init__(self):
21        ptr = isl.isl_ctx_alloc()
22        self.ptr = ptr
23
24    def __del__(self):
25        isl.isl_ctx_free(self)
26
27    def from_param(self):
28        return c_void_p(self.ptr)
29
30    @staticmethod
31    def getDefaultInstance():
32        if Context.defaultInstance == None:
33            Context.defaultInstance = Context()
34        return Context.defaultInstance
35
36isl.isl_ctx_alloc.restype = c_void_p
37isl.isl_ctx_free.argtypes = [Context]
38