Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View foolib.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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;
}
View foolib.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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))
Owner

打印结果为何是

foo ➤ python test.py                                                                                                                   
21
ooiddfggggggggggggvd
ooiddfggggggggggggvd
Owner

不应该 输出下面的吗 :

21
iooxooiddfggggggggggggvd
ooiddfggggggggggggvd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.