diff options
author | Armin Rigo <arigo@tunes.org> | 2012-05-27 13:49:02 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2012-05-27 13:49:02 +0200 |
commit | a950e65c6ca8b75b841e9612b6dc25718b5a82b0 (patch) | |
tree | 348abefc5cc77b30ad0ff9ce09a0c3d2c6ea84f2 /testing/test_function.py | |
parent | e4d94785ada05ce057b182e13d5f1ad86ac9b8f9 (diff) | |
download | cffi-a950e65c6ca8b75b841e9612b6dc25718b5a82b0.tar.gz |
Rename malloc() to new().
Keep naming the type we want a new() copy of, rather than the resulting
pointer type.
Diffstat (limited to 'testing/test_function.py')
-rw-r--r-- | testing/test_function.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/testing/test_function.py b/testing/test_function.py index d17c0d4..705d6fd 100644 --- a/testing/test_function.py +++ b/testing/test_function.py @@ -95,8 +95,8 @@ def test_vararg(): with FdWriteCapture() as fd: ffi.C.printf("hello\n") ffi.C.printf("hello, %s!\n", "world") - ffi.C.printf(ffi.malloc("char[]", "hello, %s!\n"), - ffi.malloc("char[]", "world2")) + ffi.C.printf(ffi.new("char[]", "hello, %s!\n"), + ffi.new("char[]", "world2")) ffi.C.printf("hello int %d long %ld long long %lld\n", ffi.cast("int", 42), ffi.cast("long", 84), @@ -131,21 +131,30 @@ def test_function_pointer(): int puts(const char *); int fflush(void *); """) - fptr = ffi.malloc("int()(const char *txt)", ffi.C.puts) - assert fptr != ffi.malloc("int()(const char *)", ffi.C.puts) - assert repr(fptr) == "<malloc('int()(char *)')>" + fptr = ffi.callback("int(*)(const char *txt)", ffi.C.puts) + assert fptr != ffi.callback("int(*)(const char *)", ffi.C.puts) + assert repr(fptr) == "<cdata 'int(*)(char *)' calling %r>" % (ffi.C.puts,) with FdWriteCapture() as fd: fptr("hello") ffi.C.fflush(None) res = fd.getvalue() assert res == 'hello\n' + # + fptr = ffi.cast("int(*)(const char *txt)", ffi.C.puts) + assert fptr == ffi.C.puts + assert repr(fptr) == "<cdata 'int(*)(char *)'>" + with FdWriteCapture() as fd: + fptr("world") + ffi.C.fflush(None) + res = fd.getvalue() + assert res == 'world\n' def test_passing_array(): ffi = FFI() ffi.cdef(""" int strlen(char[]); """) - p = ffi.malloc("char[]", "hello") + p = ffi.new("char[]", "hello") res = ffi.C.strlen(p) assert res == 5 @@ -173,7 +182,7 @@ def test_strchr(): ffi.cdef(""" char *strchr(const char *s, int c); """) - p = ffi.malloc("char[]", "hello world!") + p = ffi.new("char[]", "hello world!") q = ffi.C.strchr(p, ord('w')) assert str(q) == "world!" |