Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* Wrap void* pointers to be passed between C modules */ |
| 33 | |
| 34 | #include "Python.h" |
| 35 | |
| 36 | |
| 37 | /* Declarations for objects of type PyCObject */ |
| 38 | |
| 39 | typedef struct { |
| 40 | PyObject_HEAD |
| 41 | void *cobject; |
Guido van Rossum | cee555b | 1996-08-01 00:02:33 +0000 | [diff] [blame] | 42 | void (*destructor) Py_PROTO((void *)); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 43 | } PyCObject; |
| 44 | |
| 45 | PyObject * |
| 46 | PyCObject_FromVoidPtr(cobj, destr) |
| 47 | void *cobj; |
Guido van Rossum | cee555b | 1996-08-01 00:02:33 +0000 | [diff] [blame] | 48 | void (*destr) Py_PROTO((void *)); |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 49 | { |
| 50 | PyCObject *self; |
| 51 | |
| 52 | self = PyObject_NEW(PyCObject, &PyCObject_Type); |
| 53 | if (self == NULL) |
| 54 | return NULL; |
| 55 | self->cobject=cobj; |
| 56 | self->destructor=destr; |
| 57 | return (PyObject *)self; |
| 58 | } |
| 59 | |
| 60 | void * |
| 61 | PyCObject_AsVoidPtr(self) |
| 62 | PyObject *self; |
| 63 | { |
| 64 | return ((PyCObject *)self)->cobject; |
| 65 | } |
| 66 | |
| 67 | static void |
| 68 | PyCObject_dealloc(self) |
| 69 | PyCObject *self; |
| 70 | { |
| 71 | if(self->destructor) (self->destructor)(self->cobject); |
| 72 | PyMem_DEL(self); |
| 73 | } |
| 74 | |
| 75 | static char PyCObject_Type__doc__[] = |
Guido van Rossum | cee555b | 1996-08-01 00:02:33 +0000 | [diff] [blame] | 76 | "C objects to be exported from one extension module to another\n\ |
| 77 | \n\ |
| 78 | C objects are used for communication between extension modules. They\n\ |
| 79 | provide a way for an extension module to export a C interface to other\n\ |
| 80 | extension modules, so that extension modules can use the Python import\n\ |
| 81 | mechanism to link to one another.\n" |
Guido van Rossum | 77654a7 | 1996-01-12 00:44:03 +0000 | [diff] [blame] | 82 | ; |
| 83 | |
| 84 | PyTypeObject PyCObject_Type = { |
| 85 | PyObject_HEAD_INIT(&PyType_Type) |
| 86 | 0, /*ob_size*/ |
| 87 | "PyCObject", /*tp_name*/ |
| 88 | sizeof(PyCObject), /*tp_basicsize*/ |
| 89 | 0, /*tp_itemsize*/ |
| 90 | /* methods */ |
| 91 | (destructor)PyCObject_dealloc, /*tp_dealloc*/ |
| 92 | (printfunc)0, /*tp_print*/ |
| 93 | (getattrfunc)0, /*tp_getattr*/ |
| 94 | (setattrfunc)0, /*tp_setattr*/ |
| 95 | (cmpfunc)0, /*tp_compare*/ |
| 96 | (reprfunc)0, /*tp_repr*/ |
| 97 | 0, /*tp_as_number*/ |
| 98 | 0, /*tp_as_sequence*/ |
| 99 | 0, /*tp_as_mapping*/ |
| 100 | (hashfunc)0, /*tp_hash*/ |
| 101 | (ternaryfunc)0, /*tp_call*/ |
| 102 | (reprfunc)0, /*tp_str*/ |
| 103 | |
| 104 | /* Space for future expansion */ |
| 105 | 0L,0L,0L,0L, |
| 106 | PyCObject_Type__doc__ /* Documentation string */ |
| 107 | }; |