Last active
December 27, 2015 01:19
-
-
Save hit9/7244344 to your computer and use it in GitHub Desktop.
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
typedef struct post { | |
char *x; | |
char *y; | |
int x_z; | |
} post_t; | |
void | |
foo (post_t *o, char *src) | |
{ | |
int i=0; | |
char *p = src; | |
int len = strlen(src); | |
for (; *p != '\0'; i++, p++) { | |
if (*p == 'x') { | |
o->x = p; | |
o->x_z = len-i; | |
} | |
} | |
o->y=src; | |
} |
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 * | |
foolib = CDLL("./foolib.so") | |
class Post(Structure): | |
_fields_ = ( | |
("x", c_void_p), | |
("y", c_void_p), | |
("x_z", c_int), | |
) | |
o = Post() | |
s = "iooxooiddfggggggggggggvd" | |
foolib.foo(byref(o), create_string_buffer(s)) | |
print o.x_z | |
print string_at(o.x, o.x_z) | |
print string_at(o.y, len(s)) |
不应该 输出下面的吗 :
21
iooxooiddfggggggggggggvd
ooiddfggggggggggggvd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
打印结果为何是