2011-06-01 4 views
8

मुझे ctypes के साथ कार्यान्वित करते समय समस्या का सामना करना पड़ता है। मेरे पास 2 सी कार्य हैं:ctypes कॉलबैक फ़ंक्शन के लिए अमान्य परिणाम प्रकार

antichain** decompose_antichain(antichain*, int, char (*)(void*, void*), void** (*)(void*)); 
counting_function** decompose_counting_function(counting_function*); 

जहां एंटीचैन और गिनती_फंक्शन दो संरचनाएं हैं। एक एंटीचैन को एक सेट की तरह देखा जा सकता है, जिसमें अज्ञात प्रकार के तत्व होते हैं (इस उदाहरण में, counting_function)। Decompose_antichain फ़ंक्शन तर्क के रूप में होता है (अन्य चीजों के साथ) एंटीचैन तत्वों को विघटित करने के लिए उपयोग करने के लिए फ़ंक्शन (-> एक फ़ंक्शन जिसमें प्रोटोटाइप शून्य है ** (*) (शून्य *))।

अब मैं पायथन से decompose_antichain का उपयोग करना चाहता हूं। मैंने ctypes का उपयोग किया:

lib = cdll.LoadLibrary("./mylib.dylib") 
#CountingFunction, Antichain and other definitions skipped 
DECOMPOSE_COUNTING_FUNCTION_FUNC = CFUNCTYPE(POINTER(c_void_p), POINTER(CountingFunction)) 
decompose_counting_function_c = lib.decompose_counting_function 
decompose_counting_function_c.argtypes = [POINTER(CountingFunction)] 
decompose_counting_function_c.restype = POINTER(c_void_p) 
decompose_antichain_c = lib.decompose_antichain 
decompose_antichain_c.argtypes = [POINTER(Antichain), c_int, DECOMPOSE_COUNTING_FUNCTION_FUNC, COMPARE_COUNTING_FUNCTIONS_FUNC] 
decompose_antichain_c.restype = POINTER(POINTER(Antichain)) 

(...) 

antichains_list = decompose_antichain_c(antichain, nb_components, COMPARE_COUNTING_FUNCTIONS_FUNC(compare_counting_functions_c), DECOMPOSE_COUNTING_FUNCTION_FUNC(decompose_counting_function_c)) 

अंतिम पंक्ति त्रुटि उत्पन्न करती है: कॉलबैक फ़ंक्शन के लिए अमान्य परिणाम प्रकार।

मैं नहीं देख सकता कि समस्या कहां से आती है। क्या कोई मेरी मदद कर सकता है? धन्यवाद

उत्तर

1

आपको यह सुनिश्चित करने की ज़रूरत है कि तर्क और परिणाम प्रकार मेल खाते हैं। ऐसा लगता है कि आपने decompose_antichain_c के तर्क प्रकारों को बदल दिया है। आपके पास argtypes में DECOMPOSE_COUNTING_FUNCTION_FUNC, COMPARE_COUNTING_FUNCTIONS_FUNC है, जो ऊपर दिए गए सी फ़ंक्शन की घोषणा से मेल नहीं खाता है। फिर आप इसे COMPARE_COUNTING_FUNCTIONS_FUNC पहले, और DECOMPOSE_COUNTING_FUNCTION_FUNC सेकंड के साथ कॉल करने का प्रयास करें।

DECOMPOSE_COUNTING_FUNCTION_FUNC भी गलत दिखता है। यह शायद शेष कोड से अनुमानित CFUNCTYPE(POINTER(c_void_p), c_void_p) होना चाहिए।

यदि आप कोड है कि बनाता है COMPARE_COUNTING_FUNCTIONS_FUNC और CountingFunction

प्रदान मैं एक अधिक विस्तृत जवाब दे सकते हैं
संबंधित मुद्दे