comparison Python/structmember.c @ 46644:ea594306ea85

Issue #1950: Fixed misusage of PyUnicode_AsString().
author Alexandre Vassalotti <alexandre@peadrop.com>
date Sat, 03 May 2008 18:24:43 +0000
parents fefaa0e66fdd
children 85b67fb5672b
comparison
equal deleted inserted replaced
46639:bd91000c8e73 46644:ea594306ea85
237 Py_XINCREF(v); 237 Py_XINCREF(v);
238 oldv = *(PyObject **)addr; 238 oldv = *(PyObject **)addr;
239 *(PyObject **)addr = v; 239 *(PyObject **)addr = v;
240 Py_XDECREF(oldv); 240 Py_XDECREF(oldv);
241 break; 241 break;
242 case T_CHAR: 242 case T_CHAR: {
243 if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) { 243 char *string;
244 *(char*)addr = PyUnicode_AsString(v)[0]; 244 Py_ssize_t len;
245 } 245
246 else { 246 if (!PyUnicode_Check(v)) {
247 PyErr_BadArgument(); 247 PyErr_BadArgument();
248 return -1; 248 return -1;
249 } 249 }
250 break; 250 string = PyUnicode_AsStringAndSize(v, &len);
251 if (len != 1) {
252 PyErr_BadArgument();
253 return -1;
254 }
255 *(char*)addr = string[0];
256 break;
257 }
251 #ifdef HAVE_LONG_LONG 258 #ifdef HAVE_LONG_LONG
252 case T_LONGLONG:{ 259 case T_LONGLONG:{
253 PY_LONG_LONG value; 260 PY_LONG_LONG value;
254 *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v); 261 *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
255 if ((value == -1) && PyErr_Occurred()) 262 if ((value == -1) && PyErr_Occurred())