Hi,
I haven't had the chance to test ciaoc out yet but if you are at least able to build
.a libraries with it, you can use the newer
cffi� instead of ctypes in Python to access them. Here's how. Let's say you have defined your own quicksort routine in C called string_vector_quicksort() with the following prototype:
�
void string_vector_quicksort(int c, char *v[]); i.e. a routine you could call with main()'s argc and argv for instance to sort the command line arguments or similar string "vectors". Now you do the following in Python to access the routine:
'''
#!/usr/bin/env python
proj_dir="/path/to/where/you/keep/the/c/library/project"
from cffi import FFI
ffi = FFI()
ffi.cdef("""
��� void string_vector_quicksort(int c, char *v[]);
��� """)
C = ffi.verify("""
��� #include "myquicksort.h"
��� """, library_dirs=[proj_dir], libraries=["myquicksort"], include_dirs=[proj_dir])
# Let's construct the vector to sort.
# Equivalent to the following C initializer: { "foo", "baar", "bazz", "quux" }
vector_dont_garbage_collect = [ffi.new("char[]", "foo"),
������������������ ffi.new("char[]", "baar"),
������������������ ffi.new("char[]", "bazz"),
������������������ ffi.new("char[]", "quux")]
vector = ffi.new("char *[]", vector_dont_garbage_collect)
# Let's finally call our routine
C.string_vector_quicksort(len(vector), vector)
# ... and print out the sorted results.
for x in vector:
��� print ffi.string(x)
'''
The above actually calls your C compiler to make a temporary extension for Python to load. It assumes you have the files "myquicksort.h" and "libmyquicksort.a" in the project directory (proj_dir above).