]> gitweb.factorcode.org Git - factor.git/blob - extra/python/ffi/ffi.factor
python.ffi: On Arch Linux, the library is called libpython3.so
[factor.git] / extra / python / ffi / ffi.factor
1 USING: alien alien.c-types alien.destructors alien.libraries alien.libraries.finder
2 alien.syntax assocs kernel sequences system ;
3 IN: python.ffi
4
5 << "python" { "3.0" "3" "2.7" "2.6" }
6 os windows? [ [ [ CHAR: . = not ] filter ] map ] when
7 [ "python" prepend find-library* ] map-find drop
8 cdecl add-library >>
9
10 ! Functions that return borrowed references needs to be called like this:
11 ! Py_Func dup Py_IncRef &Py_DecRef
12
13 LIBRARY: python
14
15 C-TYPE: PyObject
16
17 ! Top-level
18 FUNCTION: c-string Py_GetVersion ( ) ;
19 FUNCTION: void Py_Initialize ( ) ;
20 FUNCTION: bool Py_IsInitialized ( ) ;
21 FUNCTION: void Py_Finalize ( ) ;
22 FUNCTION: void PySys_SetArgvEx ( int argc, c-string* argv, int updatepath ) ;
23
24 ! Misc
25 FUNCTION: int PyRun_SimpleString ( c-string command ) ;
26
27 ! Importing
28 FUNCTION: PyObject* PyImport_AddModule ( c-string name ) ;
29 FUNCTION: long PyImport_GetMagicNumber ( ) ;
30 FUNCTION: PyObject* PyImport_ImportModule ( c-string name ) ;
31
32 ! Sys module
33 ! Borrowed reference
34 FUNCTION: PyObject* PySys_GetObject ( c-string name ) ;
35
36 ! Dicts
37 ! Borrowed reference
38 FUNCTION: PyObject* PyDict_GetItemString ( PyObject* d, c-string key ) ;
39 FUNCTION: PyObject* PyDict_New ( ) ;
40 FUNCTION: int PyDict_Size ( PyObject* d ) ;
41 FUNCTION: int PyDict_SetItemString ( PyObject* d,
42                                      c-string key,
43                                      PyObject* val ) ;
44 FUNCTION: int PyDict_SetItem ( PyObject* d, PyObject* k, PyObject* o ) ;
45 FUNCTION: PyObject* PyDict_Items ( PyObject *d ) ;
46
47 ! Tuples
48 ! Borrowed reference
49 FUNCTION: PyObject* PyTuple_GetItem ( PyObject* t, int pos ) ;
50 FUNCTION: PyObject* PyTuple_New ( int len ) ;
51 ! Steals the reference
52 FUNCTION: int PyTuple_SetItem ( PyObject* t, int pos, PyObject* o ) ;
53 FUNCTION: int PyTuple_Size ( PyObject* t ) ;
54
55 ! Lists
56 ! Borrowed reference
57 FUNCTION: PyObject* PyList_GetItem ( PyObject* l, int pos ) ;
58 ! New reference
59 FUNCTION: PyObject* PyList_New ( int len ) ;
60 FUNCTION: int PyList_Size ( PyObject* l ) ;
61 ! Steals the reference
62 FUNCTION: int PyList_SetItem ( PyObject* l, int pos, PyObject* o ) ;
63
64
65 ! Modules
66 FUNCTION: c-string PyModule_GetName ( PyObject* module ) ;
67 FUNCTION: PyObject* PyModule_GetDict ( PyObject* module ) ;
68
69 ! Callables
70 FUNCTION: int PyCallable_Check ( PyObject* obj ) ;
71
72 ! Objects
73 FUNCTION: PyObject* PyObject_CallObject ( PyObject* callable,
74                                           PyObject* args ) ;
75 FUNCTION: PyObject* PyObject_Call ( PyObject* callable,
76                                     PyObject* args,
77                                     PyObject* kw ) ;
78 ! New reference
79 FUNCTION: PyObject* PyObject_GetAttrString ( PyObject* o,
80                                              c-string attr_name ) ;
81 FUNCTION: int PyObject_SetAttrString ( PyObject* o,
82                                        c-string attr_name,
83                                        PyObject *v ) ;
84
85 FUNCTION: PyObject* PyObject_Str ( PyObject* o ) ;
86 FUNCTION: int PyObject_IsTrue ( PyObject* o ) ;
87
88 ! Strings
89 FUNCTION: c-string PyString_AsString ( PyObject* string ) ;
90 FUNCTION: PyObject* PyString_FromString ( c-string v ) ;
91
92 ! Unicode
93 FUNCTION: PyObject* PyUnicode_DecodeUTF8 ( c-string s,
94                                            int size,
95                                            void* errors ) ;
96 FUNCTION: PyObject* PyUnicodeUCS4_FromString ( c-string s ) ;
97 FUNCTION: PyObject* PyUnicodeUCS2_FromString ( c-string s ) ;
98 FUNCTION: PyObject* PyUnicodeUCS2_AsUTF8String ( PyObject* unicode ) ;
99 FUNCTION: PyObject* PyUnicodeUCS4_AsUTF8String ( PyObject* unicode ) ;
100
101 ! Ints
102 FUNCTION: long PyInt_AsLong ( PyObject* io ) ;
103
104 ! Longs
105 FUNCTION: PyObject* PyLong_FromLong ( long v ) ;
106 FUNCTION: long PyLong_AsLong ( PyObject* o ) ;
107
108 ! Floats
109 FUNCTION: PyObject* PyFloat_FromDouble ( double d ) ;
110
111 ! Reference counting
112 FUNCTION: void Py_IncRef ( PyObject* o ) ;
113 FUNCTION: void Py_DecRef ( PyObject* o ) ;
114 DESTRUCTOR: Py_DecRef
115
116 ! Reflection
117 FUNCTION: c-string PyEval_GetFuncName ( PyObject* func ) ;
118
119 ! Errors
120 FUNCTION: void PyErr_Clear ( ) ;
121 FUNCTION: void PyErr_Print ( ) ;
122 FUNCTION: void PyErr_Fetch ( PyObject** ptype,
123                              PyObject** pvalue,
124                              PyObject** *ptraceback ) ;