Last active
August 29, 2015 14:08
-
-
Save FGtatsuro/91c570b60ddd702a1673 to your computer and use it in GitHub Desktop.
ctypesを使う際の(個人的な)ポイント ref: http://qiita.com/FGtatsuro/items/019d56287366e5f7016d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
test.func1.restype = c_int | |
test.func2.argtypes = (None) | |
test.func2.restype = c_char_p | |
test.func2.argtypes = (c_char_p, c_char_p, c_char_p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
test.func4.restype = c_char_p | |
test.func4.argtypes = (c_void_p, c_char_p, c_char_p, c_char_p, POINTER(c_void_p), POINTER(c_char_p)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
test.func4.restype = c_char_p | |
test.func4.argtypes = (c_void_p, c_char_p, c_char_p, c_char_p, POINTER(c_void_p), POINTER(c_char_p)) | |
# arg1は既に定義済みとする | |
arg2 = 'str2' | |
arg3 = 'str3' | |
arg4 = 'str4' | |
void_p_p = c_void_p(None) | |
char_p_p = c_char_p(None) | |
# 以下だとポインタのポインタにNULLが代入されるためダメ | |
# void_p_p = None | |
# char_p_p = None | |
test.func4(arg1, arg2, arg3, arg4, byref(void_p_p), byref(char_p_p)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
# 実行時に指定 | |
ret = test.func2(c_char_p("test"), c_char_p("test2"), c_char_p("test3")) | |
# restype/argtypesにより指定 | |
test.func2.restype = c_char_p | |
test.func2.argtypes = (c_char_p, c_char_p, c_char_p) | |
ret = test.func2("test", "test2", "test3") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
class JSON_T(Structure): | |
__fields__ = [('type', c_int), ('refcount', c_size_t)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
class JSON_T(Structure): | |
__fields__ = [('type', c_int), ('refcount', c_size_t)] | |
test.func3.restype = c_char_p | |
test.func3.argtypes = (c_void_p, c_char_p, c_char_p, c_char_p, POINTER(JSON_T)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment