| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /***********************************************************
 | 
					
						
							|  |  |  | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, | 
					
						
							|  |  |  | The Netherlands. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         All Rights Reserved | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Permission to use, copy, modify, and distribute this software and its | 
					
						
							|  |  |  | documentation for any purpose and without fee is hereby granted, | 
					
						
							|  |  |  | provided that the above copyright notice appear in all copies and that | 
					
						
							|  |  |  | both that copyright notice and this permission notice appear in | 
					
						
							|  |  |  | supporting documentation, and that the names of Stichting Mathematisch | 
					
						
							|  |  |  | Centrum or CWI or Corporation for National Research Initiatives or | 
					
						
							|  |  |  | CNRI not be used in advertising or publicity pertaining to | 
					
						
							|  |  |  | distribution of the software without specific, written prior | 
					
						
							|  |  |  | permission. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | While CWI is the initial source for this software, a modified version | 
					
						
							|  |  |  | is made available by the Corporation for National Research Initiatives | 
					
						
							|  |  |  | (CNRI) at the Internet address ftp://ftp.python.org.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH | 
					
						
							|  |  |  | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF | 
					
						
							|  |  |  | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH | 
					
						
							|  |  |  | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL | 
					
						
							|  |  |  | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | 
					
						
							|  |  |  | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | 
					
						
							|  |  |  | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | 
					
						
							|  |  |  | PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ******************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Sanity check */ | 
					
						
							|  |  |  | #ifndef __powerc
 | 
					
						
							|  |  |  | #error Please port this code to your architecture first...
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Define to include testroutines (at the end) | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #define TESTSUPPORT
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							|  |  |  | #include "macglue.h"
 | 
					
						
							|  |  |  | #include "macdefs.h"
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | #include <CodeFragments.h>
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Prototypes for routines not in any include file (shame, shame) */ | 
					
						
							| 
									
										
										
										
											2000-07-31 22:07:49 +00:00
										 |  |  | extern PyObject *ResObj_New(Handle); | 
					
						
							|  |  |  | extern int ResObj_Convert(PyObject *, Handle *); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *ErrorObject; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Debugging macro */ | 
					
						
							|  |  |  | #ifdef TESTSUPPORT
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | #define PARANOID(arg) \
 | 
					
						
							|  |  |  | 	if ( arg == 0 ) {PyErr_SetString(ErrorObject, "Internal error: NULL arg!"); return 0; } | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #define PARANOID(arg) /*pass*/
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Prototypes we use for routines and arguments */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef long anything; | 
					
						
							| 
									
										
										
										
											2000-07-31 22:07:49 +00:00
										 |  |  | typedef anything (*anyroutine)(...); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Other constants */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | #define MAXNAME 31	/* Maximum size of names, for printing only */
 | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | #define MAXARG 12	/* Maximum number of arguments */
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | ** Routines to convert arguments between Python and C. | 
					
						
							|  |  |  | ** Note return-value converters return NULL if this argument (or return value) | 
					
						
							|  |  |  | ** doesn't return anything. The call-wrapper code collects all return values, | 
					
						
							|  |  |  | ** and does the expected thing based on the number of return values: return None, a single | 
					
						
							|  |  |  | ** value or a tuple of values. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Hence, optional return values are also implementable. | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2000-07-31 22:07:49 +00:00
										 |  |  | typedef anything (*py2c_converter)(PyObject *); | 
					
						
							|  |  |  | typedef PyObject *(*c2py_converter)(anything); | 
					
						
							|  |  |  | typedef PyObject *(*rv2py_converter)(anything); | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Dummy routine for arguments that are output-only */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_dummy(arg) | 
					
						
							|  |  |  | 	PyObject  *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Routine to allocate storage for output integers */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_alloc(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *ptr; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( (ptr=malloc(sizeof(anything))) == 0 ) | 
					
						
							|  |  |  | 		PyErr_NoMemory(); | 
					
						
							|  |  |  | 	return (anything)ptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Dummy routine for arguments that are input-only */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_dummy(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Dummy routine for void return value */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | rv2py_none(arg) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /* Routine to de-allocate storage for input-only arguments */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | c2py_free(arg) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( arg ) | 
					
						
							|  |  |  | 		free((char *)arg); | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | ** OSErr return value. | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | rv2py_oserr(arg) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	OSErr err = (OSErr)arg; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		return PyMac_Error(err); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | ** Input integers of all sizes (PPC only) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_in_int(arg) | 
					
						
							|  |  |  | 	PyObject  *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_AsLong(arg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Integer return values of all sizes (PPC only) | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | rv2py_int(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong((long)arg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Integer output parameters | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_long(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	rv = PyInt_FromLong(*(long *)arg); | 
					
						
							|  |  |  | 	free((char *)arg); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_short(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	rv =  PyInt_FromLong((long)*(short *)arg); | 
					
						
							|  |  |  | 	free((char *)arg); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_byte(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	rv =  PyInt_FromLong((long)*(char *)arg); | 
					
						
							|  |  |  | 	free((char *)arg); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Strings | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_in_string(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (anything)PyString_AsString(arg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** Pascal-style strings | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_in_pstring(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *p; | 
					
						
							|  |  |  | 	int size; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( (size = PyString_Size(arg)) < 0) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if ( size > 255 ) { | 
					
						
							|  |  |  | 		PyErr_SetString(ErrorObject, "Pstring must be <= 255 chars"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if( (p=(unsigned char *)malloc(256)) == 0 ) { | 
					
						
							|  |  |  | 		PyErr_NoMemory(); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p[0] = size; | 
					
						
							|  |  |  | 	memcpy(p+1, PyString_AsString(arg), size); | 
					
						
							|  |  |  | 	return (anything)p; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_out_pstring(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *p; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( (p=(unsigned char *)malloc(256)) == 0 ) { | 
					
						
							|  |  |  | 		PyErr_NoMemory(); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p[0] = 0; | 
					
						
							|  |  |  | 	return (anything)p; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_pstring(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *p = (unsigned char *)arg; | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	rv = PyString_FromStringAndSize((char *)p+1, p[0]); | 
					
						
							|  |  |  | 	free(p); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | rv2py_pstring(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *p = (unsigned char *)arg; | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( arg == NULL ) return NULL; | 
					
						
							|  |  |  | 	rv = PyString_FromStringAndSize((char *)p+1, p[0]); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** C objects. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_in_cobject(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( arg == Py_None ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return (anything)PyCObject_AsVoidPtr(arg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_cobject(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void **ptr = (void **)arg; | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	if ( *ptr == 0 ) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		rv = Py_None; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		rv = PyCObject_FromVoidPtr(*ptr, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	free((char *)ptr); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | rv2py_cobject(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void *ptr = (void *)arg; | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( ptr == 0 ) return NULL; | 
					
						
							|  |  |  | 	rv = PyCObject_FromVoidPtr(ptr, 0); | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | ** Handles. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static anything | 
					
						
							|  |  |  | py2c_in_handle(arg) | 
					
						
							|  |  |  | 	PyObject *arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Handle h = 0; | 
					
						
							|  |  |  | 	ResObj_Convert(arg, &h); | 
					
						
							|  |  |  | 	return (anything)h; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | c2py_out_handle(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Handle *rv = (Handle *)arg; | 
					
						
							|  |  |  | 	PyObject *prv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PARANOID(arg); | 
					
						
							|  |  |  | 	if ( *rv == 0 ) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		prv = Py_None; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		prv = ResObj_New(*rv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	free((char *)rv); | 
					
						
							|  |  |  | 	return prv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | rv2py_handle(arg) | 
					
						
							|  |  |  | 	anything arg; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Handle rv = (Handle)arg; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ( rv == NULL ) return NULL; | 
					
						
							|  |  |  | 	return ResObj_New(rv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | typedef struct { | 
					
						
							|  |  |  | 	char *name;		/* Name */ | 
					
						
							|  |  |  | 	py2c_converter	get;	/* Get argument */ | 
					
						
							|  |  |  | 	int	get_uses_arg;	/* True if the above consumes an argument */ | 
					
						
							|  |  |  | 	c2py_converter	put;	/* Put result value */ | 
					
						
							|  |  |  | } conventry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static conventry converters[] = { | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	{"InByte",	py2c_in_int,	1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"InShort",	py2c_in_int,	1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"InLong",	py2c_in_int,	1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"OutLong",	py2c_alloc,	0,	c2py_out_long}, | 
					
						
							|  |  |  | 	{"OutShort",	py2c_alloc,	0,	c2py_out_short}, | 
					
						
							|  |  |  | 	{"OutByte",	py2c_alloc,	0,	c2py_out_byte}, | 
					
						
							|  |  |  | 	{"InString",	py2c_in_string,	1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"InPstring",	py2c_in_pstring,1,	c2py_free}, | 
					
						
							|  |  |  | 	{"OutPstring",	py2c_out_pstring,0,	c2py_out_pstring}, | 
					
						
							|  |  |  | 	{"InCobject",	py2c_in_cobject,1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"OutCobject",	py2c_alloc,	0,	c2py_out_cobject}, | 
					
						
							|  |  |  | 	{"InHandle",	py2c_in_handle,	1,	c2py_dummy}, | 
					
						
							|  |  |  | 	{"OutHandle",	py2c_alloc,	0,	c2py_out_handle}, | 
					
						
							|  |  |  | 	{0, 0, 0, 0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	rv2py_converter rtn; | 
					
						
							|  |  |  | } rvconventry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static rvconventry rvconverters[] = { | 
					
						
							|  |  |  | 	{"None",	rv2py_none}, | 
					
						
							|  |  |  | 	{"OSErr",	rv2py_oserr}, | 
					
						
							|  |  |  | 	{"Byte",	rv2py_int}, | 
					
						
							|  |  |  | 	{"Short",	rv2py_int}, | 
					
						
							|  |  |  | 	{"Long",	rv2py_int}, | 
					
						
							|  |  |  | 	{"Pstring",	rv2py_pstring}, | 
					
						
							|  |  |  | 	{"Cobject",	rv2py_cobject}, | 
					
						
							|  |  |  | 	{"Handle",	rv2py_handle}, | 
					
						
							|  |  |  | 	{0, 0} | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static conventry * | 
					
						
							|  |  |  | getconverter(name) | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(i=0; converters[i].name; i++ ) | 
					
						
							|  |  |  | 		if ( strcmp(name, converters[i].name) == 0 ) | 
					
						
							|  |  |  | 			return &converters[i]; | 
					
						
							|  |  |  | 	sprintf(buf, "Unknown argtype: %s", name); | 
					
						
							|  |  |  | 	PyErr_SetString(ErrorObject, buf); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | static rvconventry * | 
					
						
							|  |  |  | getrvconverter(name) | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(i=0; rvconverters[i].name; i++ ) | 
					
						
							|  |  |  | 		if ( strcmp(name, rvconverters[i].name) == 0 ) | 
					
						
							|  |  |  | 			return &rvconverters[i]; | 
					
						
							|  |  |  | 	sprintf(buf, "Unknown return value type: %s", name); | 
					
						
							|  |  |  | 	PyErr_SetString(ErrorObject, buf); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | argparse_conv(obj, ptr) | 
					
						
							|  |  |  | 	PyObject *obj; | 
					
						
							|  |  |  | 	conventry **ptr; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	conventry *item; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( (name=PyString_AsString(obj)) == NULL ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if( (item=getconverter(name)) == NULL ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	*ptr = item; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | argparse_rvconv(obj, ptr) | 
					
						
							|  |  |  | 	PyObject *obj; | 
					
						
							|  |  |  | 	rvconventry **ptr; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	rvconventry *item; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( (name=PyString_AsString(obj)) == NULL ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if( (item=getrvconverter(name)) == NULL ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	*ptr = item; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /* ----------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Declarations for objects of type fragment */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							|  |  |  | 	CFragConnectionID conn_id; | 
					
						
							|  |  |  | 	char name[MAXNAME+1]; | 
					
						
							|  |  |  | } cdfobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | staticforward PyTypeObject Cdftype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Declarations for objects of type routine */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							|  |  |  | 	anyroutine rtn; | 
					
						
							|  |  |  | 	char name[MAXNAME+1]; | 
					
						
							|  |  |  | } cdrobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | staticforward PyTypeObject Cdrtype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Declarations for objects of type callable */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	cdrobject *routine;		/* The routine to call */ | 
					
						
							|  |  |  | 	int npargs;			/* Python argument count */ | 
					
						
							|  |  |  | 	int ncargs;			/* C argument count + 1 */ | 
					
						
							|  |  |  | 	rvconventry *rvconv;		/* Return value converter */ | 
					
						
							|  |  |  | 	conventry *argconv[MAXARG];	/* Value converter list */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | } cdcobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | staticforward PyTypeObject Cdctype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef cdr_methods[] = { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static cdrobject * | 
					
						
							|  |  |  | newcdrobject(name, routine) | 
					
						
							|  |  |  | 	unsigned char *name; | 
					
						
							|  |  |  | 	anyroutine routine; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cdrobject *self; | 
					
						
							|  |  |  | 	int nlen; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	self = PyObject_NEW(cdrobject, &Cdrtype); | 
					
						
							|  |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( name[0] > MAXNAME ) | 
					
						
							|  |  |  | 		nlen = MAXNAME; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		nlen = name[0]; | 
					
						
							|  |  |  | 	memcpy(self->name, name+1, nlen); | 
					
						
							|  |  |  | 	self->name[nlen] = '\0'; | 
					
						
							|  |  |  | 	self->rtn = routine; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | cdr_dealloc(self) | 
					
						
							|  |  |  | 	cdrobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyMem_DEL(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdr_repr(self) | 
					
						
							|  |  |  | 	cdrobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *s; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sprintf(buf, "<Calldll routine %s address 0x%x>", self->name, self->rtn); | 
					
						
							|  |  |  | 	s = PyString_FromString(buf); | 
					
						
							|  |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char Cdrtype__doc__[] =  | 
					
						
							|  |  |  | "C Routine address" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject Cdrtype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"routine",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(cdrobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)cdr_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,			/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)0,			/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)cdr_repr,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,			/*tp_hash*/ | 
					
						
							|  |  |  | 	(ternaryfunc)0,			/*tp_call*/ | 
					
						
							|  |  |  | 	(reprfunc)0,			/*tp_str*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Space for future expansion */ | 
					
						
							|  |  |  | 	0L,0L,0L,0L, | 
					
						
							|  |  |  | 	Cdrtype__doc__ /* Documentation string */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for routine objects */ | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef cdc_methods[] = { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static cdcobject * | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | newcdcobject(routine, npargs, ncargs, rvconv, argconv) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	cdrobject *routine; | 
					
						
							|  |  |  | 	int npargs; | 
					
						
							|  |  |  | 	int ncargs; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	rvconventry *rvconv; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	conventry *argconv[]; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cdcobject *self; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	self = PyObject_NEW(cdcobject, &Cdctype); | 
					
						
							|  |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->routine = routine; | 
					
						
							|  |  |  | 	Py_INCREF(routine); | 
					
						
							|  |  |  | 	self->npargs = npargs; | 
					
						
							|  |  |  | 	self->ncargs = ncargs; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	self->rvconv = rvconv; | 
					
						
							|  |  |  | 	for(i=0; i<MAXARG; i++) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		if ( i < ncargs ) | 
					
						
							|  |  |  | 			self->argconv[i] = argconv[i]; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			self->argconv[i] = 0; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | cdc_dealloc(self) | 
					
						
							|  |  |  | 	cdcobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Py_XDECREF(self->routine); | 
					
						
							|  |  |  | 	PyMem_DEL(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdc_repr(self) | 
					
						
							|  |  |  | 	cdcobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *s; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	sprintf(buf, "<callable %s = %s(", self->rvconv->name, self->routine->name); | 
					
						
							|  |  |  | 	for(i=0; i< self->ncargs; i++) { | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		strcat(buf, self->argconv[i]->name); | 
					
						
							|  |  |  | 		if ( i < self->ncargs-1 ) | 
					
						
							|  |  |  | 			strcat(buf, ", "); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	strcat(buf, ") >"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s = PyString_FromString(buf); | 
					
						
							|  |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | ** And this is what we all do it for: call a C function. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdc_call(self, args, kwargs) | 
					
						
							|  |  |  | 	cdcobject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | 	PyObject *kwargs; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	int i, pargindex; | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | 	anything c_args[MAXARG] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	anything c_rv; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	conventry *cp; | 
					
						
							|  |  |  | 	PyObject *curarg; | 
					
						
							|  |  |  | 	anyroutine func; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	PyObject *returnvalues[MAXARG+1]; | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if( kwargs ) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, "Keyword args not allowed"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if( !PyTuple_Check(args) ) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, "Arguments not in tuple"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if( PyTuple_Size(args) != self->npargs ) { | 
					
						
							|  |  |  | 		sprintf(buf, "%d arguments, expected %d", PyTuple_Size(args), self->npargs); | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, buf); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Decode arguments */ | 
					
						
							|  |  |  | 	pargindex = 0; | 
					
						
							|  |  |  | 	for(i=0; i<self->ncargs; i++) { | 
					
						
							|  |  |  | 		cp = self->argconv[i]; | 
					
						
							|  |  |  | 		if ( cp->get_uses_arg ) { | 
					
						
							|  |  |  | 			curarg = PyTuple_GET_ITEM(args, pargindex); | 
					
						
							|  |  |  | 			pargindex++; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			curarg = (PyObject *)NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		c_args[i] = (*cp->get)(curarg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (PyErr_Occurred()) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* Call function */ | 
					
						
							|  |  |  | 	func = self->routine->rtn; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	c_rv = (*func)(c_args[0], c_args[1], c_args[2], c_args[3], | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | 			c_args[4], c_args[5], c_args[6], c_args[7], | 
					
						
							|  |  |  | 			c_args[8], c_args[9], c_args[10], c_args[11]); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	/* Decode return value, and store into returnvalues if needed */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	pargindex = 0; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	curarg = (*self->rvconv->rtn)(c_rv); | 
					
						
							|  |  |  | 	if ( curarg ) | 
					
						
							|  |  |  | 		returnvalues[pargindex++] = curarg; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* Decode returnvalue parameters and cleanup any storage allocated */ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	for(i=0; i<self->ncargs; i++) { | 
					
						
							|  |  |  | 		cp = self->argconv[i]; | 
					
						
							|  |  |  | 		curarg = (*cp->put)(c_args[i]); | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 		if(curarg) | 
					
						
							|  |  |  | 			returnvalues[pargindex++] = curarg; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		/* NOTE: We only check errors at the end (so we free() everything) */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( PyErr_Occurred() ) { | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 		/* An error did occur. Free the python objects created */ | 
					
						
							|  |  |  | 		for(i=0; i<pargindex; i++) | 
					
						
							|  |  |  | 			Py_XDECREF(returnvalues[i]); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Zero and one return values cases are special: */ | 
					
						
							|  |  |  | 	if ( pargindex == 0 ) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( pargindex == 1 ) | 
					
						
							|  |  |  | 		return returnvalues[0]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* More than one return value: put in a tuple */ | 
					
						
							|  |  |  | 	rv = PyTuple_New(pargindex); | 
					
						
							|  |  |  | 	for(i=0; i<pargindex; i++) | 
					
						
							|  |  |  | 		if(rv) | 
					
						
							|  |  |  | 			PyTuple_SET_ITEM(rv, i, returnvalues[i]); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			Py_XDECREF(returnvalues[i]); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char Cdctype__doc__[] =  | 
					
						
							|  |  |  | "" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject Cdctype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"callable",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(cdcobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)cdc_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,			/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)0,			/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)cdc_repr,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_sequence*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_mapping*/ | 
					
						
							|  |  |  | 	(hashfunc)0,			/*tp_hash*/ | 
					
						
							|  |  |  | 	(ternaryfunc)cdc_call,		/*tp_call*/ | 
					
						
							|  |  |  | 	(reprfunc)0,			/*tp_str*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Space for future expansion */ | 
					
						
							|  |  |  | 	0L,0L,0L,0L, | 
					
						
							|  |  |  | 	Cdctype__doc__ /* Documentation string */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for callable objects */ | 
					
						
							|  |  |  | /* ---------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-05-23 15:36:13 +00:00
										 |  |  | static char cdf_keys__doc__[] = | 
					
						
							|  |  |  | "Return list of symbol names in fragment"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdf_keys(self, args) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long symcount; | 
					
						
							|  |  |  | 	PyObject *rv, *obj; | 
					
						
							|  |  |  | 	Str255 symname; | 
					
						
							|  |  |  | 	Ptr dummy1; | 
					
						
							|  |  |  | 	CFragSymbolClass dummy2; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	if ( (err=CountSymbols(self->conn_id, &symcount)) < 0 ) | 
					
						
							|  |  |  | 		return PyMac_Error(err); | 
					
						
							|  |  |  | 	if ( (rv=PyList_New(symcount)) == NULL ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	for (i=0; i<symcount; i++) { | 
					
						
							|  |  |  | 		if ((err=GetIndSymbol(self->conn_id, i, symname, &dummy1, &dummy2)) < 0 ) { | 
					
						
							|  |  |  | 			Py_XDECREF(rv); | 
					
						
							|  |  |  | 			return PyMac_Error(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if ((obj=PyString_FromStringAndSize((char *)symname+1, symname[0])) == NULL ) { | 
					
						
							|  |  |  | 			Py_XDECREF(rv); | 
					
						
							|  |  |  | 			return PyMac_Error(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (PyList_SetItem(rv, i, obj) < 0 ) { | 
					
						
							|  |  |  | 			Py_XDECREF(rv); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return rv; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | static struct PyMethodDef cdf_methods[] = { | 
					
						
							| 
									
										
										
										
											1997-05-23 15:36:13 +00:00
										 |  |  | 	{"keys",		(PyCFunction)cdf_keys,		METH_VARARGS,	 | 
					
						
							|  |  |  | 							cdf_keys__doc__}, | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	{NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static cdfobject * | 
					
						
							|  |  |  | newcdfobject(conn_id, name) | 
					
						
							|  |  |  | 	CFragConnectionID conn_id; | 
					
						
							|  |  |  | 	unsigned char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	int nlen; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	self = PyObject_NEW(cdfobject, &Cdftype); | 
					
						
							|  |  |  | 	if (self == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->conn_id = conn_id; | 
					
						
							|  |  |  | 	if ( name[0] > MAXNAME ) | 
					
						
							|  |  |  | 		nlen = MAXNAME; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		nlen = name[0]; | 
					
						
							|  |  |  | 	strncpy(self->name, (char *)name+1, nlen); | 
					
						
							|  |  |  | 	self->name[nlen] = '\0'; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | cdf_dealloc(self) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyMem_DEL(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdf_repr(self) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *s; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sprintf(buf, "<fragment %s connection, id 0x%x>", self->name, self->conn_id); | 
					
						
							|  |  |  | 	s = PyString_FromString(buf); | 
					
						
							|  |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1997-05-23 15:36:13 +00:00
										 |  |  | cdf_getattr_helper(self, name) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *rtn_name; | 
					
						
							|  |  |  | 	anyroutine rtn; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	Str255 errMessage; | 
					
						
							|  |  |  | 	CFragSymbolClass class; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	rtn_name = Pstring(name); | 
					
						
							|  |  |  | 	err = FindSymbol(self->conn_id, rtn_name, (Ptr *)&rtn, &class); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		sprintf(buf, "%.*s: %s", rtn_name[0], rtn_name+1, PyMac_StrError(err)); | 
					
						
							|  |  |  | 		PyErr_SetString(ErrorObject, buf); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if( class != kTVectorCFragSymbol ) { | 
					
						
							|  |  |  | 		PyErr_SetString(ErrorObject, "Symbol is not a routine"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return (PyObject *)newcdrobject(rtn_name, rtn); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1997-05-23 15:36:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdf_getattr(self, name) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *rv; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ((rv=Py_FindMethod(cdf_methods, (PyObject *)self, name))) | 
					
						
							|  |  |  | 		return rv; | 
					
						
							|  |  |  | 	PyErr_Clear(); | 
					
						
							|  |  |  | 	return cdf_getattr_helper(self, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Code to access cdf objects as mappings */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | cdf_length(self) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long symcount; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	err = CountSymbols(self->conn_id, &symcount); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		PyMac_Error(err); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return symcount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdf_subscript(self, key) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	PyObject *key; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ((name=PyString_AsString(key)) == 0 ) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return cdf_getattr_helper(self, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | cdf_ass_sub(self, v, w) | 
					
						
							|  |  |  | 	cdfobject *self; | 
					
						
							|  |  |  | 	PyObject *v, *w; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* XXXX Put w in self under key v */ | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods cdf_as_mapping = { | 
					
						
							|  |  |  | 	(inquiry)cdf_length,		/*mp_length*/ | 
					
						
							|  |  |  | 	(binaryfunc)cdf_subscript,		/*mp_subscript*/ | 
					
						
							|  |  |  | 	(objobjargproc)cdf_ass_sub,	/*mp_ass_subscript*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char Cdftype__doc__[] =  | 
					
						
							|  |  |  | "Code Fragment library symbol table" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject Cdftype = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,				/*ob_size*/ | 
					
						
							|  |  |  | 	"fragment",			/*tp_name*/ | 
					
						
							|  |  |  | 	sizeof(cdfobject),		/*tp_basicsize*/ | 
					
						
							|  |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)cdf_dealloc,	/*tp_dealloc*/ | 
					
						
							|  |  |  | 	(printfunc)0,			/*tp_print*/ | 
					
						
							|  |  |  | 	(getattrfunc)cdf_getattr,	/*tp_getattr*/ | 
					
						
							|  |  |  | 	(setattrfunc)0,			/*tp_setattr*/ | 
					
						
							|  |  |  | 	(cmpfunc)0,			/*tp_compare*/ | 
					
						
							|  |  |  | 	(reprfunc)cdf_repr,		/*tp_repr*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_number*/ | 
					
						
							|  |  |  | 	0,				/*tp_as_sequence*/ | 
					
						
							| 
									
										
										
										
											1997-05-23 15:36:13 +00:00
										 |  |  | 	&cdf_as_mapping,		/*tp_as_mapping*/ | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 	(hashfunc)0,			/*tp_hash*/ | 
					
						
							|  |  |  | 	(ternaryfunc)0,			/*tp_call*/ | 
					
						
							|  |  |  | 	(reprfunc)0,			/*tp_str*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Space for future expansion */ | 
					
						
							|  |  |  | 	0L,0L,0L,0L, | 
					
						
							|  |  |  | 	Cdftype__doc__ /* Documentation string */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End of code for fragment objects */ | 
					
						
							|  |  |  | /* -------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char cdll_getlibrary__doc__[] = | 
					
						
							|  |  |  | "Load a shared library fragment and return the symbol table" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdll_getlibrary(self, args) | 
					
						
							|  |  |  | 	PyObject *self;	/* Not used */ | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Str255 frag_name; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	Str255 errMessage; | 
					
						
							|  |  |  | 	Ptr main_addr; | 
					
						
							|  |  |  | 	CFragConnectionID conn_id; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, frag_name)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Find the library connection ID */ | 
					
						
							| 
									
										
										
										
											1998-02-20 15:55:30 +00:00
										 |  |  | 	err = GetSharedLibrary(frag_name, kCompiledCFragArch, kLoadCFrag, &conn_id, &main_addr,  | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 			errMessage); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err)); | 
					
						
							|  |  |  | 		PyErr_SetString(ErrorObject, buf); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)newcdfobject(conn_id, frag_name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char cdll_getdiskfragment__doc__[] = | 
					
						
							|  |  |  | "Load a fragment from a disk file and return the symbol table" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdll_getdiskfragment(self, args) | 
					
						
							|  |  |  | 	PyObject *self;	/* Not used */ | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	FSSpec fsspec; | 
					
						
							|  |  |  | 	Str255 frag_name; | 
					
						
							|  |  |  | 	OSErr err; | 
					
						
							|  |  |  | 	Str255 errMessage; | 
					
						
							|  |  |  | 	Ptr main_addr; | 
					
						
							|  |  |  | 	CFragConnectionID conn_id; | 
					
						
							|  |  |  | 	char buf[256]; | 
					
						
							|  |  |  | 	Boolean isfolder, didsomething; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetFSSpec, &fsspec, | 
					
						
							|  |  |  | 			PyMac_GetStr255, frag_name)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	err = ResolveAliasFile(&fsspec, 1, &isfolder, &didsomething); | 
					
						
							|  |  |  | 	if ( err ) | 
					
						
							|  |  |  | 		return PyErr_Mac(ErrorObject, err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Load the fragment (or return the connID if it is already loaded */ | 
					
						
							|  |  |  | 	err = GetDiskFragment(&fsspec, 0, 0, frag_name,  | 
					
						
							|  |  |  | 			      kLoadCFrag, &conn_id, &main_addr, | 
					
						
							|  |  |  | 			      errMessage); | 
					
						
							|  |  |  | 	if ( err ) { | 
					
						
							|  |  |  | 		sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err)); | 
					
						
							|  |  |  | 		PyErr_SetString(ErrorObject, buf); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)newcdfobject(conn_id, frag_name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char cdll_newcall__doc__[] = | 
					
						
							|  |  |  | "" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | cdll_newcall(self, args) | 
					
						
							|  |  |  | 	PyObject *self;	/* Not used */ | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	cdrobject *routine; | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | 	conventry *argconv[MAXARG] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	rv2py_converter rvconv; | 
					
						
							|  |  |  | 	int npargs, ncargs; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	/* Note: the next format depends on MAXARG */ | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O!O&|O&O&O&O&O&O&O&O&O&O&O&O&", &Cdrtype, &routine, | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 		argparse_rvconv, &rvconv, | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		argparse_conv, &argconv[0], argparse_conv, &argconv[1], | 
					
						
							|  |  |  | 		argparse_conv, &argconv[2], argparse_conv, &argconv[3], | 
					
						
							|  |  |  | 		argparse_conv, &argconv[4], argparse_conv, &argconv[5], | 
					
						
							| 
									
										
										
										
											1999-12-03 23:35:47 +00:00
										 |  |  | 		argparse_conv, &argconv[6], argparse_conv, &argconv[7], | 
					
						
							|  |  |  | 		argparse_conv, &argconv[8], argparse_conv, &argconv[9], | 
					
						
							|  |  |  | 		argparse_conv, &argconv[10], argparse_conv, &argconv[11])) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	npargs = 0; | 
					
						
							|  |  |  | 	for(ncargs=0; ncargs < MAXARG && argconv[ncargs]; ncargs++) { | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | 		if( argconv[ncargs]->get_uses_arg ) npargs++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	return (PyObject *)newcdcobject(routine, npargs, ncargs, rvconv, argconv); | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* List of methods defined in the module */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef cdll_methods[] = { | 
					
						
							|  |  |  | 	{"getlibrary",		(PyCFunction)cdll_getlibrary,		METH_VARARGS,	 | 
					
						
							|  |  |  | 							cdll_getlibrary__doc__}, | 
					
						
							|  |  |  | 	{"getdiskfragment",	(PyCFunction)cdll_getdiskfragment,	METH_VARARGS, | 
					
						
							|  |  |  | 							cdll_getdiskfragment__doc__}, | 
					
						
							|  |  |  | 	{"newcall",		(PyCFunction)cdll_newcall,		METH_VARARGS, | 
					
						
							|  |  |  | 							cdll_newcall__doc__}, | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | 	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Initialization function for the module (*must* be called initcalldll) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char calldll_module_documentation[] =  | 
					
						
							|  |  |  | "" | 
					
						
							|  |  |  | ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | initcalldll() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *m, *d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Create the module and add the functions */ | 
					
						
							|  |  |  | 	m = Py_InitModule4("calldll", cdll_methods, | 
					
						
							|  |  |  | 		calldll_module_documentation, | 
					
						
							|  |  |  | 		(PyObject*)NULL,PYTHON_API_VERSION); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Add some symbolic constants to the module */ | 
					
						
							|  |  |  | 	d = PyModule_GetDict(m); | 
					
						
							|  |  |  | 	ErrorObject = PyString_FromString("calldll.error"); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "error", ErrorObject); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* XXXX Add constants here */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Check for errors */ | 
					
						
							|  |  |  | 	if (PyErr_Occurred()) | 
					
						
							|  |  |  | 		Py_FatalError("can't initialize module calldll"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | #ifdef TESTSUPPORT
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | /* Test routine */ | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | int cdll_b_bbbbbbbb(char a1,char  a2,char  a3,char  a4,char  a5,char  a6,char  a7,char  a8) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return a1+a2+a3+a4+a5+a6+a7+a8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | short cdll_h_hhhhhhhh(short a1,short  a2,short  a3,short  a4,short  a5,short  a6,short  a7,short  a8) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return a1+a2+a3+a4+a5+a6+a7+a8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int cdll_l_llllllll(int a1,int  a2,int  a3,int  a4,int  a5,int  a6,int  a7,int  a8) | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | 	return a1+a2+a3+a4+a5+a6+a7+a8; | 
					
						
							| 
									
										
										
										
											1997-02-17 16:56:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-02-20 15:18:32 +00:00
										 |  |  | void cdll_N_ssssssss(char *a1,char  *a2,char  *a3,char  *a4,char  *a5,char  *a6,char  *a7,char *a8) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf("cdll_N_ssssssss args: %s %s %s %s %s %s %s %s\n", a1, a2, a3, a4,  | 
					
						
							|  |  |  | 			a5, a6, a7, a8); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSErr cdll_o_l(long l) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (OSErr)l; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void cdll_N_pp(unsigned char *in, unsigned char *out) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	out[0] = in[0] + 5; | 
					
						
							|  |  |  | 	strcpy((char *)out+1, "Was: "); | 
					
						
							|  |  |  | 	memcpy(out+6, in+1, in[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void cdll_N_bb(char a1, char *a2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*a2 = a1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void cdll_N_hh(short a1, short *a2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*a2 = a1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void cdll_N_ll(long a1, long *a2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*a2 = a1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void cdll_N_sH(char *a1, Handle a2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	len = strlen(a1); | 
					
						
							|  |  |  | 	SetHandleSize(a2, len); | 
					
						
							|  |  |  | 	HLock(a2); | 
					
						
							|  |  |  | 	memcpy(*a2, a1, len); | 
					
						
							|  |  |  | 	HUnlock(a2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |