本文整理匯總了Python中ctypes.PyDLL方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.PyDLL方法的具體用法?Python ctypes.PyDLL怎麽用?Python ctypes.PyDLL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes.PyDLL方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_jl_lib
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import PyDLL [as 別名]
def get_jl_lib(conf) -> JuliaPreLoad:
jl = conf["julia"]
lib_path = jl["lib"]
sys_image = jl["image"]
binary = jl["bin"]
lib = ctypes.PyDLL(lib_path, ctypes.RTLD_GLOBAL)
lib.jl_eval_string.argtypes = [ctypes.c_char_p]
lib.jl_eval_string.restype = ctypes.c_void_p
try:
init = lib.jl_init_with_image
except AttributeError:
init = lib.jl_init_with_image__threading
return JuliaPreLoad(
lambda: init(binary.encode(), sys_image.encode()), lib)
示例2: register_deterministic_function
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import PyDLL [as 別名]
def register_deterministic_function(conn, name, num_params, func):
if not isinstance(conn, sqlite3.Connection):
raise Exception("Bad connection object: %r" % (conn,))
# This is a hack, oh well this is how I roll
# TODO: submit patch to pysqlite to do this natively
# NB: the sqlite3 library should already be loaded
# but we specify noload just in case
if sys.platform == "darwin":
RTLD_NOLOAD = 0x10
elif sys.platform.startswith("linux"):
RTLD_NOLOAD = 0x04
else:
RTLD_NOLOAD = 0
pysqlite_dll = ctypes.PyDLL(_sqlite3.__file__, ctypes.RTLD_GLOBAL | RTLD_NOLOAD)
sqlite3_create_function_proto = ctypes.CFUNCTYPE(ctypes.c_int,
ctypes.c_void_p, # db
ctypes.c_char_p, # zFunctionName
ctypes.c_int, # nArg
ctypes.c_int, # eTextRep
ctypes.c_void_p, # pApp
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p)
sqlite3_create_function = sqlite3_create_function_proto(("sqlite3_create_function",
pysqlite_dll))
# get dp pointer from connection object
dbp = ctypes.cast(id(conn) +
ctypes.sizeof(ctypes.c_ssize_t) +
ctypes.sizeof(ctypes.c_void_p),
ctypes.POINTER(ctypes.c_void_p)).contents
SQLITE_DETERMINISTIC = 0x800
SQLITE_UTF8 = 0x1
rc = sqlite3_create_function(dbp, name.encode("utf8"), num_params,
SQLITE_DETERMINISTIC | SQLITE_UTF8,
id(func),
pysqlite_dll._pysqlite_func_callback,
None,
None)
if rc:
raise Exception("Error while creating function: %r" % (rc,))
# hold ref on passed function object
with _hold_ref_lock:
if conn not in _hold_ref:
_hold_ref[conn] = []
_hold_ref[conn].append(func)