Mercurial > cpython-lru_cache-weakref
comparison Objects/bufferobject.c @ 41652:050c98cd41c4
Make the StringIO test pass.
The buffer object now special-cases Unicode when concatenating. Sigh.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 08 May 2007 23:08:31 +0000 |
| parents | 13d5e5f0e993 |
| children | c9c52b87c30b |
comparison
equal
deleted
inserted
replaced
| 41651:44ebae4f61c4 | 41652:050c98cd41c4 |
|---|---|
| 422 | 422 |
| 423 if (!get_buf(self, &ptr1, &size, ANY_BUFFER)) | 423 if (!get_buf(self, &ptr1, &size, ANY_BUFFER)) |
| 424 return NULL; | 424 return NULL; |
| 425 | 425 |
| 426 /* optimize special case */ | 426 /* optimize special case */ |
| 427 /* XXX bad idea type-wise */ | |
| 427 if ( size == 0 ) | 428 if ( size == 0 ) |
| 428 { | 429 { |
| 429 Py_INCREF(other); | 430 Py_INCREF(other); |
| 430 return other; | 431 return other; |
| 431 } | 432 } |
| 432 | 433 |
| 433 if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 ) | 434 if (PyUnicode_Check(other)) { |
| 434 return NULL; | 435 /* XXX HACK */ |
| 435 | 436 if ( (count = (*pb->bf_getcharbuffer)(other, 0, &ptr2)) < 0 ) |
| 437 return NULL; | |
| 438 } | |
| 439 else { | |
| 440 if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 ) | |
| 441 return NULL; | |
| 442 } | |
| 443 | |
| 444 /* XXX Should return a bytes object, really */ | |
| 436 ob = PyString_FromStringAndSize(NULL, size + count); | 445 ob = PyString_FromStringAndSize(NULL, size + count); |
| 437 if ( ob == NULL ) | 446 if ( ob == NULL ) |
| 438 return NULL; | 447 return NULL; |
| 439 p = PyString_AS_STRING(ob); | 448 p = PyString_AS_STRING(ob); |
| 440 memcpy(p, ptr1, size); | 449 memcpy(p, ptr1, size); |
