pycall 1.0.1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +41 -0
- data/CHANGES.md +39 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +29 -0
- data/appveyor.yml +138 -0
- data/bin/console +10 -0
- data/bin/guard +17 -0
- data/bin/rspec +17 -0
- data/bin/runner +6 -0
- data/bin/setup +8 -0
- data/config/Guardfile +30 -0
- data/docker/Dockerfile +191 -0
- data/docker/Gemfile +12 -0
- data/docker/README.md +22 -0
- data/examples/classifier_comparison.rb +135 -0
- data/examples/datascience_rb_20170519.ipynb +4836 -0
- data/examples/hist.rb +32 -0
- data/examples/notebooks/classifier_comparison.ipynb +226 -0
- data/examples/notebooks/forest_importances.ipynb +238 -0
- data/examples/notebooks/iruby_integration.ipynb +183 -0
- data/examples/notebooks/lorenz_attractor.ipynb +214 -0
- data/examples/notebooks/polar_axes.ipynb +209 -0
- data/examples/notebooks/sum_benchmarking.ipynb +374 -0
- data/examples/notebooks/xkcd_style.ipynb +149 -0
- data/examples/plot_forest_importances_faces.rb +46 -0
- data/examples/sum_benchmarking.rb +49 -0
- data/ext/pycall/extconf.rb +3 -0
- data/ext/pycall/gc.c +74 -0
- data/ext/pycall/libpython.c +217 -0
- data/ext/pycall/pycall.c +2184 -0
- data/ext/pycall/pycall_internal.h +700 -0
- data/ext/pycall/range.c +69 -0
- data/ext/pycall/ruby_wrapper.c +432 -0
- data/lib/2.1/pycall.so +0 -0
- data/lib/2.2/pycall.so +0 -0
- data/lib/2.3/pycall.so +0 -0
- data/lib/2.4/pycall.so +0 -0
- data/lib/pycall/conversion.rb +173 -0
- data/lib/pycall/dict.rb +48 -0
- data/lib/pycall/error.rb +10 -0
- data/lib/pycall/gc_guard.rb +84 -0
- data/lib/pycall/import.rb +120 -0
- data/lib/pycall/init.rb +55 -0
- data/lib/pycall/iruby_helper.rb +40 -0
- data/lib/pycall/libpython/finder.rb +170 -0
- data/lib/pycall/libpython/pyobject_struct.rb +30 -0
- data/lib/pycall/libpython/pytypeobject_struct.rb +273 -0
- data/lib/pycall/libpython.rb +12 -0
- data/lib/pycall/list.rb +45 -0
- data/lib/pycall/pretty_print.rb +9 -0
- data/lib/pycall/pyerror.rb +30 -0
- data/lib/pycall/pyobject_wrapper.rb +212 -0
- data/lib/pycall/python/PyCall/__init__.py +1 -0
- data/lib/pycall/python/PyCall/six.py +23 -0
- data/lib/pycall/python/investigator.py +7 -0
- data/lib/pycall/pytypeobject_wrapper.rb +90 -0
- data/lib/pycall/set.rb +19 -0
- data/lib/pycall/slice.rb +8 -0
- data/lib/pycall/tuple.rb +46 -0
- data/lib/pycall/version.rb +3 -0
- data/lib/pycall/wrapper_object_cache.rb +61 -0
- data/lib/pycall.rb +91 -0
- data/pycall.gemspec +40 -0
- data/tasks/docker.rake +21 -0
- data/tasks/pycall.rake +7 -0
- metadata +228 -0
@@ -0,0 +1,217 @@
|
|
1
|
+
#include "pycall_internal.h"
|
2
|
+
|
3
|
+
static pycall_libpython_api_table_t api_table = { NULL, };
|
4
|
+
static int python_string_as_bytes;
|
5
|
+
|
6
|
+
pycall_libpython_api_table_t *
|
7
|
+
pycall_libpython_api_table(void)
|
8
|
+
{
|
9
|
+
return &api_table;
|
10
|
+
}
|
11
|
+
|
12
|
+
struct lookup_libpython_api_args {
|
13
|
+
VALUE libpython_handle;
|
14
|
+
char const *name;
|
15
|
+
};
|
16
|
+
|
17
|
+
static VALUE
|
18
|
+
lookup_libpython_api_0(struct lookup_libpython_api_args *args)
|
19
|
+
{
|
20
|
+
return rb_funcall(args->libpython_handle, rb_intern("sym"), 1, rb_str_new2(args->name));
|
21
|
+
}
|
22
|
+
|
23
|
+
static void *
|
24
|
+
lookup_libpython_api(VALUE libpython_handle, char const *name)
|
25
|
+
{
|
26
|
+
struct lookup_libpython_api_args arg;
|
27
|
+
VALUE addr;
|
28
|
+
int state;
|
29
|
+
|
30
|
+
arg.libpython_handle = libpython_handle;
|
31
|
+
arg.name = name;
|
32
|
+
addr = rb_protect((VALUE (*)(VALUE))lookup_libpython_api_0, (VALUE)&arg, &state);
|
33
|
+
return (state || NIL_P(addr)) ? NULL : NUM2PTR(addr);
|
34
|
+
}
|
35
|
+
|
36
|
+
#define LOOKUP_API_ENTRY(api_name) lookup_libpython_api(libpython_handle, #api_name)
|
37
|
+
#define CHECK_API_ENTRY(api_name) (LOOKUP_API_ENTRY(api_name) != NULL)
|
38
|
+
|
39
|
+
#define required 1
|
40
|
+
#define optional 0
|
41
|
+
|
42
|
+
#define INIT_API_TABLE_ENTRY2(member_name, api_name, required) do { \
|
43
|
+
void *fptr = LOOKUP_API_ENTRY(api_name); \
|
44
|
+
if (!fptr && required) { \
|
45
|
+
rb_raise(eLibPythonFunctionNotFound, "Unable to find the required symbol in libpython: %s", #api_name); \
|
46
|
+
} \
|
47
|
+
(api_table.member_name) = fptr; \
|
48
|
+
} while (0)
|
49
|
+
|
50
|
+
#define INIT_API_TABLE_ENTRY(api_name, required) INIT_API_TABLE_ENTRY2(api_name, api_name, required)
|
51
|
+
|
52
|
+
#define INIT_API_TABLE_ENTRY_PTR(api_name, required) do { \
|
53
|
+
INIT_API_TABLE_ENTRY(api_name, required); \
|
54
|
+
(api_table.api_name) = *(void **)(api_table.api_name); \
|
55
|
+
} while (0)
|
56
|
+
|
57
|
+
void
|
58
|
+
pycall_init_libpython_api_table(VALUE libpython_handle)
|
59
|
+
{
|
60
|
+
VALUE eLibPythonFunctionNotFound = rb_const_get_at(pycall_mPyCall, rb_intern("LibPythonFunctionNotFound"));
|
61
|
+
|
62
|
+
INIT_API_TABLE_ENTRY(_Py_NoneStruct, required);
|
63
|
+
|
64
|
+
INIT_API_TABLE_ENTRY(PyBool_Type, required);
|
65
|
+
INIT_API_TABLE_ENTRY(PyClass_Type, optional);
|
66
|
+
INIT_API_TABLE_ENTRY(PyComplex_Type, required);
|
67
|
+
INIT_API_TABLE_ENTRY(PyDict_Type, required);
|
68
|
+
INIT_API_TABLE_ENTRY(PyFloat_Type, required);
|
69
|
+
INIT_API_TABLE_ENTRY(PyList_Type, required);
|
70
|
+
INIT_API_TABLE_ENTRY(PyInstance_Type, optional);
|
71
|
+
INIT_API_TABLE_ENTRY(PyInt_Type, optional);
|
72
|
+
INIT_API_TABLE_ENTRY(PyLong_Type, required);
|
73
|
+
INIT_API_TABLE_ENTRY(PyModule_Type, required);
|
74
|
+
python_string_as_bytes = !CHECK_API_ENTRY(PyString_Type);
|
75
|
+
if (python_string_as_bytes) {
|
76
|
+
INIT_API_TABLE_ENTRY2(PyString_Type, PyBytes_Type, required);
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
INIT_API_TABLE_ENTRY(PyString_Type, required);
|
80
|
+
}
|
81
|
+
INIT_API_TABLE_ENTRY(PyTuple_Type, required);
|
82
|
+
INIT_API_TABLE_ENTRY(PyType_Type, required);
|
83
|
+
INIT_API_TABLE_ENTRY(PyUnicode_Type, required);
|
84
|
+
|
85
|
+
INIT_API_TABLE_ENTRY(Py_InitializeEx, required);
|
86
|
+
INIT_API_TABLE_ENTRY(Py_IsInitialized, required);
|
87
|
+
INIT_API_TABLE_ENTRY(Py_GetVersion, required);
|
88
|
+
|
89
|
+
INIT_API_TABLE_ENTRY(PySys_SetArgvEx, required);
|
90
|
+
|
91
|
+
INIT_API_TABLE_ENTRY(Py_IncRef, required);
|
92
|
+
INIT_API_TABLE_ENTRY(Py_DecRef, required);
|
93
|
+
|
94
|
+
INIT_API_TABLE_ENTRY(_PyObject_New, required);
|
95
|
+
INIT_API_TABLE_ENTRY(PyCallable_Check, required);
|
96
|
+
INIT_API_TABLE_ENTRY(PyObject_IsInstance, required);
|
97
|
+
INIT_API_TABLE_ENTRY2(PyObject_Hash._hash_t, PyObject_Hash, required);
|
98
|
+
INIT_API_TABLE_ENTRY(PyObject_RichCompare, required);
|
99
|
+
INIT_API_TABLE_ENTRY(PyObject_Call, required);
|
100
|
+
INIT_API_TABLE_ENTRY(PyObject_CallMethod, required);
|
101
|
+
INIT_API_TABLE_ENTRY(PyObject_Dir, required);
|
102
|
+
INIT_API_TABLE_ENTRY(PyObject_GenericGetAttr, required);
|
103
|
+
INIT_API_TABLE_ENTRY(PyObject_GetAttrString, required);
|
104
|
+
INIT_API_TABLE_ENTRY(PyObject_SetAttrString, required);
|
105
|
+
INIT_API_TABLE_ENTRY(PyObject_HasAttrString, required);
|
106
|
+
INIT_API_TABLE_ENTRY(PyObject_GetItem, required);
|
107
|
+
INIT_API_TABLE_ENTRY(PyObject_SetItem, required);
|
108
|
+
INIT_API_TABLE_ENTRY(PyObject_DelItem, required);
|
109
|
+
INIT_API_TABLE_ENTRY(PyObject_GetIter, required);
|
110
|
+
INIT_API_TABLE_ENTRY(PyObject_Str, required);
|
111
|
+
INIT_API_TABLE_ENTRY(PyObject_Repr, required);
|
112
|
+
|
113
|
+
INIT_API_TABLE_ENTRY(PyType_Ready, required);
|
114
|
+
INIT_API_TABLE_ENTRY(PyType_GenericNew, required);
|
115
|
+
|
116
|
+
INIT_API_TABLE_ENTRY(PyCFunction_NewEx, required);
|
117
|
+
|
118
|
+
INIT_API_TABLE_ENTRY(PyWeakref_NewRef, required);
|
119
|
+
|
120
|
+
INIT_API_TABLE_ENTRY(PyBool_FromLong, required);
|
121
|
+
|
122
|
+
INIT_API_TABLE_ENTRY(PyComplex_RealAsDouble, required);
|
123
|
+
INIT_API_TABLE_ENTRY(PyComplex_ImagAsDouble, required);
|
124
|
+
INIT_API_TABLE_ENTRY(PyComplex_FromDoubles, required);
|
125
|
+
|
126
|
+
INIT_API_TABLE_ENTRY(PyFloat_AsDouble, required);
|
127
|
+
INIT_API_TABLE_ENTRY(PyFloat_FromDouble, required);
|
128
|
+
|
129
|
+
INIT_API_TABLE_ENTRY(PyList_New, required);
|
130
|
+
INIT_API_TABLE_ENTRY(PyList_Size, required);
|
131
|
+
INIT_API_TABLE_ENTRY(PyList_GetItem, required);
|
132
|
+
INIT_API_TABLE_ENTRY(PyList_SetItem, required);
|
133
|
+
INIT_API_TABLE_ENTRY(PyList_Insert, required);
|
134
|
+
INIT_API_TABLE_ENTRY(PyList_Append, required);
|
135
|
+
|
136
|
+
INIT_API_TABLE_ENTRY(PyInt_FromLong, optional);
|
137
|
+
INIT_API_TABLE_ENTRY(PyInt_FromSsize_t, optional);
|
138
|
+
INIT_API_TABLE_ENTRY(PyInt_AsSsize_t, optional);
|
139
|
+
|
140
|
+
INIT_API_TABLE_ENTRY(PyLong_AsLongAndOverflow, required);
|
141
|
+
INIT_API_TABLE_ENTRY(PyLong_FromLong, required);
|
142
|
+
#ifdef HAVE_LONG_LONG
|
143
|
+
INIT_API_TABLE_ENTRY(PyLong_AsLongLongAndOverflow, required);
|
144
|
+
INIT_API_TABLE_ENTRY(PyLong_FromLongLong, required);
|
145
|
+
#endif
|
146
|
+
INIT_API_TABLE_ENTRY(PyLong_AsSsize_t, required);
|
147
|
+
|
148
|
+
INIT_API_TABLE_ENTRY(PyTuple_New, required);
|
149
|
+
INIT_API_TABLE_ENTRY(PyTuple_Size, required);
|
150
|
+
INIT_API_TABLE_ENTRY(PyTuple_GetItem, required);
|
151
|
+
INIT_API_TABLE_ENTRY(PyTuple_SetItem, required);
|
152
|
+
|
153
|
+
INIT_API_TABLE_ENTRY(PySlice_New, required);
|
154
|
+
|
155
|
+
INIT_API_TABLE_ENTRY(PyIter_Next, required);
|
156
|
+
|
157
|
+
INIT_API_TABLE_ENTRY(PyErr_Occurred, required);
|
158
|
+
INIT_API_TABLE_ENTRY(PyErr_Fetch, required);
|
159
|
+
INIT_API_TABLE_ENTRY(PyErr_Restore, required);
|
160
|
+
INIT_API_TABLE_ENTRY(PyErr_Clear, required);
|
161
|
+
INIT_API_TABLE_ENTRY(PyErr_SetString, required);
|
162
|
+
INIT_API_TABLE_ENTRY(PyErr_Format, required);
|
163
|
+
|
164
|
+
INIT_API_TABLE_ENTRY(PyImport_ImportModule, required);
|
165
|
+
INIT_API_TABLE_ENTRY(PyImport_ImportModuleLevel, required);
|
166
|
+
|
167
|
+
INIT_API_TABLE_ENTRY(PyOS_AfterFork, required);
|
168
|
+
|
169
|
+
INIT_API_TABLE_ENTRY(PyList_Size, required);
|
170
|
+
INIT_API_TABLE_ENTRY(PyList_GetItem, required);
|
171
|
+
|
172
|
+
INIT_API_TABLE_ENTRY(PyDict_New, required);
|
173
|
+
INIT_API_TABLE_ENTRY(PyDict_Contains, required);
|
174
|
+
INIT_API_TABLE_ENTRY(PyDict_SetItemString, required);
|
175
|
+
INIT_API_TABLE_ENTRY(PyDict_Next, required);
|
176
|
+
|
177
|
+
INIT_API_TABLE_ENTRY(PySequence_Check, required);
|
178
|
+
INIT_API_TABLE_ENTRY(PySequence_Size, required);
|
179
|
+
INIT_API_TABLE_ENTRY(PySequence_Contains, required);
|
180
|
+
INIT_API_TABLE_ENTRY(PySequence_GetItem, required);
|
181
|
+
|
182
|
+
if (python_string_as_bytes) {
|
183
|
+
INIT_API_TABLE_ENTRY2(PyString_AsStringAndSize, PyBytes_AsStringAndSize, required);
|
184
|
+
INIT_API_TABLE_ENTRY2(PyString_FromStringAndSize, PyBytes_FromStringAndSize, required);
|
185
|
+
INIT_API_TABLE_ENTRY2(PyString_FromFormatV, PyBytes_FromFormat, required);
|
186
|
+
}
|
187
|
+
else {
|
188
|
+
INIT_API_TABLE_ENTRY(PyString_AsStringAndSize, required);
|
189
|
+
INIT_API_TABLE_ENTRY(PyString_FromStringAndSize, required);
|
190
|
+
INIT_API_TABLE_ENTRY(PyString_FromFormatV, required);
|
191
|
+
}
|
192
|
+
|
193
|
+
if (CHECK_API_ENTRY(PyUnicode_DecodeUTF8)) {
|
194
|
+
INIT_API_TABLE_ENTRY(PyUnicode_AsUTF8String, required);
|
195
|
+
INIT_API_TABLE_ENTRY(PyUnicode_DecodeUTF8, required);
|
196
|
+
INIT_API_TABLE_ENTRY(PyUnicode_FromFormatV, required);
|
197
|
+
}
|
198
|
+
else if (CHECK_API_ENTRY(PyUnicodeUCS4_DecodeUTF8)) {
|
199
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_AsUTF8String, PyUnicodeUCS4_AsUTF8String, required);
|
200
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_DecodeUTF8, PyUnicodeUCS4_DecodeUTF8, required);
|
201
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_FromFormatV, PyUnicodeUCS4_FromFormatV, required);
|
202
|
+
}
|
203
|
+
else if (CHECK_API_ENTRY(PyUnicodeUCS2_DecodeUTF8)) {
|
204
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_AsUTF8String, PyUnicodeUCS2_AsUTF8String, required);
|
205
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_DecodeUTF8, PyUnicodeUCS2_DecodeUTF8, required);
|
206
|
+
INIT_API_TABLE_ENTRY2(PyUnicode_FromFormatV, PyUnicodeUCS2_FromFormatV, required);
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
void
|
211
|
+
pycall_init_exceptions(VALUE libpython_handle)
|
212
|
+
{
|
213
|
+
VALUE eLibPythonFunctionNotFound = rb_const_get_at(pycall_mPyCall, rb_intern("LibPythonFunctionNotFound"));
|
214
|
+
|
215
|
+
INIT_API_TABLE_ENTRY_PTR(PyExc_RuntimeError, required);
|
216
|
+
INIT_API_TABLE_ENTRY_PTR(PyExc_TypeError, required);
|
217
|
+
}
|