-
Notifications
You must be signed in to change notification settings - Fork 4
/
swigtypes.i
69 lines (55 loc) · 1.43 KB
/
swigtypes.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%typemap(typecheck, precedence=3000) Ft const& {
$1 = PyLong_Check($input) ? 1 : 0;
}
%typemap(in, precedence=3000) Ft const& {
long val;
int overflow;
val = PyLong_AsLongAndOverflow($input, &overflow);
if (val!=-1 || (overflow==0 && !PyErr_Occurred())) {
if (val>=0) {
$1 = new Ft(val);
} else {
$1 = new Ft(-val);
*$1 = -*$1;
}
} else {
PyObject *str = PyObject_Str($input);
if (!str) { SWIG_fail; }
const char* cstr = PyUnicode_AsUTF8(str);
if (!cstr) { Py_DECREF(str); SWIG_fail; }
if (cstr[0]=='-') {
$1 = new Ft(libff::bigint<Ft::num_limbs>(cstr+1));
*$1 = -*$1;
} else {
$1 = new Ft(libff::bigint<Ft::num_limbs>(cstr));
}
Py_DECREF(str);
}
}
%typemap(out, precedence=3000) Ft{
stringstream ss;
mpz_t t;
mpz_init(t);
$1.as_bigint().to_mpz(t);
ss << t;
mpz_clear(t);
$result = PyLong_FromString(ss.str().c_str(), NULL, 10);
}
%typemap(out, precedence=3000) Fqt {
stringstream ss;
mpz_t t;
mpz_init(t);
$1.as_bigint().to_mpz(t);
ss << t;
mpz_clear(t);
$result = PyLong_FromString(ss.str().c_str(), NULL, 10);
}
%typemap(out, precedence=3001) libff::bigint<Ft::num_limbs> {
stringstream ss;
mpz_t t;
mpz_init(t);
$1.to_mpz(t);
ss << t;
mpz_clear(t);
$result = PyLong_FromString(ss.str().c_str(), NULL, 10);
}