Cython (0.15.2) を使用して Python (2.6.5) の拡張機能を作成しています。pxd ファイルと pyx ファイルを作成しました。私のpyxファイルの内容は次のとおりです。
cimport capifuncs
cdef class myArray:
cdef capifuncs.myArray *_my_array
def __cinit__(self, size):
self._my_array = capifuncs.array_new(size)
if (self._my_array is NULL):
raise MemoryError()
def __dealloc__(self):
if self._my_array is not NULL:
capifuncs.array_free(self._my_array)
def __bool__(self):
return not capifuncs.IsEmpty(self._my_array)
##############################
# Array methods #
##############################
cpdef getItem(self, unsigned int pos):
if capifuncs.IsEmpty(self._my_array):
raise IndexError("Array is empty")
#if ():
# raise IndexError("Array bounds exceeded")
return capifuncs.array_get_item(self._my_array, pos)
cpdef setItem(self, unsigned int pos, double val):
if capifuncs.IsEmpty(self._my_array):
raise IndexError("Array is empty")
#if ():
# raise IndexError("Array bounds exceeded")
capifuncs.array_set_item(self._my_array, pos, val)
# Free functions
cpdef long someCAPIFuncCall(capifuncs.FooBar *fb, capifuncs.myArray *arr, long start, long stop):
return capifuncs.doSomethingInteresting(fb, arr, start, stop)
フリー (つまり非メンバー) 関数定義ステートメントをコメント アウトすると、コードは正しくコンパイルされ、拡張機能が生成されます。ただし、コメントを外してファイルをコンパイルしようとすると、次のエラー メッセージが表示されます。
cafuncs.pyx:64:23: Python オブジェクトの引数を 'FooBar *' 型に変換できません
これの原因は何ですか?どうすれば修正できますか?