Ticket #4246: urlarg_3k.diff
| File urlarg_3k.diff, 2.1 KB (added by loewis, 3 years ago) |
|---|
-
_c_urlarg.c
old new 14 14 } 15 15 #endif 16 16 17 #if PY_MAJOR_VERSION < 3 18 #define Bytes_FromStringAndSize PyString_FromStringAndSize 19 #define Bytes_AsString PyString_AsString 20 #define _Bytes_Resize _PyString_Resize 21 #else 22 #define Bytes_FromStringAndSize PyBytes_FromStringAndSize 23 #define Bytes_AsString PyBytes_AsString 24 #define _Bytes_Resize _PyBytes_Resize 25 #endif 26 17 27 #ifdef __GNUC__ 18 28 # define TM_INLINE inline 19 29 #else … … 47 57 return NULL; 48 58 } 49 59 if (length == 0) { 50 return PyString_FromStringAndSize("", 0);60 return Bytes_FromStringAndSize("", 0); 51 61 } 52 62 /* Allocating an output buffer of length will be sufficient, 53 63 as the output can only be smaller. We resize the output in the end. */ 54 str = PyString_FromStringAndSize(NULL, length);64 str = Bytes_FromStringAndSize(NULL, length); 55 65 if (str == NULL) { 56 66 return NULL; 57 67 } 58 output = output_start = (unsigned char*) PyString_AsString(str);68 output = output_start = (unsigned char*)Bytes_AsString(str); 59 69 end = s + length; 60 70 s = s - 1; 61 71 while ((++s) < end) { … … 102 112 break; 103 113 } 104 114 105 _ PyString_Resize(&str, output-output_start);115 _Bytes_Resize(&str, output-output_start); 106 116 return str; 107 117 } 108 118 … … 111 121 {NULL, NULL} /* sentinel */ 112 122 }; 113 123 114 DL_EXPORT(void) init_c_urlarg(void) 124 static void 125 init(PyObject *m) 115 126 { 116 PyObject* m;117 127 PyObject* d; 118 128 unsigned char i; 119 129 120 m = Py_InitModule("_c_urlarg", _c_urlarg_methods);121 130 d = PyModule_GetDict(m); 122 131 123 132 /* add our base exception class */ … … 145 154 } 146 155 } 147 156 157 #if PY_MAJOR_VERSION < 3 158 DL_EXPORT(void) init_c_urlarg(void) 159 { 160 PyObject* m; 161 m = Py_InitModule("_c_urlarg", _c_urlarg_methods); 162 init(m); 163 } 164 #else 165 static struct PyModuleDef _module = { 166 PyModuleDef_HEAD_INIT, 167 "_c_urlarg", 168 NULL, 169 -1, 170 _c_urlarg_methods, 171 NULL, 172 NULL, 173 NULL, 174 NULL 175 }; 176 177 PyMODINIT_FUNC 178 PyInit__c_urlarg(void) 179 { 180 PyObject *m = PyModule_Create(&_module); 181 if (!m) 182 return NULL; 183 init(m); 184 return m; 185 } 186 #endif
