Skip to content

@hit9 /foolib.c
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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;
}
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))
@hit9
Owner

打印结果为何是

foo ➤ python test.py                                                                                                                   
21
ooiddfggggggggggggvd
ooiddfggggggggggggvd
@hit9
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.