本文整理汇总了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)