J'ai une question à propos de ctypes dans python3.Comment puis-je obtenir la valeur de c_char_p en octets dans les ctypes python3?
J'essaie d'obtenir un c_char_p en tant qu'objet python bytes.
Le code suivant tente d'obtenir sa valeur en tant qu'objet python3 octets.
Comment obtenir sa valeur en tant qu'objet octets?
from ctypes import *
libc = cdll.LoadLibrary("libSystem.B.dylib")
s1 = create_string_buffer(b"abc") # create a null terminated string buffer
s2 = create_string_buffer(b"bc") # same at above
g = libc.strstr(s1, s2) # execute strstr (this function return character pointer)
print(g) # print the returned value as integer
matched_point = c_char_p(g) # cast to char_p
print(matched_point.value) # trying to getting value as bytes object (cause segmentation fault here)
semble correct et cela a fonctionné pour moi. Étrange. Et 'g' n'est pas un pointeur nul? –