rubypython 0.2.11 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/{History.txt → History.markdown} +34 -28
- data/Manifest.txt +26 -40
- data/PostInstall.txt +2 -1
- data/README.markdown +103 -0
- data/Rakefile +19 -3
- data/lib/rubypython.rb +118 -114
- data/lib/rubypython/blankobject.rb +21 -0
- data/lib/rubypython/conversion.rb +198 -0
- data/lib/rubypython/core_ext/string.rb +7 -0
- data/lib/rubypython/legacy.rb +15 -0
- data/lib/rubypython/macros.rb +47 -0
- data/lib/rubypython/operators.rb +111 -0
- data/lib/rubypython/pymainclass.rb +51 -0
- data/lib/rubypython/pyobject.rb +203 -0
- data/lib/rubypython/python.rb +111 -0
- data/lib/rubypython/pythonerror.rb +78 -0
- data/lib/rubypython/rubypyproxy.rb +214 -0
- data/lib/rubypython/version.rb +4 -3
- data/spec/conversion_spec.rb +66 -0
- data/spec/legacy_spec.rb +22 -0
- data/spec/pymainclass_spec.rb +26 -0
- data/spec/pyobject_spec.rb +264 -0
- data/spec/python_helpers/objects.py +41 -0
- data/spec/pythonerror_spec.rb +43 -0
- data/spec/refcnt_spec.rb +68 -0
- data/spec/rubypyclass_spec.rb +13 -0
- data/spec/rubypyproxy_spec.rb +249 -0
- data/spec/rubypython_spec.rb +62 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +51 -0
- metadata +79 -73
- metadata.gz.sig +0 -0
- data/README.txt +0 -60
- data/ext/rubypython_bridge/cbridge.c +0 -150
- data/ext/rubypython_bridge/cbridge.h +0 -15
- data/ext/rubypython_bridge/config.h +0 -14
- data/ext/rubypython_bridge/extconf.rb +0 -43
- data/ext/rubypython_bridge/ptor.c +0 -242
- data/ext/rubypython_bridge/ptor.h +0 -15
- data/ext/rubypython_bridge/rp_blankobject.c +0 -42
- data/ext/rubypython_bridge/rp_blankobject.h +0 -11
- data/ext/rubypython_bridge/rp_class.c +0 -56
- data/ext/rubypython_bridge/rp_class.h +0 -7
- data/ext/rubypython_bridge/rp_error.c +0 -34
- data/ext/rubypython_bridge/rp_error.h +0 -11
- data/ext/rubypython_bridge/rp_function.c +0 -31
- data/ext/rubypython_bridge/rp_function.h +0 -7
- data/ext/rubypython_bridge/rp_instance.c +0 -164
- data/ext/rubypython_bridge/rp_instance.h +0 -7
- data/ext/rubypython_bridge/rp_module.c +0 -160
- data/ext/rubypython_bridge/rp_module.h +0 -8
- data/ext/rubypython_bridge/rp_object.c +0 -194
- data/ext/rubypython_bridge/rp_object.h +0 -23
- data/ext/rubypython_bridge/rp_util.c +0 -63
- data/ext/rubypython_bridge/rp_util.h +0 -11
- data/ext/rubypython_bridge/rtop.c +0 -212
- data/ext/rubypython_bridge/rtop.h +0 -17
- data/ext/rubypython_bridge/rubypython_bridge.c +0 -125
- data/ext/rubypython_bridge/rubypython_bridge.h +0 -10
- data/lib/rubypython/session.rb +0 -4
- data/lib/rubypython/wrapper_extensions.rb +0 -83
- data/setup.rb +0 -1585
- data/tasks/environment.rake +0 -7
- data/tasks/extconf.rake +0 -13
- data/tasks/extconf/rubypython_bridge.rake +0 -49
- data/test/python_helpers/objects.py +0 -12
- data/test/test.wav +0 -0
- data/test/test_helper.rb +0 -2
- data/test/test_rubypython.rb +0 -215
- data/test/test_rubypython_bridge_extn.rb +0 -133
- data/test/test_session.rb +0 -6
@@ -1,23 +0,0 @@
|
|
1
|
-
#include "config.h"
|
2
|
-
#include "ptor.h"
|
3
|
-
#include "rtop.h"
|
4
|
-
#include "cbridge.h"
|
5
|
-
#include "rp_error.h"
|
6
|
-
|
7
|
-
#ifndef _RP_OBJECT_H_
|
8
|
-
#define _RP_OBJECT_H_
|
9
|
-
|
10
|
-
typedef struct RubyPyObj
|
11
|
-
{
|
12
|
-
PyObject* pObject;
|
13
|
-
} PObj;
|
14
|
-
|
15
|
-
PyObject* rpObjectGetPyObject(VALUE);
|
16
|
-
|
17
|
-
VALUE rpObjectFromPyObject(PyObject*);
|
18
|
-
|
19
|
-
int rpHasSymbol(VALUE, ID);
|
20
|
-
|
21
|
-
VALUE rpRespondsTo(VALUE, VALUE);
|
22
|
-
inline void Init_RubyPyObject();
|
23
|
-
#endif
|
@@ -1,63 +0,0 @@
|
|
1
|
-
#include "rp_util.h"
|
2
|
-
|
3
|
-
#include "rp_object.h"
|
4
|
-
#include "rp_function.h"
|
5
|
-
#include "rp_instance.h"
|
6
|
-
#include "rp_class.h"
|
7
|
-
|
8
|
-
RUBY_EXTERN VALUE mRubyPythonBridge;
|
9
|
-
RUBY_EXTERN VALUE ePythonError;
|
10
|
-
RUBY_EXTERN VALUE cRubyPyObject;
|
11
|
-
RUBY_EXTERN VALUE cBlankObject;
|
12
|
-
RUBY_EXTERN VALUE cRubyPyClass;
|
13
|
-
RUBY_EXTERN VALUE cRubyPyFunction;
|
14
|
-
RUBY_EXTERN VALUE cRubyPyInstance;
|
15
|
-
|
16
|
-
VALUE rpObjectWrap(PyObject* pObj)
|
17
|
-
{
|
18
|
-
VALUE rObj;
|
19
|
-
|
20
|
-
if(PyFunction_Check(pObj)||PyMethod_Check(pObj)||!PyObject_HasAttrString(pObj,"__dict__"))
|
21
|
-
{
|
22
|
-
return rpFunctionFromPyObject(pObj);
|
23
|
-
|
24
|
-
}
|
25
|
-
|
26
|
-
if(PyInstance_Check(pObj))
|
27
|
-
{
|
28
|
-
rObj = rpInstanceFromPyObject(pObj);
|
29
|
-
return rObj;
|
30
|
-
}
|
31
|
-
|
32
|
-
return rpClassFromPyObject(pObj);
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
//Pass this function the argument list for a function call. Checks to see
|
37
|
-
//if the first parameter (the method symbol name here because this is called
|
38
|
-
//from within method_missing) ends with an equals
|
39
|
-
int rpSymbolIsSetter(VALUE args)
|
40
|
-
{
|
41
|
-
VALUE mname;
|
42
|
-
VALUE name_string;
|
43
|
-
VALUE isSetter_;
|
44
|
-
|
45
|
-
mname = rb_ary_entry(args, 0);
|
46
|
-
name_string = rb_funcall(mname, rb_intern("to_s"), 0);
|
47
|
-
|
48
|
-
isSetter_ = rb_funcall(name_string, rb_intern("end_with?"), 1, rb_str_new2("="));
|
49
|
-
|
50
|
-
return Qtrue == isSetter_;
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
//Tests if the first argument ends with !!. See the comment for
|
56
|
-
//rpSymbolIsSetter
|
57
|
-
int rpSymbolIsDoubleBang(VALUE args)
|
58
|
-
{
|
59
|
-
VALUE mname = rb_ary_entry(args, 0);
|
60
|
-
VALUE name_string = rb_funcall(mname, rb_intern("to_s"), 0);
|
61
|
-
|
62
|
-
return Qtrue == rb_funcall(name_string, rb_intern("end_with?"), 1, rb_str_new2("!!"));
|
63
|
-
}
|
@@ -1,212 +0,0 @@
|
|
1
|
-
#include "rtop.h"
|
2
|
-
|
3
|
-
RUBY_EXTERN VALUE cRubyPyObject;
|
4
|
-
RUBY_EXTERN PyObject* rpObjectGetPyObject(VALUE self);
|
5
|
-
|
6
|
-
/*
|
7
|
-
* Note: For the builtin types rubypython creates a copy of the ruby
|
8
|
-
* object to pass into python. Builtin types are passed by VALUE not
|
9
|
-
* by REFERENCE.
|
10
|
-
*/
|
11
|
-
|
12
|
-
PyObject* rtopString(VALUE rString)
|
13
|
-
{
|
14
|
-
|
15
|
-
PyObject* pString;
|
16
|
-
char* cString;
|
17
|
-
char* cStringCopy;
|
18
|
-
|
19
|
-
cString = STR2CSTR(rString);
|
20
|
-
cStringCopy = malloc(strlen(cString) * sizeof(char));
|
21
|
-
strcpy(cStringCopy, cString);
|
22
|
-
|
23
|
-
pString = PyString_FromString(cStringCopy);
|
24
|
-
|
25
|
-
return pString;
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
PyObject* rtopArrayToList(VALUE rArray)
|
30
|
-
{
|
31
|
-
PyObject* pList;
|
32
|
-
int i;
|
33
|
-
int size = RARRAY_LEN(rArray);
|
34
|
-
|
35
|
-
pList = PyList_New(size);
|
36
|
-
|
37
|
-
for(i = 0; i < size; i++)
|
38
|
-
{
|
39
|
-
PyList_SetItem(pList, i, rtopObject(rb_ary_entry(rArray, i), 0));
|
40
|
-
}
|
41
|
-
|
42
|
-
return pList;
|
43
|
-
}
|
44
|
-
|
45
|
-
PyObject* rtopArrayToTuple(VALUE rArray)
|
46
|
-
{
|
47
|
-
PyObject *pTuple,*pList;
|
48
|
-
|
49
|
-
pList = rtopArrayToList(rArray);
|
50
|
-
pTuple = PySequence_Tuple(pList);
|
51
|
-
Py_XDECREF(pList);
|
52
|
-
|
53
|
-
return pTuple;
|
54
|
-
}
|
55
|
-
|
56
|
-
PyObject* rtopHash(VALUE rHash)
|
57
|
-
{
|
58
|
-
PyObject *pDict;
|
59
|
-
VALUE rKeys;
|
60
|
-
VALUE rKey, rVal;
|
61
|
-
int i;
|
62
|
-
|
63
|
-
pDict = PyDict_New();
|
64
|
-
|
65
|
-
rKeys = rb_funcall(rHash, rb_intern("keys"), 0);
|
66
|
-
|
67
|
-
for(i = 0; i < RARRAY_LEN(rKeys); i++)
|
68
|
-
{
|
69
|
-
rKey = rb_ary_entry(rKeys, i);
|
70
|
-
rVal = rb_hash_aref(rHash, rKey);
|
71
|
-
PyDict_SetItem(pDict, rtopObject(rKey, 1), rtopObject(rVal, 0));
|
72
|
-
}
|
73
|
-
|
74
|
-
return pDict;
|
75
|
-
}
|
76
|
-
|
77
|
-
PyObject* rtopFixnum(VALUE rNum)
|
78
|
-
{
|
79
|
-
PyObject* pNum;
|
80
|
-
long cNum;
|
81
|
-
|
82
|
-
cNum = NUM2LONG(rNum);
|
83
|
-
pNum = PyInt_FromLong(cNum);
|
84
|
-
|
85
|
-
return pNum;
|
86
|
-
}
|
87
|
-
|
88
|
-
PyObject* rtopBignum(VALUE rNum)
|
89
|
-
{
|
90
|
-
PyObject* pNum;
|
91
|
-
long cNum;
|
92
|
-
|
93
|
-
cNum = NUM2LONG(rNum);
|
94
|
-
pNum = PyLong_FromLong(cNum);
|
95
|
-
|
96
|
-
return pNum;
|
97
|
-
}
|
98
|
-
|
99
|
-
PyObject* rtopFloat(VALUE rNum)
|
100
|
-
{
|
101
|
-
PyObject* pNum;
|
102
|
-
double cNum;
|
103
|
-
|
104
|
-
cNum = NUM2DBL(rNum);
|
105
|
-
pNum = PyFloat_FromDouble(cNum);
|
106
|
-
|
107
|
-
return pNum;
|
108
|
-
}
|
109
|
-
|
110
|
-
PyObject* rtopFalse()
|
111
|
-
{
|
112
|
-
Py_RETURN_FALSE;
|
113
|
-
}
|
114
|
-
|
115
|
-
PyObject* rtopTrue()
|
116
|
-
{
|
117
|
-
Py_RETURN_TRUE;
|
118
|
-
}
|
119
|
-
|
120
|
-
PyObject* rtopSymbol(VALUE rSymbol)
|
121
|
-
{
|
122
|
-
PyObject* pString;
|
123
|
-
char* cStr;
|
124
|
-
|
125
|
-
cStr = STR2CSTR(rb_funcall(rSymbol, rb_intern("to_s"), 0));
|
126
|
-
pString = PyString_FromString(cStr);
|
127
|
-
|
128
|
-
return pString;
|
129
|
-
|
130
|
-
}
|
131
|
-
|
132
|
-
PyObject* rtopObject(VALUE rObj, int is_key)
|
133
|
-
{
|
134
|
-
// The above is_key parameter determines whether the object
|
135
|
-
// created show be immutable if possible
|
136
|
-
|
137
|
-
PyObject *pObj;
|
138
|
-
VALUE rInspect;
|
139
|
-
|
140
|
-
// Check the object for its type and apply the appropriate
|
141
|
-
// conversion function
|
142
|
-
|
143
|
-
switch(TYPE(rObj))
|
144
|
-
{
|
145
|
-
case T_STRING:
|
146
|
-
pObj = rtopString(rObj);
|
147
|
-
break;
|
148
|
-
|
149
|
-
case T_ARRAY:
|
150
|
-
// If this object is going to be used as a
|
151
|
-
// hash key we should make it a tuple instead
|
152
|
-
// of a list
|
153
|
-
if(is_key) pObj = rtopArrayToTuple(rObj);
|
154
|
-
else
|
155
|
-
{
|
156
|
-
pObj = rtopArrayToList(rObj);
|
157
|
-
}
|
158
|
-
break;
|
159
|
-
|
160
|
-
case T_HASH:
|
161
|
-
pObj = rtopHash(rObj);
|
162
|
-
break;
|
163
|
-
|
164
|
-
case T_FIXNUM:
|
165
|
-
pObj = rtopFixnum(rObj);
|
166
|
-
break;
|
167
|
-
|
168
|
-
case T_BIGNUM:
|
169
|
-
pObj = rtopBignum(rObj);
|
170
|
-
break;
|
171
|
-
|
172
|
-
case T_FLOAT:
|
173
|
-
pObj = rtopFloat(rObj);
|
174
|
-
break;
|
175
|
-
|
176
|
-
case T_NIL:
|
177
|
-
pObj = Py_None;
|
178
|
-
break;
|
179
|
-
|
180
|
-
case T_TRUE:
|
181
|
-
pObj = rtopTrue();
|
182
|
-
break;
|
183
|
-
|
184
|
-
case T_FALSE:
|
185
|
-
pObj = rtopFalse();
|
186
|
-
break;
|
187
|
-
|
188
|
-
case T_SYMBOL:
|
189
|
-
pObj = rtopSymbol(rObj);
|
190
|
-
break;
|
191
|
-
|
192
|
-
default:
|
193
|
-
if(rb_obj_is_kind_of(rObj, cRubyPyObject) == Qtrue)
|
194
|
-
{
|
195
|
-
// rObj is a wrapped python object. We
|
196
|
-
// just take the object it wraps. In
|
197
|
-
// this case we are effectively passing
|
198
|
-
// a python object by reference
|
199
|
-
pObj = rpObjectGetPyObject(rObj);
|
200
|
-
}
|
201
|
-
else
|
202
|
-
{
|
203
|
-
// If we can't figure out what else to
|
204
|
-
// do with the ruby object we just pass
|
205
|
-
// a string representation of it
|
206
|
-
rInspect = rb_inspect(rObj);
|
207
|
-
pObj = rtopString(rInspect);
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
return pObj;
|
212
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
#include "config.h"
|
2
|
-
|
3
|
-
#ifndef _RTOP_H_
|
4
|
-
#define _RTOP_H_
|
5
|
-
PyObject* rtopString(VALUE);
|
6
|
-
PyObject* rtopArrayToList(VALUE);
|
7
|
-
PyObject* rtopArrayToTuple(VALUE);
|
8
|
-
PyObject* rtopHash(VALUE);
|
9
|
-
PyObject* rtopFixnum(VALUE);
|
10
|
-
PyObject* rtopBignum(VALUE);
|
11
|
-
PyObject* rtopFloat(VALUE);
|
12
|
-
PyObject* rtopFalse(void);
|
13
|
-
PyObject* rtopTrue(void);
|
14
|
-
PyObject* rtopSymbol(VALUE);
|
15
|
-
PyObject* rtopObject(VALUE, int);
|
16
|
-
|
17
|
-
#endif /* _RTOP_H_ */
|
@@ -1,125 +0,0 @@
|
|
1
|
-
#include "rubypython_bridge.h"
|
2
|
-
|
3
|
-
#include "ptor.h" //PyObject* to VALUE conversion
|
4
|
-
#include "rtop.h" //VALUE to PyObject* conversion
|
5
|
-
#include "cbridge.h" //General interface functions
|
6
|
-
#include "rp_error.h" //Error propogation from Python to Ruby
|
7
|
-
#include "rp_object.h"
|
8
|
-
#include "rp_blankobject.h"
|
9
|
-
#include "rp_util.h"
|
10
|
-
#include "rp_module.h"
|
11
|
-
#include "rp_class.h"
|
12
|
-
#include "rp_function.h"
|
13
|
-
#include "rp_instance.h"
|
14
|
-
|
15
|
-
VALUE mRubyPythonBridge;
|
16
|
-
|
17
|
-
RUBY_EXTERN VALUE cRubyPyObject;
|
18
|
-
RUBY_EXTERN VALUE cRubyPyModule;
|
19
|
-
RUBY_EXTERN VALUE cRubyPyClass;
|
20
|
-
RUBY_EXTERN VALUE cBlankObject;
|
21
|
-
|
22
|
-
|
23
|
-
/*
|
24
|
-
call - seq: func(modname, funcname, *args)
|
25
|
-
|
26
|
-
Given a python module name _modname_ and a function name _funcname_ calls the given function
|
27
|
-
with the supplied arguments.
|
28
|
-
|
29
|
-
Use builtins as the module for a built in function.
|
30
|
-
|
31
|
-
*/
|
32
|
-
static VALUE func_with_module(VALUE self, VALUE args)
|
33
|
-
{
|
34
|
-
// Before doing anything we attempt to start the interpreter
|
35
|
-
// Started here will be 1 if the interpreter is started by this
|
36
|
-
// function and zero otherwise
|
37
|
-
int started_here = rpSafeStart();
|
38
|
-
|
39
|
-
VALUE module, func, return_val;
|
40
|
-
|
41
|
-
// If we hav less than two arguments we cannot proceed.
|
42
|
-
// Perhaps it would make more sense to throw an error here.
|
43
|
-
if(RARRAY_LEN(args) < 2) return Qfalse;
|
44
|
-
|
45
|
-
module = rb_ary_shift(args);
|
46
|
-
func = rb_ary_shift(args);
|
47
|
-
|
48
|
-
// rpCallWithModule is defined in cbridge.c
|
49
|
-
return_val = rpCallWithModule(module, func, args);
|
50
|
-
|
51
|
-
// If we started the interpreter, we now halt it.
|
52
|
-
rpSafeStop(started_here);
|
53
|
-
|
54
|
-
return return_val;
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
/*
|
59
|
-
* call - seq: import(modname)
|
60
|
-
*
|
61
|
-
* Imports the python module _modname_ using the interpreter and returns a ruby wrapper
|
62
|
-
*/
|
63
|
-
static VALUE rp_import(VALUE self, VALUE mname)
|
64
|
-
{
|
65
|
-
return rb_class_new_instance(1,&mname, cRubyPyModule);
|
66
|
-
}
|
67
|
-
|
68
|
-
|
69
|
-
/*
|
70
|
-
* call - seq: start()
|
71
|
-
*
|
72
|
-
* Starts the python interpreter
|
73
|
-
*/
|
74
|
-
VALUE rp_start(VALUE self)
|
75
|
-
{
|
76
|
-
|
77
|
-
|
78
|
-
if(Py_IsInitialized())
|
79
|
-
{
|
80
|
-
return Qfalse;
|
81
|
-
}
|
82
|
-
Py_Initialize();
|
83
|
-
|
84
|
-
return Qtrue;
|
85
|
-
}
|
86
|
-
|
87
|
-
/*
|
88
|
-
* call - seq: stop()
|
89
|
-
*
|
90
|
-
* Stop the python interpreter
|
91
|
-
*/
|
92
|
-
VALUE rp_stop(VALUE self)
|
93
|
-
{
|
94
|
-
|
95
|
-
if(Py_IsInitialized())
|
96
|
-
{
|
97
|
-
Py_Finalize();
|
98
|
-
return Qtrue;
|
99
|
-
}
|
100
|
-
return Qfalse;
|
101
|
-
|
102
|
-
}
|
103
|
-
|
104
|
-
|
105
|
-
/*
|
106
|
-
* Module containing an interface to the the python interpreter.
|
107
|
-
*
|
108
|
-
* Use RubyPython instead.
|
109
|
-
*/
|
110
|
-
void Init_rubypython_bridge()
|
111
|
-
{
|
112
|
-
mRubyPythonBridge = rb_define_module("RubyPythonBridge");
|
113
|
-
rb_define_module_function(mRubyPythonBridge,"func", func_with_module,- 2);
|
114
|
-
rb_define_module_function(mRubyPythonBridge,"start", rp_start, 0);
|
115
|
-
rb_define_module_function(mRubyPythonBridge,"stop", rp_stop, 0);
|
116
|
-
rb_define_module_function(mRubyPythonBridge,"import", rp_import, 1);
|
117
|
-
Init_BlankObject();
|
118
|
-
Init_RubyPyObject();
|
119
|
-
Init_RubyPyModule();
|
120
|
-
Init_RubyPyClass();
|
121
|
-
Init_RubyPyFunction();
|
122
|
-
Init_RubyPyError();
|
123
|
-
Init_RubyPyInstance();
|
124
|
-
|
125
|
-
}
|