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,700 @@
|
|
1
|
+
#ifndef PYCALL_INTERNAL_H
|
2
|
+
#define PYCALL_INTERNAL_H 1
|
3
|
+
|
4
|
+
#if defined(__cplusplus)
|
5
|
+
extern "C" {
|
6
|
+
#if 0
|
7
|
+
} /* satisfy cc-mode */
|
8
|
+
#endif
|
9
|
+
#endif
|
10
|
+
|
11
|
+
#include <ruby.h>
|
12
|
+
#include <ruby/encoding.h>
|
13
|
+
#include <assert.h>
|
14
|
+
#include <inttypes.h>
|
15
|
+
#include <limits.h>
|
16
|
+
|
17
|
+
#if SIZEOF_LONG == SIZEOF_VOIDP
|
18
|
+
# define PTR2NUM(x) (LONG2NUM((long)(x)))
|
19
|
+
# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
|
20
|
+
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
21
|
+
# define PTR2NUM(x) (LL2NUM((LONG_LONG)(x)))
|
22
|
+
# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
|
23
|
+
#else
|
24
|
+
# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#ifndef RB_INTEGER_TYPE_P
|
28
|
+
# define RB_INTEGER_TYPE_P(obj) pycall_integer_type_p(obj)
|
29
|
+
static inline int
|
30
|
+
pycall_integer_type_p(VALUE obj)
|
31
|
+
{
|
32
|
+
return (FIXNUM_P(obj) || (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == RUBY_T_BIGNUM));
|
33
|
+
}
|
34
|
+
#endif
|
35
|
+
|
36
|
+
void ruby_debug_breakpoint();
|
37
|
+
|
38
|
+
/* ==== python ==== */
|
39
|
+
|
40
|
+
typedef intptr_t Py_intptr_t;
|
41
|
+
|
42
|
+
#ifdef HAVE_SSIZE_T
|
43
|
+
typedef ssize_t Py_ssize_t;
|
44
|
+
#elif SIZEOF_SIZE_T == SIZEOF_VOIDP
|
45
|
+
typedef Py_intptr_tr Py_ssize_t;
|
46
|
+
#elif SIZEOF_SIZE_T == SIZEOF_INT
|
47
|
+
typedef int Py_ssize_t;
|
48
|
+
#elif SIZEOF_SIZE_T == SIZEOF_LONG
|
49
|
+
typedef long Py_ssize_t;
|
50
|
+
#elif defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
|
51
|
+
typedef LONG_LONG Py_ssize_t;
|
52
|
+
#else
|
53
|
+
# error "Unable to typedef Py_ssize_t"
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#undef SSIZE_MIN
|
57
|
+
#undef SSIZE_MAX
|
58
|
+
|
59
|
+
#if SIZEOF_SIZE_T == SIZEOF_INT
|
60
|
+
# define SSIZE_MIN INT_MIN
|
61
|
+
# define SSIZE_MAX INT_MAX
|
62
|
+
#elif SIZEOF_SIZE_T == SIZEOF_LONG
|
63
|
+
# define SSIZE_MIN LONG_MIN
|
64
|
+
# define SSIZE_MAX LONG_MAX
|
65
|
+
#elif defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
|
66
|
+
# define SSIZE_MIN LLONG_MIN
|
67
|
+
# define SSIZE_MAX LLONG_MAX
|
68
|
+
#endif
|
69
|
+
|
70
|
+
#define SIZEOF_PY_HASH_T SIZEOF_SSIZE_T
|
71
|
+
typedef Py_ssize_t Py_hash_t;
|
72
|
+
|
73
|
+
/* NOTE: Currently Py_TRACE_REFS is not supported */
|
74
|
+
#define _PyObject_HEAD_EXTRA
|
75
|
+
#define _PyObject_EXTRA_INIT
|
76
|
+
|
77
|
+
#define PyObject_HEAD \
|
78
|
+
_PyObject_HEAD_EXTRA \
|
79
|
+
Py_ssize_t ob_refcnt; \
|
80
|
+
struct _typeobject *ob_type;
|
81
|
+
|
82
|
+
#define PyObject_VAR_HEAD \
|
83
|
+
PyObject ob_base; \
|
84
|
+
Py_ssize_t ob_size; /* Number of items in variable part */
|
85
|
+
|
86
|
+
#define PyObject_HEAD_INIT(type) \
|
87
|
+
_PyObject_EXTRA_INIT \
|
88
|
+
{ 1, type },
|
89
|
+
|
90
|
+
#define PyVarObject_HEAD_INIT(type, size) \
|
91
|
+
PyObject_HEAD_INIT(type) size,
|
92
|
+
|
93
|
+
#define Py_INVALID_SIZE ((Py_ssize_t)-1)
|
94
|
+
|
95
|
+
typedef struct {
|
96
|
+
PyObject_HEAD
|
97
|
+
} PyObject;
|
98
|
+
|
99
|
+
typedef struct {
|
100
|
+
PyObject_VAR_HEAD
|
101
|
+
} PyVarObject;
|
102
|
+
|
103
|
+
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
|
104
|
+
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
|
105
|
+
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
|
106
|
+
|
107
|
+
typedef PyObject * (*unaryfunc)(PyObject *);
|
108
|
+
typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
|
109
|
+
typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
|
110
|
+
typedef int (*inquiry)(PyObject *);
|
111
|
+
typedef Py_ssize_t (*lenfunc)(PyObject *);
|
112
|
+
typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
|
113
|
+
typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
|
114
|
+
typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
|
115
|
+
|
116
|
+
typedef struct bufferinfo {
|
117
|
+
void *buf;
|
118
|
+
PyObject *obj; /* owned reference */
|
119
|
+
Py_ssize_t len;
|
120
|
+
Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
|
121
|
+
pointed to by strides in simple case.*/
|
122
|
+
int readonly;
|
123
|
+
int ndim;
|
124
|
+
char *format;
|
125
|
+
Py_ssize_t *shape;
|
126
|
+
Py_ssize_t *strides;
|
127
|
+
Py_ssize_t *suboffsets;
|
128
|
+
void *internal;
|
129
|
+
} Py_buffer;
|
130
|
+
|
131
|
+
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
|
132
|
+
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
|
133
|
+
|
134
|
+
typedef int (*objobjproc)(PyObject *, PyObject *);
|
135
|
+
typedef int (*visitproc)(PyObject *, void *);
|
136
|
+
typedef int (*traverseproc)(PyObject *, visitproc, void *);
|
137
|
+
|
138
|
+
typedef struct {
|
139
|
+
/* Number implementations must check *both*
|
140
|
+
arguments for proper type and implement the necessary conversions
|
141
|
+
in the slot functions themselves. */
|
142
|
+
|
143
|
+
binaryfunc nb_add;
|
144
|
+
binaryfunc nb_subtract;
|
145
|
+
binaryfunc nb_multiply;
|
146
|
+
binaryfunc nb_remainder;
|
147
|
+
binaryfunc nb_divmod;
|
148
|
+
ternaryfunc nb_power;
|
149
|
+
unaryfunc nb_negative;
|
150
|
+
unaryfunc nb_positive;
|
151
|
+
unaryfunc nb_absolute;
|
152
|
+
inquiry nb_bool;
|
153
|
+
unaryfunc nb_invert;
|
154
|
+
binaryfunc nb_lshift;
|
155
|
+
binaryfunc nb_rshift;
|
156
|
+
binaryfunc nb_and;
|
157
|
+
binaryfunc nb_xor;
|
158
|
+
binaryfunc nb_or;
|
159
|
+
unaryfunc nb_int;
|
160
|
+
void *nb_reserved; /* the slot formerly known as nb_long */
|
161
|
+
unaryfunc nb_float;
|
162
|
+
|
163
|
+
binaryfunc nb_inplace_add;
|
164
|
+
binaryfunc nb_inplace_subtract;
|
165
|
+
binaryfunc nb_inplace_multiply;
|
166
|
+
binaryfunc nb_inplace_remainder;
|
167
|
+
ternaryfunc nb_inplace_power;
|
168
|
+
binaryfunc nb_inplace_lshift;
|
169
|
+
binaryfunc nb_inplace_rshift;
|
170
|
+
binaryfunc nb_inplace_and;
|
171
|
+
binaryfunc nb_inplace_xor;
|
172
|
+
binaryfunc nb_inplace_or;
|
173
|
+
|
174
|
+
binaryfunc nb_floor_divide;
|
175
|
+
binaryfunc nb_true_divide;
|
176
|
+
binaryfunc nb_inplace_floor_divide;
|
177
|
+
binaryfunc nb_inplace_true_divide;
|
178
|
+
|
179
|
+
unaryfunc nb_index;
|
180
|
+
|
181
|
+
binaryfunc nb_matrix_multiply;
|
182
|
+
binaryfunc nb_inplace_matrix_multiply;
|
183
|
+
} PyNumberMethods;
|
184
|
+
|
185
|
+
typedef struct {
|
186
|
+
lenfunc sq_length;
|
187
|
+
binaryfunc sq_concat;
|
188
|
+
ssizeargfunc sq_repeat;
|
189
|
+
ssizeargfunc sq_item;
|
190
|
+
void *was_sq_slice;
|
191
|
+
ssizeobjargproc sq_ass_item;
|
192
|
+
void *was_sq_ass_slice;
|
193
|
+
objobjproc sq_contains;
|
194
|
+
|
195
|
+
binaryfunc sq_inplace_concat;
|
196
|
+
ssizeargfunc sq_inplace_repeat;
|
197
|
+
} PySequenceMethods;
|
198
|
+
|
199
|
+
typedef struct {
|
200
|
+
lenfunc mp_length;
|
201
|
+
binaryfunc mp_subscript;
|
202
|
+
objobjargproc mp_ass_subscript;
|
203
|
+
} PyMappingMethods;
|
204
|
+
|
205
|
+
typedef struct {
|
206
|
+
unaryfunc am_await;
|
207
|
+
unaryfunc am_aiter;
|
208
|
+
unaryfunc am_anext;
|
209
|
+
} PyAsyncMethods;
|
210
|
+
|
211
|
+
typedef struct {
|
212
|
+
getbufferproc bf_getbuffer;
|
213
|
+
releasebufferproc bf_releasebuffer;
|
214
|
+
} PyBufferProcs;
|
215
|
+
|
216
|
+
typedef void (*freefunc)(void *);
|
217
|
+
typedef void (*destructor)(PyObject *);
|
218
|
+
typedef int (*printfunc)(PyObject *, FILE *, int);
|
219
|
+
typedef PyObject *(*getattrfunc)(PyObject *, char *);
|
220
|
+
typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
|
221
|
+
typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
|
222
|
+
typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
|
223
|
+
typedef PyObject *(*reprfunc)(PyObject *);
|
224
|
+
typedef long (*hashfunc_long)(PyObject *);
|
225
|
+
typedef Py_hash_t (*hashfunc_hash_t)(PyObject *);
|
226
|
+
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
|
227
|
+
typedef PyObject *(*getiterfunc) (PyObject *);
|
228
|
+
typedef PyObject *(*iternextfunc) (PyObject *);
|
229
|
+
typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
|
230
|
+
typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
|
231
|
+
typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
|
232
|
+
typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
|
233
|
+
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
|
234
|
+
|
235
|
+
typedef struct PyMemberDef {
|
236
|
+
const char *name;
|
237
|
+
int type;
|
238
|
+
Py_ssize_t offset;
|
239
|
+
int flags;
|
240
|
+
const char *doc;
|
241
|
+
} PyMemberDef;
|
242
|
+
|
243
|
+
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
|
244
|
+
|
245
|
+
struct PyMethodDef {
|
246
|
+
const char *ml_name; /* The name of the built-in function/method */
|
247
|
+
PyCFunction ml_meth; /* The C function that implements it */
|
248
|
+
int ml_flags; /* Combination of METH_xxx flags, which mostly
|
249
|
+
describe the args expected by the C func */
|
250
|
+
const char *ml_doc; /* The __doc__ attribute, or NULL */
|
251
|
+
};
|
252
|
+
typedef struct PyMethodDef PyMethodDef;
|
253
|
+
|
254
|
+
/* Flag passed to newmethodobject */
|
255
|
+
#define Py_METH_VARARGS 0x0001
|
256
|
+
#define Py_METH_KEYWORDS 0x0002
|
257
|
+
#define Py_METH_NOARGS 0x0004
|
258
|
+
#define Py_METH_O 0x0008
|
259
|
+
#define Py_METH_CLASS 0x0010
|
260
|
+
#define Py_METH_STATIC 0x0020
|
261
|
+
#define Py_METH_COEXIST 0x0040
|
262
|
+
#define Py_METH_FASTCALL 0x0080
|
263
|
+
|
264
|
+
typedef struct _typeobject {
|
265
|
+
PyObject_VAR_HEAD
|
266
|
+
const char *tp_name; /* For printing, in format "<module>.<name>" */
|
267
|
+
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
|
268
|
+
|
269
|
+
/* Methods to implement standard operations */
|
270
|
+
|
271
|
+
destructor tp_dealloc;
|
272
|
+
printfunc tp_print;
|
273
|
+
getattrfunc tp_getattr;
|
274
|
+
setattrfunc tp_setattr;
|
275
|
+
PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2)
|
276
|
+
or tp_reserved (Python 3) */
|
277
|
+
reprfunc tp_repr;
|
278
|
+
|
279
|
+
/* Method suites for standard classes */
|
280
|
+
|
281
|
+
PyNumberMethods *tp_as_number;
|
282
|
+
PySequenceMethods *tp_as_sequence;
|
283
|
+
PyMappingMethods *tp_as_mapping;
|
284
|
+
|
285
|
+
/* More standard operations (here for binary compatibility) */
|
286
|
+
|
287
|
+
union {
|
288
|
+
hashfunc_long _long;
|
289
|
+
hashfunc_hash_t _hash_t;
|
290
|
+
} tp_hash;
|
291
|
+
|
292
|
+
ternaryfunc tp_call;
|
293
|
+
reprfunc tp_str;
|
294
|
+
getattrofunc tp_getattro;
|
295
|
+
setattrofunc tp_setattro;
|
296
|
+
|
297
|
+
/* Functions to access object as input/output buffer */
|
298
|
+
PyBufferProcs *tp_as_buffer;
|
299
|
+
|
300
|
+
/* Flags to define presence of optional/expanded features */
|
301
|
+
unsigned long tp_flags;
|
302
|
+
|
303
|
+
const char *tp_doc; /* Documentation string */
|
304
|
+
|
305
|
+
/* Assigned meaning in release 2.0 */
|
306
|
+
/* call function for all accessible objects */
|
307
|
+
traverseproc tp_traverse;
|
308
|
+
|
309
|
+
/* delete references to contained objects */
|
310
|
+
inquiry tp_clear;
|
311
|
+
|
312
|
+
/* Assigned meaning in release 2.1 */
|
313
|
+
/* rich comparisons */
|
314
|
+
richcmpfunc tp_richcompare;
|
315
|
+
|
316
|
+
/* weak reference enabler */
|
317
|
+
Py_ssize_t tp_weaklistoffset;
|
318
|
+
|
319
|
+
/* Iterators */
|
320
|
+
getiterfunc tp_iter;
|
321
|
+
iternextfunc tp_iternext;
|
322
|
+
|
323
|
+
/* Attribute descriptor and subclassing stuff */
|
324
|
+
struct PyMethodDef *tp_methods;
|
325
|
+
struct PyMemberDef *tp_members;
|
326
|
+
struct PyGetSetDef *tp_getset;
|
327
|
+
struct _typeobject *tp_base;
|
328
|
+
PyObject *tp_dict;
|
329
|
+
descrgetfunc tp_descr_get;
|
330
|
+
descrsetfunc tp_descr_set;
|
331
|
+
Py_ssize_t tp_dictoffset;
|
332
|
+
initproc tp_init;
|
333
|
+
allocfunc tp_alloc;
|
334
|
+
newfunc tp_new;
|
335
|
+
freefunc tp_free; /* Low-level free-memory routine */
|
336
|
+
inquiry tp_is_gc; /* For PyObject_IS_GC */
|
337
|
+
PyObject *tp_bases;
|
338
|
+
PyObject *tp_mro; /* method resolution order */
|
339
|
+
PyObject *tp_cache;
|
340
|
+
PyObject *tp_subclasses;
|
341
|
+
PyObject *tp_weaklist;
|
342
|
+
destructor tp_del;
|
343
|
+
|
344
|
+
/* Type attribute cache version tag. Added in version 2.6 */
|
345
|
+
unsigned int tp_version_tag;
|
346
|
+
|
347
|
+
destructor tp_finalize;
|
348
|
+
|
349
|
+
#ifdef COUNT_ALLOCS
|
350
|
+
/* these must be last and never explicitly initialized */
|
351
|
+
Py_ssize_t tp_allocs;
|
352
|
+
Py_ssize_t tp_frees;
|
353
|
+
Py_ssize_t tp_maxalloc;
|
354
|
+
struct _typeobject *tp_prev;
|
355
|
+
struct _typeobject *tp_next;
|
356
|
+
#endif
|
357
|
+
} PyTypeObject;
|
358
|
+
|
359
|
+
/* Python 2.7 */
|
360
|
+
#define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
|
361
|
+
#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
|
362
|
+
#define Py_TPFLAGS_GC 0 /* was sometimes (0x00000001<<2) in Python <= 2.1 */
|
363
|
+
#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
|
364
|
+
#define Py_TPFLAGS_CHECKTYPES (1L<<4)
|
365
|
+
#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
|
366
|
+
#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
|
367
|
+
#define Py_TPFLAGS_HAVE_ITER (1L<<7)
|
368
|
+
#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
|
369
|
+
#define Py_TPFLAGS_HAVE_INDEX (1L<<17)
|
370
|
+
#define Py_TPFLAGS_HAVE_NEWBUFFER (1L<<21)
|
371
|
+
#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
|
372
|
+
|
373
|
+
/* Python 3.0+ has only the following TPFLAGS: */
|
374
|
+
#define Py_TPFLAGS_HEAPTYPE (1L<<9)
|
375
|
+
#define Py_TPFLAGS_BASETYPE (1L<<10)
|
376
|
+
#define Py_TPFLAGS_READY (1L<<12)
|
377
|
+
#define Py_TPFLAGS_READYING (1L<<13)
|
378
|
+
#define Py_TPFLAGS_HAVE_GC (1L<<14)
|
379
|
+
#define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
|
380
|
+
#define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
|
381
|
+
#define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
|
382
|
+
#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
|
383
|
+
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
|
384
|
+
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
|
385
|
+
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
|
386
|
+
#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
|
387
|
+
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
|
388
|
+
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
|
389
|
+
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
|
390
|
+
#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
|
391
|
+
|
392
|
+
/* only use this if we have the stackless extension */
|
393
|
+
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
|
394
|
+
|
395
|
+
#define PyType_HasFeature(t, f) (((t)->tp_flags & (f)) != 0)
|
396
|
+
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
|
397
|
+
|
398
|
+
/* Member Types */
|
399
|
+
#define Py_T_SHORT 0
|
400
|
+
#define Py_T_INT 1
|
401
|
+
#define Py_T_LONG 2
|
402
|
+
#define Py_T_FLOAT 3
|
403
|
+
#define Py_T_DOUBLE 4
|
404
|
+
#define Py_T_STRING 5
|
405
|
+
#define Py_T_OBJECT 6
|
406
|
+
/* XXX the ordering here is weird for binary compatibility */
|
407
|
+
#define Py_T_CHAR 7 /* 1-character string */
|
408
|
+
#define Py_T_BYTE 8 /* 8-bit signed int */
|
409
|
+
/* unsigned variants: */
|
410
|
+
#define Py_T_UBYTE 9
|
411
|
+
#define Py_T_USHORT 10
|
412
|
+
#define Py_T_UINT 11
|
413
|
+
#define Py_T_ULONG 12
|
414
|
+
|
415
|
+
/* Added by Jack: strings contained in the structure */
|
416
|
+
#define Py_T_STRING_INPLACE 13
|
417
|
+
|
418
|
+
/* Added by Lillo: bools contained in the structure (assumed char) */
|
419
|
+
#define Py_T_BOOL 14
|
420
|
+
|
421
|
+
#define Py_T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
|
422
|
+
when the value is NULL, instead of
|
423
|
+
converting to None. */
|
424
|
+
#define Py_T_LONGLONG 17
|
425
|
+
#define Py_T_ULONGLONG 18
|
426
|
+
|
427
|
+
#define Py_T_PYSSIZET 19 /* Py_ssize_t */
|
428
|
+
#define Py_T_NONE 20 /* Value is always None */
|
429
|
+
|
430
|
+
|
431
|
+
/* Member Flags */
|
432
|
+
#define Py_READONLY 1
|
433
|
+
#define Py_READ_RESTRICTED 2
|
434
|
+
#define Py_PY_WRITE_RESTRICTED 4
|
435
|
+
#define Py_RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
|
436
|
+
|
437
|
+
/* Rich comparison opcodes */
|
438
|
+
#define Py_LT 0
|
439
|
+
#define Py_LE 1
|
440
|
+
#define Py_EQ 2
|
441
|
+
#define Py_NE 3
|
442
|
+
#define Py_GT 4
|
443
|
+
#define Py_GE 5
|
444
|
+
|
445
|
+
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
|
446
|
+
#define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \
|
447
|
+
(Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
|
448
|
+
|
449
|
+
typedef union _gc_head {
|
450
|
+
struct {
|
451
|
+
union _gc_head *gc_next;
|
452
|
+
union _gc_head *gc_prev;
|
453
|
+
Py_ssize_t gc_refs;
|
454
|
+
} gc;
|
455
|
+
long double dummy; /* force worst-case alignment */
|
456
|
+
} PyGC_Head;
|
457
|
+
|
458
|
+
typedef struct {
|
459
|
+
PyObject_HEAD
|
460
|
+
PyObject *cl_bases; /* A tuple of class objects */
|
461
|
+
PyObject *cl_dict; /* A dictionary */
|
462
|
+
PyObject *cl_name; /* A string */
|
463
|
+
/* The following three are functions or NULL */
|
464
|
+
PyObject *cl_getattr;
|
465
|
+
PyObject *cl_setattr;
|
466
|
+
PyObject *cl_delattr;
|
467
|
+
PyObject *cl_weakreflist; /* List of weak references */
|
468
|
+
} PyClassObject;
|
469
|
+
|
470
|
+
typedef struct {
|
471
|
+
PyObject_HEAD
|
472
|
+
PyClassObject *in_class; /* The class object */
|
473
|
+
PyObject *in_dict; /* A dictionary */
|
474
|
+
PyObject *in_weakreflist; /* List of weak references */
|
475
|
+
} PyInstanceObject;
|
476
|
+
|
477
|
+
/* ==== ruby_object wrapper ==== */
|
478
|
+
|
479
|
+
typedef struct {
|
480
|
+
PyObject_HEAD
|
481
|
+
VALUE ruby_object;
|
482
|
+
} PyRubyObject;
|
483
|
+
|
484
|
+
extern PyTypeObject PyRuby_Type;
|
485
|
+
|
486
|
+
#define PyRuby_Check(pyobj) (Py_TYPE(pyobj) == &PyRuby_Type)
|
487
|
+
#define PyRuby_get_ruby_object(pyobj) (((PyRubyObject *)(pyobj))->ruby_object)
|
488
|
+
|
489
|
+
PyObject * PyRuby_New(VALUE ruby_object);
|
490
|
+
|
491
|
+
/* ==== pycall ==== */
|
492
|
+
|
493
|
+
typedef struct {
|
494
|
+
PyObject *_Py_NoneStruct;
|
495
|
+
PyObject *_Py_TrueStruct;
|
496
|
+
PyObject *_Py_FalseStruct;
|
497
|
+
|
498
|
+
PyTypeObject *PyBool_Type;
|
499
|
+
PyTypeObject *PyClass_Type;
|
500
|
+
PyTypeObject *PyComplex_Type;
|
501
|
+
PyTypeObject *PyDict_Type;
|
502
|
+
PyTypeObject *PyFloat_Type;
|
503
|
+
PyTypeObject *PyInstance_Type;
|
504
|
+
PyTypeObject *PyInt_Type;
|
505
|
+
PyTypeObject *PyList_Type;
|
506
|
+
PyTypeObject *PyLong_Type;
|
507
|
+
PyTypeObject *PyModule_Type;
|
508
|
+
PyTypeObject *PyString_Type;
|
509
|
+
PyTypeObject *PyTuple_Type;
|
510
|
+
PyTypeObject *PyType_Type;
|
511
|
+
PyTypeObject *PyUnicode_Type;
|
512
|
+
|
513
|
+
PyObject *PyExc_RuntimeError;
|
514
|
+
PyObject *PyExc_TypeError;
|
515
|
+
|
516
|
+
void (* Py_InitializeEx)(int);
|
517
|
+
int (* Py_IsInitialized)();
|
518
|
+
char const * (* Py_GetVersion)();
|
519
|
+
|
520
|
+
void (* PySys_SetArgvEx)(int, char **, int);
|
521
|
+
|
522
|
+
void (* Py_IncRef)(PyObject *);
|
523
|
+
void (* Py_DecRef)(PyObject *);
|
524
|
+
|
525
|
+
PyObject * (* _PyObject_New)(PyTypeObject *);
|
526
|
+
int (* PyCallable_Check)(PyObject *);
|
527
|
+
int (* PyObject_IsInstance)(PyObject *, PyObject *);
|
528
|
+
union {
|
529
|
+
long (* _long)(PyObject *);
|
530
|
+
Py_hash_t (* _hash_t)(PyObject *);
|
531
|
+
} PyObject_Hash;
|
532
|
+
PyObject * (* PyObject_RichCompare)(PyObject *, PyObject *, int);
|
533
|
+
PyObject * (* PyObject_Call)(PyObject *, PyObject *, PyObject *);
|
534
|
+
PyObject * (* PyObject_CallMethod)(PyObject *, char const *, char const *, ...);
|
535
|
+
PyObject * (* PyObject_Dir)(PyObject *);
|
536
|
+
PyObject * (* PyObject_GenericGetAttr)(PyObject *, PyObject *);
|
537
|
+
PyObject * (* PyObject_GetAttrString)(PyObject *, char const *);
|
538
|
+
int (* PyObject_SetAttrString)(PyObject *, char const *, PyObject *);
|
539
|
+
int (* PyObject_HasAttrString)(PyObject *, char const *);
|
540
|
+
PyObject * (* PyObject_GetItem)(PyObject *, PyObject *);
|
541
|
+
int (* PyObject_SetItem)(PyObject *obj, PyObject *key, PyObject *value);
|
542
|
+
int (* PyObject_DelItem)(PyObject *, PyObject *);
|
543
|
+
PyObject * (* PyObject_GetIter)(PyObject *);
|
544
|
+
PyObject * (* PyObject_Str)(PyObject *);
|
545
|
+
PyObject * (* PyObject_Repr)(PyObject *);
|
546
|
+
|
547
|
+
int (* PyType_Ready)(PyTypeObject *);
|
548
|
+
PyObject * (* PyType_GenericNew)(PyTypeObject *, PyObject *, PyObject *);
|
549
|
+
|
550
|
+
PyObject * (* PyWeakref_NewRef)(PyObject *ob, PyObject *callback);
|
551
|
+
|
552
|
+
PyObject * (* PyBool_FromLong)(long);
|
553
|
+
|
554
|
+
PyObject * (* PyCFunction_NewEx)(PyMethodDef *, PyObject *, PyObject *);
|
555
|
+
|
556
|
+
double (* PyComplex_RealAsDouble)(PyObject *);
|
557
|
+
double (* PyComplex_ImagAsDouble)(PyObject *);
|
558
|
+
PyObject * (* PyComplex_FromDoubles)(double, double);
|
559
|
+
|
560
|
+
double (* PyFloat_AsDouble)(PyObject *);
|
561
|
+
PyObject * (* PyFloat_FromDouble)(double);
|
562
|
+
|
563
|
+
PyObject * (* PyInt_FromLong)(long);
|
564
|
+
PyObject * (* PyInt_FromSsize_t)(Py_ssize_t);
|
565
|
+
Py_ssize_t (* PyInt_AsSsize_t)(PyObject *);
|
566
|
+
|
567
|
+
long (* PyLong_AsLongAndOverflow)(PyObject *, int *);
|
568
|
+
PyObject * (* PyLong_FromLong)(long);
|
569
|
+
#ifdef HAVE_LONG_LONG
|
570
|
+
LONG_LONG (* PyLong_AsLongLongAndOverflow)(PyObject *, int *);
|
571
|
+
PyObject * (* PyLong_FromLongLong)(LONG_LONG);
|
572
|
+
#endif
|
573
|
+
Py_ssize_t (* PyLong_AsSsize_t)(PyObject *);
|
574
|
+
|
575
|
+
PyObject * (* PyTuple_New)(Py_ssize_t);
|
576
|
+
Py_ssize_t (* PyTuple_Size)(PyObject *);
|
577
|
+
PyObject * (* PyTuple_GetItem)(PyObject *, Py_ssize_t);
|
578
|
+
int (* PyTuple_SetItem)(PyObject *, Py_ssize_t, PyObject *);
|
579
|
+
|
580
|
+
PyObject * (* PySlice_New)(PyObject *, PyObject *, PyObject *);
|
581
|
+
|
582
|
+
PyObject * (* PyIter_Next)(PyObject *);
|
583
|
+
|
584
|
+
PyObject * (* PyErr_Occurred)(void);
|
585
|
+
void (* PyErr_Fetch)(PyObject **, PyObject **, PyObject **);
|
586
|
+
void (* PyErr_Restore)(PyObject *, PyObject *, PyObject *);
|
587
|
+
void (* PyErr_Clear)(void);
|
588
|
+
void (* PyErr_SetString)(PyObject *, const char *); /* decoded from utf-8 */
|
589
|
+
void (* PyErr_Format)(PyObject *, const char *, ...); /* ASCII-encoded string */
|
590
|
+
|
591
|
+
PyObject * (* PyImport_ImportModule)(char const*);
|
592
|
+
PyObject * (* PyImport_ImportModuleLevel)(char const*, PyObject *, PyObject *, PyObject *, int);
|
593
|
+
|
594
|
+
void (* PyOS_AfterFork)(void);
|
595
|
+
|
596
|
+
PyObject * (* PyList_New)(Py_ssize_t);
|
597
|
+
Py_ssize_t (* PyList_Size)(PyObject *);
|
598
|
+
PyObject * (* PyList_GetItem)(PyObject *, Py_ssize_t);
|
599
|
+
int (* PyList_SetItem)(PyObject *, Py_ssize_t, PyObject *);
|
600
|
+
int (* PyList_Insert)(PyObject *, Py_ssize_t, PyObject *);
|
601
|
+
int (* PyList_Append)(PyObject *, PyObject *);
|
602
|
+
|
603
|
+
PyObject * (* PyDict_New)();
|
604
|
+
int (* PyDict_Contains)(PyObject *, PyObject *);
|
605
|
+
int (* PyDict_SetItemString)(PyObject *, char const *, PyObject *);
|
606
|
+
int (* PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **);
|
607
|
+
|
608
|
+
int (* PySequence_Check)(PyObject *);
|
609
|
+
Py_ssize_t (* PySequence_Size)(PyObject *);
|
610
|
+
int (* PySequence_Contains)(PyObject *, PyObject *);
|
611
|
+
PyObject * (* PySequence_GetItem)(PyObject *, Py_ssize_t);
|
612
|
+
|
613
|
+
int (* PyString_AsStringAndSize)(PyObject *, char **, Py_ssize_t *);
|
614
|
+
PyObject * (* PyString_FromStringAndSize)(char *, Py_ssize_t);
|
615
|
+
PyObject * (* PyString_FromFormatV)(char const*, ...);
|
616
|
+
|
617
|
+
PyObject * (* PyUnicode_AsUTF8String)(PyObject *);
|
618
|
+
PyObject * (* PyUnicode_DecodeUTF8)(char const*, Py_ssize_t, char const *);
|
619
|
+
PyObject * (* PyUnicode_FromFormatV)(char const*, ...);
|
620
|
+
} pycall_libpython_api_table_t;
|
621
|
+
|
622
|
+
pycall_libpython_api_table_t *pycall_libpython_api_table(void);
|
623
|
+
#define Py_API(name) (pycall_libpython_api_table()->name)
|
624
|
+
|
625
|
+
int pycall_python_major_version(void);
|
626
|
+
Py_ssize_t pycall_python_hexversion(void);
|
627
|
+
#define pycall_python_long_hash (pycall_python_hexversion() < 0x03020000)
|
628
|
+
|
629
|
+
void pycall_Py_DecRef(PyObject *);
|
630
|
+
|
631
|
+
RUBY_EXTERN const rb_data_type_t pycall_pyptr_data_type;
|
632
|
+
size_t pycall_pyptr_memsize(void const *);
|
633
|
+
void pycall_pyptr_free(void *);
|
634
|
+
|
635
|
+
VALUE pycall_import_module(char const *name);
|
636
|
+
VALUE pycall_import_module_level(char const *name, VALUE globals, VALUE locals, VALUE fromlist, int level);
|
637
|
+
VALUE pycall_getattr_default(VALUE pyobj, char const *name, VALUE default_value);
|
638
|
+
VALUE pycall_getattr(VALUE pyobj, char const *name);
|
639
|
+
|
640
|
+
VALUE pycall_pyobject_to_ruby(PyObject *);
|
641
|
+
VALUE pycall_pytype_to_ruby(PyObject *);
|
642
|
+
VALUE pycall_pymodule_to_ruby(PyObject *);
|
643
|
+
VALUE pycall_pybool_to_ruby(PyObject *);
|
644
|
+
VALUE pycall_pycomplex_to_ruby(PyObject *);
|
645
|
+
VALUE pycall_pyfloat_to_ruby(PyObject *);
|
646
|
+
VALUE pycall_pyint_to_ruby(PyObject *);
|
647
|
+
VALUE pycall_pylong_to_ruby(PyObject *);
|
648
|
+
VALUE pycall_pystring_to_ruby(PyObject *);
|
649
|
+
VALUE pycall_pyobject_to_a(PyObject *);
|
650
|
+
|
651
|
+
VALUE pycall_conv_to_str(VALUE);
|
652
|
+
|
653
|
+
PyObject *pycall_pyobject_from_ruby(VALUE);
|
654
|
+
PyObject *pycall_pystring_from_ruby(VALUE);
|
655
|
+
PyObject *pycall_pytuple_from_ruby(VALUE);
|
656
|
+
PyObject *pycall_pylist_from_ruby(VALUE);
|
657
|
+
PyObject *pycall_pydict_from_ruby(VALUE);
|
658
|
+
PyObject *pycall_pyslice_from_ruby(VALUE);
|
659
|
+
|
660
|
+
NORETURN(void pycall_pyerror_fetch_and_raise(char const *format, ...));
|
661
|
+
|
662
|
+
unsigned long pycall_default_tp_flags(void);
|
663
|
+
PyObject *pycall_pystring_from_format(char const *format, ...);
|
664
|
+
PyObject *pycall_pystring_from_formatv(char const *format, va_list vargs);
|
665
|
+
|
666
|
+
VALUE pycall_pyrubyptr_new(PyObject *pyrubyobj);
|
667
|
+
|
668
|
+
int pycall_obj_is_step_range(VALUE obj);
|
669
|
+
int pycall_extract_range(VALUE obj, VALUE *pbegin, VALUE *pend, int *pexclude_end, VALUE *pstep);
|
670
|
+
|
671
|
+
void pycall_gcguard_register(PyObject *, VALUE);
|
672
|
+
void pycall_gcguard_delete(PyObject *);
|
673
|
+
void pycall_gcguard_register_pyrubyobj(PyObject *);
|
674
|
+
void pycall_gcguard_unregister_pyrubyobj(PyObject *);
|
675
|
+
|
676
|
+
void pycall_init_libpython_api_table(VALUE handle);
|
677
|
+
void pycall_init_exceptions(VALUE handle);
|
678
|
+
void pycall_init_gcguard(void);
|
679
|
+
void pycall_init_ruby_wrapper(void);
|
680
|
+
|
681
|
+
#define pycall_hash_salt_32 0xb592cd9b
|
682
|
+
extern long pycall_hash_salt;
|
683
|
+
extern VALUE pycall_mPyCall;
|
684
|
+
extern VALUE pycall_cPyPtr;
|
685
|
+
extern VALUE pycall_eError;
|
686
|
+
|
687
|
+
#define mPyCall pycall_mPyCall
|
688
|
+
#define cPyPtr pycall_cPyPtr
|
689
|
+
#define eError pycall_eError
|
690
|
+
|
691
|
+
/* #define PYCALL_DEBUG_DUMP_REFCNT */
|
692
|
+
|
693
|
+
#if defined(__cplusplus)
|
694
|
+
#if 0
|
695
|
+
{ /* satisfy cc-mode */
|
696
|
+
#endif
|
697
|
+
} /* extern "C" { */
|
698
|
+
#endif
|
699
|
+
|
700
|
+
#endif /* PYCALL_INTERNAL_H */
|