2022-09-18 11:55:34 +00:00
|
|
|
%module ckzg
|
|
|
|
%{
|
|
|
|
#include "c_kzg.h"
|
2022-09-18 18:50:49 +00:00
|
|
|
#include "bls12_381.h"
|
2022-09-18 21:35:30 +00:00
|
|
|
#include "test_util.h"
|
2022-09-18 11:55:34 +00:00
|
|
|
%}
|
2022-09-19 09:50:34 +00:00
|
|
|
%include "stdint.i"
|
|
|
|
%include "carrays.i"
|
|
|
|
%include "cpointer.i"
|
2022-09-18 11:55:34 +00:00
|
|
|
%rename(alloc_poly) new_poly;
|
|
|
|
%rename(alloc_poly_l) new_poly_l;
|
2022-09-18 18:50:49 +00:00
|
|
|
|
2022-09-18 21:35:30 +00:00
|
|
|
%typemap(in, numinputs=0) OBJECT *OUTPUT($1_basetype tmp) { $1 = &tmp; }
|
|
|
|
%typemap(argout) OBJECT *OUTPUT {
|
2022-09-18 18:50:49 +00:00
|
|
|
PyObject *obj = SWIG_NewPointerObj(memcpy(malloc(sizeof($1_basetype)),$1,sizeof($1_basetype)),
|
|
|
|
$descriptor, SWIG_POINTER_NEW);
|
|
|
|
$result = ($result == NULL) ? obj : SWIG_Python_AppendOutput($result, obj);
|
|
|
|
}
|
2022-09-18 21:35:30 +00:00
|
|
|
%apply OBJECT *OUTPUT {
|
|
|
|
fr_t *out, poly *out, poly_l *out,
|
|
|
|
g1_t *out, g2_t *out,
|
|
|
|
blst_scalar *out,
|
|
|
|
FFTSettings *out, KZGSettings *out
|
|
|
|
}
|
2022-09-18 18:50:49 +00:00
|
|
|
|
2022-09-19 09:50:34 +00:00
|
|
|
%typemap(in, numinputs=0) bool *OUTPUT(bool tmp) { $1 = &tmp; }
|
|
|
|
%typemap(argout) bool *OUTPUT {
|
|
|
|
PyObject *obj = *$1 ? Py_True : Py_False;
|
|
|
|
$result = ($result == NULL) ? obj : SWIG_Python_AppendOutput($result, obj);
|
|
|
|
}
|
|
|
|
%apply bool *OUTPUT { bool *out }
|
|
|
|
|
2022-09-18 18:50:49 +00:00
|
|
|
%typemap(in, numinputs=0) uint64_t out[4] (uint64_t tmp[4]) { $1 = tmp; }
|
|
|
|
%typemap(argout) uint64_t out[4] {
|
|
|
|
PyObject *obj = PyTuple_Pack(4,
|
2022-09-19 09:13:08 +00:00
|
|
|
PyLong_FromUnsignedLong($1[0]),
|
|
|
|
PyLong_FromUnsignedLong($1[1]),
|
|
|
|
PyLong_FromUnsignedLong($1[2]),
|
|
|
|
PyLong_FromUnsignedLong($1[3]));
|
2022-09-18 18:50:49 +00:00
|
|
|
$result = ($result == NULL) ? obj : SWIG_Python_AppendOutput($result, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
%typemap(in) const uint64_t[4] (uint64_t tmp[4]) {
|
|
|
|
if (PyTuple_Check($input)) {
|
2022-09-19 09:13:08 +00:00
|
|
|
if (!PyArg_ParseTuple($input, "kkkk", tmp, tmp+1, tmp+2, tmp+3)) {
|
2022-09-18 18:50:49 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "tuple must have 4 elements");
|
|
|
|
SWIG_fail;
|
|
|
|
}
|
|
|
|
$1 = &tmp[0];
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "expected a tuple.");
|
|
|
|
SWIG_fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
%array_class(fr_t, frArray)
|
2022-09-19 18:56:15 +00:00
|
|
|
%array_class(byte, byteArray)
|
2022-09-18 21:35:30 +00:00
|
|
|
%array_class(g1_t, g1Array)
|
|
|
|
%array_class(g2_t, g2Array)
|
2022-09-18 18:50:49 +00:00
|
|
|
%pointer_class(poly, polyp)
|
|
|
|
%pointer_class(poly_l, poly_lp)
|
|
|
|
|
2022-09-18 11:55:34 +00:00
|
|
|
%include "../src/c_kzg.h"
|
2022-09-18 18:50:49 +00:00
|
|
|
%include "../src/bls12_381.h"
|
2022-09-18 21:35:30 +00:00
|
|
|
%include "../inc/blst.h"
|
|
|
|
%include "../src/test_util.h"
|