Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread Matteo Lasagni
Thank you, John! I fixed it by adding the following into base-typemaps.i: %typemap(in) GList * { $1 = NULL; /* Check if is a list */ if (PyList_Check($input)) { int i; int size = PyList_Size($input); for (i = size-1; i >= 0; i--) { PyObject *o = PyL

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread john
> On May 10, 2022, at 1:53 AM, Matteo Lasagni wrote: > > Thank you, John! > > I fixed it by adding the following into base-typemaps.i: > > %typemap(in) GList * { > $1 = NULL; > /* Check if is a list */ > if (PyList_Check($input)) { > int i; > int size = PyList_Siz

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread Matteo Lasagni
If I can find a good solution, yes, I will put it in a pull request. I have tried to encapsulate Transaction* in a list, but of course it doesn't work without touching swig definitions. I am now trying to create a specific typemap for handling the double pointer. I think this would be the cleanest

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread Derek Atkins
Hi, A "Transaction**" means that the new Transaction is a "return value" (it's unlikely that it would be asking for an array of Transaction* pointers). Your best bet is to write a swig/python wrapper that returns a Transaction*, possibly in a tuple with the current return value of the function.

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread Derek Atkins
More specifically... The issue here is that there are multiple return values. gncOwnerCreatePaymentLotSecs() is *RETURNING* both a GNCLot* and a Transaction*. However, C doesn't allow you to do that, so the function returns the GNCLot* and assigns the Transaction* to the Transaction** argument

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread Matteo Lasagni
Thank you Derek, I understand what you mean. The point here is that I was not interested in the value returned through the pointer, but only in making that function callable from Python. I was looking for a solution to automatically associate multiple invoices to the same transaction, as it is poss

Re: [GNC-dev] Python-Bindings: issue when C expects GList argument

2022-05-10 Thread john
gncOwnerCreatePaymentLotSecs is a bad design because it tries to fit two use cases. One, in gncInvoiceApplyPayment, has a transaction already and passes it to gncOwnerCreatePaymentLotSecs. That's OK. The other, in gnc_payment_ok_cb via gncOwnerApplyPayemtSecs, asks it to create a transaction