annotate Mac/Modules/calldll.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents fdd1e1a530af
children 365526c4cf8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 /***********************************************************
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 The Netherlands.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 All Rights Reserved
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 distribution of the software without specific, written prior
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 permission.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 While CWI is the initial source for this software, a modified version
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 is made available by the Corporation for National Research Initiatives
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 ******************************************************************/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
32 /* Sanity check */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
33 #ifndef __powerc
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
34 #error Please port this code to your architecture first...
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
35 #endif
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
36
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
37 /*
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
38 ** Define to include testroutines (at the end)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
39 */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
40 #define TESTSUPPORT
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
41
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 #include "Python.h"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 #include "macglue.h"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 #include "macdefs.h"
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
45 #include <CodeFragments.h>
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
47 /* Prototypes for routines not in any include file (shame, shame) */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 extern PyObject *ResObj_New Py_PROTO((Handle));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 extern int ResObj_Convert Py_PROTO((PyObject *, Handle *));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 static PyObject *ErrorObject;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
53 /* Debugging macro */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
54 #ifdef TESTSUPPORT
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 #define PARANOID(arg) \
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 if ( arg == 0 ) {PyErr_SetString(ErrorObject, "Internal error: NULL arg!"); return 0; }
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
57 #else
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
58 #define PARANOID(arg) /*pass*/
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
59 #endif
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
60
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
61 /* Prototypes we use for routines and arguments */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 typedef long anything;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 typedef anything (*anyroutine) Py_PROTO((...));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
66 /* Other constants */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 #define MAXNAME 31 /* Maximum size of names, for printing only */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 #define MAXARG 8 /* Maximum number of arguments */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 /*
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
71 ** Routines to convert arguments between Python and C.
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
72 ** Note return-value converters return NULL if this argument (or return value)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
73 ** doesn't return anything. The call-wrapper code collects all return values,
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
74 ** and does the expected thing based on the number of return values: return None, a single
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
75 ** value or a tuple of values.
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
76 **
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
77 ** Hence, optional return values are also implementable.
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 typedef anything (*py2c_converter) Py_PROTO((PyObject *));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 typedef PyObject *(*c2py_converter) Py_PROTO((anything));
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
81 typedef PyObject *(*rv2py_converter) Py_PROTO((anything));
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
82
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 /* Dummy routine for arguments that are output-only */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 py2c_dummy(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 /* Routine to allocate storage for output integers */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 py2c_alloc(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 char *ptr;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 if( (ptr=malloc(sizeof(anything))) == 0 )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 PyErr_NoMemory();
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 return (anything)ptr;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 /* Dummy routine for arguments that are input-only */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 c2py_dummy(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
112 /* Dummy routine for void return value */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
113 static PyObject *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
114 rv2py_none(arg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
115 anything arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
116 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
117 return 0;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
118 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
119
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 /* Routine to de-allocate storage for input-only arguments */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 c2py_free(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 if ( arg )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 free((char *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 /*
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
131 ** OSErr return value.
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 static PyObject *
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
134 rv2py_oserr(arg)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 {
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
137 OSErr err = (OSErr)arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
138
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
139 if (err)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
140 return PyMac_Error(err);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
141 return 0;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 /*
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
145 ** Input integers of all sizes (PPC only)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 py2c_in_int(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 return PyInt_AsLong(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
154 /*
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
155 ** Integer return values of all sizes (PPC only)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
156 */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
157 static PyObject *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
158 rv2py_int(arg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
159 anything arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
160 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
161 return PyInt_FromLong((long)arg);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
162 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
163
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
164 /*
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
165 ** Integer output parameters
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
166 */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 c2py_out_long(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 PyObject *rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 rv = PyInt_FromLong(*(long *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 free((char *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 c2py_out_short(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 PyObject *rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 rv = PyInt_FromLong((long)*(short *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 free((char *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192 c2py_out_byte(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 PyObject *rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 rv = PyInt_FromLong((long)*(char *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 free((char *)arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 /*
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 ** Strings
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 py2c_in_string(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 return (anything)PyString_AsString(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 /*
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214 ** Pascal-style strings
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 py2c_in_pstring(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 unsigned char *p;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 int size;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223 if( (size = PyString_Size(arg)) < 0)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 if ( size > 255 ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226 PyErr_SetString(ErrorObject, "Pstring must be <= 255 chars");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 if( (p=(unsigned char *)malloc(256)) == 0 ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 PyErr_NoMemory();
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
231 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 p[0] = size;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 memcpy(p+1, PyString_AsString(arg), size);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 return (anything)p;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 py2c_out_pstring(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 unsigned char *p;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
243
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 if( (p=(unsigned char *)malloc(256)) == 0 ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 PyErr_NoMemory();
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 p[0] = 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 return (anything)p;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 c2py_out_pstring(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
256 unsigned char *p = (unsigned char *)arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
257 PyObject *rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260 rv = PyString_FromStringAndSize((char *)p+1, p[0]);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261 free(p);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
262 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
263 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
264
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
265 static PyObject *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
266 rv2py_pstring(arg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
267 anything arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
268 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
269 unsigned char *p = (unsigned char *)arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
270 PyObject *rv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
271
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
272 if ( arg == NULL ) return NULL;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
273 rv = PyString_FromStringAndSize((char *)p+1, p[0]);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
274 return rv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
275 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
276
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 /*
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 ** C objects.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
279 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281 py2c_in_cobject(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
283 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
284 if ( arg == Py_None )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 return (anything)PyCObject_AsVoidPtr(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 c2py_out_cobject(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 void **ptr = (void **)arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 PyObject *rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 if ( *ptr == 0 ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 Py_INCREF(Py_None);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 rv = Py_None;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 } else {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 rv = PyCObject_FromVoidPtr(*ptr, 0);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 free((char *)ptr);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
307 static PyObject *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
308 rv2py_cobject(arg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
309 anything arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
310 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
311 void *ptr = (void *)arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
312 PyObject *rv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
313
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
314 if ( ptr == 0 ) return NULL;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
315 rv = PyCObject_FromVoidPtr(ptr, 0);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
316 return rv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
317 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
318
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 /*
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320 ** Handles.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
322 static anything
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
323 py2c_in_handle(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
324 PyObject *arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
326 Handle h = 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
327 ResObj_Convert(arg, &h);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
328 return (anything)h;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
329 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
330
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
331 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
332 c2py_out_handle(arg)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
333 anything arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 Handle *rv = (Handle *)arg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 PyObject *prv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
337
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 PARANOID(arg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
339 if ( *rv == 0 ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340 Py_INCREF(Py_None);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341 prv = Py_None;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 } else {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343 prv = ResObj_New(*rv);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
345 free((char *)rv);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 return prv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
348
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
349 static PyObject *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
350 rv2py_handle(arg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
351 anything arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
352 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
353 Handle rv = (Handle)arg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
354
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
355 if ( rv == NULL ) return NULL;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
356 return ResObj_New(rv);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
357 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
358
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
359 typedef struct {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
360 char *name; /* Name */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
361 py2c_converter get; /* Get argument */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
362 int get_uses_arg; /* True if the above consumes an argument */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
363 c2py_converter put; /* Put result value */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
364 } conventry;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
365
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
366 static conventry converters[] = {
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
367 {"InByte", py2c_in_int, 1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
368 {"InShort", py2c_in_int, 1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
369 {"InLong", py2c_in_int, 1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
370 {"OutLong", py2c_alloc, 0, c2py_out_long},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
371 {"OutShort", py2c_alloc, 0, c2py_out_short},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
372 {"OutByte", py2c_alloc, 0, c2py_out_byte},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
373 {"InString", py2c_in_string, 1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
374 {"InPstring", py2c_in_pstring,1, c2py_free},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
375 {"OutPstring", py2c_out_pstring,0, c2py_out_pstring},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
376 {"InCobject", py2c_in_cobject,1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
377 {"OutCobject", py2c_alloc, 0, c2py_out_cobject},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
378 {"InHandle", py2c_in_handle, 1, c2py_dummy},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
379 {"OutHandle", py2c_alloc, 0, c2py_out_handle},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
380 {0, 0, 0, 0}
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
381 };
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
382
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
383 typedef struct {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
384 char *name;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
385 rv2py_converter rtn;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
386 } rvconventry;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
387
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
388 static rvconventry rvconverters[] = {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
389 {"None", rv2py_none},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
390 {"OSErr", rv2py_oserr},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
391 {"Byte", rv2py_int},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
392 {"Short", rv2py_int},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
393 {"Long", rv2py_int},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
394 {"Pstring", rv2py_pstring},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
395 {"Cobject", rv2py_cobject},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
396 {"Handle", rv2py_handle},
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
397 {0, 0}
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 static conventry *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 getconverter(name)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402 char *name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404 int i;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
405 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
406
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
407 for(i=0; converters[i].name; i++ )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
408 if ( strcmp(name, converters[i].name) == 0 )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 return &converters[i];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 sprintf(buf, "Unknown argtype: %s", name);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 PyErr_SetString(ErrorObject, buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
415 static rvconventry *
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
416 getrvconverter(name)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
417 char *name;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
418 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
419 int i;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
420 char buf[256];
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
421
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
422 for(i=0; rvconverters[i].name; i++ )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
423 if ( strcmp(name, rvconverters[i].name) == 0 )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
424 return &rvconverters[i];
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
425 sprintf(buf, "Unknown return value type: %s", name);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
426 PyErr_SetString(ErrorObject, buf);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
427 return 0;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
428 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
429
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 static int
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431 argparse_conv(obj, ptr)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
432 PyObject *obj;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
433 conventry **ptr;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
434 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
435 char *name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
436 int i;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
437 conventry *item;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
438
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
439 if( (name=PyString_AsString(obj)) == NULL )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
440 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
441 if( (item=getconverter(name)) == NULL )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
442 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
443 *ptr = item;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
444 return 1;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
445 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
446
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
447 static int
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
448 argparse_rvconv(obj, ptr)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
449 PyObject *obj;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
450 rvconventry **ptr;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
451 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
452 char *name;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
453 int i;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
454 rvconventry *item;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
455
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
456 if( (name=PyString_AsString(obj)) == NULL )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
457 return 0;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
458 if( (item=getrvconverter(name)) == NULL )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
459 return 0;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
460 *ptr = item;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
461 return 1;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
462 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
463
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
464 /* ----------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
465
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
466 /* Declarations for objects of type fragment */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
467
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
468 typedef struct {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
469 PyObject_HEAD
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
470 CFragConnectionID conn_id;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
471 char name[MAXNAME+1];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
472 } cdfobject;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
473
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
474 staticforward PyTypeObject Cdftype;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
475
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
476
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
477
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
478 /* ---------------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
479
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
480 /* Declarations for objects of type routine */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
481
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
482 typedef struct {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
483 PyObject_HEAD
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
484 anyroutine rtn;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
485 char name[MAXNAME+1];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
486 } cdrobject;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
487
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
488 staticforward PyTypeObject Cdrtype;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
489
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
490
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
491
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
492 /* ---------------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
493
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
494 /* Declarations for objects of type callable */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
495
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
496
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
497 typedef struct {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
498 PyObject_HEAD
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
499 cdrobject *routine; /* The routine to call */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
500 int npargs; /* Python argument count */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
501 int ncargs; /* C argument count + 1 */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
502 rvconventry *rvconv; /* Return value converter */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
503 conventry *argconv[MAXARG]; /* Value converter list */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
504 } cdcobject;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
505
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
506 staticforward PyTypeObject Cdctype;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
507
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
508
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
509
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
510 /* -------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
511
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
512
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
513 static struct PyMethodDef cdr_methods[] = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
514
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
515 {NULL, NULL} /* sentinel */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
516 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
517
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
518 /* ---------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
519
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
520
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
521 static cdrobject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
522 newcdrobject(name, routine)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
523 unsigned char *name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
524 anyroutine routine;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
525 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
526 cdrobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
527 int nlen;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
528
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
529 self = PyObject_NEW(cdrobject, &Cdrtype);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
530 if (self == NULL)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
531 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
532 if ( name[0] > MAXNAME )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
533 nlen = MAXNAME;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
534 else
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
535 nlen = name[0];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
536 memcpy(self->name, name+1, nlen);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
537 self->name[nlen] = '\0';
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
538 self->rtn = routine;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
539 return self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
540 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
541
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
542 static void
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
543 cdr_dealloc(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
544 cdrobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
545 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
546 PyMem_DEL(self);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
547 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
548
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
549 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
550 cdr_repr(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
551 cdrobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
552 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
553 PyObject *s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
554 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
555
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
556 sprintf(buf, "<Calldll routine %s address 0x%x>", self->name, self->rtn);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
557 s = PyString_FromString(buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
558 return s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
559 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
560
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
561 static char Cdrtype__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
562 "C Routine address"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
563 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
564
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
565 static PyTypeObject Cdrtype = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
566 PyObject_HEAD_INIT(&PyType_Type)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
567 0, /*ob_size*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
568 "routine", /*tp_name*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
569 sizeof(cdrobject), /*tp_basicsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
570 0, /*tp_itemsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
571 /* methods */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
572 (destructor)cdr_dealloc, /*tp_dealloc*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
573 (printfunc)0, /*tp_print*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
574 (getattrfunc)0, /*tp_getattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
575 (setattrfunc)0, /*tp_setattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
576 (cmpfunc)0, /*tp_compare*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
577 (reprfunc)cdr_repr, /*tp_repr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
578 0, /*tp_as_number*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
579 0, /*tp_as_sequence*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
580 0, /*tp_as_mapping*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
581 (hashfunc)0, /*tp_hash*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
582 (ternaryfunc)0, /*tp_call*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
583 (reprfunc)0, /*tp_str*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
584
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
585 /* Space for future expansion */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
586 0L,0L,0L,0L,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
587 Cdrtype__doc__ /* Documentation string */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
588 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
589
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
590 /* End of code for routine objects */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
591 /* -------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
592
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
593
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
594 static struct PyMethodDef cdc_methods[] = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
595
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
596 {NULL, NULL} /* sentinel */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
597 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
598
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
599 /* ---------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
600
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
601
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
602 static cdcobject *
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
603 newcdcobject(routine, npargs, ncargs, rvconv, argconv)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
604 cdrobject *routine;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
605 int npargs;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
606 int ncargs;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
607 rvconventry *rvconv;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
608 conventry *argconv[];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
609 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
610 cdcobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
611 int i;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
612
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
613 self = PyObject_NEW(cdcobject, &Cdctype);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
614 if (self == NULL)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
615 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
616 self->routine = routine;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
617 Py_INCREF(routine);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
618 self->npargs = npargs;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
619 self->ncargs = ncargs;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
620 self->rvconv = rvconv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
621 for(i=0; i<MAXARG; i++)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
622 if ( i < ncargs )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
623 self->argconv[i] = argconv[i];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
624 else
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
625 self->argconv[i] = 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
626 return self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
627 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
628
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
629 static void
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
630 cdc_dealloc(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
631 cdcobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
632 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
633 Py_XDECREF(self->routine);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
634 PyMem_DEL(self);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
635 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
636
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
637
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
638 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
639 cdc_repr(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
640 cdcobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
641 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
642 PyObject *s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
643 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
644 int i;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
645
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
646 sprintf(buf, "<callable %s = %s(", self->rvconv->name, self->routine->name);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
647 for(i=0; i< self->ncargs; i++) {
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
648 strcat(buf, self->argconv[i]->name);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
649 if ( i < self->ncargs-1 )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
650 strcat(buf, ", ");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
651 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
652 strcat(buf, ") >");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
653
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
654 s = PyString_FromString(buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
655 return s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
656 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
657
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
658 /*
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
659 ** And this is what we all do it for: call a C function.
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
660 */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
661 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
662 cdc_call(self, args, kwargs)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
663 cdcobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
664 PyObject *args;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
665 PyObject *kwargs;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
666 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
667 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
668 int i, pargindex;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
669 anything c_args[MAXARG] = {0, 0, 0, 0, 0, 0, 0, 0};
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
670 anything c_rv;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
671 conventry *cp;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
672 PyObject *curarg;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
673 anyroutine func;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
674 PyObject *returnvalues[MAXARG+1];
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
675 PyObject *rv;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
676
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
677 if( kwargs ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
678 PyErr_SetString(PyExc_TypeError, "Keyword args not allowed");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
679 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
680 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
681 if( !PyTuple_Check(args) ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
682 PyErr_SetString(PyExc_TypeError, "Arguments not in tuple");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
683 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
684 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
685 if( PyTuple_Size(args) != self->npargs ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
686 sprintf(buf, "%d arguments, expected %d", PyTuple_Size(args), self->npargs);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
687 PyErr_SetString(PyExc_TypeError, buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
688 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
689 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
690
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
691 /* Decode arguments */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
692 pargindex = 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
693 for(i=0; i<self->ncargs; i++) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
694 cp = self->argconv[i];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
695 if ( cp->get_uses_arg ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
696 curarg = PyTuple_GET_ITEM(args, pargindex);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
697 pargindex++;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
698 } else {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
699 curarg = (PyObject *)NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
700 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
701 c_args[i] = (*cp->get)(curarg);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
702 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
703 if (PyErr_Occurred())
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
704 return 0;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
705
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
706 /* Call function */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
707 func = self->routine->rtn;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
708 c_rv = (*func)(c_args[0], c_args[1], c_args[2], c_args[3],
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
709 c_args[4], c_args[5], c_args[6], c_args[7]);
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
710
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
711 /* Decode return value, and store into returnvalues if needed */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
712 pargindex = 0;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
713 curarg = (*self->rvconv->rtn)(c_rv);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
714 if ( curarg )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
715 returnvalues[pargindex++] = curarg;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
716
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
717 /* Decode returnvalue parameters and cleanup any storage allocated */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
718 for(i=0; i<self->ncargs; i++) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
719 cp = self->argconv[i];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
720 curarg = (*cp->put)(c_args[i]);
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
721 if(curarg)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
722 returnvalues[pargindex++] = curarg;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
723 /* NOTE: We only check errors at the end (so we free() everything) */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
724 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
725 if ( PyErr_Occurred() ) {
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
726 /* An error did occur. Free the python objects created */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
727 for(i=0; i<pargindex; i++)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
728 Py_XDECREF(returnvalues[i]);
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
729 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
730 }
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
731
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
732 /* Zero and one return values cases are special: */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
733 if ( pargindex == 0 ) {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
734 Py_INCREF(Py_None);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
735 return Py_None;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
736 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
737 if ( pargindex == 1 )
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
738 return returnvalues[0];
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
739
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
740 /* More than one return value: put in a tuple */
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
741 rv = PyTuple_New(pargindex);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
742 for(i=0; i<pargindex; i++)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
743 if(rv)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
744 PyTuple_SET_ITEM(rv, i, returnvalues[i]);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
745 else
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
746 Py_XDECREF(returnvalues[i]);
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
747 return rv;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
748 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
749
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
750 static char Cdctype__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
751 ""
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
752 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
753
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
754 static PyTypeObject Cdctype = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
755 PyObject_HEAD_INIT(&PyType_Type)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
756 0, /*ob_size*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
757 "callable", /*tp_name*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
758 sizeof(cdcobject), /*tp_basicsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
759 0, /*tp_itemsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
760 /* methods */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
761 (destructor)cdc_dealloc, /*tp_dealloc*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
762 (printfunc)0, /*tp_print*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
763 (getattrfunc)0, /*tp_getattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
764 (setattrfunc)0, /*tp_setattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
765 (cmpfunc)0, /*tp_compare*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
766 (reprfunc)cdc_repr, /*tp_repr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
767 0, /*tp_as_number*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
768 0, /*tp_as_sequence*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
769 0, /*tp_as_mapping*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
770 (hashfunc)0, /*tp_hash*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
771 (ternaryfunc)cdc_call, /*tp_call*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
772 (reprfunc)0, /*tp_str*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
773
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
774 /* Space for future expansion */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
775 0L,0L,0L,0L,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
776 Cdctype__doc__ /* Documentation string */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
777 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
778
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
779 /* End of code for callable objects */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
780 /* ---------------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
781
5618
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
782 static char cdf_keys__doc__[] =
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
783 "Return list of symbol names in fragment";
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
784
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
785 static PyObject *
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
786 cdf_keys(self, args)
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
787 cdfobject *self;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
788 PyObject *args;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
789 {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
790 long symcount;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
791 PyObject *rv, *obj;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
792 Str255 symname;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
793 Ptr dummy1;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
794 CFragSymbolClass dummy2;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
795 int i;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
796 OSErr err;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
797
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
798 if (!PyArg_ParseTuple(args, ""))
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
799 return NULL;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
800 if ( (err=CountSymbols(self->conn_id, &symcount)) < 0 )
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
801 return PyMac_Error(err);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
802 if ( (rv=PyList_New(symcount)) == NULL )
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
803 return NULL;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
804 for (i=0; i<symcount; i++) {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
805 if ((err=GetIndSymbol(self->conn_id, i, symname, &dummy1, &dummy2)) < 0 ) {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
806 Py_XDECREF(rv);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
807 return PyMac_Error(err);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
808 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
809 if ((obj=PyString_FromStringAndSize((char *)symname+1, symname[0])) == NULL ) {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
810 Py_XDECREF(rv);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
811 return PyMac_Error(err);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
812 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
813 if (PyList_SetItem(rv, i, obj) < 0 ) {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
814 Py_XDECREF(rv);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
815 return NULL;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
816 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
817 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
818 return rv;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
819 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
820
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
821
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
822 static struct PyMethodDef cdf_methods[] = {
5618
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
823 {"keys", (PyCFunction)cdf_keys, METH_VARARGS,
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
824 cdf_keys__doc__},
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
825
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
826 {NULL, NULL} /* sentinel */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
827 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
828
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
829 /* ---------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
830
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
831
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
832 static cdfobject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
833 newcdfobject(conn_id, name)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
834 CFragConnectionID conn_id;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
835 unsigned char *name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
836 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
837 cdfobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
838 int nlen;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
839
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
840 self = PyObject_NEW(cdfobject, &Cdftype);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
841 if (self == NULL)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
842 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
843 self->conn_id = conn_id;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
844 if ( name[0] > MAXNAME )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
845 nlen = MAXNAME;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
846 else
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
847 nlen = name[0];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
848 strncpy(self->name, (char *)name+1, nlen);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
849 self->name[nlen] = '\0';
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
850 return self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
851 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
852
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
853 static void
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
854 cdf_dealloc(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
855 cdfobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
856 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
857 PyMem_DEL(self);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
858 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
859
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
860 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
861 cdf_repr(self)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
862 cdfobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
863 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
864 PyObject *s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
865 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
866
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
867 sprintf(buf, "<fragment %s connection, id 0x%x>", self->name, self->conn_id);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
868 s = PyString_FromString(buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
869 return s;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
870 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
871
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
872 static PyObject *
5618
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
873 cdf_getattr_helper(self, name)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
874 cdfobject *self;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
875 char *name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
876 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
877 unsigned char *rtn_name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
878 anyroutine rtn;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
879 OSErr err;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
880 Str255 errMessage;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
881 CFragSymbolClass class;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
882 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
883
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
884 rtn_name = Pstring(name);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
885 err = FindSymbol(self->conn_id, rtn_name, (Ptr *)&rtn, &class);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
886 if ( err ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
887 sprintf(buf, "%.*s: %s", rtn_name[0], rtn_name+1, PyMac_StrError(err));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
888 PyErr_SetString(ErrorObject, buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
889 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
890 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
891 if( class != kTVectorCFragSymbol ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
892 PyErr_SetString(ErrorObject, "Symbol is not a routine");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
893 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
894 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
895
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
896 return (PyObject *)newcdrobject(rtn_name, rtn);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
897 }
5618
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
898
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
899 static PyObject *
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
900 cdf_getattr(self, name)
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
901 cdfobject *self;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
902 char *name;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
903 {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
904 PyObject *rv;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
905
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
906 if ((rv=Py_FindMethod(cdf_methods, (PyObject *)self, name)))
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
907 return rv;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
908 PyErr_Clear();
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
909 return cdf_getattr_helper(self, name);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
910 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
911
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
912 /* -------------------------------------------------------- */
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
913 /* Code to access cdf objects as mappings */
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
914
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
915 static int
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
916 cdf_length(self)
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
917 cdfobject *self;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
918 {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
919 long symcount;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
920 OSErr err;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
921
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
922 err = CountSymbols(self->conn_id, &symcount);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
923 if ( err ) {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
924 PyMac_Error(err);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
925 return -1;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
926 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
927 return symcount;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
928 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
929
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
930 static PyObject *
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
931 cdf_subscript(self, key)
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
932 cdfobject *self;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
933 PyObject *key;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
934 {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
935 char *name;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
936
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
937 if ((name=PyString_AsString(key)) == 0 )
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
938 return 0;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
939 return cdf_getattr_helper(self, name);
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
940 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
941
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
942 static int
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
943 cdf_ass_sub(self, v, w)
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
944 cdfobject *self;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
945 PyObject *v, *w;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
946 {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
947 /* XXXX Put w in self under key v */
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
948 return 0;
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
949 }
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
950
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
951 static PyMappingMethods cdf_as_mapping = {
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
952 (inquiry)cdf_length, /*mp_length*/
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
953 (binaryfunc)cdf_subscript, /*mp_subscript*/
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
954 (objobjargproc)cdf_ass_sub, /*mp_ass_subscript*/
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
955 };
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
956
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
957 /* -------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
958
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
959 static char Cdftype__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
960 "Code Fragment library symbol table"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
961 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
962
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
963 static PyTypeObject Cdftype = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
964 PyObject_HEAD_INIT(&PyType_Type)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
965 0, /*ob_size*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
966 "fragment", /*tp_name*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
967 sizeof(cdfobject), /*tp_basicsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
968 0, /*tp_itemsize*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
969 /* methods */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
970 (destructor)cdf_dealloc, /*tp_dealloc*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
971 (printfunc)0, /*tp_print*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
972 (getattrfunc)cdf_getattr, /*tp_getattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
973 (setattrfunc)0, /*tp_setattr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
974 (cmpfunc)0, /*tp_compare*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
975 (reprfunc)cdf_repr, /*tp_repr*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
976 0, /*tp_as_number*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
977 0, /*tp_as_sequence*/
5618
fdd1e1a530af Added keys() and mapping interface to shared-library objects, allowing
Jack Jansen <jack.jansen@cwi.nl>
parents: 5139
diff changeset
978 &cdf_as_mapping, /*tp_as_mapping*/
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
979 (hashfunc)0, /*tp_hash*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
980 (ternaryfunc)0, /*tp_call*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
981 (reprfunc)0, /*tp_str*/
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
982
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
983 /* Space for future expansion */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
984 0L,0L,0L,0L,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
985 Cdftype__doc__ /* Documentation string */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
986 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
987
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
988 /* End of code for fragment objects */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
989 /* -------------------------------------------------------- */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
990
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
991
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
992 static char cdll_getlibrary__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
993 "Load a shared library fragment and return the symbol table"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
994 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
995
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
996 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
997 cdll_getlibrary(self, args)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
998 PyObject *self; /* Not used */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
999 PyObject *args;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1000 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1001 Str255 frag_name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1002 OSErr err;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1003 Str255 errMessage;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1004 Ptr main_addr;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1005 CFragConnectionID conn_id;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1006 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1007
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1008 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, frag_name))
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1009 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1010
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1011 /* Find the library connection ID */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1012 err = GetSharedLibrary(frag_name, kCurrentCFragArch, kLoadCFrag, &conn_id, &main_addr,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1013 errMessage);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1014 if ( err ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1015 sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1016 PyErr_SetString(ErrorObject, buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1017 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1018 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1019 return (PyObject *)newcdfobject(conn_id, frag_name);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1020 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1021
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1022 static char cdll_getdiskfragment__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1023 "Load a fragment from a disk file and return the symbol table"
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1024 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1025
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1026 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1027 cdll_getdiskfragment(self, args)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1028 PyObject *self; /* Not used */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1029 PyObject *args;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1030 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1031 FSSpec fsspec;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1032 Str255 frag_name;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1033 OSErr err;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1034 Str255 errMessage;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1035 Ptr main_addr;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1036 CFragConnectionID conn_id;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1037 char buf[256];
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1038 Boolean isfolder, didsomething;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1039
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1040 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetFSSpec, &fsspec,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1041 PyMac_GetStr255, frag_name))
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1042 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1043 err = ResolveAliasFile(&fsspec, 1, &isfolder, &didsomething);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1044 if ( err )
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1045 return PyErr_Mac(ErrorObject, err);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1046
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1047 /* Load the fragment (or return the connID if it is already loaded */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1048 err = GetDiskFragment(&fsspec, 0, 0, frag_name,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1049 kLoadCFrag, &conn_id, &main_addr,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1050 errMessage);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1051 if ( err ) {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1052 sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err));
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1053 PyErr_SetString(ErrorObject, buf);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1054 return NULL;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1055 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1056 return (PyObject *)newcdfobject(conn_id, frag_name);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1057 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1058
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1059 static char cdll_newcall__doc__[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1060 ""
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1061 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1062
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1063 static PyObject *
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1064 cdll_newcall(self, args)
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1065 PyObject *self; /* Not used */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1066 PyObject *args;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1067 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1068 cdrobject *routine;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1069 conventry *argconv[MAXARG] = {0, 0, 0, 0, 0, 0, 0, 0};
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1070 rv2py_converter rvconv;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1071 int npargs, ncargs;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1072
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1073 /* Note: the next format depends on MAXARG */
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1074 if (!PyArg_ParseTuple(args, "O!O&|O&O&O&O&O&O&O&O&", &Cdrtype, &routine,
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1075 argparse_rvconv, &rvconv,
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1076 argparse_conv, &argconv[0], argparse_conv, &argconv[1],
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1077 argparse_conv, &argconv[2], argparse_conv, &argconv[3],
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1078 argparse_conv, &argconv[4], argparse_conv, &argconv[5],
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1079 argparse_conv, &argconv[6], argparse_conv, &argconv[7]))
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1080 return NULL;
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1081 npargs = 0;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1082 for(ncargs=0; ncargs < MAXARG && argconv[ncargs]; ncargs++) {
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1083 if( argconv[ncargs]->get_uses_arg ) npargs++;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1084 }
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1085 return (PyObject *)newcdcobject(routine, npargs, ncargs, rvconv, argconv);
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1086 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1087
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1088 /* List of methods defined in the module */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1089
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1090 static struct PyMethodDef cdll_methods[] = {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1091 {"getlibrary", (PyCFunction)cdll_getlibrary, METH_VARARGS,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1092 cdll_getlibrary__doc__},
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1093 {"getdiskfragment", (PyCFunction)cdll_getdiskfragment, METH_VARARGS,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1094 cdll_getdiskfragment__doc__},
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1095 {"newcall", (PyCFunction)cdll_newcall, METH_VARARGS,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1096 cdll_newcall__doc__},
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1097
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1098 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1099 };
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1100
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1101
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1102 /* Initialization function for the module (*must* be called initcalldll) */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1103
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1104 static char calldll_module_documentation[] =
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1105 ""
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1106 ;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1107
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1108 void
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1109 initcalldll()
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1110 {
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1111 PyObject *m, *d;
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1112
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1113 /* Create the module and add the functions */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1114 m = Py_InitModule4("calldll", cdll_methods,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1115 calldll_module_documentation,
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1116 (PyObject*)NULL,PYTHON_API_VERSION);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1117
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1118 /* Add some symbolic constants to the module */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1119 d = PyModule_GetDict(m);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1120 ErrorObject = PyString_FromString("calldll.error");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1121 PyDict_SetItemString(d, "error", ErrorObject);
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1122
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1123 /* XXXX Add constants here */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1124
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1125 /* Check for errors */
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1126 if (PyErr_Occurred())
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1127 Py_FatalError("can't initialize module calldll");
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1128 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1129
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1130 #ifdef TESTSUPPORT
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1131
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1132 /* Test routine */
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1133 int cdll_b_bbbbbbbb(char a1,char a2,char a3,char a4,char a5,char a6,char a7,char a8)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1134 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1135 return a1+a2+a3+a4+a5+a6+a7+a8;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1136 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1137
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1138 short cdll_h_hhhhhhhh(short a1,short a2,short a3,short a4,short a5,short a6,short a7,short a8)
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1139 {
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1140 return a1+a2+a3+a4+a5+a6+a7+a8;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1141 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1142
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1143 int cdll_l_llllllll(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1144 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1145 return a1+a2+a3+a4+a5+a6+a7+a8;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1146 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1147
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1148 void cdll_N_ssssssss(char *a1,char *a2,char *a3,char *a4,char *a5,char *a6,char *a7,char *a8)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1149 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1150 printf("cdll_N_ssssssss args: %s %s %s %s %s %s %s %s\n", a1, a2, a3, a4,
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1151 a5, a6, a7, a8);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1152 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1153
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1154 OSErr cdll_o_l(long l)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1155 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1156 return (OSErr)l;
5125
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1157 }
54a9adca215c An initial stab at calling random C routines from Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1158
5139
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1159 void cdll_N_pp(unsigned char *in, unsigned char *out)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1160 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1161 out[0] = in[0] + 5;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1162 strcpy((char *)out+1, "Was: ");
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1163 memcpy(out+6, in+1, in[0]);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1164 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1165
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1166 void cdll_N_bb(char a1, char *a2)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1167 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1168 *a2 = a1;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1169 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1170
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1171 void cdll_N_hh(short a1, short *a2)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1172 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1173 *a2 = a1;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1174 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1175
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1176 void cdll_N_ll(long a1, long *a2)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1177 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1178 *a2 = a1;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1179 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1180
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1181 void cdll_N_sH(char *a1, Handle a2)
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1182 {
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1183 int len;
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1184
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1185 len = strlen(a1);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1186 SetHandleSize(a2, len);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1187 HLock(a2);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1188 memcpy(*a2, a1, len);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1189 HUnlock(a2);
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1190 }
9216f5c25e4e Redid arg/return handling (still not as I would like it to be, though).
Jack Jansen <jack.jansen@cwi.nl>
parents: 5125
diff changeset
1191 #endif