fplll / fpylll

A Python interface for https://github.com/fplll/fplll
GNU General Public License v2.0
122 stars 62 forks source link

Expose fplll::set_external_enumerator #85

Closed cr-marcstevens closed 6 years ago

cr-marcstevens commented 7 years ago

To activate an external enumeration library we need this function exposed in fpylll.

https://github.com/fplll/fplll/blob/master/fplll/enum/enumerate_ext.h#L80 : set_external_enumerator

malb commented 7 years ago

What Python objects should the function expect and accept?

cr-marcstevens commented 7 years ago

Well, not sure what the exact type is, but I'd like this code to work:

import ctypes enumlib = ctypes.cdll.LoadLibrary("../enumlib/enumlib.so") fpylll.set_external_enumerator(enumlib.enumlib_enumerate)

See also https://github.com/cr-marcstevens/fplll-extenum/blob/master/lib/enumlib.hpp

malb commented 7 years ago

I've started to look into this, have you used ctypes for this successfully? I'm hitting two roadblocks:

  1. C++ name mangling means that enumlib.enumlib_enumerate won't work. But

    enumlib_enumerate = enumlib._Z17enumlib_enumerateidSt8functionIFvPdmbS0_S0_EES_IFddS0_EES_IFvdS0_iEEbb

    does the trick.

  2. I'm having a hard time convincing the compiler to accept some, say, void* as a parameter for set_external_enumerator I guess I could hack around it by using ctypes for set_external_enumerator as well, instead of mixing Cython and Ctypes. It'd be nice to have a cleaner solution, though.

cr-marcstevens commented 6 years ago

Note that e.g. https://github.com/cr-marcstevens/fplll-extenum has now more convenient usage:

import ctypes
enumlib = ctypes.cdll.LoadLibrary("libfplll_enumlib.so")
enumlib.fplll_register_enumlib()

This is a C interface, so it has no C++ name mangling, and is therefore easier and more robust to use from python.