4
* Python-specific OpenIPMI SWIG language information
6
* Author: MontaVista Software, Inc.
7
* Corey Minyard <minyard@mvista.com>
10
* Copyright 2004 MontaVista Software Inc.
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU Lesser General Public License
14
* as published by the Free Software Foundation; either version 2 of
15
* the License, or (at your option) any later version.
18
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* You should have received a copy of the GNU Lesser General Public
30
* License along with this program; if not, write to the Free
31
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35
%typemap(in) swig_cb {
39
%typemap(arginit) intarray {
43
%typemap(in) intarray {
46
if (!PySequence_Check($input)) {
47
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
50
$1.len = PyObject_Length($input);
51
$1.val = (int *) malloc($1.len*sizeof(int));
53
for (i=0; i<$1.len; i++) {
54
PyObject *o = PySequence_GetItem($input,i);
56
PyErr_SetString(PyExc_ValueError, "Expecting a sequence of ints");
59
if (!PyInt_Check(o)) {
61
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of ints");
65
$1.val[i] = PyInt_AS_LONG(o);
70
%typemap(freearg) intarray {
75
%typemap(out) intarray {
79
list = PyList_New($1.len);
81
PyErr_SetString(PyExc_ValueError,
82
"Unable to allocate intarray object");
85
for (i=0; i<$1.len; i++) {
86
PyObject *o = PyInt_FromLong($1.val[i]);
90
o = PyList_GetItem(list, j);
94
PyErr_SetString(PyExc_ValueError,
95
"Unable to allocate intarray object");
98
PyList_SET_ITEM(list, i, o);
103
%typemap(in) char ** {
106
if (!PySequence_Check($input)) {
107
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
110
len = PyObject_Length($input);
111
$1 = (char **) malloc((len+1)*sizeof(char *));
112
for (i=0; i<len; i++) {
113
PyObject *o = PySequence_GetItem($input,i);
115
PyErr_SetString(PyExc_ValueError, "Expecting a sequence of strings");
118
if (!PyString_Check(o)) {
119
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of strings");
123
$1[i] = PyString_AS_STRING(o);
129
%typemap(freearg) char ** {
133
%typemap(in) double * (double dvalue) {
135
if (!PySequence_Check($input)) {
136
PyErr_SetString(PyExc_ValueError,"Expecting a sequence");
139
o = PySequence_GetItem($input,0);
141
PyErr_SetString(PyExc_ValueError, "Expecting a floating point number");
144
if (!PyFloat_Check(o)) {
146
PyErr_SetString(PyExc_ValueError, "expected a floating point number");
149
dvalue = PyFloat_AS_DOUBLE(o);
154
%typemap(argout) double * {
155
PyObject *o = PyFloat_FromDouble(*$1);
157
PyErr_SetString(PyExc_TypeError, "Unable to allocate double object");
160
if (PySequence_SetItem($input, 0, o) == -1) {
161
PyErr_SetString(PyExc_TypeError, "Unable to set double object item");
168
%typemap(in) int * (int ivalue) {
170
if (!PySequence_Check($input)) {
171
PyErr_SetString(PyExc_ValueError, "Expecting a sequence");
174
o = PySequence_GetItem($input, 0);
176
PyErr_SetString(PyExc_ValueError, "Expecting an integer number");
179
if (!PyInt_Check(o)) {
181
PyErr_SetString(PyExc_ValueError, "expected an integer number");
184
ivalue = PyInt_AS_LONG(o);
189
%typemap(argout) int * {
190
PyObject *o = PyInt_FromLong(*$1);
192
PyErr_SetString(PyExc_TypeError, "Unable to allocate int object");
195
if (PySequence_SetItem($input, 0, o) == -1) {
196
PyErr_SetString(PyExc_TypeError, "Unable to set int object item");
203
%typemap(in) unsigned int * (unsigned int ivalue) {
205
if (!PySequence_Check($input)) {
206
PyErr_SetString(PyExc_ValueError, "Expecting a sequence");
209
o = PySequence_GetItem($input, 0);
211
PyErr_SetString(PyExc_ValueError, "Expecting an integer number");
214
if (!PyInt_Check(o)) {
215
PyErr_SetString(PyExc_ValueError, "expected an integer number");
219
ivalue = PyInt_AS_LONG(o);
224
%typemap(argout) unsigned int * {
225
PyObject *o = PyInt_FromLong(*$1);
227
PyErr_SetString(PyExc_TypeError, "Unable to allocate int object");
230
if (PySequence_SetItem($input, 0, o) == -1) {
231
PyErr_SetString(PyExc_TypeError, "Unable to set int object item");
241
swig_make_ref_destruct_i(void *item, swig_type_info *class)
245
rv.val = SWIG_NewPointerObj(item, class, 1);
249
/* Make a reference whose destructor will be called when everything
251
#define swig_make_ref_destruct(item, name) \
252
swig_make_ref_destruct_i(item, SWIGTYPE_p_ ## name)
255
swig_make_ref_i(void *item, swig_type_info *class)
259
rv.val = SWIG_NewPointerObj(item, class, 0);
263
#define swig_make_ref(item, name) \
264
swig_make_ref_i(item, SWIGTYPE_p_ ## name)
267
swig_free_ref(swig_ref ref)
273
get_swig_cb_i(swig_cb cb)
277
#define get_swig_cb(cb, func) get_swig_cb_i(cb)
280
ref_swig_cb_i(swig_cb cb)
285
#define ref_swig_cb(cb, func) ref_swig_cb_i(cb)
288
deref_swig_cb(swig_cb cb)
295
deref_swig_cb_val(swig_cb_val cb)
302
valid_swig_cb_i(swig_cb cb, char *func)
304
PyObject *meth = PyObject_GetAttrString(cb, func);
307
if (!PyMethod_Check(meth))
312
#define valid_swig_cb(v, func) valid_swig_cb_i(v, #func)
315
swig_count_format(char *format)
319
for (; *format; format++) {
370
static void swig_call_cb(swig_cb_val cb, char *method_name, char *format, ...)
372
__attribute__ ((__format__ (__printf__, 3, 4)))
376
swig_call_cb(swig_cb_val cb, char *method_name,
383
PyObject *args = NULL;
391
n = swig_count_format(format);
393
args = PyTuple_New(n);
395
errstr = "cannot allocate PyTyple";
399
va_start(ap, format);
402
for (; *format; format++) {
411
o = PyInt_FromLong(va_arg(ap, int));
415
o = PyFloat_FromDouble(va_arg(ap, double));
424
/* An array of unsigned characters */
425
len = va_arg(ap, int);
426
data = va_arg(ap, unsigned char *);
429
errstr = "cannot allocate list";
432
for (i=0; i<len; i++, data++) {
433
p = PyInt_FromLong(*data);
435
errstr = "cannot allocate uchar list item";
438
PyList_SET_ITEM(o, i, p);
443
/* An array of integers */
444
len = va_arg(ap, int);
445
idata = va_arg(ap, int *);
448
errstr = "cannot allocate list";
451
for (i=0; i<len; i++, idata++) {
452
p = PyInt_FromLong(*idata);
454
errstr = "cannot allocate uchar list item";
457
PyList_SET_ITEM(o, i, p);
462
/* An array of objects */
465
len = va_arg(ap, int);
466
list = va_arg(ap, swig_ref **);
469
errstr = "cannot allocate list";
472
for (i=0; i<len; i++, list++)
473
PyList_SET_ITEM(o, i, (*list)->val);
489
o = PyInt_FromLong(va_arg(ap, long));
499
o = PyString_FromString(va_arg(ap, char *));
503
/* Object pointer (swig_ref) */
505
swig_ref *v = va_arg(ap, swig_ref *);
515
errstr = "Problem getting object";
519
PyTuple_SET_ITEM(args, pos, o);
526
p = PyObject_GetAttrString(cb, method_name);
528
o = PyObject_CallObject(p, args);