Ticket #4245: urlarg_nostringio.diff
| File urlarg_nostringio.diff, 2.1 KB (added by loewis, 3 years ago) |
|---|
-
twisted/protocols/_c_urlarg.c
10 10 extern "C" { 11 11 #endif 12 12 #include <Python.h> 13 #include <cStringIO.h>14 13 #ifdef __cplusplus 15 14 } 16 15 #endif … … 23 22 24 23 static PyObject* UrlargError; 25 24 26 #define OUTPUTCHAR(c,n) PycStringIO->cwrite(output, (const char *)c, n)25 #define OUTPUTCHAR(c,n) do{memcpy(output, c, n);output+=n;}while(0) 27 26 28 27 #define STATE_INITIAL 0 29 28 #define STATE_PERCENT 1 … … 38 37 39 38 static PyObject *unquote(PyObject *self, PyObject *args, PyObject *kwargs) 40 39 { 41 unsigned char *s, *r, *end ;40 unsigned char *s, *r, *end, *output_start, *output; 42 41 unsigned char quotedchar, quotedchartmp = 0, tmp; 43 42 unsigned char escchar = '%'; /* the character we use to begin %AB sequences */ 44 43 static char *kwlist[] = {"s", "escchar", NULL}; 45 44 int state = STATE_INITIAL, length; 46 PyObject * output, *str;45 PyObject *str; 47 46 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|c:unquote", kwlist, &s, &length, &escchar)) { 48 47 return NULL; 49 48 } 50 49 if (length == 0) { 51 50 return PyString_FromStringAndSize("", 0); 52 51 } 53 /* output = cStringIO() */ 54 output = PycStringIO->NewOutput(length); 55 if (output == NULL) { 52 /* Allocating an output buffer of length will be sufficient, 53 as the output can only be smaller. We resize the output in the end. */ 54 str = PyString_FromStringAndSize(NULL, length); 55 if (str == NULL) { 56 56 return NULL; 57 57 } 58 output = output_start = (unsigned char*)PyString_AsString(str); 58 59 end = s + length; 59 60 s = s - 1; 60 61 while ((++s) < end) { … … 101 102 break; 102 103 } 103 104 104 /* return output.getvalue() */ 105 str = PycStringIO->cgetvalue(output); 106 Py_DECREF(output); 105 _PyString_Resize(&str, output-output_start); 107 106 return str; 108 107 } 109 108 … … 118 117 PyObject* d; 119 118 unsigned char i; 120 119 121 PycString_IMPORT;122 120 m = Py_InitModule("_c_urlarg", _c_urlarg_methods); 123 121 d = PyModule_GetDict(m); 124 122
