Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 1 | #ifndef CSTRINGIO_INCLUDED |
| 2 | #define CSTRINGIO_INCLUDED |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame^] | 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 6 | /* |
| 7 | |
Guido van Rossum | cd8732a | 1997-12-08 15:16:08 +0000 | [diff] [blame] | 8 | cStringIO.h,v 1.4 1997/12/07 14:27:00 jim Exp |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 9 | |
| 10 | cStringIO C API |
| 11 | |
| 12 | Copyright |
| 13 | |
| 14 | Copyright 1996 Digital Creations, L.C., 910 Princess Anne |
| 15 | Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All |
| 16 | rights reserved. Copyright in this software is owned by DCLC, |
| 17 | unless otherwise indicated. Permission to use, copy and |
| 18 | distribute this software is hereby granted, provided that the |
| 19 | above copyright notice appear in all copies and that both that |
| 20 | copyright notice and this permission notice appear. Note that |
| 21 | any product, process or technology described in this software |
| 22 | may be the subject of other Intellectual Property rights |
| 23 | reserved by Digital Creations, L.C. and are not licensed |
| 24 | hereunder. |
| 25 | |
| 26 | Trademarks |
| 27 | |
| 28 | Digital Creations & DCLC, are trademarks of Digital Creations, L.C.. |
| 29 | All other trademarks are owned by their respective companies. |
| 30 | |
| 31 | No Warranty |
| 32 | |
| 33 | The software is provided "as is" without warranty of any kind, |
| 34 | either express or implied, including, but not limited to, the |
| 35 | implied warranties of merchantability, fitness for a particular |
| 36 | purpose, or non-infringement. This software could include |
| 37 | technical inaccuracies or typographical errors. Changes are |
| 38 | periodically made to the software; these changes will be |
| 39 | incorporated in new editions of the software. DCLC may make |
| 40 | improvements and/or changes in this software at any time |
| 41 | without notice. |
| 42 | |
| 43 | Limitation Of Liability |
| 44 | |
| 45 | In no event will DCLC be liable for direct, indirect, special, |
| 46 | incidental, economic, cover, or consequential damages arising |
| 47 | out of the use of or inability to use this software even if |
| 48 | advised of the possibility of such damages. Some states do not |
| 49 | allow the exclusion or limitation of implied warranties or |
| 50 | limitation of liability for incidental or consequential |
| 51 | damages, so the above limitation or exclusion may not apply to |
| 52 | you. |
| 53 | |
| 54 | If you have questions regarding this software, |
| 55 | contact: |
| 56 | |
| 57 | info@digicool.com |
| 58 | Digital Creations L.C. |
| 59 | |
| 60 | (540) 371-6909 |
| 61 | |
| 62 | |
| 63 | This header provides access to cStringIO objects from C. |
| 64 | Functions are provided for calling cStringIO objects and |
| 65 | macros are provided for testing whether you have cStringIO |
| 66 | objects. |
| 67 | |
| 68 | Before calling any of the functions or macros, you must initialize |
| 69 | the routines with: |
| 70 | |
Guido van Rossum | 7999bfb | 1999-01-25 21:36:13 +0000 | [diff] [blame] | 71 | PycString_IMPORT |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 72 | |
| 73 | This would typically be done in your init function. |
| 74 | |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 75 | */ |
| 76 | |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 77 | /* Basic functions to manipulate cStringIO objects from C */ |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 78 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 79 | static struct PycStringIO_CAPI { |
| 80 | |
| 81 | /* Read a string. If the last argument is -1, the remainder will be read. */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 82 | int(*cread)(PyObject *, char **, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 83 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 84 | /* Read a line */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 85 | int(*creadline)(PyObject *, char **); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 86 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 87 | /* Write a string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 88 | int(*cwrite)(PyObject *, char *, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 89 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 90 | /* Get the cStringIO object as a Python string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 91 | PyObject *(*cgetvalue)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 92 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 93 | /* Create a new output object */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 94 | PyObject *(*NewOutput)(int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 95 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 96 | /* Create an input object from a Python string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 97 | PyObject *(*NewInput)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 98 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 99 | /* The Python types for cStringIO input and output objects. |
| 100 | Note that you can do input on an output object. |
| 101 | */ |
| 102 | PyTypeObject *InputType, *OutputType; |
| 103 | |
| 104 | } * PycStringIO = NULL; |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 105 | |
| 106 | /* These can be used to test if you have one */ |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 107 | #define PycStringIO_InputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 108 | ((O)->ob_type==PycStringIO->InputType) |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 109 | #define PycStringIO_OutputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 110 | ((O)->ob_type==PycStringIO->OutputType) |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 111 | |
Guido van Rossum | f0f3600 | 1998-12-08 13:23:22 +0000 | [diff] [blame] | 112 | static void * |
Thomas Wouters | 7889010 | 2000-07-22 19:25:51 +0000 | [diff] [blame] | 113 | xxxPyCObject_Import(char *module_name, char *name) |
Guido van Rossum | 142eeb8 | 1997-08-13 03:14:41 +0000 | [diff] [blame] | 114 | { |
| 115 | PyObject *m, *c; |
| 116 | void *r=NULL; |
| 117 | |
| 118 | if((m=PyImport_ImportModule(module_name))) |
| 119 | { |
| 120 | if((c=PyObject_GetAttrString(m,name))) |
| 121 | { |
| 122 | r=PyCObject_AsVoidPtr(c); |
| 123 | Py_DECREF(c); |
| 124 | } |
| 125 | Py_DECREF(m); |
| 126 | } |
| 127 | |
| 128 | return r; |
| 129 | } |
| 130 | |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 131 | #define PycString_IMPORT \ |
Martin v. Löwis | eefa964 | 2001-06-09 07:59:43 +0000 | [diff] [blame] | 132 | PycStringIO=(struct PycStringIO_CAPI*)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI") |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 133 | |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame^] | 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 137 | #endif /* CSTRINGIO_INCLUDED */ |