Skip to content

C++ interface #127

@coldfire0200

Description

@coldfire0200

The current implementation of ctypeslib does not support C++ interface (I understand this could be a very complicated issue). If I have a c++ interface like this:

class TestClassInterface
{
	public:
	virtual void test() = 0;
	virtual void test1() = 0;
};
TestClassInterface* createTestClass();

the output of clang2py is like this:

class class_TestClassInterface(Structure):
    pass

class_TestClassInterface._pack_ = 1 # source:False
class_TestClassInterface._fields_ = [
    ('PADDING_0', ctypes.c_ubyte * 8),
]

createTestClass = _libraries['FIXME_STUB'].createTestClass
createTestClass.restype = ctypes.POINTER(class_TestClassInterface)
createTestClass.argtypes = []

Which basically generates a dummy class.

I would expect something like this:

class TestClassInterface(ctypes.Structure):
    class VTable(ctypes.Structure):
        _pack_ = 1
        _fields_ = [
            ('test1', ctypes.CFUNCTYPE(None, ctypes.POINTER(None))),
            ('test2', ctypes.CFUNCTYPE(None, ctypes.POINTER(None))),
        ]
    _pack_= 1
    _fields_ = [
        ('vtable', ctypes.POINTER(VTable)),
    ]
python_dll.getTestClass.restype = ctypes.POINTER(TestClassInterface)

And I can call the function from python like:

test_wrapper = python_dll.getTestClass()
test_wrapper.contents.vtable.contents.test1(test_wrapper)
test_wrapper.contents.vtable.contents.test2(test_wrapper)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions