You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
422 B
24 lines
422 B
10 years ago
|
import sys
|
||
|
try:
|
||
|
import ffi
|
||
|
except ImportError:
|
||
|
print("SKIP")
|
||
|
sys.exit()
|
||
|
|
||
|
libc = ffi.open("libc.so.6")
|
||
|
|
||
|
qsort = libc.func("v", "qsort", "piip")
|
||
|
|
||
|
def cmp(pa, pb):
|
||
|
a = ffi.as_bytearray(pa, 1)
|
||
|
b = ffi.as_bytearray(pb, 1)
|
||
|
#print("cmp:", a, b)
|
||
|
return a[0] - b[0]
|
||
|
|
||
|
cmp_c = ffi.callback("i", cmp, "pp")
|
||
|
|
||
|
s = bytearray(b"foobar")
|
||
|
print("org string:", s)
|
||
|
qsort(s, len(s), 1, cmp_c)
|
||
|
print("qsort'ed:", s)
|