-
Notifications
You must be signed in to change notification settings - Fork 4
/
picosat_python.i
67 lines (45 loc) · 1.19 KB
/
picosat_python.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
/* -*- swig -*- */
/* SWIG interface file to create the Python API for PicoSAT */
/* author: Andrea Micheli <[email protected]> */
%include "typemaps.i"
/***************************************************************************/
/* EXTRA_SWIG_CODE_TAG */
/* %typemap(in) FILE * { */
/* %#if PY_VERSION_HEX < 0x03000000 */
/* if (!PyFile_Check($input)) { */
/* PyErr_SetString(PyExc_TypeError, "Need a file!"); */
/* goto fail; */
/* } */
/* $1 = PyFile_AsFile($input); */
/* %#else */
/* int fd = PyObject_AsFileDescriptor($input); */
/* $1 = fdopen(fd, "w"); */
/* %#endif */
/* } */
%ignore picosat_set_output ;
%module picosat
%{
#include "picosat.h"
/* EXTRA_C_INCLUDE_TAG */
%}
%include "picosat.h"
/* EXTRA_SWIG_INCLUDE_TAG */
%{
/* EXTRA_C_STATIC_CODE_TAG */
%}
%inline %{
/* EXTRA_C_INLINE_CODE_TAG */
static FILE* picosat_set_output_fd(PicoSAT* self, int fd) {
FILE* fout = fdopen(fd, "w");
picosat_set_output(self, fout);
return fout;
}
static void picosat_flushout(FILE* fout) {
fflush(fout);
}
%}
%pythoncode %{
## EXTRA_PYTHON_CODE_TAG
def picosat_set_output(picosat, fileout):
picosat_set_output_fd(picosat, fileout.fileno())
%}