This reverts r63675 based on the discussion in this thread:

http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
This commit is contained in:
Gregory P. Smith 2008-06-09 04:58:54 +00:00
parent e98839a1f4
commit dd96db63f6
173 changed files with 2275 additions and 2280 deletions

View file

@ -23,14 +23,14 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (Noddy *)type->tp_alloc(type, 0); self = (Noddy *)type->tp_alloc(type, 0);
if (self != NULL) { if (self != NULL) {
self->first = PyBytes_FromString(""); self->first = PyString_FromString("");
if (self->first == NULL) if (self->first == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->last = PyBytes_FromString(""); self->last = PyString_FromString("");
if (self->last == NULL) if (self->last == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
@ -90,7 +90,7 @@ Noddy_name(Noddy* self)
PyObject *args, *result; PyObject *args, *result;
if (format == NULL) { if (format == NULL) {
format = PyBytes_FromString("%s %s"); format = PyString_FromString("%s %s");
if (format == NULL) if (format == NULL)
return NULL; return NULL;
} }
@ -109,7 +109,7 @@ Noddy_name(Noddy* self)
if (args == NULL) if (args == NULL)
return NULL; return NULL;
result = PyBytes_Format(format, args); result = PyString_Format(format, args);
Py_DECREF(args); Py_DECREF(args);
return result; return result;

View file

@ -23,14 +23,14 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (Noddy *)type->tp_alloc(type, 0); self = (Noddy *)type->tp_alloc(type, 0);
if (self != NULL) { if (self != NULL) {
self->first = PyBytes_FromString(""); self->first = PyString_FromString("");
if (self->first == NULL) if (self->first == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->last = PyBytes_FromString(""); self->last = PyString_FromString("");
if (self->last == NULL) if (self->last == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
@ -93,7 +93,7 @@ Noddy_setfirst(Noddy *self, PyObject *value, void *closure)
return -1; return -1;
} }
if (! PyBytes_Check(value)) { if (! PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"The first attribute value must be a string"); "The first attribute value must be a string");
return -1; return -1;
@ -121,7 +121,7 @@ Noddy_setlast(Noddy *self, PyObject *value, void *closure)
return -1; return -1;
} }
if (! PyBytes_Check(value)) { if (! PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"The last attribute value must be a string"); "The last attribute value must be a string");
return -1; return -1;
@ -153,7 +153,7 @@ Noddy_name(Noddy* self)
PyObject *args, *result; PyObject *args, *result;
if (format == NULL) { if (format == NULL) {
format = PyBytes_FromString("%s %s"); format = PyString_FromString("%s %s");
if (format == NULL) if (format == NULL)
return NULL; return NULL;
} }
@ -162,7 +162,7 @@ Noddy_name(Noddy* self)
if (args == NULL) if (args == NULL)
return NULL; return NULL;
result = PyBytes_Format(format, args); result = PyString_Format(format, args);
Py_DECREF(args); Py_DECREF(args);
return result; return result;

View file

@ -57,14 +57,14 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (Noddy *)type->tp_alloc(type, 0); self = (Noddy *)type->tp_alloc(type, 0);
if (self != NULL) { if (self != NULL) {
self->first = PyBytes_FromString(""); self->first = PyString_FromString("");
if (self->first == NULL) if (self->first == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->last = PyBytes_FromString(""); self->last = PyString_FromString("");
if (self->last == NULL) if (self->last == NULL)
{ {
Py_DECREF(self); Py_DECREF(self);
@ -124,7 +124,7 @@ Noddy_name(Noddy* self)
PyObject *args, *result; PyObject *args, *result;
if (format == NULL) { if (format == NULL) {
format = PyBytes_FromString("%s %s"); format = PyString_FromString("%s %s");
if (format == NULL) if (format == NULL)
return NULL; return NULL;
} }
@ -143,7 +143,7 @@ Noddy_name(Noddy* self)
if (args == NULL) if (args == NULL)
return NULL; return NULL;
result = PyBytes_Format(format, args); result = PyString_Format(format, args);
Py_DECREF(args); Py_DECREF(args);
return result; return result;

View file

@ -13,7 +13,7 @@ main(int argc, char *argv[])
} }
Py_Initialize(); Py_Initialize();
pName = PyBytes_FromString(argv[1]); pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */ /* Error checking of pName left out */
pModule = PyImport_Import(pName); pModule = PyImport_Import(pName);

View file

@ -1,5 +1,5 @@
/* Bytes (String) object interface */ /* String (Bytes) object interface */
#ifndef Py_BYTESOBJECT_H #ifndef Py_BYTESOBJECT_H
#define Py_BYTESOBJECT_H #define Py_BYTESOBJECT_H
@ -10,7 +10,7 @@ extern "C" {
#include <stdarg.h> #include <stdarg.h>
/* /*
Type PyBytesObject represents a character string. An extra zero byte is Type PyStringObject represents a character string. An extra zero byte is
reserved at the end to ensure it is zero-terminated, but a size is reserved at the end to ensure it is zero-terminated, but a size is
present so strings with null bytes in them can be represented. This present so strings with null bytes in them can be represented. This
is an immutable object type. is an immutable object type.
@ -46,61 +46,61 @@ typedef struct {
* 'interned' dictionary; in this case the two references * 'interned' dictionary; in this case the two references
* from 'interned' to this object are *not counted* in ob_refcnt. * from 'interned' to this object are *not counted* in ob_refcnt.
*/ */
} PyBytesObject; } PyStringObject;
#define SSTATE_NOT_INTERNED 0 #define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1 #define SSTATE_INTERNED_MORTAL 1
#define SSTATE_INTERNED_IMMORTAL 2 #define SSTATE_INTERNED_IMMORTAL 2
PyAPI_DATA(PyTypeObject) PyBaseString_Type; PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyBytes_Type; PyAPI_DATA(PyTypeObject) PyString_Type;
#define PyBytes_Check(op) \ #define PyString_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS) PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) #define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list) PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
Py_GCC_ATTRIBUTE((format(printf, 1, 0))); Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...) PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
Py_GCC_ATTRIBUTE((format(printf, 1, 2))); Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); PyAPI_FUNC(char *) PyString_AsString(PyObject *);
PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
PyAPI_FUNC(int) _PyBytes_Eq(PyObject *, PyObject*); PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
PyAPI_FUNC(PyObject *) PyBytes_Format(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyBytes_FormatLong(PyObject*, int, int, PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
int, char**, int*); int, char**, int*);
PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t, PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
const char *, Py_ssize_t, const char *, Py_ssize_t,
const char *); const char *);
PyAPI_FUNC(void) PyBytes_InternInPlace(PyObject **); PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
PyAPI_FUNC(void) PyBytes_InternImmortal(PyObject **); PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
PyAPI_FUNC(PyObject *) PyBytes_InternFromString(const char *); PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void); PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
/* Use only if you know it's a string */ /* Use only if you know it's a string */
#define PyBytes_CHECK_INTERNED(op) (((PyBytesObject *)(op))->ob_sstate) #define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
#define PyBytes_AS_STRING(op) (((PyBytesObject *)(op))->ob_sval) #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
#define PyBytes_GET_SIZE(op) Py_SIZE(op) #define PyString_GET_SIZE(op) Py_SIZE(op)
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*, /* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
x must be an iterable object. */ x must be an iterable object. */
PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x); PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
/* --- Generic Codecs ----------------------------------------------------- */ /* --- Generic Codecs ----------------------------------------------------- */
/* Create an object by decoding the encoded string s of the /* Create an object by decoding the encoded string s of the
given size. */ given size. */
PyAPI_FUNC(PyObject*) PyBytes_Decode( PyAPI_FUNC(PyObject*) PyString_Decode(
const char *s, /* encoded string */ const char *s, /* encoded string */
Py_ssize_t size, /* size of buffer */ Py_ssize_t size, /* size of buffer */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
@ -110,7 +110,7 @@ PyAPI_FUNC(PyObject*) PyBytes_Decode(
/* Encodes a char buffer of the given size and returns a /* Encodes a char buffer of the given size and returns a
Python object. */ Python object. */
PyAPI_FUNC(PyObject*) PyBytes_Encode( PyAPI_FUNC(PyObject*) PyString_Encode(
const char *s, /* string char buffer */ const char *s, /* string char buffer */
Py_ssize_t size, /* number of chars to encode */ Py_ssize_t size, /* number of chars to encode */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
@ -120,7 +120,7 @@ PyAPI_FUNC(PyObject*) PyBytes_Encode(
/* Encodes a string object and returns the result as Python /* Encodes a string object and returns the result as Python
object. */ object. */
PyAPI_FUNC(PyObject*) PyBytes_AsEncodedObject( PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
PyObject *str, /* string object */ PyObject *str, /* string object */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
const char *errors /* error handling */ const char *errors /* error handling */
@ -132,9 +132,9 @@ PyAPI_FUNC(PyObject*) PyBytes_AsEncodedObject(
If the codec returns an Unicode object, the object is converted If the codec returns an Unicode object, the object is converted
back to a string using the default encoding. back to a string using the default encoding.
DEPRECATED - use PyBytes_AsEncodedObject() instead. */ DEPRECATED - use PyString_AsEncodedObject() instead. */
PyAPI_FUNC(PyObject*) PyBytes_AsEncodedString( PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
PyObject *str, /* string object */ PyObject *str, /* string object */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
const char *errors /* error handling */ const char *errors /* error handling */
@ -143,7 +143,7 @@ PyAPI_FUNC(PyObject*) PyBytes_AsEncodedString(
/* Decodes a string object and returns the result as Python /* Decodes a string object and returns the result as Python
object. */ object. */
PyAPI_FUNC(PyObject*) PyBytes_AsDecodedObject( PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
PyObject *str, /* string object */ PyObject *str, /* string object */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
const char *errors /* error handling */ const char *errors /* error handling */
@ -155,9 +155,9 @@ PyAPI_FUNC(PyObject*) PyBytes_AsDecodedObject(
If the codec returns an Unicode object, the object is converted If the codec returns an Unicode object, the object is converted
back to a string using the default encoding. back to a string using the default encoding.
DEPRECATED - use PyBytes_AsDecodedObject() instead. */ DEPRECATED - use PyString_AsDecodedObject() instead. */
PyAPI_FUNC(PyObject*) PyBytes_AsDecodedString( PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
PyObject *str, /* string object */ PyObject *str, /* string object */
const char *encoding, /* encoding */ const char *encoding, /* encoding */
const char *errors /* error handling */ const char *errors /* error handling */
@ -169,7 +169,7 @@ PyAPI_FUNC(PyObject*) PyBytes_AsDecodedString(
0-terminated (passing a string with embedded NULL characters will 0-terminated (passing a string with embedded NULL characters will
cause an exception). */ cause an exception). */
PyAPI_FUNC(int) PyBytes_AsStringAndSize( PyAPI_FUNC(int) PyString_AsStringAndSize(
register PyObject *obj, /* string or Unicode object */ register PyObject *obj, /* string or Unicode object */
register char **s, /* pointer to buffer variable */ register char **s, /* pointer to buffer variable */
register Py_ssize_t *len /* pointer to length variable or NULL register Py_ssize_t *len /* pointer to length variable or NULL
@ -181,7 +181,7 @@ PyAPI_FUNC(int) PyBytes_AsStringAndSize(
into the string pointed to by buffer. For the argument descriptions, into the string pointed to by buffer. For the argument descriptions,
see Objects/stringlib/localeutil.h */ see Objects/stringlib/localeutil.h */
PyAPI_FUNC(int) _PyBytes_InsertThousandsGrouping(char *buffer, PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
Py_ssize_t len, Py_ssize_t len,
char *plast, char *plast,
Py_ssize_t buf_size, Py_ssize_t buf_size,

View file

@ -504,7 +504,7 @@ PyAPI_FUNC(long) _Py_HashDouble(double);
PyAPI_FUNC(long) _Py_HashPointer(void*); PyAPI_FUNC(long) _Py_HashPointer(void*);
/* Helper for passing objects to printf and the like */ /* Helper for passing objects to printf and the like */
#define PyObject_REPR(obj) PyBytes_AS_STRING(PyObject_Repr(obj)) #define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))
/* Flag bits for printing: */ /* Flag bits for printing: */
#define Py_PRINT_RAW 1 /* No string quotes etc. */ #define Py_PRINT_RAW 1 /* No string quotes etc. */
@ -598,7 +598,7 @@ given type object has a specified feature.
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24) #define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25) #define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26) #define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27) #define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28) #define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29) #define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30) #define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)

View file

@ -146,7 +146,7 @@ static PyObject *PyCurses_ ## X (PyObject *self) \
static PyObject *PyCurses_ ## X (PyObject *self) \ static PyObject *PyCurses_ ## X (PyObject *self) \
{ \ { \
PyCursesInitialised \ PyCursesInitialised \
return PyBytes_FromString(X()); } return PyString_FromString(X()); }
#define NoArgTrueFalseFunction(X) \ #define NoArgTrueFalseFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self) \ static PyObject *PyCurses_ ## X (PyObject *self) \

View file

@ -104,7 +104,7 @@ PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
#define PyExceptionClass_Name(x) \ #define PyExceptionClass_Name(x) \
(PyClass_Check((x)) \ (PyClass_Check((x)) \
? PyBytes_AS_STRING(((PyClassObject*)(x))->cl_name) \ ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
: (char *)(((PyTypeObject*)(x))->tp_name)) : (char *)(((PyTypeObject*)(x))->tp_name))
#define PyExceptionInstance_Class(x) \ #define PyExceptionInstance_Class(x) \

View file

@ -135,9 +135,9 @@ typedef Py_intptr_t Py_ssize_t;
* all platforms (Python interprets the format string itself, and does whatever * all platforms (Python interprets the format string itself, and does whatever
* the platform C requires to convert a size_t/Py_ssize_t argument): * the platform C requires to convert a size_t/Py_ssize_t argument):
* *
* PyBytes_FromFormat * PyString_FromFormat
* PyErr_Format * PyErr_Format
* PyBytes_FromFormatV * PyString_FromFormatV
* *
* Lower-level uses require that you interpolate the correct format modifier * Lower-level uses require that you interpolate the correct format modifier
* yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for

View file

@ -136,7 +136,7 @@ PyAPI_FUNC(void) PyDict_Fini(void);
PyAPI_FUNC(void) PyTuple_Fini(void); PyAPI_FUNC(void) PyTuple_Fini(void);
PyAPI_FUNC(void) PyList_Fini(void); PyAPI_FUNC(void) PyList_Fini(void);
PyAPI_FUNC(void) PySet_Fini(void); PyAPI_FUNC(void) PySet_Fini(void);
PyAPI_FUNC(void) PyBytes_Fini(void); PyAPI_FUNC(void) PyString_Fini(void);
PyAPI_FUNC(void) PyInt_Fini(void); PyAPI_FUNC(void) PyInt_Fini(void);
PyAPI_FUNC(void) PyFloat_Fini(void); PyAPI_FUNC(void) PyFloat_Fini(void);
PyAPI_FUNC(void) PyOS_FiniInterrupts(void); PyAPI_FUNC(void) PyOS_FiniInterrupts(void);

View file

@ -1,13 +1,12 @@
#define PyBytesObject PyStringObject #define PyBytesObject PyStringObject
#define PyBytes_Type PyString_Type #define PyBytes_Type PyString_Type
#define PyString_Check PyBytes_Check #define PyBytes_Check PyString_Check
#define PyString_CheckExact PyBytes_CheckExact #define PyBytes_CheckExact PyString_CheckExact
#define PyString_CHECK_INTERNED PyBytes_CHECK_INTERNED #define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
#define PyString_AS_STRING PyBytes_AS_STRING #define PyBytes_AS_STRING PyString_AS_STRING
#define PyString_GET_SIZE PyBytes_GET_SIZE #define PyBytes_GET_SIZE PyString_GET_SIZE
#define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
#define Py_TPFLAGS_STRING_SUBCLASS Py_TPFLAGS_BYTES_SUBCLASS
#define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromStringAndSize PyString_FromStringAndSize
#define PyBytes_FromString PyString_FromString #define PyBytes_FromString PyString_FromString
@ -23,9 +22,6 @@
#define PyBytes_Format PyString_Format #define PyBytes_Format PyString_Format
#define _PyBytes_FormatLong _PyString_FormatLong #define _PyBytes_FormatLong _PyString_FormatLong
#define PyBytes_DecodeEscape PyString_DecodeEscape #define PyBytes_DecodeEscape PyString_DecodeEscape
#define PyBytes_InternInPlace PyString_InternInPlace
#define PyBytes_InternImmortal PyString_InternImmortal
#define PyBytes_InternFromString PyString_InternFromString
#define _PyBytes_Join _PyString_Join #define _PyBytes_Join _PyString_Join
#define PyBytes_Decode PyString_Decode #define PyBytes_Decode PyString_Decode
#define PyBytes_Encode PyString_Encode #define PyBytes_Encode PyString_Encode

View file

@ -706,7 +706,7 @@ initMacOS(void)
** some of the image and sound processing interfaces on the mac:-( ** some of the image and sound processing interfaces on the mac:-(
*/ */
{ {
PyBytesObject *p = 0; PyStringObject *p = 0;
long off = (long)&(p->ob_sval[0]); long off = (long)&(p->ob_sval[0]);
if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0) if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0)

View file

@ -139,11 +139,11 @@ filldialogoptions(PyObject *d,
NavGetDefaultDialogOptions(opt); NavGetDefaultDialogOptions(opt);
while ( PyDict_Next(d, &pos, &key, &value) ) { while ( PyDict_Next(d, &pos, &key, &value) ) {
if ( !key || !value || !PyBytes_Check(key) ) { if ( !key || !value || !PyString_Check(key) ) {
PyErr_SetString(ErrorObject, "DialogOption has non-string key"); PyErr_SetString(ErrorObject, "DialogOption has non-string key");
return 0; return 0;
} }
keystr = PyBytes_AsString(key); keystr = PyString_AsString(key);
if( strcmp(keystr, "defaultLocation") == 0 ) { if( strcmp(keystr, "defaultLocation") == 0 ) {
if ( (defaultLocation_storage = PyMem_NEW(AEDesc, 1)) == NULL ) { if ( (defaultLocation_storage = PyMem_NEW(AEDesc, 1)) == NULL ) {
PyErr_NoMemory(); PyErr_NoMemory();
@ -963,7 +963,7 @@ initNav(void)
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
ErrorObject = PyBytes_FromString("Nav.error"); ErrorObject = PyString_FromString("Nav.error");
PyDict_SetItemString(d, "error", ErrorObject); PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */ /* XXXX Add constants here */

View file

@ -840,9 +840,9 @@ static PyObject *AEDesc_get_data(AEDescObject *self, void *closure)
OSErr err; OSErr err;
size = AEGetDescDataSize(&self->ob_itself); size = AEGetDescDataSize(&self->ob_itself);
if ( (res = PyBytes_FromStringAndSize(NULL, size)) == NULL ) if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
return NULL; return NULL;
if ( (ptr = PyBytes_AsString(res)) == NULL ) if ( (ptr = PyString_AsString(res)) == NULL )
return NULL; return NULL;
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 ) if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
return PyMac_Error(err); return PyMac_Error(err);

View file

@ -392,7 +392,7 @@ static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFTypeRefObj_hash(CFTypeRefObject *self) static int CFTypeRefObj_hash(CFTypeRefObject *self)
@ -596,7 +596,7 @@ static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFArrayRefObj_hash(CFArrayRefObject *self) static int CFArrayRefObj_hash(CFArrayRefObject *self)
@ -836,7 +836,7 @@ static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self) static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
@ -1029,7 +1029,7 @@ static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self) static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
@ -1206,7 +1206,7 @@ static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *s
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self) static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
@ -1327,10 +1327,10 @@ int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
{ {
if (v == Py_None) { *p_itself = NULL; return 1; } if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyBytes_Check(v)) { if (PyString_Check(v)) {
char *cStr; char *cStr;
Py_ssize_t cLen; Py_ssize_t cLen;
if( PyBytes_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0; if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
*p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen); *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
return 1; return 1;
} }
@ -1405,7 +1405,7 @@ static PyObject *CFDataRefObj_CFDataGetData(CFDataRefObject *_self, PyObject *_a
int size = CFDataGetLength(_self->ob_itself); int size = CFDataGetLength(_self->ob_itself);
char *data = (char *)CFDataGetBytePtr(_self->ob_itself); char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
_res = (PyObject *)PyBytes_FromStringAndSize(data, size); _res = (PyObject *)PyString_FromStringAndSize(data, size);
return _res; return _res;
} }
@ -1437,7 +1437,7 @@ static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFDataRefObj_hash(CFDataRefObject *self) static int CFDataRefObj_hash(CFDataRefObject *self)
@ -1702,7 +1702,7 @@ static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self) static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
@ -1823,7 +1823,7 @@ int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
{ {
if (v == Py_None) { *p_itself = NULL; return 1; } if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyBytes_Check(v)) { if (PyString_Check(v)) {
char *cStr; char *cStr;
if (!PyArg_Parse(v, "es", "ascii", &cStr)) if (!PyArg_Parse(v, "es", "ascii", &cStr))
return 0; return 0;
@ -2344,7 +2344,7 @@ static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyOb
if( data == NULL ) return PyErr_NoMemory(); if( data == NULL ) return PyErr_NoMemory();
if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) { if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
_res = (PyObject *)PyBytes_FromString(data); _res = (PyObject *)PyString_FromString(data);
} else { } else {
PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string"); PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
_res = NULL; _res = NULL;
@ -2445,7 +2445,7 @@ static PyObject * CFStringRefObj_repr(CFStringRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFStringRefObj_hash(CFStringRefObject *self) static int CFStringRefObj_hash(CFStringRefObject *self)
@ -2833,7 +2833,7 @@ static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFMutableStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFMutableStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self) static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self)
@ -3485,7 +3485,7 @@ static PyObject * CFURLRefObj_repr(CFURLRefObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<CFURL object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<CFURL object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int CFURLRefObj_hash(CFURLRefObject *self) static int CFURLRefObj_hash(CFURLRefObject *self)

View file

@ -146,7 +146,7 @@ PyCF_CF2Python_string(CFStringRef src) {
int int
PyCF_Python2CF(PyObject *src, CFTypeRef *dst) { PyCF_Python2CF(PyObject *src, CFTypeRef *dst) {
if (PyBytes_Check(src) || PyUnicode_Check(src)) if (PyString_Check(src) || PyUnicode_Check(src))
return PyCF_Python2CF_simple(src, dst); return PyCF_Python2CF_simple(src, dst);
if (PySequence_Check(src)) if (PySequence_Check(src))
return PyCF_Python2CF_sequence(src, (CFArrayRef *)dst); return PyCF_Python2CF_sequence(src, (CFArrayRef *)dst);
@ -249,7 +249,7 @@ PyCF_Python2CF_simple(PyObject *src, CFTypeRef *dst) {
return (*dst != NULL); return (*dst != NULL);
} }
#endif #endif
if (PyBytes_Check(src) || PyUnicode_Check(src)) if (PyString_Check(src) || PyUnicode_Check(src))
return PyCF_Python2CF_string(src, (CFStringRef *)dst); return PyCF_Python2CF_string(src, (CFStringRef *)dst);
if (PyBool_Check(src)) { if (PyBool_Check(src)) {
if (src == Py_True) if (src == Py_True)
@ -281,7 +281,7 @@ PyCF_Python2CF_string(PyObject *src, CFStringRef *dst) {
CFIndex size; CFIndex size;
UniChar *unichars; UniChar *unichars;
if (PyBytes_Check(src)) { if (PyString_Check(src)) {
if (!PyArg_Parse(src, "es", "ascii", &chars)) if (!PyArg_Parse(src, "es", "ascii", &chars))
return 0; /* This error is more descriptive than the general one below */ return 0; /* This error is more descriptive than the general one below */
*dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, kCFStringEncodingASCII); *dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, kCFStringEncodingASCII);

View file

@ -961,7 +961,7 @@ static PyObject *Alias_get_data(AliasObject *self, void *closure)
size = GetHandleSize((Handle)self->ob_itself); size = GetHandleSize((Handle)self->ob_itself);
HLock((Handle)self->ob_itself); HLock((Handle)self->ob_itself);
rv = PyBytes_FromStringAndSize(*(Handle)self->ob_itself, size); rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size);
HUnlock((Handle)self->ob_itself); HUnlock((Handle)self->ob_itself);
return rv; return rv;
@ -1362,7 +1362,7 @@ static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
PyMac_Error(err); PyMac_Error(err);
return NULL; return NULL;
} }
_res = PyBytes_FromString(strbuf); _res = PyString_FromString(strbuf);
return _res; return _res;
} }
@ -1419,7 +1419,7 @@ static PyMethodDef FSSpec_methods[] = {
static PyObject *FSSpec_get_data(FSSpecObject *self, void *closure) static PyObject *FSSpec_get_data(FSSpecObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself)); return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
} }
#define FSSpec_set_data NULL #define FSSpec_set_data NULL
@ -1440,7 +1440,7 @@ static PyObject * FSSpec_repr(FSSpecObject *self)
self->ob_itself.vRefNum, self->ob_itself.vRefNum,
self->ob_itself.parID, self->ob_itself.parID,
self->ob_itself.name[0], self->ob_itself.name+1); self->ob_itself.name[0], self->ob_itself.name+1);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
#define FSSpec_hash NULL #define FSSpec_hash NULL
@ -2015,7 +2015,7 @@ static PyMethodDef FSRef_methods[] = {
static PyObject *FSRef_get_data(FSRefObject *self, void *closure) static PyObject *FSRef_get_data(FSRefObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself)); return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
} }
#define FSRef_set_data NULL #define FSRef_set_data NULL
@ -3131,7 +3131,7 @@ static PyObject *File_pathname(PyObject *_self, PyObject *_args)
if (!PyArg_ParseTuple(_args, "O", &obj)) if (!PyArg_ParseTuple(_args, "O", &obj))
return NULL; return NULL;
if (PyBytes_Check(obj)) { if (PyString_Check(obj)) {
Py_INCREF(obj); Py_INCREF(obj);
return obj; return obj;
} }
@ -3301,7 +3301,7 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
} }
/* On OSX we now try a pathname */ /* On OSX we now try a pathname */
if ( PyBytes_Check(v) || PyUnicode_Check(v)) { if ( PyString_Check(v) || PyUnicode_Check(v)) {
char *path = NULL; char *path = NULL;
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path)) if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
return 0; return 0;

View file

@ -1458,7 +1458,7 @@ static PyObject *BMObj_getdata(BitMapObject *_self, PyObject *_args)
if ( !PyArg_ParseTuple(_args, "ii", &from, &length) ) if ( !PyArg_ParseTuple(_args, "ii", &from, &length) )
return NULL; return NULL;
cp = _self->ob_itself->baseAddr+from; cp = _self->ob_itself->baseAddr+from;
_res = PyBytes_FromStringAndSize(cp, length); _res = PyString_FromStringAndSize(cp, length);
return _res; return _res;
} }
@ -1511,14 +1511,14 @@ static PyObject *BMObj_get_bounds(BitMapObject *self, void *closure)
static PyObject *BMObj_get_bitmap_data(BitMapObject *self, void *closure) static PyObject *BMObj_get_bitmap_data(BitMapObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize((char *)self->ob_itself, sizeof(BitMap)); return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(BitMap));
} }
#define BMObj_set_bitmap_data NULL #define BMObj_set_bitmap_data NULL
static PyObject *BMObj_get_pixmap_data(BitMapObject *self, void *closure) static PyObject *BMObj_get_pixmap_data(BitMapObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap)); return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap));
} }
#define BMObj_set_pixmap_data NULL #define BMObj_set_pixmap_data NULL
@ -6501,10 +6501,10 @@ static PyObject *Qd_BitMap(PyObject *_self, PyObject *_args)
int rowbytes; int rowbytes;
char *data; char *data;
if ( !PyArg_ParseTuple(_args, "O!iO&", &PyBytes_Type, &source, &rowbytes, PyMac_GetRect, if ( !PyArg_ParseTuple(_args, "O!iO&", &PyString_Type, &source, &rowbytes, PyMac_GetRect,
&bounds) ) &bounds) )
return NULL; return NULL;
data = PyBytes_AsString(source); data = PyString_AsString(source);
if ((ptr=(BitMap *)malloc(sizeof(BitMap))) == NULL ) if ((ptr=(BitMap *)malloc(sizeof(BitMap))) == NULL )
return PyErr_NoMemory(); return PyErr_NoMemory();
ptr->baseAddr = (Ptr)data; ptr->baseAddr = (Ptr)data;
@ -6528,15 +6528,15 @@ static PyObject *Qd_RawBitMap(PyObject *_self, PyObject *_args)
BitMap *ptr; BitMap *ptr;
PyObject *source; PyObject *source;
if ( !PyArg_ParseTuple(_args, "O!", &PyBytes_Type, &source) ) if ( !PyArg_ParseTuple(_args, "O!", &PyString_Type, &source) )
return NULL; return NULL;
if ( PyBytes_Size(source) != sizeof(BitMap) && PyBytes_Size(source) != sizeof(PixMap) ) { if ( PyString_Size(source) != sizeof(BitMap) && PyString_Size(source) != sizeof(PixMap) ) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Argument size was %ld, should be %lu (sizeof BitMap) or %lu (sizeof PixMap)", "Argument size was %ld, should be %lu (sizeof BitMap) or %lu (sizeof PixMap)",
PyBytes_Size(source), sizeof(BitMap), sizeof(PixMap)); PyString_Size(source), sizeof(BitMap), sizeof(PixMap));
return NULL; return NULL;
} }
ptr = (BitMapPtr)PyBytes_AsString(source); ptr = (BitMapPtr)PyString_AsString(source);
if ( (_res = BMObj_New(ptr)) == NULL ) { if ( (_res = BMObj_New(ptr)) == NULL ) {
return NULL; return NULL;
} }

View file

@ -609,7 +609,7 @@ static PyObject *Qdoffs_GetPixMapBytes(PyObject *_self, PyObject *_args)
if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) ) if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) )
return NULL; return NULL;
cp = GetPixBaseAddr(pm)+from; cp = GetPixBaseAddr(pm)+from;
_res = PyBytes_FromStringAndSize(cp, length); _res = PyString_FromStringAndSize(cp, length);
return _res; return _res;
} }

View file

@ -523,7 +523,7 @@ static PyObject *ResObj_get_data(ResourceObject *self, void *closure)
state = HGetState(self->ob_itself); state = HGetState(self->ob_itself);
HLock(self->ob_itself); HLock(self->ob_itself);
res = PyBytes_FromStringAndSize( res = PyString_FromStringAndSize(
*self->ob_itself, *self->ob_itself,
GetHandleSize(self->ob_itself)); GetHandleSize(self->ob_itself));
HUnlock(self->ob_itself); HUnlock(self->ob_itself);
@ -540,10 +540,10 @@ static int ResObj_set_data(ResourceObject *self, PyObject *v, void *closure)
if ( v == NULL ) if ( v == NULL )
return -1; return -1;
if ( !PyBytes_Check(v) ) if ( !PyString_Check(v) )
return -1; return -1;
size = PyBytes_Size(v); size = PyString_Size(v);
data = PyBytes_AsString(v); data = PyString_AsString(v);
/* XXXX Do I need the GetState/SetState calls? */ /* XXXX Do I need the GetState/SetState calls? */
SetHandleSize(self->ob_itself, size); SetHandleSize(self->ob_itself, size);
if ( MemError()) if ( MemError())

View file

@ -106,12 +106,12 @@ static PyObject *ScrapObj_GetScrapFlavorData(ScrapObject *_self, PyObject *_args
flavorType, flavorType,
&byteCount); &byteCount);
if (_err != noErr) return PyMac_Error(_err); if (_err != noErr) return PyMac_Error(_err);
_res = PyBytes_FromStringAndSize(NULL, (int)byteCount); _res = PyString_FromStringAndSize(NULL, (int)byteCount);
if ( _res == NULL ) return NULL; if ( _res == NULL ) return NULL;
_err = GetScrapFlavorData(_self->ob_itself, _err = GetScrapFlavorData(_self->ob_itself,
flavorType, flavorType,
&byteCount, &byteCount,
PyBytes_AS_STRING(_res)); PyString_AS_STRING(_res));
if (_err != noErr) { if (_err != noErr) {
Py_XDECREF(_res); Py_XDECREF(_res);
return PyMac_Error(_err); return PyMac_Error(_err);

View file

@ -500,7 +500,7 @@ init_Sndihooks()
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
ErrorObject = PyBytes_FromString("Sndihooks.error"); ErrorObject = PyString_FromString("Sndihooks.error");
PyDict_SetItemString(d, "error", ErrorObject); PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */ /* XXXX Add constants here */

View file

@ -2580,7 +2580,7 @@ static PyObject * WinObj_repr(WindowObject *self)
{ {
char buf[100]; char buf[100];
sprintf(buf, "<Window object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); sprintf(buf, "<Window object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int WinObj_hash(WindowObject *self) static int WinObj_hash(WindowObject *self)

View file

@ -584,7 +584,6 @@ PYTHON_HEADERS= \
Include/bitset.h \ Include/bitset.h \
Include/boolobject.h \ Include/boolobject.h \
Include/bytes_methods.h \ Include/bytes_methods.h \
Include/bytearrayobject.h \
Include/bytesobject.h \ Include/bytesobject.h \
Include/bufferobject.h \ Include/bufferobject.h \
Include/cellobject.h \ Include/cellobject.h \

View file

@ -175,7 +175,7 @@ static PyObject *
bytesio_getvalue(BytesIOObject *self) bytesio_getvalue(BytesIOObject *self)
{ {
CHECK_CLOSED(self); CHECK_CLOSED(self);
return PyBytes_FromStringAndSize(self->buf, self->string_size); return PyString_FromStringAndSize(self->buf, self->string_size);
} }
PyDoc_STRVAR(isatty_doc, PyDoc_STRVAR(isatty_doc,
@ -244,7 +244,7 @@ bytesio_read(BytesIOObject *self, PyObject *args)
output = self->buf + self->pos; output = self->buf + self->pos;
self->pos += size; self->pos += size;
return PyBytes_FromStringAndSize(output, size); return PyString_FromStringAndSize(output, size);
} }
@ -307,7 +307,7 @@ bytesio_readline(BytesIOObject *self, PyObject *args)
self->pos -= size; self->pos -= size;
} }
return PyBytes_FromStringAndSize(output, n); return PyString_FromStringAndSize(output, n);
} }
PyDoc_STRVAR(readlines_doc, PyDoc_STRVAR(readlines_doc,
@ -349,7 +349,7 @@ bytesio_readlines(BytesIOObject *self, PyObject *args)
return NULL; return NULL;
while ((n = get_line(self, &output)) != 0) { while ((n = get_line(self, &output)) != 0) {
line = PyBytes_FromStringAndSize(output, n); line = PyString_FromStringAndSize(output, n);
if (!line) if (!line)
goto on_error; goto on_error;
if (PyList_Append(result, line) == -1) { if (PyList_Append(result, line) == -1) {
@ -455,7 +455,7 @@ bytesio_iternext(BytesIOObject *self)
if (!next || n == 0) if (!next || n == 0)
return NULL; return NULL;
return PyBytes_FromStringAndSize(next, n); return PyString_FromStringAndSize(next, n);
} }
PyDoc_STRVAR(seek_doc, PyDoc_STRVAR(seek_doc,

View file

@ -168,7 +168,7 @@ escape_decode(PyObject *self,
if (!PyArg_ParseTuple(args, "s#|z:escape_decode", if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
&data, &size, &errors)) &data, &size, &errors))
return NULL; return NULL;
return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL), return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
size); size);
} }
@ -182,21 +182,21 @@ escape_encode(PyObject *self,
Py_ssize_t len; Py_ssize_t len;
if (!PyArg_ParseTuple(args, "O!|z:escape_encode", if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
&PyBytes_Type, &str, &errors)) &PyString_Type, &str, &errors))
return NULL; return NULL;
str = PyBytes_Repr(str, 0); str = PyString_Repr(str, 0);
if (!str) if (!str)
return NULL; return NULL;
/* The string will be quoted. Unquote, similar to unicode-escape. */ /* The string will be quoted. Unquote, similar to unicode-escape. */
buf = PyBytes_AS_STRING (str); buf = PyString_AS_STRING (str);
len = PyBytes_GET_SIZE (str); len = PyString_GET_SIZE (str);
memmove(buf, buf+1, len-2); memmove(buf, buf+1, len-2);
if (_PyBytes_Resize(&str, len-2) < 0) if (_PyString_Resize(&str, len-2) < 0)
return NULL; return NULL;
return codec_tuple(str, PyBytes_Size(str)); return codec_tuple(str, PyString_Size(str));
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
@ -640,7 +640,7 @@ readbuffer_encode(PyObject *self,
&data, &size, &errors)) &data, &size, &errors))
return NULL; return NULL;
return codec_tuple(PyBytes_FromStringAndSize(data, size), return codec_tuple(PyString_FromStringAndSize(data, size),
size); size);
} }
@ -656,7 +656,7 @@ charbuffer_encode(PyObject *self,
&data, &size, &errors)) &data, &size, &errors))
return NULL; return NULL;
return codec_tuple(PyBytes_FromStringAndSize(data, size), return codec_tuple(PyString_FromStringAndSize(data, size),
size); size);
} }
@ -676,13 +676,13 @@ unicode_internal_encode(PyObject *self,
if (PyUnicode_Check(obj)) { if (PyUnicode_Check(obj)) {
data = PyUnicode_AS_DATA(obj); data = PyUnicode_AS_DATA(obj);
size = PyUnicode_GET_DATA_SIZE(obj); size = PyUnicode_GET_DATA_SIZE(obj);
return codec_tuple(PyBytes_FromStringAndSize(data, size), return codec_tuple(PyString_FromStringAndSize(data, size),
size); size);
} }
else { else {
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
return NULL; return NULL;
return codec_tuple(PyBytes_FromStringAndSize(data, size), return codec_tuple(PyString_FromStringAndSize(data, size),
size); size);
} }
} }

View file

@ -668,7 +668,7 @@ deque_repr(PyObject *deque)
if (i != 0) { if (i != 0) {
if (i < 0) if (i < 0)
return NULL; return NULL;
return PyBytes_FromString("[...]"); return PyString_FromString("[...]");
} }
aslist = PySequence_List(deque); aslist = PySequence_List(deque);
@ -677,16 +677,16 @@ deque_repr(PyObject *deque)
return NULL; return NULL;
} }
if (((dequeobject *)deque)->maxlen != -1) if (((dequeobject *)deque)->maxlen != -1)
fmt = PyBytes_FromFormat("deque(%%r, maxlen=%i)", fmt = PyString_FromFormat("deque(%%r, maxlen=%i)",
((dequeobject *)deque)->maxlen); ((dequeobject *)deque)->maxlen);
else else
fmt = PyBytes_FromString("deque(%r)"); fmt = PyString_FromString("deque(%r)");
if (fmt == NULL) { if (fmt == NULL) {
Py_DECREF(aslist); Py_DECREF(aslist);
Py_ReprLeave(deque); Py_ReprLeave(deque);
return NULL; return NULL;
} }
result = PyBytes_Format(fmt, aslist); result = PyString_Format(fmt, aslist);
Py_DECREF(fmt); Py_DECREF(fmt);
Py_DECREF(aslist); Py_DECREF(aslist);
Py_ReprLeave(deque); Py_ReprLeave(deque);
@ -1298,14 +1298,14 @@ defdict_repr(defdictobject *dd)
if (baserepr == NULL) if (baserepr == NULL)
return NULL; return NULL;
if (dd->default_factory == NULL) if (dd->default_factory == NULL)
defrepr = PyBytes_FromString("None"); defrepr = PyString_FromString("None");
else else
{ {
int status = Py_ReprEnter(dd->default_factory); int status = Py_ReprEnter(dd->default_factory);
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
return NULL; return NULL;
defrepr = PyBytes_FromString("..."); defrepr = PyString_FromString("...");
} }
else else
defrepr = PyObject_Repr(dd->default_factory); defrepr = PyObject_Repr(dd->default_factory);
@ -1315,9 +1315,9 @@ defdict_repr(defdictobject *dd)
Py_DECREF(baserepr); Py_DECREF(baserepr);
return NULL; return NULL;
} }
result = PyBytes_FromFormat("defaultdict(%s, %s)", result = PyString_FromFormat("defaultdict(%s, %s)",
PyBytes_AS_STRING(defrepr), PyString_AS_STRING(defrepr),
PyBytes_AS_STRING(baserepr)); PyString_AS_STRING(baserepr));
Py_DECREF(defrepr); Py_DECREF(defrepr);
Py_DECREF(baserepr); Py_DECREF(baserepr);
return result; return result;

View file

@ -176,7 +176,7 @@ get_nullchar_as_None(char c)
return Py_None; return Py_None;
} }
else else
return PyBytes_FromStringAndSize((char*)&c, 1); return PyString_FromStringAndSize((char*)&c, 1);
} }
static PyObject * static PyObject *
@ -235,16 +235,16 @@ _set_char(const char *name, char *target, PyObject *src, char dflt)
if (src == NULL) if (src == NULL)
*target = dflt; *target = dflt;
else { else {
if (src == Py_None || PyBytes_Size(src) == 0) if (src == Py_None || PyString_Size(src) == 0)
*target = '\0'; *target = '\0';
else if (!PyBytes_Check(src) || PyBytes_Size(src) != 1) { else if (!PyString_Check(src) || PyString_Size(src) != 1) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"\"%s\" must be an 1-character string", "\"%s\" must be an 1-character string",
name); name);
return -1; return -1;
} }
else { else {
char *s = PyBytes_AsString(src); char *s = PyString_AsString(src);
if (s == NULL) if (s == NULL)
return -1; return -1;
*target = s[0]; *target = s[0];
@ -257,7 +257,7 @@ static int
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt) _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
{ {
if (src == NULL) if (src == NULL)
*target = PyBytes_FromString(dflt); *target = PyString_FromString(dflt);
else { else {
if (src == Py_None) if (src == Py_None)
*target = NULL; *target = NULL;
@ -528,7 +528,7 @@ parse_save_field(ReaderObj *self)
{ {
PyObject *field; PyObject *field;
field = PyBytes_FromStringAndSize(self->field, self->field_len); field = PyString_FromStringAndSize(self->field, self->field_len);
if (field == NULL) if (field == NULL)
return -1; return -1;
self->field_len = 0; self->field_len = 0;
@ -787,8 +787,8 @@ Reader_iternext(ReaderObj *self)
} }
++self->line_num; ++self->line_num;
line = PyBytes_AsString(lineobj); line = PyString_AsString(lineobj);
linelen = PyBytes_Size(lineobj); linelen = PyString_Size(lineobj);
if (line == NULL || linelen < 0) { if (line == NULL || linelen < 0) {
Py_DECREF(lineobj); Py_DECREF(lineobj);
@ -976,7 +976,7 @@ join_append_data(WriterObj *self, char *field, int quote_empty,
rec_len++;\ rec_len++;\
} while(0) } while(0)
lineterm = PyBytes_AsString(dialect->lineterminator); lineterm = PyString_AsString(dialect->lineterminator);
if (lineterm == NULL) if (lineterm == NULL)
return -1; return -1;
@ -1101,7 +1101,7 @@ join_append_lineterminator(WriterObj *self)
int terminator_len; int terminator_len;
char *terminator; char *terminator;
terminator_len = PyBytes_Size(self->dialect->lineterminator); terminator_len = PyString_Size(self->dialect->lineterminator);
if (terminator_len == -1) if (terminator_len == -1)
return 0; return 0;
@ -1109,7 +1109,7 @@ join_append_lineterminator(WriterObj *self)
if (!join_check_rec_size(self, self->rec_len + terminator_len)) if (!join_check_rec_size(self, self->rec_len + terminator_len))
return 0; return 0;
terminator = PyBytes_AsString(self->dialect->lineterminator); terminator = PyString_AsString(self->dialect->lineterminator);
if (terminator == NULL) if (terminator == NULL)
return 0; return 0;
memmove(self->rec + self->rec_len, terminator, terminator_len); memmove(self->rec + self->rec_len, terminator, terminator_len);
@ -1161,9 +1161,9 @@ csv_writerow(WriterObj *self, PyObject *seq)
break; break;
} }
if (PyBytes_Check(field)) { if (PyString_Check(field)) {
append_ok = join_append(self, append_ok = join_append(self,
PyBytes_AS_STRING(field), PyString_AS_STRING(field),
&quoted, len == 1); &quoted, len == 1);
Py_DECREF(field); Py_DECREF(field);
} }
@ -1179,7 +1179,7 @@ csv_writerow(WriterObj *self, PyObject *seq)
if (str == NULL) if (str == NULL)
return NULL; return NULL;
append_ok = join_append(self, PyBytes_AS_STRING(str), append_ok = join_append(self, PyString_AS_STRING(str),
&quoted, len == 1); &quoted, len == 1);
Py_DECREF(str); Py_DECREF(str);
} }

View file

@ -714,8 +714,8 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
if (-1 == PyType_Type.tp_setattro(self, key, value)) if (-1 == PyType_Type.tp_setattro(self, key, value))
return -1; return -1;
if (value && PyBytes_Check(key) && if (value && PyString_Check(key) &&
0 == strcmp(PyBytes_AS_STRING(key), "_fields_")) 0 == strcmp(PyString_AS_STRING(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 1); return StructUnionType_update_stgdict(self, value, 1);
return 0; return 0;
} }
@ -728,8 +728,8 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
if (-1 == PyObject_GenericSetAttr(self, key, value)) if (-1 == PyObject_GenericSetAttr(self, key, value))
return -1; return -1;
if (PyBytes_Check(key) && if (PyString_Check(key) &&
0 == strcmp(PyBytes_AS_STRING(key), "_fields_")) 0 == strcmp(PyString_AS_STRING(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 0); return StructUnionType_update_stgdict(self, value, 0);
return 0; return 0;
} }
@ -1065,7 +1065,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr); size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
if (size < 0) if (size < 0)
return -1; return -1;
} else if (-1 == PyBytes_AsStringAndSize(value, &ptr, &size)) { } else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) {
return -1; return -1;
} }
if (size > self->b_size) { if (size > self->b_size) {
@ -1082,7 +1082,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
static PyObject * static PyObject *
CharArray_get_raw(CDataObject *self) CharArray_get_raw(CDataObject *self)
{ {
return PyBytes_FromStringAndSize(self->b_ptr, self->b_size); return PyString_FromStringAndSize(self->b_ptr, self->b_size);
} }
static PyObject * static PyObject *
@ -1093,7 +1093,7 @@ CharArray_get_value(CDataObject *self)
for (i = 0; i < self->b_size; ++i) for (i = 0; i < self->b_size; ++i)
if (*ptr++ == '\0') if (*ptr++ == '\0')
break; break;
return PyBytes_FromStringAndSize(self->b_ptr, i); return PyString_FromStringAndSize(self->b_ptr, i);
} }
static int static int
@ -1114,14 +1114,14 @@ CharArray_set_value(CDataObject *self, PyObject *value)
conversion_mode_errors); conversion_mode_errors);
if (!value) if (!value)
return -1; return -1;
} else if (!PyBytes_Check(value)) { } else if (!PyString_Check(value)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"string expected instead of %s instance", "string expected instead of %s instance",
Py_TYPE(value)->tp_name); Py_TYPE(value)->tp_name);
return -1; return -1;
} else } else
Py_INCREF(value); Py_INCREF(value);
size = PyBytes_GET_SIZE(value); size = PyString_GET_SIZE(value);
if (size > self->b_size) { if (size > self->b_size) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"string too long"); "string too long");
@ -1129,7 +1129,7 @@ CharArray_set_value(CDataObject *self, PyObject *value)
return -1; return -1;
} }
ptr = PyBytes_AS_STRING(value); ptr = PyString_AS_STRING(value);
memcpy(self->b_ptr, ptr, size); memcpy(self->b_ptr, ptr, size);
if (size < self->b_size) if (size < self->b_size)
self->b_ptr[size] = '\0'; self->b_ptr[size] = '\0';
@ -1168,7 +1168,7 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
"can't delete attribute"); "can't delete attribute");
return -1; return -1;
} }
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, conversion_mode_encoding,
conversion_mode_errors); conversion_mode_errors);
@ -1465,7 +1465,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
if (PyUnicode_Check(value) || PyBytes_Check(value)) { if (PyUnicode_Check(value) || PyString_Check(value)) {
PyCArgObject *parg; PyCArgObject *parg;
struct fielddesc *fd = getentry("Z"); struct fielddesc *fd = getentry("Z");
@ -1529,7 +1529,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
if (PyBytes_Check(value) || PyUnicode_Check(value)) { if (PyString_Check(value) || PyUnicode_Check(value)) {
PyCArgObject *parg; PyCArgObject *parg;
struct fielddesc *fd = getentry("z"); struct fielddesc *fd = getentry("z");
@ -1615,7 +1615,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return (PyObject *)parg; return (PyObject *)parg;
} }
/* string */ /* string */
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
PyCArgObject *parg; PyCArgObject *parg;
struct fielddesc *fd = getentry("z"); struct fielddesc *fd = getentry("z");
@ -1686,10 +1686,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
} }
/* c_char_p, c_wchar_p */ /* c_char_p, c_wchar_p */
stgd = PyObject_stgdict(value); stgd = PyObject_stgdict(value);
if (stgd && CDataObject_Check(value) && stgd->proto && PyBytes_Check(stgd->proto)) { if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) {
PyCArgObject *parg; PyCArgObject *parg;
switch (PyBytes_AS_STRING(stgd->proto)[0]) { switch (PyString_AS_STRING(stgd->proto)[0]) {
case 'z': /* c_char_p */ case 'z': /* c_char_p */
case 'Z': /* c_wchar_p */ case 'Z': /* c_wchar_p */
parg = new_CArgObject(); parg = new_CArgObject();
@ -1746,13 +1746,13 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
if (suffix == NULL) if (suffix == NULL)
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
suffix = PyBytes_InternFromString("_le"); suffix = PyString_InternFromString("_le");
#else #else
suffix = PyBytes_InternFromString("_be"); suffix = PyString_InternFromString("_be");
#endif #endif
Py_INCREF(name); Py_INCREF(name);
PyBytes_Concat(&name, suffix); PyString_Concat(&name, suffix);
if (name == NULL) if (name == NULL)
return NULL; return NULL;
@ -1807,7 +1807,7 @@ SimpleType_paramfunc(CDataObject *self)
dict = PyObject_stgdict((PyObject *)self); dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for CDataObject instances */ assert(dict); /* Cannot be NULL for CDataObject instances */
fmt = PyBytes_AsString(dict->proto); fmt = PyString_AsString(dict->proto);
assert(fmt); assert(fmt);
fd = getentry(fmt); fd = getentry(fmt);
@ -1872,12 +1872,12 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
SIMPLE_TYPE_CHARS); SIMPLE_TYPE_CHARS);
goto error; goto error;
} }
fmt = getentry(PyBytes_AS_STRING(proto)); fmt = getentry(PyString_AS_STRING(proto));
if (fmt == NULL) { if (fmt == NULL) {
Py_DECREF(result); Py_DECREF(result);
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"_type_ '%s' not supported", "_type_ '%s' not supported",
PyBytes_AS_STRING(proto)); PyString_AS_STRING(proto));
return NULL; return NULL;
} }
@ -1927,7 +1927,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Overrides the SimpleType_from_param generic method. Overrides the SimpleType_from_param generic method.
*/ */
if (result->tp_base == &Simple_Type) { if (result->tp_base == &Simple_Type) {
switch (PyBytes_AS_STRING(proto)[0]) { switch (PyString_AS_STRING(proto)[0]) {
case 'z': /* c_char_p */ case 'z': /* c_char_p */
ml = &c_char_p_method; ml = &c_char_p_method;
stgdict->flags |= TYPEFLAG_ISPOINTER; stgdict->flags |= TYPEFLAG_ISPOINTER;
@ -2042,7 +2042,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
assert(dict); assert(dict);
/* I think we can rely on this being a one-character string */ /* I think we can rely on this being a one-character string */
fmt = PyBytes_AsString(dict->proto); fmt = PyString_AsString(dict->proto);
assert(fmt); assert(fmt);
fd = getentry(fmt); fd = getentry(fmt);
@ -2399,7 +2399,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
#endif #endif
target = target->b_base; target = target->b_base;
} }
return PyBytes_FromStringAndSize(string, cp-string); return PyString_FromStringAndSize(string, cp-string);
} }
/* /*
@ -2571,7 +2571,7 @@ CData_reduce(PyObject *_self, PyObject *args)
_unpickle, _unpickle,
Py_TYPE(_self), Py_TYPE(_self),
PyObject_GetAttrString(_self, "__dict__"), PyObject_GetAttrString(_self, "__dict__"),
PyBytes_FromStringAndSize(self->b_ptr, self->b_size)); PyString_FromStringAndSize(self->b_ptr, self->b_size));
} }
static PyObject * static PyObject *
@ -3120,9 +3120,9 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
dict = PyType_stgdict(arg); dict = PyType_stgdict(arg);
if (dict if (dict
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
&& PyBytes_Check(dict->proto) && PyString_Check(dict->proto)
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */ /* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
&& (strchr("PzZ", PyBytes_AS_STRING(dict->proto)[0]))) { && (strchr("PzZ", PyString_AS_STRING(dict->proto)[0]))) {
return 1; return 1;
} }
@ -3207,8 +3207,8 @@ _get_name(PyObject *obj, char **pname)
return 1; return 1;
} }
#endif #endif
if (PyBytes_Check(obj) || PyUnicode_Check(obj)) { if (PyString_Check(obj) || PyUnicode_Check(obj)) {
*pname = PyBytes_AsString(obj); *pname = PyString_AsString(obj);
return *pname ? 1 : 0; return *pname ? 1 : 0;
} }
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
@ -3558,7 +3558,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
/* We HAVE already checked that the tuple can be parsed with "i|zO", so... */ /* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
Py_ssize_t tsize = PyTuple_GET_SIZE(item); Py_ssize_t tsize = PyTuple_GET_SIZE(item);
flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0)); flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0));
name = tsize > 1 ? PyBytes_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL; name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL; defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL;
switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) { switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
@ -3612,7 +3612,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
"NULL stgdict unexpected"); "NULL stgdict unexpected");
goto error; goto error;
} }
if (PyBytes_Check(dict->proto)) { if (PyString_Check(dict->proto)) {
PyErr_Format( PyErr_Format(
PyExc_TypeError, PyExc_TypeError,
"%s 'out' parameter must be passed as default value", "%s 'out' parameter must be passed as default value",
@ -3910,12 +3910,12 @@ CFuncPtr_repr(CFuncPtrObject *self)
{ {
#ifdef MS_WIN32 #ifdef MS_WIN32
if (self->index) if (self->index)
return PyBytes_FromFormat("<COM method offset %d: %s at %p>", return PyString_FromFormat("<COM method offset %d: %s at %p>",
self->index - 0x1000, self->index - 0x1000,
Py_TYPE(self)->tp_name, Py_TYPE(self)->tp_name,
self); self);
#endif #endif
return PyBytes_FromFormat("<%s object at %p>", return PyString_FromFormat("<%s object at %p>",
Py_TYPE(self)->tp_name, Py_TYPE(self)->tp_name,
self); self);
} }
@ -4044,7 +4044,7 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
} }
if (kwds && PyDict_GetItem(kwds, name)) { if (kwds && PyDict_GetItem(kwds, name)) {
char *field = PyBytes_AsString(name); char *field = PyString_AsString(name);
if (field == NULL) { if (field == NULL) {
PyErr_Clear(); PyErr_Clear();
field = "???"; field = "???";
@ -4246,7 +4246,7 @@ Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
type, so this cannot be NULL */ type, so this cannot be NULL */
if (itemdict->getfunc == getentry("c")->getfunc) { if (itemdict->getfunc == getentry("c")->getfunc) {
char *ptr = (char *)self->b_ptr; char *ptr = (char *)self->b_ptr;
return PyBytes_FromStringAndSize(ptr + ilow, len); return PyString_FromStringAndSize(ptr + ilow, len);
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == getentry("u")->getfunc) { } else if (itemdict->getfunc == getentry("u")->getfunc) {
wchar_t *ptr = (wchar_t *)self->b_ptr; wchar_t *ptr = (wchar_t *)self->b_ptr;
@ -4303,9 +4303,9 @@ Array_subscript(PyObject *_self, PyObject *item)
char *dest; char *dest;
if (slicelen <= 0) if (slicelen <= 0)
return PyBytes_FromString(""); return PyString_FromString("");
if (step == 1) { if (step == 1) {
return PyBytes_FromStringAndSize(ptr + start, return PyString_FromStringAndSize(ptr + start,
slicelen); slicelen);
} }
dest = (char *)PyMem_Malloc(slicelen); dest = (char *)PyMem_Malloc(slicelen);
@ -4318,7 +4318,7 @@ Array_subscript(PyObject *_self, PyObject *item)
dest[i] = ptr[cur]; dest[i] = ptr[cur];
} }
np = PyBytes_FromStringAndSize(dest, slicelen); np = PyString_FromStringAndSize(dest, slicelen);
PyMem_Free(dest); PyMem_Free(dest);
return np; return np;
} }
@ -4728,12 +4728,12 @@ Simple_repr(CDataObject *self)
static PyObject *format; static PyObject *format;
if (Py_TYPE(self)->tp_base != &Simple_Type) { if (Py_TYPE(self)->tp_base != &Simple_Type) {
return PyBytes_FromFormat("<%s object at %p>", return PyString_FromFormat("<%s object at %p>",
Py_TYPE(self)->tp_name, self); Py_TYPE(self)->tp_name, self);
} }
if (format == NULL) { if (format == NULL) {
format = PyBytes_InternFromString("%s(%r)"); format = PyString_InternFromString("%s(%r)");
if (format == NULL) if (format == NULL)
return NULL; return NULL;
} }
@ -4742,7 +4742,7 @@ Simple_repr(CDataObject *self)
if (val == NULL) if (val == NULL)
return NULL; return NULL;
name = PyBytes_FromString(Py_TYPE(self)->tp_name); name = PyString_FromString(Py_TYPE(self)->tp_name);
if (name == NULL) { if (name == NULL) {
Py_DECREF(val); Py_DECREF(val);
return NULL; return NULL;
@ -4754,7 +4754,7 @@ Simple_repr(CDataObject *self)
if (args == NULL) if (args == NULL)
return NULL; return NULL;
result = PyBytes_Format(format, args); result = PyString_Format(format, args);
Py_DECREF(args); Py_DECREF(args);
return result; return result;
} }
@ -4988,7 +4988,7 @@ Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
assert(itemdict); assert(itemdict);
if (itemdict->getfunc == getentry("c")->getfunc) { if (itemdict->getfunc == getentry("c")->getfunc) {
char *ptr = *(char **)self->b_ptr; char *ptr = *(char **)self->b_ptr;
return PyBytes_FromStringAndSize(ptr + ilow, len); return PyString_FromStringAndSize(ptr + ilow, len);
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == getentry("u")->getfunc) { } else if (itemdict->getfunc == getentry("u")->getfunc) {
wchar_t *ptr = *(wchar_t **)self->b_ptr; wchar_t *ptr = *(wchar_t **)self->b_ptr;
@ -5085,9 +5085,9 @@ Pointer_subscript(PyObject *_self, PyObject *item)
char *dest; char *dest;
if (len <= 0) if (len <= 0)
return PyBytes_FromString(""); return PyString_FromString("");
if (step == 1) { if (step == 1) {
return PyBytes_FromStringAndSize(ptr + start, return PyString_FromStringAndSize(ptr + start,
len); len);
} }
dest = (char *)PyMem_Malloc(len); dest = (char *)PyMem_Malloc(len);
@ -5096,7 +5096,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
for (cur = start, i = 0; i < len; cur += step, i++) { for (cur = start, i = 0; i < len; cur += step, i++) {
dest[i] = ptr[cur]; dest[i] = ptr[cur];
} }
np = PyBytes_FromStringAndSize(dest, len); np = PyString_FromStringAndSize(dest, len);
PyMem_Free(dest); PyMem_Free(dest);
return np; return np;
} }
@ -5276,7 +5276,7 @@ create_comerror(void)
++methods; ++methods;
} }
s = PyBytes_FromString(comerror_doc); s = PyString_FromString(comerror_doc);
if (s == NULL) if (s == NULL)
goto error; goto error;
status = PyDict_SetItemString(dict, "__doc__", s); status = PyDict_SetItemString(dict, "__doc__", s);
@ -5302,8 +5302,8 @@ static PyObject *
string_at(const char *ptr, int size) string_at(const char *ptr, int size)
{ {
if (size == -1) if (size == -1)
return PyBytes_FromString(ptr); return PyString_FromString(ptr);
return PyBytes_FromStringAndSize(ptr, size); return PyString_FromStringAndSize(ptr, size);
} }
static int static int
@ -5317,8 +5317,8 @@ cast_check_pointertype(PyObject *arg)
return 1; return 1;
dict = PyType_stgdict(arg); dict = PyType_stgdict(arg);
if (dict) { if (dict) {
if (PyBytes_Check(dict->proto) if (PyString_Check(dict->proto)
&& (strchr("sPzUZXO", PyBytes_AS_STRING(dict->proto)[0]))) { && (strchr("sPzUZXO", PyString_AS_STRING(dict->proto)[0]))) {
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
return 1; return 1;
} }

View file

@ -107,15 +107,15 @@ void _AddTraceback(char *funcname, char *filename, int lineno)
PyCodeObject *py_code = 0; PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0; PyFrameObject *py_frame = 0;
py_srcfile = PyBytes_FromString(filename); py_srcfile = PyString_FromString(filename);
if (!py_srcfile) goto bad; if (!py_srcfile) goto bad;
py_funcname = PyBytes_FromString(funcname); py_funcname = PyString_FromString(funcname);
if (!py_funcname) goto bad; if (!py_funcname) goto bad;
py_globals = PyDict_New(); py_globals = PyDict_New();
if (!py_globals) goto bad; if (!py_globals) goto bad;
empty_tuple = PyTuple_New(0); empty_tuple = PyTuple_New(0);
if (!empty_tuple) goto bad; if (!empty_tuple) goto bad;
empty_string = PyBytes_FromString(""); empty_string = PyString_FromString("");
if (!empty_string) goto bad; if (!empty_string) goto bad;
py_code = PyCode_New( py_code = PyCode_New(
0, /*int argcount,*/ 0, /*int argcount,*/
@ -498,7 +498,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
static PyObject *context; static PyObject *context;
if (context == NULL) if (context == NULL)
context = PyBytes_InternFromString("_ctypes.DllGetClassObject"); context = PyString_InternFromString("_ctypes.DllGetClassObject");
mod = PyImport_ImportModuleNoBlock("ctypes"); mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) { if (!mod) {
@ -577,7 +577,7 @@ long Call_CanUnloadNow(void)
static PyObject *context; static PyObject *context;
if (context == NULL) if (context == NULL)
context = PyBytes_InternFromString("_ctypes.DllCanUnloadNow"); context = PyString_InternFromString("_ctypes.DllCanUnloadNow");
mod = PyImport_ImportModuleNoBlock("ctypes"); mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) { if (!mod) {

View file

@ -498,7 +498,7 @@ PyCArg_repr(PyCArgObject *self)
self->tag, self); self->tag, self);
break; break;
} }
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
static PyMemberDef PyCArgType_members[] = { static PyMemberDef PyCArgType_members[] = {
@ -646,9 +646,9 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
return 0; return 0;
} }
if (PyBytes_Check(obj)) { if (PyString_Check(obj)) {
pa->ffi_type = &ffi_type_pointer; pa->ffi_type = &ffi_type_pointer;
pa->value.p = PyBytes_AS_STRING(obj); pa->value.p = PyString_AS_STRING(obj);
Py_INCREF(obj); Py_INCREF(obj);
pa->keep = obj; pa->keep = obj;
return 0; return 0;
@ -937,7 +937,7 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...)
PyObject *tp, *v, *tb, *s, *cls_str, *msg_str; PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;
va_start(vargs, fmt); va_start(vargs, fmt);
s = PyBytes_FromFormatV(fmt, vargs); s = PyString_FromFormatV(fmt, vargs);
va_end(vargs); va_end(vargs);
if (!s) if (!s)
return; return;
@ -946,18 +946,18 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...)
PyErr_NormalizeException(&tp, &v, &tb); PyErr_NormalizeException(&tp, &v, &tb);
cls_str = PyObject_Str(tp); cls_str = PyObject_Str(tp);
if (cls_str) { if (cls_str) {
PyBytes_ConcatAndDel(&s, cls_str); PyString_ConcatAndDel(&s, cls_str);
PyBytes_ConcatAndDel(&s, PyBytes_FromString(": ")); PyString_ConcatAndDel(&s, PyString_FromString(": "));
if (s == NULL) if (s == NULL)
goto error; goto error;
} else } else
PyErr_Clear(); PyErr_Clear();
msg_str = PyObject_Str(v); msg_str = PyObject_Str(v);
if (msg_str) if (msg_str)
PyBytes_ConcatAndDel(&s, msg_str); PyString_ConcatAndDel(&s, msg_str);
else { else {
PyErr_Clear(); PyErr_Clear();
PyBytes_ConcatAndDel(&s, PyBytes_FromString("???")); PyString_ConcatAndDel(&s, PyString_FromString("???"));
if (s == NULL) if (s == NULL)
goto error; goto error;
} }
@ -1261,7 +1261,7 @@ static PyObject *load_library(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored)) if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored))
return NULL; return NULL;
#ifdef _UNICODE #ifdef _UNICODE
name = alloca((PyBytes_Size(nameobj) + 1) * sizeof(WCHAR)); name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
if (!name) { if (!name) {
PyErr_NoMemory(); PyErr_NoMemory();
return NULL; return NULL;
@ -1269,14 +1269,14 @@ static PyObject *load_library(PyObject *self, PyObject *args)
{ {
int r; int r;
char *aname = PyBytes_AsString(nameobj); char *aname = PyString_AsString(nameobj);
if(!aname) if(!aname)
return NULL; return NULL;
r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyBytes_Size(nameobj) + 1); r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyString_Size(nameobj) + 1);
name[r] = 0; name[r] = 0;
} }
#else #else
name = PyBytes_AsString(nameobj); name = PyString_AsString(nameobj);
if(!name) if(!name)
return NULL; return NULL;
#endif #endif
@ -1769,9 +1769,9 @@ POINTER(PyObject *self, PyObject *cls)
Py_INCREF(result); Py_INCREF(result);
return result; return result;
} }
if (PyBytes_CheckExact(cls)) { if (PyString_CheckExact(cls)) {
buf = alloca(strlen(PyBytes_AS_STRING(cls)) + 3 + 1); buf = alloca(strlen(PyString_AS_STRING(cls)) + 3 + 1);
sprintf(buf, "LP_%s", PyBytes_AS_STRING(cls)); sprintf(buf, "LP_%s", PyString_AS_STRING(cls));
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type), result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),
"s(O){}", "s(O){}",
buf, buf,

View file

@ -272,7 +272,7 @@ CField_repr(CFieldObject *self)
name = ((PyTypeObject *)self->proto)->tp_name; name = ((PyTypeObject *)self->proto)->tp_name;
if (bits) if (bits)
result = PyBytes_FromFormat( result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000) #if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d:%d, bits=%d>", "<Field type=%s, ofs=%d:%d, bits=%d>",
#else #else
@ -280,7 +280,7 @@ CField_repr(CFieldObject *self)
#endif #endif
name, self->offset, size, bits); name, self->offset, size, bits);
else else
result = PyBytes_FromFormat( result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000) #if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d, size=%d>", "<Field type=%s, ofs=%d, size=%d>",
#else #else
@ -1164,12 +1164,12 @@ O_set(void *ptr, PyObject *value, Py_ssize_t size)
static PyObject * static PyObject *
c_set(void *ptr, PyObject *value, Py_ssize_t size) c_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
if (!PyBytes_Check(value) || (1 != PyBytes_Size(value))) { if (!PyString_Check(value) || (1 != PyString_Size(value))) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"one character string expected"); "one character string expected");
return NULL; return NULL;
} }
*(char *)ptr = PyBytes_AS_STRING(value)[0]; *(char *)ptr = PyString_AS_STRING(value)[0];
_RET(value); _RET(value);
} }
@ -1177,7 +1177,7 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size)
static PyObject * static PyObject *
c_get(void *ptr, Py_ssize_t size) c_get(void *ptr, Py_ssize_t size)
{ {
return PyBytes_FromStringAndSize((char *)ptr, 1); return PyString_FromStringAndSize((char *)ptr, 1);
} }
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
@ -1187,7 +1187,7 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
Py_ssize_t len; Py_ssize_t len;
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, conversion_mode_encoding,
conversion_mode_errors); conversion_mode_errors);
@ -1262,7 +1262,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
/* It's easier to calculate in characters than in bytes */ /* It's easier to calculate in characters than in bytes */
length /= sizeof(wchar_t); length /= sizeof(wchar_t);
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, conversion_mode_encoding,
conversion_mode_errors); conversion_mode_errors);
@ -1301,21 +1301,21 @@ s_get(void *ptr, Py_ssize_t size)
PyObject *result; PyObject *result;
size_t slen; size_t slen;
result = PyBytes_FromString((char *)ptr); result = PyString_FromString((char *)ptr);
if (!result) if (!result)
return NULL; return NULL;
/* chop off at the first NUL character, if any. /* chop off at the first NUL character, if any.
* On error, result will be deallocated and set to NULL. * On error, result will be deallocated and set to NULL.
*/ */
slen = strlen(PyBytes_AS_STRING(result)); slen = strlen(PyString_AS_STRING(result));
size = min(size, (Py_ssize_t)slen); size = min(size, (Py_ssize_t)slen);
if (result->ob_refcnt == 1) { if (result->ob_refcnt == 1) {
/* shorten the result */ /* shorten the result */
_PyBytes_Resize(&result, size); _PyString_Resize(&result, size);
return result; return result;
} else } else
/* cannot shorten the result */ /* cannot shorten the result */
return PyBytes_FromStringAndSize(ptr, size); return PyString_FromStringAndSize(ptr, size);
} }
static PyObject * static PyObject *
@ -1324,7 +1324,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
char *data; char *data;
Py_ssize_t size; Py_ssize_t size;
data = PyBytes_AsString(value); data = PyString_AsString(value);
if (!data) if (!data)
return NULL; return NULL;
size = strlen(data); size = strlen(data);
@ -1356,8 +1356,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF(value); Py_INCREF(value);
return value; return value;
} }
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
*(char **)ptr = PyBytes_AS_STRING(value); *(char **)ptr = PyString_AS_STRING(value);
Py_INCREF(value); Py_INCREF(value);
return value; return value;
} else if (PyUnicode_Check(value)) { } else if (PyUnicode_Check(value)) {
@ -1366,7 +1366,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
conversion_mode_errors); conversion_mode_errors);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
*(char **)ptr = PyBytes_AS_STRING(str); *(char **)ptr = PyString_AS_STRING(str);
return str; return str;
} else if (PyInt_Check(value) || PyLong_Check(value)) { } else if (PyInt_Check(value) || PyLong_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
@ -1395,7 +1395,7 @@ z_get(void *ptr, Py_ssize_t size)
return NULL; return NULL;
} }
#endif #endif
return PyBytes_FromString(*(char **)ptr); return PyString_FromString(*(char **)ptr);
} else { } else {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@ -1411,7 +1411,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF(value); Py_INCREF(value);
return value; return value;
} }
if (PyBytes_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, conversion_mode_encoding,
conversion_mode_errors); conversion_mode_errors);
@ -1502,7 +1502,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
/* convert value into a PyUnicodeObject or NULL */ /* convert value into a PyUnicodeObject or NULL */
if (Py_None == value) { if (Py_None == value) {
value = NULL; value = NULL;
} else if (PyBytes_Check(value)) { } else if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, conversion_mode_encoding,
conversion_mode_errors); conversion_mode_errors);

View file

@ -472,7 +472,7 @@ init_curses_panel(void)
PyDict_SetItemString(d, "error", PyCursesError); PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */ /* Make the version available */
v = PyBytes_FromString(PyCursesVersion); v = PyString_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v); PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v); PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v); Py_DECREF(v);

View file

@ -198,9 +198,9 @@ PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{ {
if (PyInt_Check(obj)) { if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj); *ch = (chtype) PyInt_AsLong(obj);
} else if(PyBytes_Check(obj) } else if(PyString_Check(obj)
&& (PyBytes_Size(obj) == 1)) { && (PyString_Size(obj) == 1)) {
*ch = (chtype) *PyBytes_AsString(obj); *ch = (chtype) *PyString_AsString(obj);
} else { } else {
return 0; return 0;
} }
@ -886,9 +886,9 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
return Py_BuildValue("c", rtn); return Py_BuildValue("c", rtn);
else else
#if defined(__NetBSD__) #if defined(__NetBSD__)
return PyBytes_FromString(unctrl(rtn)); return PyString_FromString(unctrl(rtn));
#else #else
return PyBytes_FromString((char *)keyname(rtn)); return PyString_FromString((char *)keyname(rtn));
#endif #endif
} }
@ -943,7 +943,7 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
} }
if (rtn2 == ERR) if (rtn2 == ERR)
rtn[0] = 0; rtn[0] = 0;
return PyBytes_FromString(rtn); return PyString_FromString(rtn);
} }
static PyObject * static PyObject *
@ -1095,7 +1095,7 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
} }
if (rtn2 == ERR) if (rtn2 == ERR)
rtn[0] = 0; rtn[0] = 0;
return PyBytes_FromString(rtn); return PyString_FromString(rtn);
} }
static PyObject * static PyObject *
@ -1757,7 +1757,7 @@ PyCurses_EraseChar(PyObject *self)
ch = erasechar(); ch = erasechar();
return PyBytes_FromStringAndSize(&ch, 1); return PyString_FromStringAndSize(&ch, 1);
} }
static PyObject * static PyObject *
@ -2114,7 +2114,7 @@ PyCurses_KeyName(PyObject *self, PyObject *args)
} }
knp = keyname(ch); knp = keyname(ch);
return PyBytes_FromString((knp == NULL) ? "" : (char *)knp); return PyString_FromString((knp == NULL) ? "" : (char *)knp);
} }
#endif #endif
@ -2125,7 +2125,7 @@ PyCurses_KillChar(PyObject *self)
ch = killchar(); ch = killchar();
return PyBytes_FromStringAndSize(&ch, 1); return PyString_FromStringAndSize(&ch, 1);
} }
static PyObject * static PyObject *
@ -2496,7 +2496,7 @@ PyCurses_tigetstr(PyObject *self, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString( capname ); return PyString_FromString( capname );
} }
static PyObject * static PyObject *
@ -2520,7 +2520,7 @@ PyCurses_tparm(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
return PyBytes_FromString(result); return PyString_FromString(result);
} }
static PyObject * static PyObject *
@ -2547,14 +2547,14 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args)
if (PyInt_Check(temp)) if (PyInt_Check(temp))
ch = (chtype) PyInt_AsLong(temp); ch = (chtype) PyInt_AsLong(temp);
else if (PyBytes_Check(temp)) else if (PyString_Check(temp))
ch = (chtype) *PyBytes_AsString(temp); ch = (chtype) *PyString_AsString(temp);
else { else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL; return NULL;
} }
return PyBytes_FromString(unctrl(ch)); return PyString_FromString(unctrl(ch));
} }
static PyObject * static PyObject *
@ -2569,8 +2569,8 @@ PyCurses_UngetCh(PyObject *self, PyObject *args)
if (PyInt_Check(temp)) if (PyInt_Check(temp))
ch = (int) PyInt_AsLong(temp); ch = (int) PyInt_AsLong(temp);
else if (PyBytes_Check(temp)) else if (PyString_Check(temp))
ch = (int) *PyBytes_AsString(temp); ch = (int) *PyString_AsString(temp);
else { else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL; return NULL;
@ -2753,7 +2753,7 @@ init_curses(void)
PyDict_SetItemString(d, "error", PyCursesError); PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */ /* Make the version available */
v = PyBytes_FromString(PyCursesVersion); v = PyString_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v); PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v); PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v); Py_DECREF(v);

View file

@ -103,7 +103,7 @@ typedef int Py_ssize_t;
#define PyDict_CheckExact PyDict_Check #define PyDict_CheckExact PyDict_Check
#if (PY_VERSION_HEX < 0x02020000) #if (PY_VERSION_HEX < 0x02020000)
#define PyList_CheckExact PyList_Check #define PyList_CheckExact PyList_Check
#define PyBytes_CheckExact PyBytes_Check #define PyString_CheckExact PyString_Check
#if (PY_VERSION_HEX >= 0x01060000) #if (PY_VERSION_HEX >= 0x01060000)
#define Py_USING_UNICODE /* always enabled for 2.0 and 2.1 */ #define Py_USING_UNICODE /* always enabled for 2.0 and 2.1 */
#endif #endif
@ -173,7 +173,7 @@ list_join(PyObject* list)
switch (PyList_GET_SIZE(list)) { switch (PyList_GET_SIZE(list)) {
case 0: case 0:
Py_DECREF(list); Py_DECREF(list);
return PyBytes_FromString(""); return PyString_FromString("");
case 1: case 1:
result = PyList_GET_ITEM(list, 0); result = PyList_GET_ITEM(list, 0);
Py_INCREF(result); Py_INCREF(result);
@ -748,9 +748,9 @@ checkpath(PyObject* tag)
return 0; return 0;
} }
#endif #endif
if (PyBytes_Check(tag)) { if (PyString_Check(tag)) {
char *p = PyBytes_AS_STRING(tag); char *p = PyString_AS_STRING(tag);
for (i = 0; i < PyBytes_GET_SIZE(tag); i++) { for (i = 0; i < PyString_GET_SIZE(tag); i++) {
if (p[i] == '{') if (p[i] == '{')
check = 0; check = 0;
else if (p[i] == '}') else if (p[i] == '}')
@ -818,7 +818,7 @@ element_findtext(ElementObject* self, PyObject* args)
if (Element_CheckExact(item) && !PyObject_Compare(item->tag, tag)) { if (Element_CheckExact(item) && !PyObject_Compare(item->tag, tag)) {
PyObject* text = element_get_text(item); PyObject* text = element_get_text(item);
if (text == Py_None) if (text == Py_None)
return PyBytes_FromString(""); return PyString_FromString("");
Py_XINCREF(text); Py_XINCREF(text);
return text; return text;
} }
@ -1154,12 +1154,12 @@ element_repr(ElementObject* self)
PyObject* repr; PyObject* repr;
char buffer[100]; char buffer[100];
repr = PyBytes_FromString("<Element "); repr = PyString_FromString("<Element ");
PyBytes_ConcatAndDel(&repr, PyObject_Repr(self->tag)); PyString_ConcatAndDel(&repr, PyObject_Repr(self->tag));
sprintf(buffer, " at %p>", self); sprintf(buffer, " at %p>", self);
PyBytes_ConcatAndDel(&repr, PyBytes_FromString(buffer)); PyString_ConcatAndDel(&repr, PyString_FromString(buffer));
return repr; return repr;
} }
@ -1617,14 +1617,14 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
Py_INCREF(data); self->data = data; Py_INCREF(data); self->data = data;
} else { } else {
/* more than one item; use a list to collect items */ /* more than one item; use a list to collect items */
if (PyBytes_CheckExact(self->data) && Py_REFCNT(self->data) == 1 && if (PyString_CheckExact(self->data) && Py_REFCNT(self->data) == 1 &&
PyBytes_CheckExact(data) && PyBytes_GET_SIZE(data) == 1) { PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
/* expat often generates single character data sections; handle /* expat often generates single character data sections; handle
the most common case by resizing the existing string... */ the most common case by resizing the existing string... */
Py_ssize_t size = PyBytes_GET_SIZE(self->data); Py_ssize_t size = PyString_GET_SIZE(self->data);
if (_PyBytes_Resize(&self->data, size + 1) < 0) if (_PyString_Resize(&self->data, size + 1) < 0)
return NULL; return NULL;
PyBytes_AS_STRING(self->data)[size] = PyBytes_AS_STRING(data)[0]; PyString_AS_STRING(self->data)[size] = PyString_AS_STRING(data)[0];
} else if (PyList_CheckExact(self->data)) { } else if (PyList_CheckExact(self->data)) {
if (PyList_Append(self->data, data) < 0) if (PyList_Append(self->data, data) < 0)
return NULL; return NULL;
@ -1896,7 +1896,7 @@ makestring(const char* string, int size)
return PyUnicode_DecodeUTF8(string, size, "strict"); return PyUnicode_DecodeUTF8(string, size, "strict");
#endif #endif
return PyBytes_FromStringAndSize(string, size); return PyString_FromStringAndSize(string, size);
} }
LOCAL(PyObject*) LOCAL(PyObject*)
@ -1910,7 +1910,7 @@ makeuniversal(XMLParserObject* self, const char* string)
PyObject* value; PyObject* value;
/* look the 'raw' name up in the names dictionary */ /* look the 'raw' name up in the names dictionary */
key = PyBytes_FromStringAndSize(string, size); key = PyString_FromStringAndSize(string, size);
if (!key) if (!key)
return NULL; return NULL;
@ -1932,8 +1932,8 @@ makeuniversal(XMLParserObject* self, const char* string)
break; break;
if (i != size) { if (i != size) {
/* convert to universal name */ /* convert to universal name */
tag = PyBytes_FromStringAndSize(NULL, size+1); tag = PyString_FromStringAndSize(NULL, size+1);
p = PyBytes_AS_STRING(tag); p = PyString_AS_STRING(tag);
p[0] = '{'; p[0] = '{';
memcpy(p+1, string, size); memcpy(p+1, string, size);
size++; size++;
@ -1947,7 +1947,7 @@ makeuniversal(XMLParserObject* self, const char* string)
#if defined(Py_USING_UNICODE) #if defined(Py_USING_UNICODE)
/* inline makestring, to avoid duplicating the source string if /* inline makestring, to avoid duplicating the source string if
it's not an utf-8 string */ it's not an utf-8 string */
p = PyBytes_AS_STRING(tag); p = PyString_AS_STRING(tag);
if (checkstring(p, size)) { if (checkstring(p, size)) {
value = PyUnicode_DecodeUTF8(p, size, "strict"); value = PyUnicode_DecodeUTF8(p, size, "strict");
Py_DECREF(tag); Py_DECREF(tag);
@ -2004,7 +2004,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
} else { } else {
PyErr_Format( PyErr_Format(
PyExc_SyntaxError, "undefined entity &%s;: line %ld, column %ld", PyExc_SyntaxError, "undefined entity &%s;: line %ld, column %ld",
PyBytes_AS_STRING(key), PyString_AS_STRING(key),
EXPAT(GetErrorLineNumber)(self->parser), EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser) EXPAT(GetErrorColumnNumber)(self->parser)
); );
@ -2435,13 +2435,13 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
return NULL; return NULL;
} }
if (!PyBytes_CheckExact(buffer) || PyBytes_GET_SIZE(buffer) == 0) { if (!PyString_CheckExact(buffer) || PyString_GET_SIZE(buffer) == 0) {
Py_DECREF(buffer); Py_DECREF(buffer);
break; break;
} }
res = expat_parse( res = expat_parse(
self, PyBytes_AS_STRING(buffer), PyBytes_GET_SIZE(buffer), 0 self, PyString_AS_STRING(buffer), PyString_GET_SIZE(buffer), 0
); );
Py_DECREF(buffer); Py_DECREF(buffer);
@ -2503,7 +2503,7 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
if (event_set == Py_None) { if (event_set == Py_None) {
/* default is "end" only */ /* default is "end" only */
target->end_event_obj = PyBytes_FromString("end"); target->end_event_obj = PyString_FromString("end");
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -2513,9 +2513,9 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
for (i = 0; i < PyTuple_GET_SIZE(event_set); i++) { for (i = 0; i < PyTuple_GET_SIZE(event_set); i++) {
PyObject* item = PyTuple_GET_ITEM(event_set, i); PyObject* item = PyTuple_GET_ITEM(event_set, i);
char* event; char* event;
if (!PyBytes_Check(item)) if (!PyString_Check(item))
goto error; goto error;
event = PyBytes_AS_STRING(item); event = PyString_AS_STRING(item);
if (strcmp(event, "start") == 0) { if (strcmp(event, "start") == 0) {
Py_INCREF(item); Py_INCREF(item);
target->start_event_obj = item; target->start_event_obj = item;
@ -2587,7 +2587,7 @@ xmlparser_getattr(XMLParserObject* self, char* name)
char buffer[100]; char buffer[100];
sprintf(buffer, "Expat %d.%d.%d", XML_MAJOR_VERSION, sprintf(buffer, "Expat %d.%d.%d", XML_MAJOR_VERSION,
XML_MINOR_VERSION, XML_MICRO_VERSION); XML_MINOR_VERSION, XML_MICRO_VERSION);
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} else { } else {
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
return NULL; return NULL;

View file

@ -392,14 +392,14 @@ fileio_readall(PyFileIOObject *self)
Py_ssize_t total = 0; Py_ssize_t total = 0;
int n; int n;
result = PyBytes_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE); result = PyString_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
while (1) { while (1) {
Py_ssize_t newsize = total + DEFAULT_BUFFER_SIZE; Py_ssize_t newsize = total + DEFAULT_BUFFER_SIZE;
if (PyBytes_GET_SIZE(result) < newsize) { if (PyString_GET_SIZE(result) < newsize) {
if (_PyBytes_Resize(&result, newsize) < 0) { if (_PyString_Resize(&result, newsize) < 0) {
if (total == 0) { if (total == 0) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
@ -411,7 +411,7 @@ fileio_readall(PyFileIOObject *self)
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
errno = 0; errno = 0;
n = read(self->fd, n = read(self->fd,
PyBytes_AS_STRING(result) + total, PyString_AS_STRING(result) + total,
newsize - total); newsize - total);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (n == 0) if (n == 0)
@ -430,8 +430,8 @@ fileio_readall(PyFileIOObject *self)
total += n; total += n;
} }
if (PyBytes_GET_SIZE(result) > total) { if (PyString_GET_SIZE(result) > total) {
if (_PyBytes_Resize(&result, total) < 0) { if (_PyString_Resize(&result, total) < 0) {
/* This should never happen, but just in case */ /* This should never happen, but just in case */
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
@ -460,10 +460,10 @@ fileio_read(PyFileIOObject *self, PyObject *args)
return fileio_readall(self); return fileio_readall(self);
} }
bytes = PyBytes_FromStringAndSize(NULL, size); bytes = PyString_FromStringAndSize(NULL, size);
if (bytes == NULL) if (bytes == NULL)
return NULL; return NULL;
ptr = PyBytes_AS_STRING(bytes); ptr = PyString_AS_STRING(bytes);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
errno = 0; errno = 0;
@ -478,7 +478,7 @@ fileio_read(PyFileIOObject *self, PyObject *args)
} }
if (n != size) { if (n != size) {
if (_PyBytes_Resize(&bytes, n) < 0) { if (_PyString_Resize(&bytes, n) < 0) {
Py_DECREF(bytes); Py_DECREF(bytes);
return NULL; return NULL;
} }
@ -690,9 +690,9 @@ static PyObject *
fileio_repr(PyFileIOObject *self) fileio_repr(PyFileIOObject *self)
{ {
if (self->fd < 0) if (self->fd < 0)
return PyBytes_FromFormat("_fileio._FileIO(-1)"); return PyString_FromFormat("_fileio._FileIO(-1)");
return PyBytes_FromFormat("_fileio._FileIO(%d, '%s')", return PyString_FromFormat("_fileio._FileIO(%d, '%s')",
self->fd, mode_string(self)); self->fd, mode_string(self));
} }
@ -816,7 +816,7 @@ get_closed(PyFileIOObject *self, void *closure)
static PyObject * static PyObject *
get_mode(PyFileIOObject *self, void *closure) get_mode(PyFileIOObject *self, void *closure)
{ {
return PyBytes_FromString(mode_string(self)); return PyString_FromString(mode_string(self));
} }
static PyGetSetDef fileio_getsetlist[] = { static PyGetSetDef fileio_getsetlist[] = {

View file

@ -103,7 +103,7 @@ EVP_digest(EVPobject *self, PyObject *unused)
digest_size = EVP_MD_CTX_size(&temp_ctx); digest_size = EVP_MD_CTX_size(&temp_ctx);
EVP_DigestFinal(&temp_ctx, digest, NULL); EVP_DigestFinal(&temp_ctx, digest, NULL);
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size); retval = PyString_FromStringAndSize((const char *)digest, digest_size);
EVP_MD_CTX_cleanup(&temp_ctx); EVP_MD_CTX_cleanup(&temp_ctx);
return retval; return retval;
} }
@ -130,10 +130,10 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
/* Create a new string */ /* Create a new string */
/* NOTE: not thread safe! modifying an already created string object */ /* NOTE: not thread safe! modifying an already created string object */
/* (not a problem because we hold the GIL by default) */ /* (not a problem because we hold the GIL by default) */
retval = PyBytes_FromStringAndSize(NULL, digest_size * 2); retval = PyString_FromStringAndSize(NULL, digest_size * 2);
if (!retval) if (!retval)
return NULL; return NULL;
hex_digest = PyBytes_AsString(retval); hex_digest = PyString_AsString(retval);
if (!hex_digest) { if (!hex_digest) {
Py_DECREF(retval); Py_DECREF(retval);
return NULL; return NULL;
@ -220,8 +220,8 @@ EVP_repr(PyObject *self)
{ {
char buf[100]; char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>", PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>",
PyBytes_AsString(((EVPobject *)self)->name), self); PyString_AsString(((EVPobject *)self)->name), self);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
#if HASH_OBJ_CONSTRUCTOR #if HASH_OBJ_CONSTRUCTOR
@ -421,7 +421,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
/* used in the init function to setup a constructor */ /* used in the init function to setup a constructor */
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \ #define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
CONST_ ## NAME ## _name_obj = PyBytes_FromString(#NAME); \ CONST_ ## NAME ## _name_obj = PyString_FromString(#NAME); \
if (EVP_get_digestbyname(#NAME)) { \ if (EVP_get_digestbyname(#NAME)) { \
CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \
EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \

View file

@ -687,6 +687,6 @@ init_heapq(void)
m = Py_InitModule3("_heapq", heapq_methods, module_doc); m = Py_InitModule3("_heapq", heapq_methods, module_doc);
if (m == NULL) if (m == NULL)
return; return;
PyModule_AddObject(m, "__about__", PyBytes_FromString(__about__)); PyModule_AddObject(m, "__about__", PyString_FromString(__about__));
} }

View file

@ -326,7 +326,7 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
return ERR_EOF; return ERR_EOF;
} }
} }
*pvalue = PyBytes_FromStringAndSize(buf, len); *pvalue = PyString_FromStringAndSize(buf, len);
free(buf); free(buf);
if (*pvalue == NULL) { if (*pvalue == NULL) {
return ERR_EXCEPTION; return ERR_EXCEPTION;
@ -562,7 +562,7 @@ flush_data(ProfilerObject *self)
self->index - written); self->index - written);
self->index -= written; self->index -= written;
if (written == 0) { if (written == 0) {
char *s = PyBytes_AsString(self->logfilename); char *s = PyString_AsString(self->logfilename);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, s); PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
do_stop(self); do_stop(self);
return -1; return -1;
@ -570,7 +570,7 @@ flush_data(ProfilerObject *self)
} }
if (written > 0) { if (written > 0) {
if (fflush(self->logfp)) { if (fflush(self->logfp)) {
char *s = PyBytes_AsString(self->logfilename); char *s = PyString_AsString(self->logfilename);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, s); PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
do_stop(self); do_stop(self);
return -1; return -1;
@ -792,7 +792,7 @@ get_fileno(ProfilerObject *self, PyCodeObject *fcode)
self->next_fileno++; self->next_fileno++;
Py_DECREF(obj); Py_DECREF(obj);
if (pack_define_file(self, fileno, if (pack_define_file(self, fileno,
PyBytes_AS_STRING(fcode->co_filename)) < 0) PyString_AS_STRING(fcode->co_filename)) < 0)
return -1; return -1;
} }
else { else {
@ -810,7 +810,7 @@ get_fileno(ProfilerObject *self, PyCodeObject *fcode)
PyObject *name = PyDict_GetItem(dict, obj); PyObject *name = PyDict_GetItem(dict, obj);
if (name == NULL) { if (name == NULL) {
if (pack_define_func(self, fileno, fcode->co_firstlineno, if (pack_define_func(self, fileno, fcode->co_firstlineno,
PyBytes_AS_STRING(fcode->co_name)) < 0) { PyString_AS_STRING(fcode->co_name)) < 0) {
Py_DECREF(obj); Py_DECREF(obj);
return -1; return -1;
} }
@ -1471,7 +1471,7 @@ write_header(ProfilerObject *self)
len = PyList_GET_SIZE(temp); len = PyList_GET_SIZE(temp);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
PyObject *item = PyList_GET_ITEM(temp, i); PyObject *item = PyList_GET_ITEM(temp, i);
buffer = PyBytes_AsString(item); buffer = PyString_AsString(item);
if (buffer == NULL) { if (buffer == NULL) {
pack_add_info(self, "sys-path-entry", "<non-string-path-entry>"); pack_add_info(self, "sys-path-entry", "<non-string-path-entry>");
PyErr_Clear(); PyErr_Clear();

View file

@ -70,11 +70,11 @@ ascii_escape_unicode(PyObject *pystr)
input_unicode = PyUnicode_AS_UNICODE(pystr); input_unicode = PyUnicode_AS_UNICODE(pystr);
/* One char input can be up to 6 chars output, estimate 4 of these */ /* One char input can be up to 6 chars output, estimate 4 of these */
output_size = 2 + (MIN_EXPANSION * 4) + input_chars; output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
rval = PyBytes_FromStringAndSize(NULL, output_size); rval = PyString_FromStringAndSize(NULL, output_size);
if (rval == NULL) { if (rval == NULL) {
return NULL; return NULL;
} }
output = PyBytes_AS_STRING(rval); output = PyString_AS_STRING(rval);
chars = 0; chars = 0;
output[chars++] = '"'; output[chars++] = '"';
for (i = 0; i < input_chars; i++) { for (i = 0; i < input_chars; i++) {
@ -92,14 +92,14 @@ ascii_escape_unicode(PyObject *pystr)
if (output_size > 2 + (input_chars * MAX_EXPANSION)) { if (output_size > 2 + (input_chars * MAX_EXPANSION)) {
output_size = 2 + (input_chars * MAX_EXPANSION); output_size = 2 + (input_chars * MAX_EXPANSION);
} }
if (_PyBytes_Resize(&rval, output_size) == -1) { if (_PyString_Resize(&rval, output_size) == -1) {
return NULL; return NULL;
} }
output = PyBytes_AS_STRING(rval); output = PyString_AS_STRING(rval);
} }
} }
output[chars++] = '"'; output[chars++] = '"';
if (_PyBytes_Resize(&rval, chars) == -1) { if (_PyString_Resize(&rval, chars) == -1) {
return NULL; return NULL;
} }
return rval; return rval;
@ -116,15 +116,15 @@ ascii_escape_str(PyObject *pystr)
char *output; char *output;
char *input_str; char *input_str;
input_chars = PyBytes_GET_SIZE(pystr); input_chars = PyString_GET_SIZE(pystr);
input_str = PyBytes_AS_STRING(pystr); input_str = PyString_AS_STRING(pystr);
/* One char input can be up to 6 chars output, estimate 4 of these */ /* One char input can be up to 6 chars output, estimate 4 of these */
output_size = 2 + (MIN_EXPANSION * 4) + input_chars; output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
rval = PyBytes_FromStringAndSize(NULL, output_size); rval = PyString_FromStringAndSize(NULL, output_size);
if (rval == NULL) { if (rval == NULL) {
return NULL; return NULL;
} }
output = PyBytes_AS_STRING(rval); output = PyString_AS_STRING(rval);
chars = 0; chars = 0;
output[chars++] = '"'; output[chars++] = '"';
for (i = 0; i < input_chars; i++) { for (i = 0; i < input_chars; i++) {
@ -154,14 +154,14 @@ ascii_escape_str(PyObject *pystr)
if (output_size > 2 + (input_chars * MIN_EXPANSION)) { if (output_size > 2 + (input_chars * MIN_EXPANSION)) {
output_size = 2 + (input_chars * MIN_EXPANSION); output_size = 2 + (input_chars * MIN_EXPANSION);
} }
if (_PyBytes_Resize(&rval, output_size) == -1) { if (_PyString_Resize(&rval, output_size) == -1) {
return NULL; return NULL;
} }
output = PyBytes_AS_STRING(rval); output = PyString_AS_STRING(rval);
} }
} }
output[chars++] = '"'; output[chars++] = '"';
if (_PyBytes_Resize(&rval, chars) == -1) { if (_PyString_Resize(&rval, chars) == -1) {
return NULL; return NULL;
} }
return rval; return rval;
@ -215,7 +215,7 @@ join_list_unicode(PyObject *lst)
ustr = PyUnicode_FromUnicode(&c, 0); ustr = PyUnicode_FromUnicode(&c, 0);
} }
if (joinstr == NULL) { if (joinstr == NULL) {
joinstr = PyBytes_InternFromString("join"); joinstr = PyString_InternFromString("join");
} }
if (joinstr == NULL || ustr == NULL) { if (joinstr == NULL || ustr == NULL) {
return NULL; return NULL;
@ -227,10 +227,10 @@ static PyObject *
scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict) scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
{ {
PyObject *rval; PyObject *rval;
Py_ssize_t len = PyBytes_GET_SIZE(pystr); Py_ssize_t len = PyString_GET_SIZE(pystr);
Py_ssize_t begin = end - 1; Py_ssize_t begin = end - 1;
Py_ssize_t next = begin; Py_ssize_t next = begin;
char *buf = PyBytes_AS_STRING(pystr); char *buf = PyString_AS_STRING(pystr);
PyObject *chunks = PyList_New(0); PyObject *chunks = PyList_New(0);
if (chunks == NULL) { if (chunks == NULL) {
goto bail; goto bail;
@ -555,7 +555,7 @@ py_scanstring(PyObject* self, PyObject *args)
if (encoding == NULL) { if (encoding == NULL) {
encoding = DEFAULT_ENCODING; encoding = DEFAULT_ENCODING;
} }
if (PyBytes_Check(pystr)) { if (PyString_Check(pystr)) {
return scanstring_str(pystr, end, encoding, strict); return scanstring_str(pystr, end, encoding, strict);
} }
else if (PyUnicode_Check(pystr)) { else if (PyUnicode_Check(pystr)) {
@ -576,7 +576,7 @@ static PyObject *
py_encode_basestring_ascii(PyObject* self, PyObject *pystr) py_encode_basestring_ascii(PyObject* self, PyObject *pystr)
{ {
/* METH_O */ /* METH_O */
if (PyBytes_Check(pystr)) { if (PyString_Check(pystr)) {
return ascii_escape_str(pystr); return ascii_escape_str(pystr);
} }
else if (PyUnicode_Check(pystr)) { else if (PyUnicode_Check(pystr)) {

View file

@ -119,7 +119,7 @@ fixup_ulcase(void)
if (isupper(c)) if (isupper(c))
ul[n++] = c; ul[n++] = c;
} }
ulo = PyBytes_FromStringAndSize((const char *)ul, n); ulo = PyString_FromStringAndSize((const char *)ul, n);
if (!ulo) if (!ulo)
return; return;
if (string) if (string)
@ -134,7 +134,7 @@ fixup_ulcase(void)
if (islower(c)) if (islower(c))
ul[n++] = c; ul[n++] = c;
} }
ulo = PyBytes_FromStringAndSize((const char *)ul, n); ulo = PyString_FromStringAndSize((const char *)ul, n);
if (!ulo) if (!ulo)
return; return;
if (string) if (string)
@ -149,7 +149,7 @@ fixup_ulcase(void)
if (isalpha(c)) if (isalpha(c))
ul[n++] = c; ul[n++] = c;
} }
ulo = PyBytes_FromStringAndSize((const char *)ul, n); ulo = PyString_FromStringAndSize((const char *)ul, n);
if (!ulo) if (!ulo)
return; return;
if (string) if (string)
@ -175,7 +175,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
PyErr_SetString(Error, "unsupported locale setting"); PyErr_SetString(Error, "unsupported locale setting");
return NULL; return NULL;
} }
result_object = PyBytes_FromString(result); result_object = PyString_FromString(result);
if (!result_object) if (!result_object)
return NULL; return NULL;
/* record changes to LC_CTYPE */ /* record changes to LC_CTYPE */
@ -190,7 +190,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
PyErr_SetString(Error, "locale query failed"); PyErr_SetString(Error, "locale query failed");
return NULL; return NULL;
} }
result_object = PyBytes_FromString(result); result_object = PyString_FromString(result);
} }
return result_object; return result_object;
} }
@ -216,7 +216,7 @@ PyLocale_localeconv(PyObject* self)
involved herein */ involved herein */
#define RESULT_STRING(s)\ #define RESULT_STRING(s)\
x = PyBytes_FromString(l->s);\ x = PyString_FromString(l->s);\
if (!x) goto failed;\ if (!x) goto failed;\
PyDict_SetItemString(result, #s, x);\ PyDict_SetItemString(result, #s, x);\
Py_XDECREF(x) Py_XDECREF(x)
@ -284,9 +284,9 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2)) if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
return NULL; return NULL;
/* If both arguments are byte strings, use strcoll. */ /* If both arguments are byte strings, use strcoll. */
if (PyBytes_Check(os1) && PyBytes_Check(os2)) if (PyString_Check(os1) && PyString_Check(os2))
return PyInt_FromLong(strcoll(PyBytes_AS_STRING(os1), return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
PyBytes_AS_STRING(os2))); PyString_AS_STRING(os2)));
/* If neither argument is unicode, it's an error. */ /* If neither argument is unicode, it's an error. */
if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) { if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings"); PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
@ -368,7 +368,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
return PyErr_NoMemory(); return PyErr_NoMemory();
strxfrm(buf, s, n2); strxfrm(buf, s, n2);
} }
result = PyBytes_FromString(buf); result = PyString_FromString(buf);
PyMem_Free(buf); PyMem_Free(buf);
return result; return result;
} }
@ -563,13 +563,13 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
return NULL; return NULL;
/* Check whether this is a supported constant. GNU libc sometimes /* Check whether this is a supported constant. GNU libc sometimes
returns numeric values in the char* return value, which would returns numeric values in the char* return value, which would
crash PyBytes_FromString. */ crash PyString_FromString. */
for (i = 0; langinfo_constants[i].name; i++) for (i = 0; langinfo_constants[i].name; i++)
if (langinfo_constants[i].value == item) { if (langinfo_constants[i].value == item) {
/* Check NULL as a workaround for GNU libc's returning NULL /* Check NULL as a workaround for GNU libc's returning NULL
instead of an empty string for nl_langinfo(ERA). */ instead of an empty string for nl_langinfo(ERA). */
const char *result = nl_langinfo(item); const char *result = nl_langinfo(item);
return PyBytes_FromString(result != NULL ? result : ""); return PyString_FromString(result != NULL ? result : "");
} }
PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant"); PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
return NULL; return NULL;
@ -588,7 +588,7 @@ PyIntl_gettext(PyObject* self, PyObject *args)
char *in; char *in;
if (!PyArg_ParseTuple(args, "z", &in)) if (!PyArg_ParseTuple(args, "z", &in))
return 0; return 0;
return PyBytes_FromString(gettext(in)); return PyString_FromString(gettext(in));
} }
PyDoc_STRVAR(dgettext__doc__, PyDoc_STRVAR(dgettext__doc__,
@ -601,7 +601,7 @@ PyIntl_dgettext(PyObject* self, PyObject *args)
char *domain, *in; char *domain, *in;
if (!PyArg_ParseTuple(args, "zz", &domain, &in)) if (!PyArg_ParseTuple(args, "zz", &domain, &in))
return 0; return 0;
return PyBytes_FromString(dgettext(domain, in)); return PyString_FromString(dgettext(domain, in));
} }
PyDoc_STRVAR(dcgettext__doc__, PyDoc_STRVAR(dcgettext__doc__,
@ -615,7 +615,7 @@ PyIntl_dcgettext(PyObject *self, PyObject *args)
int category; int category;
if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category)) if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
return 0; return 0;
return PyBytes_FromString(dcgettext(domain,msgid,category)); return PyString_FromString(dcgettext(domain,msgid,category));
} }
PyDoc_STRVAR(textdomain__doc__, PyDoc_STRVAR(textdomain__doc__,
@ -633,7 +633,7 @@ PyIntl_textdomain(PyObject* self, PyObject* args)
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
return NULL; return NULL;
} }
return PyBytes_FromString(domain); return PyString_FromString(domain);
} }
PyDoc_STRVAR(bindtextdomain__doc__, PyDoc_STRVAR(bindtextdomain__doc__,
@ -651,7 +651,7 @@ PyIntl_bindtextdomain(PyObject* self,PyObject*args)
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
return NULL; return NULL;
} }
return PyBytes_FromString(dirname); return PyString_FromString(dirname);
} }
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@ -667,7 +667,7 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
return NULL; return NULL;
codeset = bind_textdomain_codeset(domain, codeset); codeset = bind_textdomain_codeset(domain, codeset);
if (codeset) if (codeset)
return PyBytes_FromString(codeset); return PyString_FromString(codeset);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#endif #endif
@ -760,7 +760,7 @@ init_locale(void)
Error = PyErr_NewException("locale.Error", NULL, NULL); Error = PyErr_NewException("locale.Error", NULL, NULL);
PyDict_SetItemString(d, "Error", Error); PyDict_SetItemString(d, "Error", Error);
x = PyBytes_FromString(locale__doc__); x = PyString_FromString(locale__doc__);
PyDict_SetItemString(d, "__doc__", x); PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x); Py_XDECREF(x);

View file

@ -179,8 +179,8 @@ normalizeUserObj(PyObject *obj)
/* built-in function: look up the module name */ /* built-in function: look up the module name */
PyObject *mod = fn->m_module; PyObject *mod = fn->m_module;
char *modname; char *modname;
if (mod && PyBytes_Check(mod)) { if (mod && PyString_Check(mod)) {
modname = PyBytes_AS_STRING(mod); modname = PyString_AS_STRING(mod);
} }
else if (mod && PyModule_Check(mod)) { else if (mod && PyModule_Check(mod)) {
modname = PyModule_GetName(mod); modname = PyModule_GetName(mod);
@ -193,11 +193,11 @@ normalizeUserObj(PyObject *obj)
modname = "__builtin__"; modname = "__builtin__";
} }
if (strcmp(modname, "__builtin__") != 0) if (strcmp(modname, "__builtin__") != 0)
return PyBytes_FromFormat("<%s.%s>", return PyString_FromFormat("<%s.%s>",
modname, modname,
fn->m_ml->ml_name); fn->m_ml->ml_name);
else else
return PyBytes_FromFormat("<%s>", return PyString_FromFormat("<%s>",
fn->m_ml->ml_name); fn->m_ml->ml_name);
} }
else { else {
@ -205,7 +205,7 @@ normalizeUserObj(PyObject *obj)
repr(getattr(type(__self__), __name__)) repr(getattr(type(__self__), __name__))
*/ */
PyObject *self = fn->m_self; PyObject *self = fn->m_self;
PyObject *name = PyBytes_FromString(fn->m_ml->ml_name); PyObject *name = PyString_FromString(fn->m_ml->ml_name);
if (name != NULL) { if (name != NULL) {
PyObject *mo = _PyType_Lookup(Py_TYPE(self), name); PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
Py_XINCREF(mo); Py_XINCREF(mo);
@ -218,7 +218,7 @@ normalizeUserObj(PyObject *obj)
} }
} }
PyErr_Clear(); PyErr_Clear();
return PyBytes_FromFormat("<built-in method %s>", return PyString_FromFormat("<built-in method %s>",
fn->m_ml->ml_name); fn->m_ml->ml_name);
} }
} }

View file

@ -241,12 +241,12 @@ PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
if (!fmt_args) { if (!fmt_args) {
return NULL; return NULL;
} }
template = PyBytes_FromString("%s <- %s ->%s\n"); template = PyString_FromString("%s <- %s ->%s\n");
if (!template) { if (!template) {
Py_DECREF(fmt_args); Py_DECREF(fmt_args);
return NULL; return NULL;
} }
display_str = PyBytes_Format(template, fmt_args); display_str = PyString_Format(template, fmt_args);
Py_DECREF(template); Py_DECREF(template);
Py_DECREF(fmt_args); Py_DECREF(fmt_args);
if (!display_str) { if (!display_str) {

View file

@ -84,8 +84,8 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
Py_INCREF(&PyUnicode_Type); Py_INCREF(&PyUnicode_Type);
self->text_factory = (PyObject*)&PyUnicode_Type; self->text_factory = (PyObject*)&PyUnicode_Type;
if (PyBytes_Check(database) || PyUnicode_Check(database)) { if (PyString_Check(database) || PyUnicode_Check(database)) {
if (PyBytes_Check(database)) { if (PyString_Check(database)) {
database_utf8 = database; database_utf8 = database;
Py_INCREF(database_utf8); Py_INCREF(database_utf8);
} else { } else {
@ -96,7 +96,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
} }
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
rc = sqlite3_open(PyBytes_AsString(database_utf8), &self->db); rc = sqlite3_open(PyString_AsString(database_utf8), &self->db);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_DECREF(database_utf8); Py_DECREF(database_utf8);
@ -111,7 +111,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
if (class_attr) { if (class_attr) {
class_attr_str = PyObject_Str(class_attr); class_attr_str = PyObject_Str(class_attr);
if (class_attr_str) { if (class_attr_str) {
if (strcmp(PyBytes_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) { if (strcmp(PyString_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) {
/* In the APSW Connection object, the first entry after /* In the APSW Connection object, the first entry after
* PyObject_HEAD is the sqlite3* we want to get hold of. * PyObject_HEAD is the sqlite3* we want to get hold of.
* Luckily, this is the same layout as we have in our * Luckily, this is the same layout as we have in our
@ -134,7 +134,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
} }
if (!isolation_level) { if (!isolation_level) {
isolation_level = PyBytes_FromString(""); isolation_level = PyString_FromString("");
if (!isolation_level) { if (!isolation_level) {
return -1; return -1;
} }
@ -499,12 +499,12 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else { } else {
sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
} }
} else if (PyBytes_Check(py_val)) { } else if (PyString_Check(py_val)) {
sqlite3_result_text(context, PyBytes_AsString(py_val), -1, SQLITE_TRANSIENT); sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
} else if (PyUnicode_Check(py_val)) { } else if (PyUnicode_Check(py_val)) {
stringval = PyUnicode_AsUTF8String(py_val); stringval = PyUnicode_AsUTF8String(py_val);
if (stringval) { if (stringval) {
sqlite3_result_text(context, PyBytes_AsString(stringval), -1, SQLITE_TRANSIENT); sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT);
Py_DECREF(stringval); Py_DECREF(stringval);
} }
} else { } else {
@ -963,21 +963,21 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
Py_INCREF(isolation_level); Py_INCREF(isolation_level);
self->isolation_level = isolation_level; self->isolation_level = isolation_level;
begin_statement = PyBytes_FromString("BEGIN "); begin_statement = PyString_FromString("BEGIN ");
if (!begin_statement) { if (!begin_statement) {
return -1; return -1;
} }
PyBytes_Concat(&begin_statement, isolation_level); PyString_Concat(&begin_statement, isolation_level);
if (!begin_statement) { if (!begin_statement) {
return -1; return -1;
} }
self->begin_statement = PyMem_Malloc(PyBytes_Size(begin_statement) + 2); self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2);
if (!self->begin_statement) { if (!self->begin_statement) {
return -1; return -1;
} }
strcpy(self->begin_statement, PyBytes_AsString(begin_statement)); strcpy(self->begin_statement, PyString_AsString(begin_statement));
Py_DECREF(begin_statement); Py_DECREF(begin_statement);
} }
@ -1152,8 +1152,8 @@ pysqlite_collation_callback(
goto finally; goto finally;
} }
string1 = PyBytes_FromStringAndSize((const char*)text1_data, text1_length); string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
string2 = PyBytes_FromStringAndSize((const char*)text2_data, text2_length); string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
if (!string1 || !string2) { if (!string1 || !string2) {
goto finally; /* failed to allocate strings */ goto finally; /* failed to allocate strings */
@ -1259,7 +1259,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally; goto finally;
} }
if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyBytes_Type, &name, &callable)) { if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) {
goto finally; goto finally;
} }
@ -1268,7 +1268,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally; goto finally;
} }
chk = PyBytes_AsString(uppercase_name); chk = PyString_AsString(uppercase_name);
while (*chk) { while (*chk) {
if ((*chk >= '0' && *chk <= '9') if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z') || (*chk >= 'A' && *chk <= 'Z')
@ -1293,7 +1293,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
} }
rc = sqlite3_create_collation(self->db, rc = sqlite3_create_collation(self->db,
PyBytes_AsString(uppercase_name), PyString_AsString(uppercase_name),
SQLITE_UTF8, SQLITE_UTF8,
(callable != Py_None) ? callable : NULL, (callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL); (callable != Py_None) ? pysqlite_collation_callback : NULL);

View file

@ -80,7 +80,7 @@ typedef struct
/* Determines how bytestrings from SQLite are converted to Python objects: /* Determines how bytestrings from SQLite are converted to Python objects:
* - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
* - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created. * - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created.
* - PyBytes_Type: PyStrings are created as-is. * - PyString_Type: PyStrings are created as-is.
* - Any custom callable: Any object returned from the callable called with the bytestring * - Any custom callable: Any object returned from the callable called with the bytestring
* as single parameter. * as single parameter.
*/ */

View file

@ -178,7 +178,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
if (*pos == '[') { if (*pos == '[') {
type_start = pos + 1; type_start = pos + 1;
} else if (*pos == ']' && type_start != (const char*)-1) { } else if (*pos == ']' && type_start != (const char*)-1) {
key = PyBytes_FromStringAndSize(type_start, pos - type_start); key = PyString_FromStringAndSize(type_start, pos - type_start);
if (!key) { if (!key) {
/* creating a string failed, but it is too complicated /* creating a string failed, but it is too complicated
* to propagate the error here, we just assume there is * to propagate the error here, we just assume there is
@ -203,7 +203,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
* 'NUMBER(10)' to be treated as 'NUMBER', for example. * 'NUMBER(10)' to be treated as 'NUMBER', for example.
* In other words, it will work as people expect it to work.*/ * In other words, it will work as people expect it to work.*/
if (*pos == ' ' || *pos == '(' || *pos == 0) { if (*pos == ' ' || *pos == '(' || *pos == 0) {
py_decltype = PyBytes_FromStringAndSize(decltype, pos - decltype); py_decltype = PyString_FromStringAndSize(decltype, pos - decltype);
if (!py_decltype) { if (!py_decltype) {
return -1; return -1;
} }
@ -248,7 +248,7 @@ PyObject* _pysqlite_build_column_name(const char* colname)
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) { if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
pos--; pos--;
} }
return PyBytes_FromStringAndSize(colname, pos - colname); return PyString_FromStringAndSize(colname, pos - colname);
} }
} }
} }
@ -273,7 +273,7 @@ PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
} }
if (is_ascii) { if (is_ascii) {
return PyBytes_FromString(val_str); return PyString_FromString(val_str);
} else { } else {
return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL); return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
} }
@ -327,7 +327,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
Py_INCREF(Py_None); Py_INCREF(Py_None);
converted = Py_None; converted = Py_None;
} else { } else {
item = PyBytes_FromStringAndSize(val_str, nbytes); item = PyString_FromStringAndSize(val_str, nbytes);
if (!item) { if (!item) {
return NULL; return NULL;
} }
@ -370,8 +370,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
colname , val_str); colname , val_str);
PyErr_SetString(pysqlite_OperationalError, buf); PyErr_SetString(pysqlite_OperationalError, buf);
} }
} else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { } else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
converted = PyBytes_FromString(val_str); converted = PyString_FromString(val_str);
} else { } else {
converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str); converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str);
} }
@ -442,7 +442,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
return NULL; return NULL;
} }
if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) { if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL; return NULL;
} }
@ -464,7 +464,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
return NULL; return NULL;
} }
if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) { if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode"); PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL; return NULL;
} }
@ -499,15 +499,15 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
rc = pysqlite_statement_reset(self->statement); rc = pysqlite_statement_reset(self->statement);
} }
if (PyBytes_Check(operation)) { if (PyString_Check(operation)) {
operation_cstr = PyBytes_AsString(operation); operation_cstr = PyString_AsString(operation);
} else { } else {
operation_bytestr = PyUnicode_AsUTF8String(operation); operation_bytestr = PyUnicode_AsUTF8String(operation);
if (!operation_bytestr) { if (!operation_bytestr) {
goto error; goto error;
} }
operation_cstr = PyBytes_AsString(operation_bytestr); operation_cstr = PyString_AsString(operation_bytestr);
} }
/* reset description and rowcount */ /* reset description and rowcount */
@ -764,15 +764,15 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
return NULL; return NULL;
} }
if (PyBytes_Check(script_obj)) { if (PyString_Check(script_obj)) {
script_cstr = PyBytes_AsString(script_obj); script_cstr = PyString_AsString(script_obj);
} else if (PyUnicode_Check(script_obj)) { } else if (PyUnicode_Check(script_obj)) {
script_str = PyUnicode_AsUTF8String(script_obj); script_str = PyUnicode_AsUTF8String(script_obj);
if (!script_str) { if (!script_str) {
return NULL; return NULL;
} }
script_cstr = PyBytes_AsString(script_str); script_cstr = PyString_AsString(script_str);
} else { } else {
PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string."); PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string.");
return NULL; return NULL;

View file

@ -137,7 +137,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
/* a basic type is adapted; there's a performance optimization if that's not the case /* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */ * (99 % of all usages) */
if (type == &PyInt_Type || type == &PyLong_Type || type == &PyFloat_Type if (type == &PyInt_Type || type == &PyLong_Type || type == &PyFloat_Type
|| type == &PyBytes_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) { || type == &PyString_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) {
pysqlite_BaseTypeAdapted = 1; pysqlite_BaseTypeAdapted = 1;
} }
@ -367,13 +367,13 @@ PyMODINIT_FUNC init_sqlite3(void)
Py_DECREF(tmp_obj); Py_DECREF(tmp_obj);
} }
if (!(tmp_obj = PyBytes_FromString(PYSQLITE_VERSION))) { if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
goto error; goto error;
} }
PyDict_SetItemString(dict, "version", tmp_obj); PyDict_SetItemString(dict, "version", tmp_obj);
Py_DECREF(tmp_obj); Py_DECREF(tmp_obj);
if (!(tmp_obj = PyBytes_FromString(sqlite3_libversion()))) { if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
goto error; goto error;
} }
PyDict_SetItemString(dict, "sqlite_version", tmp_obj); PyDict_SetItemString(dict, "sqlite_version", tmp_obj);

View file

@ -86,13 +86,13 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
item = PyTuple_GetItem(self->data, _idx); item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item); Py_XINCREF(item);
return item; return item;
} else if (PyBytes_Check(idx)) { } else if (PyString_Check(idx)) {
key = PyBytes_AsString(idx); key = PyString_AsString(idx);
nitems = PyTuple_Size(self->description); nitems = PyTuple_Size(self->description);
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
compare_key = PyBytes_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)); compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
if (!compare_key) { if (!compare_key) {
return NULL; return NULL;
} }

View file

@ -60,7 +60,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->st = NULL; self->st = NULL;
self->in_use = 0; self->in_use = 0;
if (PyBytes_Check(sql)) { if (PyString_Check(sql)) {
sql_str = sql; sql_str = sql;
Py_INCREF(sql_str); Py_INCREF(sql_str);
} else if (PyUnicode_Check(sql)) { } else if (PyUnicode_Check(sql)) {
@ -77,7 +77,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->in_weakreflist = NULL; self->in_weakreflist = NULL;
self->sql = sql_str; self->sql = sql_str;
sql_cstr = PyBytes_AsString(sql_str); sql_cstr = PyString_AsString(sql_str);
rc = sqlite3_prepare(connection->db, rc = sqlite3_prepare(connection->db,
sql_cstr, sql_cstr,
@ -119,7 +119,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
paramtype = TYPE_LONG; paramtype = TYPE_LONG;
} else if (PyFloat_CheckExact(parameter)) { } else if (PyFloat_CheckExact(parameter)) {
paramtype = TYPE_FLOAT; paramtype = TYPE_FLOAT;
} else if (PyBytes_CheckExact(parameter)) { } else if (PyString_CheckExact(parameter)) {
paramtype = TYPE_STRING; paramtype = TYPE_STRING;
} else if (PyUnicode_CheckExact(parameter)) { } else if (PyUnicode_CheckExact(parameter)) {
paramtype = TYPE_UNICODE; paramtype = TYPE_UNICODE;
@ -131,7 +131,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
paramtype = TYPE_LONG; paramtype = TYPE_LONG;
} else if (PyFloat_Check(parameter)) { } else if (PyFloat_Check(parameter)) {
paramtype = TYPE_FLOAT; paramtype = TYPE_FLOAT;
} else if (PyBytes_Check(parameter)) { } else if (PyString_Check(parameter)) {
paramtype = TYPE_STRING; paramtype = TYPE_STRING;
} else if (PyUnicode_Check(parameter)) { } else if (PyUnicode_Check(parameter)) {
paramtype = TYPE_UNICODE; paramtype = TYPE_UNICODE;
@ -140,7 +140,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
} }
if (paramtype == TYPE_STRING && !allow_8bit_chars) { if (paramtype == TYPE_STRING && !allow_8bit_chars) {
string = PyBytes_AS_STRING(parameter); string = PyString_AS_STRING(parameter);
for (c = string; *c != 0; c++) { for (c = string; *c != 0; c++) {
if (*c & 0x80) { if (*c & 0x80) {
PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings."); PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
@ -164,12 +164,12 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
break; break;
case TYPE_STRING: case TYPE_STRING:
string = PyBytes_AS_STRING(parameter); string = PyString_AS_STRING(parameter);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
break; break;
case TYPE_UNICODE: case TYPE_UNICODE:
stringval = PyUnicode_AsUTF8String(parameter); stringval = PyUnicode_AsUTF8String(parameter);
string = PyBytes_AsString(stringval); string = PyString_AsString(stringval);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
Py_DECREF(stringval); Py_DECREF(stringval);
break; break;
@ -197,7 +197,7 @@ static int _need_adapt(PyObject* obj)
} }
if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj) if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
|| PyFloat_CheckExact(obj) || PyBytes_CheckExact(obj) || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
|| PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) { || PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
return 0; return 0;
} else { } else {
@ -326,7 +326,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
char* sql_cstr; char* sql_cstr;
sqlite3_stmt* new_st; sqlite3_stmt* new_st;
sql_cstr = PyBytes_AsString(self->sql); sql_cstr = PyString_AsString(self->sql);
rc = sqlite3_prepare(self->db, rc = sqlite3_prepare(self->db,
sql_cstr, sql_cstr,

View file

@ -1715,7 +1715,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
size = PyObject_Length(string); size = PyObject_Length(string);
#endif #endif
if (PyBytes_Check(string) || bytes == size) if (PyString_Check(string) || bytes == size)
charsize = 1; charsize = 1;
#if defined(HAVE_UNICODE) #if defined(HAVE_UNICODE)
else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE))) else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE)))
@ -1949,7 +1949,7 @@ call(char* module, char* function, PyObject* args)
if (!args) if (!args)
return NULL; return NULL;
name = PyBytes_FromString(module); name = PyString_FromString(module);
if (!name) if (!name)
return NULL; return NULL;
mod = PyImport_Import(name); mod = PyImport_Import(name);
@ -3416,7 +3416,7 @@ PyMODINIT_FUNC init_sre(void)
Py_DECREF(x); Py_DECREF(x);
} }
x = PyBytes_FromString(copyright); x = PyString_FromString(copyright);
if (x) { if (x) {
PyDict_SetItemString(d, "copyright", x); PyDict_SetItemString(d, "copyright", x);
Py_DECREF(x); Py_DECREF(x);

View file

@ -491,13 +491,13 @@ PyDoc_STRVAR(ssl_doc,
static PyObject * static PyObject *
PySSL_server(PySSLObject *self) PySSL_server(PySSLObject *self)
{ {
return PyBytes_FromString(self->server); return PyString_FromString(self->server);
} }
static PyObject * static PyObject *
PySSL_issuer(PySSLObject *self) PySSL_issuer(PySSLObject *self)
{ {
return PyBytes_FromString(self->issuer); return PyString_FromString(self->issuer);
} }
static PyObject * static PyObject *
@ -515,7 +515,7 @@ _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
_setSSLError(NULL, 0, __FILE__, __LINE__); _setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail; goto fail;
} }
name_obj = PyBytes_FromStringAndSize(namebuf, buflen); name_obj = PyString_FromStringAndSize(namebuf, buflen);
if (name_obj == NULL) if (name_obj == NULL)
goto fail; goto fail;
@ -603,8 +603,8 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
/* /*
fprintf(stderr, "RDN level %d, attribute %s: %s\n", fprintf(stderr, "RDN level %d, attribute %s: %s\n",
entry->set, entry->set,
PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 0)), PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 1))); PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
*/ */
if (attr == NULL) if (attr == NULL)
goto fail1; goto fail1;
@ -711,7 +711,7 @@ _get_peer_alt_names (X509 *certificate) {
goto fail; goto fail;
} }
v = PyBytes_FromString("DirName"); v = PyString_FromString("DirName");
if (v == NULL) { if (v == NULL) {
Py_DECREF(t); Py_DECREF(t);
goto fail; goto fail;
@ -742,13 +742,13 @@ _get_peer_alt_names (X509 *certificate) {
t = PyTuple_New(2); t = PyTuple_New(2);
if (t == NULL) if (t == NULL)
goto fail; goto fail;
v = PyBytes_FromStringAndSize(buf, (vptr - buf)); v = PyString_FromStringAndSize(buf, (vptr - buf));
if (v == NULL) { if (v == NULL) {
Py_DECREF(t); Py_DECREF(t);
goto fail; goto fail;
} }
PyTuple_SET_ITEM(t, 0, v); PyTuple_SET_ITEM(t, 0, v);
v = PyBytes_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1))); v = PyString_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1)));
if (v == NULL) { if (v == NULL) {
Py_DECREF(t); Py_DECREF(t);
goto fail; goto fail;
@ -849,7 +849,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__); _setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1; goto fail1;
} }
sn_obj = PyBytes_FromStringAndSize(buf, len); sn_obj = PyString_FromStringAndSize(buf, len);
if (sn_obj == NULL) if (sn_obj == NULL)
goto fail1; goto fail1;
if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) { if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) {
@ -866,7 +866,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__); _setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1; goto fail1;
} }
pnotBefore = PyBytes_FromStringAndSize(buf, len); pnotBefore = PyString_FromStringAndSize(buf, len);
if (pnotBefore == NULL) if (pnotBefore == NULL)
goto fail1; goto fail1;
if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) { if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) {
@ -884,7 +884,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__); _setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1; goto fail1;
} }
pnotAfter = PyBytes_FromStringAndSize(buf, len); pnotAfter = PyString_FromStringAndSize(buf, len);
if (pnotAfter == NULL) if (pnotAfter == NULL)
goto fail1; goto fail1;
if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) { if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) {
@ -981,7 +981,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
PySSL_SetError(self, len, __FILE__, __LINE__); PySSL_SetError(self, len, __FILE__, __LINE__);
return NULL; return NULL;
} }
retval = PyBytes_FromStringAndSize((const char *) bytes_buf, len); retval = PyString_FromStringAndSize((const char *) bytes_buf, len);
OPENSSL_free(bytes_buf); OPENSSL_free(bytes_buf);
return retval; return retval;
@ -1028,7 +1028,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
if (cipher_name == NULL) { if (cipher_name == NULL) {
PyTuple_SET_ITEM(retval, 0, Py_None); PyTuple_SET_ITEM(retval, 0, Py_None);
} else { } else {
v = PyBytes_FromString(cipher_name); v = PyString_FromString(cipher_name);
if (v == NULL) if (v == NULL)
goto fail0; goto fail0;
PyTuple_SET_ITEM(retval, 0, v); PyTuple_SET_ITEM(retval, 0, v);
@ -1037,7 +1037,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
if (cipher_protocol == NULL) { if (cipher_protocol == NULL) {
PyTuple_SET_ITEM(retval, 1, Py_None); PyTuple_SET_ITEM(retval, 1, Py_None);
} else { } else {
v = PyBytes_FromString(cipher_protocol); v = PyString_FromString(cipher_protocol);
if (v == NULL) if (v == NULL)
goto fail0; goto fail0;
PyTuple_SET_ITEM(retval, 1, v); PyTuple_SET_ITEM(retval, 1, v);
@ -1211,7 +1211,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:read", &len)) if (!PyArg_ParseTuple(args, "|i:read", &len))
return NULL; return NULL;
if (!(buf = PyBytes_FromStringAndSize((char *) 0, len))) if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
return NULL; return NULL;
/* first check if there are bytes ready to be read */ /* first check if there are bytes ready to be read */
@ -1233,14 +1233,14 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return NULL; return NULL;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
/* should contain a zero-length string */ /* should contain a zero-length string */
_PyBytes_Resize(&buf, 0); _PyString_Resize(&buf, 0);
return buf; return buf;
} }
} }
do { do {
err = 0; err = 0;
PySSL_BEGIN_ALLOW_THREADS PySSL_BEGIN_ALLOW_THREADS
count = SSL_read(self->ssl, PyBytes_AsString(buf), len); count = SSL_read(self->ssl, PyString_AsString(buf), len);
err = SSL_get_error(self->ssl, count); err = SSL_get_error(self->ssl, count);
PySSL_END_ALLOW_THREADS PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) { if(PyErr_CheckSignals()) {
@ -1257,7 +1257,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
(SSL_get_shutdown(self->ssl) == (SSL_get_shutdown(self->ssl) ==
SSL_RECEIVED_SHUTDOWN)) SSL_RECEIVED_SHUTDOWN))
{ {
_PyBytes_Resize(&buf, 0); _PyString_Resize(&buf, 0);
return buf; return buf;
} else { } else {
sockstate = SOCKET_OPERATION_OK; sockstate = SOCKET_OPERATION_OK;
@ -1276,7 +1276,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return PySSL_SetError(self, count, __FILE__, __LINE__); return PySSL_SetError(self, count, __FILE__, __LINE__);
} }
if (count != len) if (count != len)
_PyBytes_Resize(&buf, count); _PyString_Resize(&buf, count);
return buf; return buf;
} }
@ -1362,11 +1362,11 @@ PySSL_RAND_egd(PyObject *self, PyObject *arg)
{ {
int bytes; int bytes;
if (!PyBytes_Check(arg)) if (!PyString_Check(arg))
return PyErr_Format(PyExc_TypeError, return PyErr_Format(PyExc_TypeError,
"RAND_egd() expected string, found %s", "RAND_egd() expected string, found %s",
Py_TYPE(arg)->tp_name); Py_TYPE(arg)->tp_name);
bytes = RAND_egd(PyBytes_AS_STRING(arg)); bytes = RAND_egd(PyString_AS_STRING(arg));
if (bytes == -1) { if (bytes == -1) {
PyErr_SetString(PySSLErrorObject, PyErr_SetString(PySSLErrorObject,
"EGD connection failed or EGD did not return " "EGD connection failed or EGD did not return "

View file

@ -413,7 +413,7 @@ _range_error(const formatdef *f, int is_unsigned)
if (msg == NULL) if (msg == NULL)
return -1; return -1;
rval = PyErr_WarnEx(PyExc_DeprecationWarning, rval = PyErr_WarnEx(PyExc_DeprecationWarning,
PyBytes_AS_STRING(msg), 2); PyString_AS_STRING(msg), 2);
Py_DECREF(msg); Py_DECREF(msg);
if (rval == 0) if (rval == 0)
return 0; return 0;
@ -446,7 +446,7 @@ _range_error(const formatdef *f, int is_unsigned)
static PyObject * static PyObject *
nu_char(const char *p, const formatdef *f) nu_char(const char *p, const formatdef *f)
{ {
return PyBytes_FromStringAndSize(p, 1); return PyString_FromStringAndSize(p, 1);
} }
static PyObject * static PyObject *
@ -610,12 +610,12 @@ np_ubyte(char *p, PyObject *v, const formatdef *f)
static int static int
np_char(char *p, PyObject *v, const formatdef *f) np_char(char *p, PyObject *v, const formatdef *f)
{ {
if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) { if (!PyString_Check(v) || PyString_Size(v) != 1) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"char format require string of length 1"); "char format require string of length 1");
return -1; return -1;
} }
*p = *PyBytes_AsString(v); *p = *PyString_AsString(v);
return 0; return 0;
} }
@ -1335,7 +1335,7 @@ prepare_s(PyStructObject *self)
char c; char c;
Py_ssize_t size, len, num, itemsize, x; Py_ssize_t size, len, num, itemsize, x;
fmt = PyBytes_AS_STRING(self->s_format); fmt = PyString_AS_STRING(self->s_format);
f = whichtable((char **)&fmt); f = whichtable((char **)&fmt);
@ -1503,12 +1503,12 @@ s_unpack_internal(PyStructObject *soself, char *startfrom) {
const formatdef *e = code->fmtdef; const formatdef *e = code->fmtdef;
const char *res = startfrom + code->offset; const char *res = startfrom + code->offset;
if (e->format == 's') { if (e->format == 's') {
v = PyBytes_FromStringAndSize(res, code->size); v = PyString_FromStringAndSize(res, code->size);
} else if (e->format == 'p') { } else if (e->format == 'p') {
Py_ssize_t n = *(unsigned char*)res; Py_ssize_t n = *(unsigned char*)res;
if (n >= code->size) if (n >= code->size)
n = code->size - 1; n = code->size - 1;
v = PyBytes_FromStringAndSize(res + 1, n); v = PyString_FromStringAndSize(res + 1, n);
} else { } else {
v = e->unpack(res, e); v = e->unpack(res, e);
} }
@ -1542,9 +1542,9 @@ s_unpack(PyObject *self, PyObject *inputstr)
assert(soself->s_codes != NULL); assert(soself->s_codes != NULL);
if (inputstr == NULL) if (inputstr == NULL)
goto fail; goto fail;
if (PyBytes_Check(inputstr) && if (PyString_Check(inputstr) &&
PyBytes_GET_SIZE(inputstr) == soself->s_size) { PyString_GET_SIZE(inputstr) == soself->s_size) {
return s_unpack_internal(soself, PyBytes_AS_STRING(inputstr)); return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
} }
args = PyTuple_Pack(1, inputstr); args = PyTuple_Pack(1, inputstr);
if (args == NULL) if (args == NULL)
@ -1637,27 +1637,27 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
const formatdef *e = code->fmtdef; const formatdef *e = code->fmtdef;
char *res = buf + code->offset; char *res = buf + code->offset;
if (e->format == 's') { if (e->format == 's') {
if (!PyBytes_Check(v)) { if (!PyString_Check(v)) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"argument for 's' must be a string"); "argument for 's' must be a string");
return -1; return -1;
} }
n = PyBytes_GET_SIZE(v); n = PyString_GET_SIZE(v);
if (n > code->size) if (n > code->size)
n = code->size; n = code->size;
if (n > 0) if (n > 0)
memcpy(res, PyBytes_AS_STRING(v), n); memcpy(res, PyString_AS_STRING(v), n);
} else if (e->format == 'p') { } else if (e->format == 'p') {
if (!PyBytes_Check(v)) { if (!PyString_Check(v)) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"argument for 'p' must be a string"); "argument for 'p' must be a string");
return -1; return -1;
} }
n = PyBytes_GET_SIZE(v); n = PyString_GET_SIZE(v);
if (n > (code->size - 1)) if (n > (code->size - 1))
n = code->size - 1; n = code->size - 1;
if (n > 0) if (n > 0)
memcpy(res + 1, PyBytes_AS_STRING(v), n); memcpy(res + 1, PyString_AS_STRING(v), n);
if (n > 255) if (n > 255)
n = 255; n = 255;
*res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char); *res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char);
@ -1700,12 +1700,12 @@ s_pack(PyObject *self, PyObject *args)
} }
/* Allocate a new string */ /* Allocate a new string */
result = PyBytes_FromStringAndSize((char *)NULL, soself->s_size); result = PyString_FromStringAndSize((char *)NULL, soself->s_size);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
/* Call the guts */ /* Call the guts */
if ( s_pack_internal(soself, args, 0, PyBytes_AS_STRING(result)) != 0 ) { if ( s_pack_internal(soself, args, 0, PyString_AS_STRING(result)) != 0 ) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
@ -2061,7 +2061,7 @@ init_struct(void)
{ {
PyObject *ver, *m; PyObject *ver, *m;
ver = PyBytes_FromString("0.2"); ver = PyString_FromString("0.2");
if (ver == NULL) if (ver == NULL)
return; return;

View file

@ -691,7 +691,7 @@ test_thread_state(PyObject *self, PyObject *args)
} }
#endif #endif
/* Some tests of PyBytes_FromFormat(). This needs more tests. */ /* Some tests of PyString_FromFormat(). This needs more tests. */
static PyObject * static PyObject *
test_string_from_format(PyObject *self, PyObject *args) test_string_from_format(PyObject *self, PyObject *args)
{ {
@ -699,10 +699,10 @@ test_string_from_format(PyObject *self, PyObject *args)
char *msg; char *msg;
#define CHECK_1_FORMAT(FORMAT, TYPE) \ #define CHECK_1_FORMAT(FORMAT, TYPE) \
result = PyBytes_FromFormat(FORMAT, (TYPE)1); \ result = PyString_FromFormat(FORMAT, (TYPE)1); \
if (result == NULL) \ if (result == NULL) \
return NULL; \ return NULL; \
if (strcmp(PyBytes_AsString(result), "1")) { \ if (strcmp(PyString_AsString(result), "1")) { \
msg = FORMAT " failed at 1"; \ msg = FORMAT " failed at 1"; \
goto Fail; \ goto Fail; \
} \ } \

View file

@ -335,8 +335,8 @@ WaitForMainloop(TkappObject* self)
static char * static char *
AsString(PyObject *value, PyObject *tmp) AsString(PyObject *value, PyObject *tmp)
{ {
if (PyBytes_Check(value)) if (PyString_Check(value))
return PyBytes_AsString(value); return PyString_AsString(value);
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) { else if (PyUnicode_Check(value)) {
PyObject *v = PyUnicode_AsUTF8String(value); PyObject *v = PyUnicode_AsUTF8String(value);
@ -347,7 +347,7 @@ AsString(PyObject *value, PyObject *tmp)
return NULL; return NULL;
} }
Py_DECREF(v); Py_DECREF(v);
return PyBytes_AsString(v); return PyString_AsString(v);
} }
#endif #endif
else { else {
@ -359,7 +359,7 @@ AsString(PyObject *value, PyObject *tmp)
return NULL; return NULL;
} }
Py_DECREF(v); Py_DECREF(v);
return PyBytes_AsString(v); return PyString_AsString(v);
} }
} }
@ -462,13 +462,13 @@ Split(char *list)
* Could be a quoted string containing funnies, e.g. {"}. * Could be a quoted string containing funnies, e.g. {"}.
* Return the string itself. * Return the string itself.
*/ */
return PyBytes_FromString(list); return PyString_FromString(list);
} }
if (argc == 0) if (argc == 0)
v = PyBytes_FromString(""); v = PyString_FromString("");
else if (argc == 1) else if (argc == 1)
v = PyBytes_FromString(argv[0]); v = PyString_FromString(argv[0]);
else if ((v = PyTuple_New(argc)) != NULL) { else if ((v = PyTuple_New(argc)) != NULL) {
int i; int i;
PyObject *w; PyObject *w;
@ -530,10 +530,10 @@ SplitObj(PyObject *arg)
return result; return result;
/* Fall through, returning arg. */ /* Fall through, returning arg. */
} }
else if (PyBytes_Check(arg)) { else if (PyString_Check(arg)) {
int argc; int argc;
char **argv; char **argv;
char *list = PyBytes_AsString(arg); char *list = PyString_AsString(arg);
if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
Py_INCREF(arg); Py_INCREF(arg);
@ -541,7 +541,7 @@ SplitObj(PyObject *arg)
} }
Tcl_Free(FREECAST argv); Tcl_Free(FREECAST argv);
if (argc > 1) if (argc > 1)
return Split(PyBytes_AsString(arg)); return Split(PyString_AsString(arg));
/* Fall through, returning arg. */ /* Fall through, returning arg. */
} }
Py_INCREF(arg); Py_INCREF(arg);
@ -747,12 +747,12 @@ PyTclObject_dealloc(PyTclObject *self)
static PyObject * static PyObject *
PyTclObject_str(PyTclObject *self) PyTclObject_str(PyTclObject *self)
{ {
if (self->string && PyBytes_Check(self->string)) { if (self->string && PyString_Check(self->string)) {
Py_INCREF(self->string); Py_INCREF(self->string);
return self->string; return self->string;
} }
/* XXX Could cache value if it is an ASCII string. */ /* XXX Could cache value if it is an ASCII string. */
return PyBytes_FromString(Tcl_GetString(self->value)); return PyString_FromString(Tcl_GetString(self->value));
} }
static char* static char*
@ -778,16 +778,16 @@ PyTclObject_string(PyTclObject *self, void *ignored)
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
if (i == len) if (i == len)
/* It is an ASCII string. */ /* It is an ASCII string. */
self->string = PyBytes_FromStringAndSize(s, len); self->string = PyString_FromStringAndSize(s, len);
else { else {
self->string = PyUnicode_DecodeUTF8(s, len, "strict"); self->string = PyUnicode_DecodeUTF8(s, len, "strict");
if (!self->string) { if (!self->string) {
PyErr_Clear(); PyErr_Clear();
self->string = PyBytes_FromStringAndSize(s, len); self->string = PyString_FromStringAndSize(s, len);
} }
} }
#else #else
self->string = PyBytes_FromStringAndSize(s, len); self->string = PyString_FromStringAndSize(s, len);
#endif #endif
if (!self->string) if (!self->string)
return NULL; return NULL;
@ -820,7 +820,7 @@ PyTclObject_repr(PyTclObject *self)
char buf[50]; char buf[50];
PyOS_snprintf(buf, 50, "<%s object at %p>", PyOS_snprintf(buf, 50, "<%s object at %p>",
self->value->typePtr->name, self->value); self->value->typePtr->name, self->value);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int static int
@ -839,7 +839,7 @@ PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type");
static PyObject* static PyObject*
get_typename(PyTclObject* obj, void* ignored) get_typename(PyTclObject* obj, void* ignored)
{ {
return PyBytes_FromString(obj->value->typePtr->name); return PyString_FromString(obj->value->typePtr->name);
} }
@ -908,9 +908,9 @@ AsObj(PyObject *value)
{ {
Tcl_Obj *result; Tcl_Obj *result;
if (PyBytes_Check(value)) if (PyString_Check(value))
return Tcl_NewStringObj(PyBytes_AS_STRING(value), return Tcl_NewStringObj(PyString_AS_STRING(value),
PyBytes_GET_SIZE(value)); PyString_GET_SIZE(value));
else if (PyBool_Check(value)) else if (PyBool_Check(value))
return Tcl_NewBooleanObj(PyObject_IsTrue(value)); return Tcl_NewBooleanObj(PyObject_IsTrue(value));
else if (PyInt_Check(value)) else if (PyInt_Check(value))
@ -999,17 +999,17 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
} }
if (i == value->length) if (i == value->length)
result = PyBytes_FromStringAndSize(s, len); result = PyString_FromStringAndSize(s, len);
else { else {
/* Convert UTF-8 to Unicode string */ /* Convert UTF-8 to Unicode string */
result = PyUnicode_DecodeUTF8(s, len, "strict"); result = PyUnicode_DecodeUTF8(s, len, "strict");
if (result == NULL) { if (result == NULL) {
PyErr_Clear(); PyErr_Clear();
result = PyBytes_FromStringAndSize(s, len); result = PyString_FromStringAndSize(s, len);
} }
} }
#else #else
result = PyBytes_FromStringAndSize(value->bytes, value->length); result = PyString_FromStringAndSize(value->bytes, value->length);
#endif #endif
return result; return result;
} }
@ -1023,7 +1023,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
if (value->typePtr == app->ByteArrayType) { if (value->typePtr == app->ByteArrayType) {
int size; int size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
return PyBytes_FromStringAndSize(data, size); return PyString_FromStringAndSize(data, size);
} }
if (value->typePtr == app->DoubleType) { if (value->typePtr == app->DoubleType) {
@ -1092,7 +1092,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
int size; int size;
char *c; char *c;
c = Tcl_GetStringFromObj(value, &size); c = Tcl_GetStringFromObj(value, &size);
return PyBytes_FromStringAndSize(c, size); return PyString_FromStringAndSize(c, size);
#endif #endif
} }
@ -1204,19 +1204,19 @@ Tkapp_CallResult(TkappObject *self)
} }
if (*p == '\0') if (*p == '\0')
res = PyBytes_FromStringAndSize(s, (int)(p-s)); res = PyString_FromStringAndSize(s, (int)(p-s));
else { else {
/* Convert UTF-8 to Unicode string */ /* Convert UTF-8 to Unicode string */
p = strchr(p, '\0'); p = strchr(p, '\0');
res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict"); res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
if (res == NULL) { if (res == NULL) {
PyErr_Clear(); PyErr_Clear();
res = PyBytes_FromStringAndSize(s, (int)(p-s)); res = PyString_FromStringAndSize(s, (int)(p-s));
} }
} }
#else #else
p = strchr(p, '\0'); p = strchr(p, '\0');
res = PyBytes_FromStringAndSize(s, (int)(p-s)); res = PyString_FromStringAndSize(s, (int)(p-s));
#endif #endif
} }
return res; return res;
@ -1370,7 +1370,7 @@ Tkapp_GlobalCall(PyObject *self, PyObject *args)
if (err == TCL_ERROR) if (err == TCL_ERROR)
res = Tkinter_Error(self); res = Tkinter_Error(self);
else else
res = PyBytes_FromString(Tkapp_Result(self)); res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
ckfree(cmd); ckfree(cmd);
} }
@ -1396,7 +1396,7 @@ Tkapp_Eval(PyObject *self, PyObject *args)
if (err == TCL_ERROR) if (err == TCL_ERROR)
res = Tkinter_Error(self); res = Tkinter_Error(self);
else else
res = PyBytes_FromString(Tkapp_Result(self)); res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
return res; return res;
} }
@ -1419,7 +1419,7 @@ Tkapp_GlobalEval(PyObject *self, PyObject *args)
if (err == TCL_ERROR) if (err == TCL_ERROR)
res = Tkinter_Error(self); res = Tkinter_Error(self);
else else
res = PyBytes_FromString(Tkapp_Result(self)); res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
return res; return res;
} }
@ -1443,7 +1443,7 @@ Tkapp_EvalFile(PyObject *self, PyObject *args)
res = Tkinter_Error(self); res = Tkinter_Error(self);
else else
res = PyBytes_FromString(Tkapp_Result(self)); res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
return res; return res;
} }
@ -1466,7 +1466,7 @@ Tkapp_Record(PyObject *self, PyObject *args)
if (err == TCL_ERROR) if (err == TCL_ERROR)
res = Tkinter_Error(self); res = Tkinter_Error(self);
else else
res = PyBytes_FromString(Tkapp_Result(self)); res = PyString_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
return res; return res;
} }
@ -1511,8 +1511,8 @@ static int
varname_converter(PyObject *in, void *_out) varname_converter(PyObject *in, void *_out)
{ {
char **out = (char**)_out; char **out = (char**)_out;
if (PyBytes_Check(in)) { if (PyString_Check(in)) {
*out = PyBytes_AsString(in); *out = PyString_AsString(in);
return 1; return 1;
} }
if (PyTclObject_Check(in)) { if (PyTclObject_Check(in)) {
@ -1676,7 +1676,7 @@ GetVar(PyObject *self, PyObject *args, int flags)
res = FromObj(self, tres); res = FromObj(self, tres);
} }
else { else {
res = PyBytes_FromString(Tcl_GetString(tres)); res = PyString_FromString(Tcl_GetString(tres));
} }
} }
LEAVE_OVERLAP_TCL LEAVE_OVERLAP_TCL
@ -1920,7 +1920,7 @@ Tkapp_SplitList(PyObject *self, PyObject *args)
goto finally; goto finally;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
PyObject *s = PyBytes_FromString(argv[i]); PyObject *s = PyString_FromString(argv[i]);
if (!s || PyTuple_SetItem(v, i, s)) { if (!s || PyTuple_SetItem(v, i, s)) {
Py_DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
@ -1961,7 +1961,7 @@ Tkapp_Merge(PyObject *self, PyObject *args)
PyObject *res = NULL; PyObject *res = NULL;
if (s) { if (s) {
res = PyBytes_FromString(s); res = PyString_FromString(s);
ckfree(s); ckfree(s);
} }
@ -2011,7 +2011,7 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
return PythonCmd_Error(interp); return PythonCmd_Error(interp);
for (i = 0; i < (argc - 1); i++) { for (i = 0; i < (argc - 1); i++) {
PyObject *s = PyBytes_FromString(argv[i + 1]); PyObject *s = PyString_FromString(argv[i + 1]);
if (!s || PyTuple_SetItem(arg, i, s)) { if (!s || PyTuple_SetItem(arg, i, s)) {
Py_DECREF(arg); Py_DECREF(arg);
return PythonCmd_Error(interp); return PythonCmd_Error(interp);
@ -2406,7 +2406,7 @@ Tktt_Repr(PyObject *self)
PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v, PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
v->func == NULL ? ", handler deleted" : ""); v->func == NULL ? ", handler deleted" : "");
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static PyObject * static PyObject *
@ -3087,7 +3087,7 @@ ins_long(PyObject *d, char *name, long val)
static void static void
ins_string(PyObject *d, char *name, char *val) ins_string(PyObject *d, char *name, char *val)
{ {
PyObject *v = PyBytes_FromString(val); PyObject *v = PyString_FromString(val);
if (v) { if (v) {
PyDict_SetItemString(d, name, v); PyDict_SetItemString(d, name, v);
Py_DECREF(v); Py_DECREF(v);

View file

@ -84,7 +84,7 @@ param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString((char *) value.ptr); return PyString_FromString((char *) value.ptr);
default: default:
PyErr_SetString(ErrorObject, "unknown element type"); PyErr_SetString(ErrorObject, "unknown element type");
return NULL; return NULL;
@ -149,12 +149,12 @@ python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
PyErr_SetString(ErrorObject, "unknown element type"); PyErr_SetString(ErrorObject, "unknown element type");
return -1; return -1;
} }
if (!PyBytes_Check(value)) { if (!PyString_Check(value)) {
PyErr_BadArgument(); PyErr_BadArgument();
return -1; return -1;
} }
param->value.ptr = PyBytes_AS_STRING(value); param->value.ptr = PyString_AS_STRING(value);
param->sizeIn = PyBytes_GET_SIZE(value)+1; /*account for NUL*/ param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
break; break;
case AL_SET_VAL: case AL_SET_VAL:
case AL_VECTOR_VAL: case AL_VECTOR_VAL:
@ -765,12 +765,12 @@ alp_ReadFrames(alpobject *self, PyObject *args)
return NULL; return NULL;
} }
size *= ch; size *= ch;
v = PyBytes_FromStringAndSize((char *) NULL, size * framecount); v = PyString_FromStringAndSize((char *) NULL, size * framecount);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
alReadFrames(self->port, (void *) PyBytes_AS_STRING(v), framecount); alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
return v; return v;
@ -1068,12 +1068,12 @@ alp_readsamps(alpobject *self, PyObject *args)
width = ALgetwidth(c); width = ALgetwidth(c);
#endif /* AL_405 */ #endif /* AL_405 */
ALfreeconfig(c); ALfreeconfig(c);
v = PyBytes_FromStringAndSize((char *)NULL, width * count); v = PyString_FromStringAndSize((char *)NULL, width * count);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
ret = ALreadsamps(self->port, (void *) PyBytes_AsString(v), count); ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (ret == -1) { if (ret == -1) {
Py_DECREF(v); Py_DECREF(v);
@ -1498,7 +1498,7 @@ al_GetParams(PyObject *self, PyObject *args)
Py_INCREF(item); Py_INCREF(item);
break; break;
case AL_STRING_VAL: case AL_STRING_VAL:
item = PyBytes_FromString(pvs[i].value.ptr); item = PyString_FromString(pvs[i].value.ptr);
PyMem_DEL(pvs[i].value.ptr); PyMem_DEL(pvs[i].value.ptr);
break; break;
case AL_MATRIX_VAL: case AL_MATRIX_VAL:
@ -1725,7 +1725,7 @@ al_GetParamInfo(PyObject *self, PyObject *args)
PyDict_SetItemString(v, "elementType", item); PyDict_SetItemString(v, "elementType", item);
Py_DECREF(item); Py_DECREF(item);
item = PyBytes_FromString(pinfo.name); item = PyString_FromString(pinfo.name);
PyDict_SetItemString(v, "name", item); PyDict_SetItemString(v, "name", item);
Py_DECREF(item); Py_DECREF(item);
@ -1920,7 +1920,7 @@ al_getname(PyObject *self, PyObject *args)
return NULL; return NULL;
if ((name = ALgetname(device, descriptor)) == NULL) if ((name = ALgetname(device, descriptor)) == NULL)
return NULL; return NULL;
return PyBytes_FromString(name); return PyString_FromString(name);
} }
static PyObject * static PyObject *

View file

@ -104,7 +104,7 @@ in bounds; that's the responsibility of the caller.
static PyObject * static PyObject *
c_getitem(arrayobject *ap, Py_ssize_t i) c_getitem(arrayobject *ap, Py_ssize_t i)
{ {
return PyBytes_FromStringAndSize(&((char *)ap->ob_item)[i], 1); return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
} }
static int static int
@ -1414,7 +1414,7 @@ values,as if it had been read from a file using the fromfile() method).");
static PyObject * static PyObject *
array_tostring(arrayobject *self, PyObject *unused) array_tostring(arrayobject *self, PyObject *unused)
{ {
return PyBytes_FromStringAndSize(self->ob_item, return PyString_FromStringAndSize(self->ob_item,
Py_SIZE(self) * self->ob_descr->itemsize); Py_SIZE(self) * self->ob_descr->itemsize);
} }
@ -1494,7 +1494,7 @@ static PyObject *
array_get_typecode(arrayobject *a, void *closure) array_get_typecode(arrayobject *a, void *closure)
{ {
char tc = a->ob_descr->typecode; char tc = a->ob_descr->typecode;
return PyBytes_FromStringAndSize(&tc, 1); return PyString_FromStringAndSize(&tc, 1);
} }
static PyObject * static PyObject *
@ -1578,7 +1578,7 @@ array_repr(arrayobject *a)
typecode = a->ob_descr->typecode; typecode = a->ob_descr->typecode;
if (len == 0) { if (len == 0) {
PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode); PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
if (typecode == 'c') if (typecode == 'c')
@ -1593,9 +1593,9 @@ array_repr(arrayobject *a)
Py_XDECREF(v); Py_XDECREF(v);
PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode); PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode);
s = PyBytes_FromString(buf); s = PyString_FromString(buf);
PyBytes_ConcatAndDel(&s, t); PyString_ConcatAndDel(&s, t);
PyBytes_ConcatAndDel(&s, PyBytes_FromString(")")); PyString_ConcatAndDel(&s, PyString_FromString(")"));
return s; return s;
} }
@ -1881,7 +1881,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL; return NULL;
if (!(initial == NULL || PyList_Check(initial) if (!(initial == NULL || PyList_Check(initial)
|| PyBytes_Check(initial) || PyTuple_Check(initial) || PyString_Check(initial) || PyTuple_Check(initial)
|| (c == 'u' && PyUnicode_Check(initial)))) { || (c == 'u' && PyUnicode_Check(initial)))) {
it = PyObject_GetIter(initial); it = PyObject_GetIter(initial);
if (it == NULL) if (it == NULL)
@ -1924,7 +1924,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
} }
Py_DECREF(v); Py_DECREF(v);
} }
} else if (initial != NULL && PyBytes_Check(initial)) { } else if (initial != NULL && PyString_Check(initial)) {
PyObject *t_initial, *v; PyObject *t_initial, *v;
t_initial = PyTuple_Pack(1, initial); t_initial = PyTuple_Pack(1, initial);
if (t_initial == NULL) { if (t_initial == NULL) {

View file

@ -474,7 +474,7 @@ audioop_findfit(PyObject *self, PyObject *args)
/* Passing a short** for an 's' argument is correct only /* Passing a short** for an 's' argument is correct only
if the string contents is aligned for interpretation if the string contents is aligned for interpretation
as short[]. Due to the definition of PyBytesObject, as short[]. Due to the definition of PyStringObject,
this is currently (Python 2.6) the case. */ this is currently (Python 2.6) the case. */
if ( !PyArg_ParseTuple(args, "s#s#:findfit", if ( !PyArg_ParseTuple(args, "s#s#:findfit",
(char**)&cp1, &len1, (char**)&cp2, &len2) ) (char**)&cp1, &len1, (char**)&cp2, &len2) )
@ -759,10 +759,10 @@ audioop_mul(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len); rv = PyString_FromStringAndSize(NULL, len);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
@ -801,10 +801,10 @@ audioop_tomono(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len/2); rv = PyString_FromStringAndSize(NULL, len/2);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len; i += size*2 ) { for ( i=0; i < len; i += size*2 ) {
@ -846,10 +846,10 @@ audioop_tostereo(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len*2); rv = PyString_FromStringAndSize(NULL, len*2);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
@ -903,10 +903,10 @@ audioop_add(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len1); rv = PyString_FromStringAndSize(NULL, len1);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len1; i += size ) { for ( i=0; i < len1; i += size ) {
if ( size == 1 ) val1 = (int)*CHARP(cp1, i); if ( size == 1 ) val1 = (int)*CHARP(cp1, i);
@ -949,10 +949,10 @@ audioop_bias(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len); rv = PyString_FromStringAndSize(NULL, len);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
@ -985,10 +985,10 @@ audioop_reverse(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len); rv = PyString_FromStringAndSize(NULL, len);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@ -1023,10 +1023,10 @@ audioop_lin2lin(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len/size)*size2); rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0, j=0; i < len; i += size, j += size2 ) { for ( i=0, j=0; i < len; i += size, j += size2 ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@ -1157,7 +1157,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
nbytes / bytes_per_frame != ceiling) nbytes / bytes_per_frame != ceiling)
str = NULL; str = NULL;
else else
str = PyBytes_FromStringAndSize(NULL, nbytes); str = PyString_FromStringAndSize(NULL, nbytes);
if (str == NULL) { if (str == NULL) {
PyErr_SetString(PyExc_MemoryError, PyErr_SetString(PyExc_MemoryError,
@ -1165,7 +1165,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
goto exit; goto exit;
} }
} }
ncp = PyBytes_AsString(str); ncp = PyString_AsString(str);
for (;;) { for (;;) {
while (d < 0) { while (d < 0) {
@ -1182,13 +1182,13 @@ audioop_ratecv(PyObject *self, PyObject *args)
goto exit; goto exit;
/* We have checked before that the length /* We have checked before that the length
* of the string fits into int. */ * of the string fits into int. */
len = (int)(ncp - PyBytes_AsString(str)); len = (int)(ncp - PyString_AsString(str));
if (len == 0) { if (len == 0) {
/*don't want to resize to zero length*/ /*don't want to resize to zero length*/
rv = PyBytes_FromStringAndSize("", 0); rv = PyString_FromStringAndSize("", 0);
Py_DECREF(str); Py_DECREF(str);
str = rv; str = rv;
} else if (_PyBytes_Resize(&str, len) < 0) } else if (_PyString_Resize(&str, len) < 0)
goto exit; goto exit;
rv = Py_BuildValue("(O(iO))", str, d, samps); rv = Py_BuildValue("(O(iO))", str, d, samps);
Py_DECREF(samps); Py_DECREF(samps);
@ -1255,10 +1255,10 @@ audioop_lin2ulaw(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len/size); rv = PyString_FromStringAndSize(NULL, len/size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@ -1289,10 +1289,10 @@ audioop_ulaw2lin(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len*size); rv = PyString_FromStringAndSize(NULL, len*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len*size; i += size ) { for ( i=0; i < len*size; i += size ) {
cval = *cp++; cval = *cp++;
@ -1323,10 +1323,10 @@ audioop_lin2alaw(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len/size); rv = PyString_FromStringAndSize(NULL, len/size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < len; i += size ) { for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8; if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@ -1357,10 +1357,10 @@ audioop_alaw2lin(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len*size); rv = PyString_FromStringAndSize(NULL, len*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(rv); ncp = (signed char *)PyString_AsString(rv);
for ( i=0; i < len*size; i += size ) { for ( i=0; i < len*size; i += size ) {
cval = *cp++; cval = *cp++;
@ -1393,10 +1393,10 @@ audioop_lin2adpcm(PyObject *self, PyObject *args)
return 0; return 0;
} }
str = PyBytes_FromStringAndSize(NULL, len/(size*2)); str = PyString_FromStringAndSize(NULL, len/(size*2));
if ( str == 0 ) if ( str == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(str); ncp = (signed char *)PyString_AsString(str);
/* Decode state, should have (value, step) */ /* Decode state, should have (value, step) */
if ( state == Py_None ) { if ( state == Py_None ) {
@ -1509,10 +1509,10 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) ) } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
return 0; return 0;
str = PyBytes_FromStringAndSize(NULL, len*size*2); str = PyString_FromStringAndSize(NULL, len*size*2);
if ( str == 0 ) if ( str == 0 )
return 0; return 0;
ncp = (signed char *)PyBytes_AsString(str); ncp = (signed char *)PyString_AsString(str);
step = stepsizeTable[index]; step = stepsizeTable[index];
bufferstep = 0; bufferstep = 0;

View file

@ -141,7 +141,7 @@ static char table_a2b_base64[] = {
#define BASE64_PAD '=' #define BASE64_PAD '='
/* Max binary chunk size; limited only by available memory */ /* Max binary chunk size; limited only by available memory */
#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyBytesObject) - 3) #define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyStringObject) - 3)
static unsigned char table_b2a_base64[] = static unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@ -203,9 +203,9 @@ binascii_a2b_uu(PyObject *self, PyObject *args)
ascii_len--; ascii_len--;
/* Allocate the buffer */ /* Allocate the buffer */
if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL; return NULL;
bin_data = (unsigned char *)PyBytes_AsString(rv); bin_data = (unsigned char *)PyString_AsString(rv);
for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) { for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) {
/* XXX is it really best to add NULs if there's no more data */ /* XXX is it really best to add NULs if there's no more data */
@ -280,9 +280,9 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
} }
/* We're lazy and allocate to much (fixed up later) */ /* We're lazy and allocate to much (fixed up later) */
if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
return NULL; return NULL;
ascii_data = (unsigned char *)PyBytes_AsString(rv); ascii_data = (unsigned char *)PyString_AsString(rv);
/* Store the length */ /* Store the length */
*ascii_data++ = ' ' + (bin_len & 077); *ascii_data++ = ' ' + (bin_len & 077);
@ -304,8 +304,8 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
} }
*ascii_data++ = '\n'; /* Append a courtesy newline */ *ascii_data++ = '\n'; /* Append a courtesy newline */
_PyBytes_Resize(&rv, (ascii_data - _PyString_Resize(&rv, (ascii_data -
(unsigned char *)PyBytes_AsString(rv))); (unsigned char *)PyString_AsString(rv)));
return rv; return rv;
} }
@ -354,9 +354,9 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */ bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
/* Allocate the buffer */ /* Allocate the buffer */
if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL; return NULL;
bin_data = (unsigned char *)PyBytes_AsString(rv); bin_data = (unsigned char *)PyString_AsString(rv);
bin_len = 0; bin_len = 0;
for( ; ascii_len > 0; ascii_len--, ascii_data++) { for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@ -415,13 +415,13 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
/* And set string size correctly. If the result string is empty /* And set string size correctly. If the result string is empty
** (because the input was all invalid) return the shared empty ** (because the input was all invalid) return the shared empty
** string instead; _PyBytes_Resize() won't do this for us. ** string instead; _PyString_Resize() won't do this for us.
*/ */
if (bin_len > 0) if (bin_len > 0)
_PyBytes_Resize(&rv, bin_len); _PyString_Resize(&rv, bin_len);
else { else {
Py_DECREF(rv); Py_DECREF(rv);
rv = PyBytes_FromString(""); rv = PyString_FromString("");
} }
return rv; return rv;
} }
@ -448,9 +448,9 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
/* We're lazy and allocate too much (fixed up later). /* We're lazy and allocate too much (fixed up later).
"+3" leaves room for up to two pad characters and a trailing "+3" leaves room for up to two pad characters and a trailing
newline. Note that 'b' gets encoded as 'Yg==\n' (1 in, 5 out). */ newline. Note that 'b' gets encoded as 'Yg==\n' (1 in, 5 out). */
if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
return NULL; return NULL;
ascii_data = (unsigned char *)PyBytes_AsString(rv); ascii_data = (unsigned char *)PyString_AsString(rv);
for( ; bin_len > 0 ; bin_len--, bin_data++ ) { for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
/* Shift the data into our buffer */ /* Shift the data into our buffer */
@ -474,8 +474,8 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
} }
*ascii_data++ = '\n'; /* Append a courtesy newline */ *ascii_data++ = '\n'; /* Append a courtesy newline */
_PyBytes_Resize(&rv, (ascii_data - _PyString_Resize(&rv, (ascii_data -
(unsigned char *)PyBytes_AsString(rv))); (unsigned char *)PyString_AsString(rv)));
return rv; return rv;
} }
@ -498,9 +498,9 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
/* Allocate a string that is too big (fixed later) /* Allocate a string that is too big (fixed later)
Add two to the initial length to prevent interning which Add two to the initial length to prevent interning which
would preclude subsequent resizing. */ would preclude subsequent resizing. */
if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL )
return NULL; return NULL;
bin_data = (unsigned char *)PyBytes_AsString(rv); bin_data = (unsigned char *)PyString_AsString(rv);
for( ; len > 0 ; len--, ascii_data++ ) { for( ; len > 0 ; len--, ascii_data++ ) {
/* Get the byte and look it up */ /* Get the byte and look it up */
@ -534,8 +534,8 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_DECREF(rv); Py_DECREF(rv);
return NULL; return NULL;
} }
_PyBytes_Resize( _PyString_Resize(
&rv, (bin_data - (unsigned char *)PyBytes_AsString(rv))); &rv, (bin_data - (unsigned char *)PyString_AsString(rv)));
if (rv) { if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done); PyObject *rrv = Py_BuildValue("Oi", rv, done);
Py_DECREF(rv); Py_DECREF(rv);
@ -559,9 +559,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
return NULL; return NULL;
/* Worst case: output is twice as big as input (fixed later) */ /* Worst case: output is twice as big as input (fixed later) */
if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL; return NULL;
out_data = (unsigned char *)PyBytes_AsString(rv); out_data = (unsigned char *)PyString_AsString(rv);
for( in=0; in<len; in++) { for( in=0; in<len; in++) {
ch = in_data[in]; ch = in_data[in];
@ -587,8 +587,8 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
} }
} }
} }
_PyBytes_Resize(&rv, (out_data - _PyString_Resize(&rv, (out_data -
(unsigned char *)PyBytes_AsString(rv))); (unsigned char *)PyString_AsString(rv)));
return rv; return rv;
} }
@ -608,9 +608,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
return NULL; return NULL;
/* Allocate a buffer that is at least large enough */ /* Allocate a buffer that is at least large enough */
if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL; return NULL;
ascii_data = (unsigned char *)PyBytes_AsString(rv); ascii_data = (unsigned char *)PyString_AsString(rv);
for( ; len > 0 ; len--, bin_data++ ) { for( ; len > 0 ; len--, bin_data++ ) {
/* Shift into our buffer, and output any 6bits ready */ /* Shift into our buffer, and output any 6bits ready */
@ -627,8 +627,8 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
leftchar <<= (6-leftbits); leftchar <<= (6-leftbits);
*ascii_data++ = table_b2a_hqx[leftchar & 0x3f]; *ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
} }
_PyBytes_Resize(&rv, (ascii_data - _PyString_Resize(&rv, (ascii_data -
(unsigned char *)PyBytes_AsString(rv))); (unsigned char *)PyString_AsString(rv)));
return rv; return rv;
} }
@ -647,14 +647,14 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
/* Empty string is a special case */ /* Empty string is a special case */
if ( in_len == 0 ) if ( in_len == 0 )
return PyBytes_FromString(""); return PyString_FromString("");
/* Allocate a buffer of reasonable size. Resized when needed */ /* Allocate a buffer of reasonable size. Resized when needed */
out_len = in_len*2; out_len = in_len*2;
if ( (rv=PyBytes_FromStringAndSize(NULL, out_len)) == NULL ) if ( (rv=PyString_FromStringAndSize(NULL, out_len)) == NULL )
return NULL; return NULL;
out_len_left = out_len; out_len_left = out_len;
out_data = (unsigned char *)PyBytes_AsString(rv); out_data = (unsigned char *)PyString_AsString(rv);
/* /*
** We need two macros here to get/put bytes and handle ** We need two macros here to get/put bytes and handle
@ -673,9 +673,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
#define OUTBYTE(b) \ #define OUTBYTE(b) \
do { \ do { \
if ( --out_len_left < 0 ) { \ if ( --out_len_left < 0 ) { \
_PyBytes_Resize(&rv, 2*out_len); \ _PyString_Resize(&rv, 2*out_len); \
if ( rv == NULL ) return NULL; \ if ( rv == NULL ) return NULL; \
out_data = (unsigned char *)PyBytes_AsString(rv) \ out_data = (unsigned char *)PyString_AsString(rv) \
+ out_len; \ + out_len; \
out_len_left = out_len-1; \ out_len_left = out_len-1; \
out_len = out_len * 2; \ out_len = out_len * 2; \
@ -723,8 +723,8 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
OUTBYTE(in_byte); OUTBYTE(in_byte);
} }
} }
_PyBytes_Resize(&rv, (out_data - _PyString_Resize(&rv, (out_data -
(unsigned char *)PyBytes_AsString(rv))); (unsigned char *)PyString_AsString(rv)));
return rv; return rv;
} }
@ -923,10 +923,10 @@ binascii_hexlify(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen)) if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
return NULL; return NULL;
retval = PyBytes_FromStringAndSize(NULL, arglen*2); retval = PyString_FromStringAndSize(NULL, arglen*2);
if (!retval) if (!retval)
return NULL; return NULL;
retbuf = PyBytes_AsString(retval); retbuf = PyString_AsString(retval);
if (!retbuf) if (!retbuf)
goto finally; goto finally;
@ -989,10 +989,10 @@ binascii_unhexlify(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
retval = PyBytes_FromStringAndSize(NULL, (arglen/2)); retval = PyString_FromStringAndSize(NULL, (arglen/2));
if (!retval) if (!retval)
return NULL; return NULL;
retbuf = PyBytes_AsString(retval); retbuf = PyString_AsString(retval);
if (!retbuf) if (!retbuf)
goto finally; goto finally;
@ -1106,7 +1106,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs)
out++; out++;
} }
} }
if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) { if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata); PyMem_Free(odata);
return NULL; return NULL;
} }
@ -1306,7 +1306,7 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
} }
} }
} }
if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) { if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata); PyMem_Free(odata);
return NULL; return NULL;
} }
@ -1354,7 +1354,7 @@ initbinascii(void)
return; return;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
x = PyBytes_FromString(doc_binascii); x = PyString_FromString(doc_binascii);
PyDict_SetItemString(d, "__doc__", x); PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x); Py_XDECREF(x);

View file

@ -312,7 +312,7 @@ bsddb_subscript(bsddbobject *dp, PyObject *key)
return NULL; return NULL;
} }
result = PyBytes_FromStringAndSize(data, (int)drec.size); result = PyString_FromStringAndSize(data, (int)drec.size);
if (data != buf) free(data); if (data != buf) free(data);
return result; return result;
} }
@ -424,7 +424,7 @@ bsddb_keys(bsddbobject *dp)
if (dp->di_type == DB_RECNO) if (dp->di_type == DB_RECNO)
item = PyInt_FromLong(*((int*)data)); item = PyInt_FromLong(*((int*)data));
else else
item = PyBytes_FromStringAndSize(data, item = PyString_FromStringAndSize(data,
(int)krec.size); (int)krec.size);
if (data != buf) free(data); if (data != buf) free(data);
if (item == NULL) { if (item == NULL) {

View file

@ -34,7 +34,7 @@ typedef fpos_t Py_off_t;
#error "Large file support, but neither off_t nor fpos_t is large enough." #error "Large file support, but neither off_t nor fpos_t is large enough."
#endif #endif
#define BUF(v) PyBytes_AS_STRING((PyBytesObject *)v) #define BUF(v) PyString_AS_STRING((PyStringObject *)v)
#define MODE_CLOSED 0 #define MODE_CLOSED 0
#define MODE_READ 1 #define MODE_READ 1
@ -241,7 +241,7 @@ Util_GetLine(BZ2FileObject *f, int n)
int univ_newline = f->f_univ_newline; int univ_newline = f->f_univ_newline;
total_v_size = n > 0 ? n : 100; total_v_size = n > 0 ? n : 100;
v = PyBytes_FromStringAndSize((char *)NULL, total_v_size); v = PyString_FromStringAndSize((char *)NULL, total_v_size);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
@ -307,7 +307,7 @@ Util_GetLine(BZ2FileObject *f, int n)
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
if (_PyBytes_Resize(&v, total_v_size) < 0) if (_PyString_Resize(&v, total_v_size) < 0)
return NULL; return NULL;
buf = BUF(v) + used_v_size; buf = BUF(v) + used_v_size;
end = BUF(v) + total_v_size; end = BUF(v) + total_v_size;
@ -315,7 +315,7 @@ Util_GetLine(BZ2FileObject *f, int n)
used_v_size = buf - BUF(v); used_v_size = buf - BUF(v);
if (used_v_size != total_v_size) if (used_v_size != total_v_size)
_PyBytes_Resize(&v, used_v_size); _PyString_Resize(&v, used_v_size);
return v; return v;
} }
@ -438,10 +438,10 @@ Util_ReadAhead(BZ2FileObject *f, int bufsize)
/* This is a hacked version of Python's /* This is a hacked version of Python's
* fileobject.c:readahead_get_line_skip(). */ * fileobject.c:readahead_get_line_skip(). */
static PyBytesObject * static PyStringObject *
Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize) Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
{ {
PyBytesObject* s; PyStringObject* s;
char *bufptr; char *bufptr;
char *buf; char *buf;
int len; int len;
@ -452,17 +452,17 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
len = f->f_bufend - f->f_bufptr; len = f->f_bufend - f->f_bufptr;
if (len == 0) if (len == 0)
return (PyBytesObject *) return (PyStringObject *)
PyBytes_FromStringAndSize(NULL, skip); PyString_FromStringAndSize(NULL, skip);
bufptr = memchr(f->f_bufptr, '\n', len); bufptr = memchr(f->f_bufptr, '\n', len);
if (bufptr != NULL) { if (bufptr != NULL) {
bufptr++; /* Count the '\n' */ bufptr++; /* Count the '\n' */
len = bufptr - f->f_bufptr; len = bufptr - f->f_bufptr;
s = (PyBytesObject *) s = (PyStringObject *)
PyBytes_FromStringAndSize(NULL, skip+len); PyString_FromStringAndSize(NULL, skip+len);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
memcpy(PyBytes_AS_STRING(s)+skip, f->f_bufptr, len); memcpy(PyString_AS_STRING(s)+skip, f->f_bufptr, len);
f->f_bufptr = bufptr; f->f_bufptr = bufptr;
if (bufptr == f->f_bufend) if (bufptr == f->f_bufend)
Util_DropReadAhead(f); Util_DropReadAhead(f);
@ -476,7 +476,7 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
PyMem_Free(buf); PyMem_Free(buf);
return NULL; return NULL;
} }
memcpy(PyBytes_AS_STRING(s)+skip, bufptr, len); memcpy(PyString_AS_STRING(s)+skip, bufptr, len);
PyMem_Free(buf); PyMem_Free(buf);
} }
return s; return s;
@ -509,7 +509,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
case MODE_READ: case MODE_READ:
break; break;
case MODE_READ_EOF: case MODE_READ_EOF:
ret = PyBytes_FromString(""); ret = PyString_FromString("");
goto cleanup; goto cleanup;
case MODE_CLOSED: case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
@ -531,7 +531,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
"more than a Python string can hold"); "more than a Python string can hold");
goto cleanup; goto cleanup;
} }
ret = PyBytes_FromStringAndSize((char *)NULL, buffersize); ret = PyString_FromStringAndSize((char *)NULL, buffersize);
if (ret == NULL) if (ret == NULL)
goto cleanup; goto cleanup;
bytesread = 0; bytesread = 0;
@ -557,14 +557,14 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
} }
if (bytesrequested < 0) { if (bytesrequested < 0) {
buffersize = Util_NewBufferSize(buffersize); buffersize = Util_NewBufferSize(buffersize);
if (_PyBytes_Resize(&ret, buffersize) < 0) if (_PyString_Resize(&ret, buffersize) < 0)
goto cleanup; goto cleanup;
} else { } else {
break; break;
} }
} }
if (bytesread != buffersize) if (bytesread != buffersize)
_PyBytes_Resize(&ret, bytesread); _PyString_Resize(&ret, bytesread);
cleanup: cleanup:
RELEASE_LOCK(self); RELEASE_LOCK(self);
@ -594,7 +594,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
case MODE_READ: case MODE_READ:
break; break;
case MODE_READ_EOF: case MODE_READ_EOF:
ret = PyBytes_FromString(""); ret = PyString_FromString("");
goto cleanup; goto cleanup;
case MODE_CLOSED: case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
@ -607,7 +607,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
} }
if (sizehint == 0) if (sizehint == 0)
ret = PyBytes_FromString(""); ret = PyString_FromString("");
else else
ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint); ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint);
@ -701,17 +701,17 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
} }
if (big_buffer == NULL) { if (big_buffer == NULL) {
/* Create the big buffer */ /* Create the big buffer */
big_buffer = PyBytes_FromStringAndSize( big_buffer = PyString_FromStringAndSize(
NULL, buffersize); NULL, buffersize);
if (big_buffer == NULL) if (big_buffer == NULL)
goto error; goto error;
buffer = PyBytes_AS_STRING(big_buffer); buffer = PyString_AS_STRING(big_buffer);
memcpy(buffer, small_buffer, nfilled); memcpy(buffer, small_buffer, nfilled);
} }
else { else {
/* Grow the big buffer */ /* Grow the big buffer */
_PyBytes_Resize(&big_buffer, buffersize); _PyString_Resize(&big_buffer, buffersize);
buffer = PyBytes_AS_STRING(big_buffer); buffer = PyString_AS_STRING(big_buffer);
} }
continue; continue;
} }
@ -720,7 +720,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
while (p != NULL) { while (p != NULL) {
/* Process complete lines */ /* Process complete lines */
p++; p++;
line = PyBytes_FromStringAndSize(q, p-q); line = PyString_FromStringAndSize(q, p-q);
if (line == NULL) if (line == NULL)
goto error; goto error;
err = PyList_Append(list, line); err = PyList_Append(list, line);
@ -743,7 +743,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
} }
if (nfilled != 0) { if (nfilled != 0) {
/* Partial last line */ /* Partial last line */
line = PyBytes_FromStringAndSize(buffer, nfilled); line = PyString_FromStringAndSize(buffer, nfilled);
if (line == NULL) if (line == NULL)
goto error; goto error;
if (sizehint > 0) { if (sizehint > 0) {
@ -753,7 +753,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
Py_DECREF(line); Py_DECREF(line);
goto error; goto error;
} }
PyBytes_Concat(&line, rest); PyString_Concat(&line, rest);
Py_DECREF(rest); Py_DECREF(rest);
if (line == NULL) if (line == NULL)
goto error; goto error;
@ -915,7 +915,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
could potentially execute Python code. */ could potentially execute Python code. */
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
PyObject *v = PyList_GET_ITEM(list, i); PyObject *v = PyList_GET_ITEM(list, i);
if (!PyBytes_Check(v)) { if (!PyString_Check(v)) {
const char *buffer; const char *buffer;
Py_ssize_t len; Py_ssize_t len;
if (PyObject_AsCharBuffer(v, &buffer, &len)) { if (PyObject_AsCharBuffer(v, &buffer, &len)) {
@ -926,7 +926,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
"strings"); "strings");
goto error; goto error;
} }
line = PyBytes_FromStringAndSize(buffer, line = PyString_FromStringAndSize(buffer,
len); len);
if (line == NULL) if (line == NULL)
goto error; goto error;
@ -942,9 +942,9 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
line = PyList_GET_ITEM(list, i); line = PyList_GET_ITEM(list, i);
len = PyBytes_GET_SIZE(line); len = PyString_GET_SIZE(line);
BZ2_bzWrite (&bzerror, self->fp, BZ2_bzWrite (&bzerror, self->fp,
PyBytes_AS_STRING(line), len); PyString_AS_STRING(line), len);
if (bzerror != BZ_OK) { if (bzerror != BZ_OK) {
Py_BLOCK_THREADS Py_BLOCK_THREADS
Util_CatchBZ2Error(bzerror); Util_CatchBZ2Error(bzerror);
@ -1224,13 +1224,13 @@ BZ2File_get_newlines(BZ2FileObject *self, void *closure)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
case NEWLINE_CR: case NEWLINE_CR:
return PyBytes_FromString("\r"); return PyString_FromString("\r");
case NEWLINE_LF: case NEWLINE_LF:
return PyBytes_FromString("\n"); return PyString_FromString("\n");
case NEWLINE_CR|NEWLINE_LF: case NEWLINE_CR|NEWLINE_LF:
return Py_BuildValue("(ss)", "\r", "\n"); return Py_BuildValue("(ss)", "\r", "\n");
case NEWLINE_CRLF: case NEWLINE_CRLF:
return PyBytes_FromString("\r\n"); return PyString_FromString("\r\n");
case NEWLINE_CR|NEWLINE_CRLF: case NEWLINE_CR|NEWLINE_CRLF:
return Py_BuildValue("(ss)", "\r", "\r\n"); return Py_BuildValue("(ss)", "\r", "\r\n");
case NEWLINE_LF|NEWLINE_CRLF: case NEWLINE_LF|NEWLINE_CRLF:
@ -1448,7 +1448,7 @@ BZ2File_getiter(BZ2FileObject *self)
static PyObject * static PyObject *
BZ2File_iternext(BZ2FileObject *self) BZ2File_iternext(BZ2FileObject *self)
{ {
PyBytesObject* ret; PyStringObject* ret;
ACQUIRE_LOCK(self); ACQUIRE_LOCK(self);
if (self->mode == MODE_CLOSED) { if (self->mode == MODE_CLOSED) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
@ -1457,7 +1457,7 @@ BZ2File_iternext(BZ2FileObject *self)
} }
ret = Util_ReadAheadGetLineSkip(self, 0, READAHEAD_BUFSIZE); ret = Util_ReadAheadGetLineSkip(self, 0, READAHEAD_BUFSIZE);
RELEASE_LOCK(self); RELEASE_LOCK(self);
if (ret == NULL || PyBytes_GET_SIZE(ret) == 0) { if (ret == NULL || PyString_GET_SIZE(ret) == 0) {
Py_XDECREF(ret); Py_XDECREF(ret);
return NULL; return NULL;
} }
@ -1559,7 +1559,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
return NULL; return NULL;
if (datasize == 0) if (datasize == 0)
return PyBytes_FromString(""); return PyString_FromString("");
ACQUIRE_LOCK(self); ACQUIRE_LOCK(self);
if (!self->running) { if (!self->running) {
@ -1568,7 +1568,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
goto error; goto error;
} }
ret = PyBytes_FromStringAndSize(NULL, bufsize); ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret) if (!ret)
goto error; goto error;
@ -1591,7 +1591,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
break; /* no more input data */ break; /* no more input data */
if (bzs->avail_out == 0) { if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize); bufsize = Util_NewBufferSize(bufsize);
if (_PyBytes_Resize(&ret, bufsize) < 0) { if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs); BZ2_bzCompressEnd(bzs);
goto error; goto error;
} }
@ -1601,7 +1601,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
} }
} }
_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)); _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self); RELEASE_LOCK(self);
return ret; return ret;
@ -1636,7 +1636,7 @@ BZ2Comp_flush(BZ2CompObject *self)
} }
self->running = 0; self->running = 0;
ret = PyBytes_FromStringAndSize(NULL, bufsize); ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret) if (!ret)
goto error; goto error;
@ -1657,7 +1657,7 @@ BZ2Comp_flush(BZ2CompObject *self)
} }
if (bzs->avail_out == 0) { if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize); bufsize = Util_NewBufferSize(bufsize);
if (_PyBytes_Resize(&ret, bufsize) < 0) if (_PyString_Resize(&ret, bufsize) < 0)
goto error; goto error;
bzs->next_out = BUF(ret); bzs->next_out = BUF(ret);
bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs) bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
@ -1667,7 +1667,7 @@ BZ2Comp_flush(BZ2CompObject *self)
} }
if (bzs->avail_out != 0) if (bzs->avail_out != 0)
_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)); _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self); RELEASE_LOCK(self);
return ret; return ret;
@ -1849,7 +1849,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
goto error; goto error;
} }
ret = PyBytes_FromStringAndSize(NULL, bufsize); ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret) if (!ret)
goto error; goto error;
@ -1868,7 +1868,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
if (bzs->avail_in != 0) { if (bzs->avail_in != 0) {
Py_DECREF(self->unused_data); Py_DECREF(self->unused_data);
self->unused_data = self->unused_data =
PyBytes_FromStringAndSize(bzs->next_in, PyString_FromStringAndSize(bzs->next_in,
bzs->avail_in); bzs->avail_in);
} }
self->running = 0; self->running = 0;
@ -1882,7 +1882,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
break; /* no more input data */ break; /* no more input data */
if (bzs->avail_out == 0) { if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize); bufsize = Util_NewBufferSize(bufsize);
if (_PyBytes_Resize(&ret, bufsize) < 0) { if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs); BZ2_bzDecompressEnd(bzs);
goto error; goto error;
} }
@ -1894,7 +1894,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
} }
if (bzs->avail_out != 0) if (bzs->avail_out != 0)
_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)); _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self); RELEASE_LOCK(self);
return ret; return ret;
@ -1930,7 +1930,7 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
} }
#endif #endif
self->unused_data = PyBytes_FromString(""); self->unused_data = PyString_FromString("");
if (!self->unused_data) if (!self->unused_data)
goto error; goto error;
@ -2063,7 +2063,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
* data in one shot. We will check it later anyway. */ * data in one shot. We will check it later anyway. */
bufsize = datasize + (datasize/100+1) + 600; bufsize = datasize + (datasize/100+1) + 600;
ret = PyBytes_FromStringAndSize(NULL, bufsize); ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret) if (!ret)
return NULL; return NULL;
@ -2095,7 +2095,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
} }
if (bzs->avail_out == 0) { if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize); bufsize = Util_NewBufferSize(bufsize);
if (_PyBytes_Resize(&ret, bufsize) < 0) { if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs); BZ2_bzCompressEnd(bzs);
Py_DECREF(ret); Py_DECREF(ret);
return NULL; return NULL;
@ -2106,7 +2106,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
} }
if (bzs->avail_out != 0) if (bzs->avail_out != 0)
_PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)); _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzCompressEnd(bzs); BZ2_bzCompressEnd(bzs);
return ret; return ret;
@ -2134,9 +2134,9 @@ bz2_decompress(PyObject *self, PyObject *args)
return NULL; return NULL;
if (datasize == 0) if (datasize == 0)
return PyBytes_FromString(""); return PyString_FromString("");
ret = PyBytes_FromStringAndSize(NULL, bufsize); ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret) if (!ret)
return NULL; return NULL;
@ -2175,7 +2175,7 @@ bz2_decompress(PyObject *self, PyObject *args)
} }
if (bzs->avail_out == 0) { if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize); bufsize = Util_NewBufferSize(bufsize);
if (_PyBytes_Resize(&ret, bufsize) < 0) { if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs); BZ2_bzDecompressEnd(bzs);
Py_DECREF(ret); Py_DECREF(ret);
return NULL; return NULL;
@ -2186,7 +2186,7 @@ bz2_decompress(PyObject *self, PyObject *args)
} }
if (bzs->avail_out != 0) if (bzs->avail_out != 0)
_PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)); _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzDecompressEnd(bzs); BZ2_bzDecompressEnd(bzs);
return ret; return ret;
@ -2223,7 +2223,7 @@ initbz2(void)
if (m == NULL) if (m == NULL)
return; return;
PyModule_AddObject(m, "__author__", PyBytes_FromString(__author__)); PyModule_AddObject(m, "__author__", PyString_FromString(__author__));
Py_INCREF(&BZ2File_Type); Py_INCREF(&BZ2File_Type);
PyModule_AddObject(m, "BZ2File", (PyObject *)&BZ2File_Type); PyModule_AddObject(m, "BZ2File", (PyObject *)&BZ2File_Type);

View file

@ -393,13 +393,13 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
if (format) args = Py_VaBuildValue(format, va); if (format) args = Py_VaBuildValue(format, va);
va_end(va); va_end(va);
if (format && ! args) return NULL; if (format && ! args) return NULL;
if (stringformat && !(retval=PyBytes_FromString(stringformat))) if (stringformat && !(retval=PyString_FromString(stringformat)))
return NULL; return NULL;
if (retval) { if (retval) {
if (args) { if (args) {
PyObject *v; PyObject *v;
v=PyBytes_Format(retval, args); v=PyString_Format(retval, args);
Py_DECREF(retval); Py_DECREF(retval);
Py_DECREF(args); Py_DECREF(args);
if (! v) return NULL; if (! v) return NULL;
@ -477,7 +477,7 @@ write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
n = (int)_n; n = (int)_n;
if (s == NULL) { if (s == NULL) {
if (!( self->buf_size )) return 0; if (!( self->buf_size )) return 0;
py_str = PyBytes_FromStringAndSize(self->write_buf, py_str = PyString_FromStringAndSize(self->write_buf,
self->buf_size); self->buf_size);
if (!py_str) if (!py_str)
return -1; return -1;
@ -490,7 +490,7 @@ write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
if (n > WRITE_BUF_SIZE) { if (n > WRITE_BUF_SIZE) {
if (!( py_str = if (!( py_str =
PyBytes_FromStringAndSize(s, n))) PyString_FromStringAndSize(s, n)))
return -1; return -1;
} }
else { else {
@ -655,7 +655,7 @@ read_other(Unpicklerobject *self, char **s, Py_ssize_t n)
Py_XDECREF(self->last_string); Py_XDECREF(self->last_string);
self->last_string = str; self->last_string = str;
if (! (*s = PyBytes_AsString(str))) return -1; if (! (*s = PyString_AsString(str))) return -1;
return n; return n;
} }
@ -670,13 +670,13 @@ readline_other(Unpicklerobject *self, char **s)
return -1; return -1;
} }
if ((str_size = PyBytes_Size(str)) < 0) if ((str_size = PyString_Size(str)) < 0)
return -1; return -1;
Py_XDECREF(self->last_string); Py_XDECREF(self->last_string);
self->last_string = str; self->last_string = str;
if (! (*s = PyBytes_AsString(str))) if (! (*s = PyString_AsString(str)))
return -1; return -1;
return str_size; return str_size;
@ -1078,9 +1078,9 @@ save_long(Picklerobject *self, PyObject *args)
"to pickle"); "to pickle");
goto finally; goto finally;
} }
repr = PyBytes_FromStringAndSize(NULL, (int)nbytes); repr = PyString_FromStringAndSize(NULL, (int)nbytes);
if (repr == NULL) goto finally; if (repr == NULL) goto finally;
pdata = (unsigned char *)PyBytes_AS_STRING(repr); pdata = (unsigned char *)PyString_AS_STRING(repr);
i = _PyLong_AsByteArray((PyLongObject *)args, i = _PyLong_AsByteArray((PyLongObject *)args,
pdata, nbytes, pdata, nbytes,
1 /* little endian */, 1 /* signed */); 1 /* little endian */, 1 /* signed */);
@ -1121,14 +1121,14 @@ save_long(Picklerobject *self, PyObject *args)
if (!( repr = PyObject_Repr(args))) if (!( repr = PyObject_Repr(args)))
goto finally; goto finally;
if ((size = PyBytes_Size(repr)) < 0) if ((size = PyString_Size(repr)) < 0)
goto finally; goto finally;
if (self->write_func(self, &l, 1) < 0) if (self->write_func(self, &l, 1) < 0)
goto finally; goto finally;
if (self->write_func(self, if (self->write_func(self,
PyBytes_AS_STRING((PyBytesObject *)repr), PyString_AS_STRING((PyStringObject *)repr),
size) < 0) size) < 0)
goto finally; goto finally;
@ -1177,7 +1177,7 @@ save_string(Picklerobject *self, PyObject *args, int doput)
int size, len; int size, len;
PyObject *repr=0; PyObject *repr=0;
if ((size = PyBytes_Size(args)) < 0) if ((size = PyString_Size(args)) < 0)
return -1; return -1;
if (!self->bin) { if (!self->bin) {
@ -1188,9 +1188,9 @@ save_string(Picklerobject *self, PyObject *args, int doput)
if (!( repr = PyObject_Repr(args))) if (!( repr = PyObject_Repr(args)))
return -1; return -1;
if ((len = PyBytes_Size(repr)) < 0) if ((len = PyString_Size(repr)) < 0)
goto err; goto err;
repr_str = PyBytes_AS_STRING((PyBytesObject *)repr); repr_str = PyString_AS_STRING((PyStringObject *)repr);
if (self->write_func(self, &string, 1) < 0) if (self->write_func(self, &string, 1) < 0)
goto err; goto err;
@ -1207,7 +1207,7 @@ save_string(Picklerobject *self, PyObject *args, int doput)
int i; int i;
char c_str[5]; char c_str[5];
if ((size = PyBytes_Size(args)) < 0) if ((size = PyString_Size(args)) < 0)
return -1; return -1;
if (size < 256) { if (size < 256) {
@ -1233,8 +1233,8 @@ save_string(Picklerobject *self, PyObject *args, int doput)
} }
else { else {
if (self->write_func(self, if (self->write_func(self,
PyBytes_AS_STRING( PyString_AS_STRING(
(PyBytesObject *)args), (PyStringObject *)args),
size) < 0) size) < 0)
return -1; return -1;
} }
@ -1264,13 +1264,13 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size)
static const char *hexdigit = "0123456789ABCDEF"; static const char *hexdigit = "0123456789ABCDEF";
repr = PyBytes_FromStringAndSize(NULL, 6 * size); repr = PyString_FromStringAndSize(NULL, 6 * size);
if (repr == NULL) if (repr == NULL)
return NULL; return NULL;
if (size == 0) if (size == 0)
return repr; return repr;
p = q = PyBytes_AS_STRING(repr); p = q = PyString_AS_STRING(repr);
while (size-- > 0) { while (size-- > 0) {
Py_UNICODE ch = *s++; Py_UNICODE ch = *s++;
/* Map 16-bit characters to '\uxxxx' */ /* Map 16-bit characters to '\uxxxx' */
@ -1287,7 +1287,7 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size)
*p++ = (char) ch; *p++ = (char) ch;
} }
*p = '\0'; *p = '\0';
_PyBytes_Resize(&repr, p - q); _PyString_Resize(&repr, p - q);
return repr; return repr;
} }
@ -1310,9 +1310,9 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
if (!repr) if (!repr)
return -1; return -1;
if ((len = PyBytes_Size(repr)) < 0) if ((len = PyString_Size(repr)) < 0)
goto err; goto err;
repr_str = PyBytes_AS_STRING((PyBytesObject *)repr); repr_str = PyString_AS_STRING((PyStringObject *)repr);
if (self->write_func(self, &string, 1) < 0) if (self->write_func(self, &string, 1) < 0)
goto err; goto err;
@ -1332,7 +1332,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
if (!( repr = PyUnicode_AsUTF8String(args))) if (!( repr = PyUnicode_AsUTF8String(args)))
return -1; return -1;
if ((size = PyBytes_Size(repr)) < 0) if ((size = PyString_Size(repr)) < 0)
goto err; goto err;
if (size > INT_MAX) if (size > INT_MAX)
return -1; /* string too large */ return -1; /* string too large */
@ -1351,7 +1351,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
PDATA_APPEND(self->file, repr, -1); PDATA_APPEND(self->file, repr, -1);
} }
else { else {
if (self->write_func(self, PyBytes_AS_STRING(repr), if (self->write_func(self, PyString_AS_STRING(repr),
size) < 0) size) < 0)
goto err; goto err;
} }
@ -1861,12 +1861,12 @@ save_inst(Picklerobject *self, PyObject *args)
goto finally; goto finally;
if ((module_size = PyBytes_Size(module)) < 0 || if ((module_size = PyString_Size(module)) < 0 ||
(name_size = PyBytes_Size(name)) < 0) (name_size = PyString_Size(name)) < 0)
goto finally; goto finally;
module_str = PyBytes_AS_STRING((PyBytesObject *)module); module_str = PyString_AS_STRING((PyStringObject *)module);
name_str = PyBytes_AS_STRING((PyBytesObject *)name); name_str = PyString_AS_STRING((PyStringObject *)name);
if (self->write_func(self, &inst, 1) < 0) if (self->write_func(self, &inst, 1) < 0)
goto finally; goto finally;
@ -1961,12 +1961,12 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
if (!( module = whichmodule(args, global_name))) if (!( module = whichmodule(args, global_name)))
goto finally; goto finally;
if ((module_size = PyBytes_Size(module)) < 0 || if ((module_size = PyString_Size(module)) < 0 ||
(name_size = PyBytes_Size(global_name)) < 0) (name_size = PyString_Size(global_name)) < 0)
goto finally; goto finally;
module_str = PyBytes_AS_STRING((PyBytesObject *)module); module_str = PyString_AS_STRING((PyStringObject *)module);
name_str = PyBytes_AS_STRING((PyBytesObject *)global_name); name_str = PyString_AS_STRING((PyStringObject *)global_name);
/* XXX This can be doing a relative import. Clearly it shouldn't, /* XXX This can be doing a relative import. Clearly it shouldn't,
but I don't know how to stop it. :-( */ but I don't know how to stop it. :-( */
@ -2099,7 +2099,7 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f)
if (pid != Py_None) { if (pid != Py_None) {
if (!self->bin) { if (!self->bin) {
if (!PyBytes_Check(pid)) { if (!PyString_Check(pid)) {
PyErr_SetString(PicklingError, PyErr_SetString(PicklingError,
"persistent id must be string"); "persistent id must be string");
goto finally; goto finally;
@ -2108,12 +2108,12 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f)
if (self->write_func(self, &persid, 1) < 0) if (self->write_func(self, &persid, 1) < 0)
goto finally; goto finally;
if ((size = PyBytes_Size(pid)) < 0) if ((size = PyString_Size(pid)) < 0)
goto finally; goto finally;
if (self->write_func(self, if (self->write_func(self,
PyBytes_AS_STRING( PyString_AS_STRING(
(PyBytesObject *)pid), (PyStringObject *)pid),
size) < 0) size) < 0)
goto finally; goto finally;
@ -2194,8 +2194,8 @@ save_reduce(Picklerobject *self, PyObject *args, PyObject *ob)
use_newobj = 0; use_newobj = 0;
} }
else { else {
use_newobj = PyBytes_Check(temp) && use_newobj = PyString_Check(temp) &&
strcmp(PyBytes_AS_STRING(temp), strcmp(PyString_AS_STRING(temp),
"__newobj__") == 0; "__newobj__") == 0;
Py_DECREF(temp); Py_DECREF(temp);
} }
@ -2362,14 +2362,14 @@ save(Picklerobject *self, PyObject *args, int pers_save)
break; break;
case 's': case 's':
if ((type == &PyBytes_Type) && (PyBytes_GET_SIZE(args) < 2)) { if ((type == &PyString_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_string(self, args, 0); res = save_string(self, args, 0);
goto finally; goto finally;
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
case 'u': case 'u':
if ((type == &PyUnicode_Type) && (PyBytes_GET_SIZE(args) < 2)) { if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0); res = save_unicode(self, args, 0);
goto finally; goto finally;
} }
@ -2391,7 +2391,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
switch (type->tp_name[0]) { switch (type->tp_name[0]) {
case 's': case 's':
if (type == &PyBytes_Type) { if (type == &PyString_Type) {
res = save_string(self, args, 1); res = save_string(self, args, 1);
goto finally; goto finally;
} }
@ -2526,7 +2526,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
if (t == NULL) if (t == NULL)
goto finally; goto finally;
if (PyBytes_Check(t)) { if (PyString_Check(t)) {
res = save_global(self, args, t); res = save_global(self, args, t);
goto finally; goto finally;
} }
@ -2640,8 +2640,8 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
for (rsize = 0, i = l; --i >= 0; ) { for (rsize = 0, i = l; --i >= 0; ) {
k = data->data[i]; k = data->data[i];
if (PyBytes_Check(k)) if (PyString_Check(k))
rsize += PyBytes_GET_SIZE(k); rsize += PyString_GET_SIZE(k);
else if (PyInt_Check(k)) { /* put */ else if (PyInt_Check(k)) { /* put */
ik = PyInt_AS_LONG((PyIntObject*)k); ik = PyInt_AS_LONG((PyIntObject*)k);
@ -2676,17 +2676,17 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
} }
/* Now generate the result */ /* Now generate the result */
r = PyBytes_FromStringAndSize(NULL, rsize); r = PyString_FromStringAndSize(NULL, rsize);
if (r == NULL) goto err; if (r == NULL) goto err;
s = PyBytes_AS_STRING((PyBytesObject *)r); s = PyString_AS_STRING((PyStringObject *)r);
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
k = data->data[i]; k = data->data[i];
if (PyBytes_Check(k)) { if (PyString_Check(k)) {
ssize = PyBytes_GET_SIZE(k); ssize = PyString_GET_SIZE(k);
if (ssize) { if (ssize) {
p=PyBytes_AS_STRING((PyBytesObject *)k); p=PyString_AS_STRING((PyStringObject *)k);
while (--ssize >= 0) while (--ssize >= 0)
*s++ = *p++; *s++ = *p++;
} }
@ -3410,7 +3410,7 @@ load_string(Unpicklerobject *self)
goto insecure; goto insecure;
/********************************************/ /********************************************/
str = PyBytes_DecodeEscape(p, len, NULL, 0, NULL); str = PyString_DecodeEscape(p, len, NULL, 0, NULL);
free(s); free(s);
if (str) { if (str) {
PDATA_PUSH(self->stack, str, -1); PDATA_PUSH(self->stack, str, -1);
@ -3439,7 +3439,7 @@ load_binstring(Unpicklerobject *self)
if (self->read_func(self, &s, l) < 0) if (self->read_func(self, &s, l) < 0)
return -1; return -1;
if (!( py_string = PyBytes_FromStringAndSize(s, l))) if (!( py_string = PyString_FromStringAndSize(s, l)))
return -1; return -1;
PDATA_PUSH(self->stack, py_string, -1); PDATA_PUSH(self->stack, py_string, -1);
@ -3461,7 +3461,7 @@ load_short_binstring(Unpicklerobject *self)
if (self->read_func(self, &s, l) < 0) return -1; if (self->read_func(self, &s, l) < 0) return -1;
if (!( py_string = PyBytes_FromStringAndSize(s, l))) return -1; if (!( py_string = PyString_FromStringAndSize(s, l))) return -1;
PDATA_PUSH(self->stack, py_string, -1); PDATA_PUSH(self->stack, py_string, -1);
return 0; return 0;
@ -3688,12 +3688,12 @@ load_inst(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1; if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
module_name = PyBytes_FromStringAndSize(s, len - 1); module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1; if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) { if ((len = self->readline_func(self, &s)) >= 0) {
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) { if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name, class = find_class(module_name, class_name,
self->find_class); self->find_class);
Py_DECREF(class_name); Py_DECREF(class_name);
@ -3772,7 +3772,7 @@ load_global(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1; if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
module_name = PyBytes_FromStringAndSize(s, len - 1); module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1; if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) { if ((len = self->readline_func(self, &s)) >= 0) {
@ -3780,7 +3780,7 @@ load_global(Unpicklerobject *self)
Py_DECREF(module_name); Py_DECREF(module_name);
return bad_readline(); return bad_readline();
} }
if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) { if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name, class = find_class(module_name, class_name,
self->find_class); self->find_class);
Py_DECREF(class_name); Py_DECREF(class_name);
@ -3805,7 +3805,7 @@ load_persid(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1; if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
pid = PyBytes_FromStringAndSize(s, len - 1); pid = PyString_FromStringAndSize(s, len - 1);
if (!pid) return -1; if (!pid) return -1;
if (PyList_Check(self->pers_func)) { if (PyList_Check(self->pers_func)) {
@ -3938,7 +3938,7 @@ load_get(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1; if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if (!( py_str = PyBytes_FromStringAndSize(s, len - 1))) return -1; if (!( py_str = PyString_FromStringAndSize(s, len - 1))) return -1;
value = PyDict_GetItem(self->memo, py_str); value = PyDict_GetItem(self->memo, py_str);
if (! value) { if (! value) {
@ -4064,8 +4064,8 @@ load_extension(Unpicklerobject *self, int nbytes)
* confirm that pair is really a 2-tuple of strings. * confirm that pair is really a 2-tuple of strings.
*/ */
if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 || if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 ||
!PyBytes_Check(module_name = PyTuple_GET_ITEM(pair, 0)) || !PyString_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
!PyBytes_Check(class_name = PyTuple_GET_ITEM(pair, 1))) { !PyString_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
Py_DECREF(py_code); Py_DECREF(py_code);
PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] " PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
"isn't a 2-tuple of strings", code); "isn't a 2-tuple of strings", code);
@ -4098,7 +4098,7 @@ load_put(Unpicklerobject *self)
if ((l = self->readline_func(self, &s)) < 0) return -1; if ((l = self->readline_func(self, &s)) < 0) return -1;
if (l < 2) return bad_readline(); if (l < 2) return bad_readline();
if (!( len=self->stack->length )) return stackUnderflow(); if (!( len=self->stack->length )) return stackUnderflow();
if (!( py_str = PyBytes_FromStringAndSize(s, l - 1))) return -1; if (!( py_str = PyString_FromStringAndSize(s, l - 1))) return -1;
value=self->stack->data[len-1]; value=self->stack->data[len-1];
l=PyDict_SetItem(self->memo, py_str, value); l=PyDict_SetItem(self->memo, py_str, value);
Py_DECREF(py_str); Py_DECREF(py_str);
@ -5568,7 +5568,7 @@ init_stuff(PyObject *module_dict)
{ {
PyObject *copyreg, *t, *r; PyObject *copyreg, *t, *r;
#define INIT_STR(S) if (!( S ## _str=PyBytes_InternFromString(#S))) return -1; #define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
if (PyType_Ready(&Unpicklertype) < 0) if (PyType_Ready(&Unpicklertype) < 0)
return -1; return -1;
@ -5736,7 +5736,7 @@ initcPickle(void)
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
v = PyBytes_FromString(rev); v = PyString_FromString(rev);
PyDict_SetItemString(d, "__version__", v); PyDict_SetItemString(d, "__version__", v);
Py_XDECREF(v); Py_XDECREF(v);
@ -5755,7 +5755,7 @@ initcPickle(void)
/* These are purely informational; no code uses them. */ /* These are purely informational; no code uses them. */
/* File format version we write. */ /* File format version we write. */
format_version = PyBytes_FromString("2.0"); format_version = PyString_FromString("2.0");
/* Format versions we can read. */ /* Format versions we can read. */
compatible_formats = Py_BuildValue("[sssss]", compatible_formats = Py_BuildValue("[sssss]",
"1.0", /* Original protocol 0 */ "1.0", /* Original protocol 0 */

View file

@ -119,7 +119,7 @@ PyDoc_STRVAR(IO_getval__doc__,
static PyObject * static PyObject *
IO_cgetval(PyObject *self) { IO_cgetval(PyObject *self) {
if (!IO__opencheck(IOOOBJECT(self))) return NULL; if (!IO__opencheck(IOOOBJECT(self))) return NULL;
return PyBytes_FromStringAndSize(((IOobject*)self)->buf, return PyString_FromStringAndSize(((IOobject*)self)->buf,
((IOobject*)self)->pos); ((IOobject*)self)->pos);
} }
@ -137,7 +137,7 @@ IO_getval(IOobject *self, PyObject *args) {
} }
else else
s=self->string_size; s=self->string_size;
return PyBytes_FromStringAndSize(self->buf, s); return PyString_FromStringAndSize(self->buf, s);
} }
PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0"); PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0");
@ -177,7 +177,7 @@ IO_read(IOobject *self, PyObject *args) {
if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL; if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;
return PyBytes_FromStringAndSize(output, n); return PyString_FromStringAndSize(output, n);
} }
PyDoc_STRVAR(IO_readline__doc__, "readline() -- Read one line"); PyDoc_STRVAR(IO_readline__doc__, "readline() -- Read one line");
@ -215,7 +215,7 @@ IO_readline(IOobject *self, PyObject *args) {
n -= m; n -= m;
self->pos -= m; self->pos -= m;
} }
return PyBytes_FromStringAndSize(output, n); return PyString_FromStringAndSize(output, n);
} }
PyDoc_STRVAR(IO_readlines__doc__, "readlines() -- Read all lines"); PyDoc_STRVAR(IO_readlines__doc__, "readlines() -- Read all lines");
@ -238,7 +238,7 @@ IO_readlines(IOobject *self, PyObject *args) {
goto err; goto err;
if (n == 0) if (n == 0)
break; break;
line = PyBytes_FromStringAndSize (output, n); line = PyString_FromStringAndSize (output, n);
if (!line) if (!line)
goto err; goto err;
if (PyList_Append (result, line) == -1) { if (PyList_Append (result, line) == -1) {
@ -315,7 +315,7 @@ IO_iternext(Iobject *self)
next = IO_readline((IOobject *)self, NULL); next = IO_readline((IOobject *)self, NULL);
if (!next) if (!next)
return NULL; return NULL;
if (!PyBytes_GET_SIZE(next)) { if (!PyString_GET_SIZE(next)) {
Py_DECREF(next); Py_DECREF(next);
PyErr_SetNone(PyExc_StopIteration); PyErr_SetNone(PyExc_StopIteration);
return NULL; return NULL;
@ -456,7 +456,7 @@ O_writelines(Oobject *self, PyObject *args) {
while ((s = PyIter_Next(it)) != NULL) { while ((s = PyIter_Next(it)) != NULL) {
Py_ssize_t n; Py_ssize_t n;
char *c; char *c;
if (PyBytes_AsStringAndSize(s, &c, &n) == -1) { if (PyString_AsStringAndSize(s, &c, &n) == -1) {
Py_DECREF(it); Py_DECREF(it);
Py_DECREF(s); Py_DECREF(s);
return NULL; return NULL;

View file

@ -239,19 +239,19 @@ CD_readda(cdplayerobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:readda", &numframes)) if (!PyArg_ParseTuple(args, "i:readda", &numframes))
return NULL; return NULL;
result = PyBytes_FromStringAndSize(NULL, numframes * sizeof(CDFRAME)); result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME));
if (result == NULL) if (result == NULL)
return NULL; return NULL;
n = CDreadda(self->ob_cdplayer, n = CDreadda(self->ob_cdplayer,
(CDFRAME *) PyBytes_AsString(result), numframes); (CDFRAME *) PyString_AsString(result), numframes);
if (n == -1) { if (n == -1) {
Py_DECREF(result); Py_DECREF(result);
PyErr_SetFromErrno(CdError); PyErr_SetFromErrno(CdError);
return NULL; return NULL;
} }
if (n < numframes) if (n < numframes)
_PyBytes_Resize(&result, n * sizeof(CDFRAME)); _PyString_Resize(&result, n * sizeof(CDFRAME));
return result; return result;
} }
@ -468,7 +468,7 @@ CD_callback(void *arg, CDDATATYPES type, void *data)
PyTuple_SetItem(args, 1, PyInt_FromLong((long) type)); PyTuple_SetItem(args, 1, PyInt_FromLong((long) type));
switch (type) { switch (type) {
case cd_audio: case cd_audio:
v = PyBytes_FromStringAndSize(data, CDDA_DATASIZE); v = PyString_FromStringAndSize(data, CDDA_DATASIZE);
break; break;
case cd_pnum: case cd_pnum:
case cd_index: case cd_index:
@ -484,15 +484,15 @@ CD_callback(void *arg, CDDATATYPES type, void *data)
#undef ptr #undef ptr
break; break;
case cd_catalog: case cd_catalog:
v = PyBytes_FromStringAndSize(NULL, 13); v = PyString_FromStringAndSize(NULL, 13);
p = PyBytes_AsString(v); p = PyString_AsString(v);
for (i = 0; i < 13; i++) for (i = 0; i < 13; i++)
*p++ = ((char *) data)[i] + '0'; *p++ = ((char *) data)[i] + '0';
break; break;
case cd_ident: case cd_ident:
#define ptr ((struct cdident *) data) #define ptr ((struct cdident *) data)
v = PyBytes_FromStringAndSize(NULL, 12); v = PyString_FromStringAndSize(NULL, 12);
p = PyBytes_AsString(v); p = PyString_AsString(v);
CDsbtoa(p, ptr->country, 2); CDsbtoa(p, ptr->country, 2);
p += 2; p += 2;
CDsbtoa(p, ptr->owner, 3); CDsbtoa(p, ptr->owner, 3);

View file

@ -119,10 +119,10 @@ PyArg_GetString(PyObject *args, int nargs, int i, string *p_arg)
PyObject *v; PyObject *v;
if (!PyArg_GetObject(args, nargs, i, &v)) if (!PyArg_GetObject(args, nargs, i, &v))
return 0; return 0;
if (!PyBytes_Check(v)) { if (!PyString_Check(v)) {
return PyErr_BadArgument(); return PyErr_BadArgument();
} }
*p_arg = PyBytes_AsString(v); *p_arg = PyString_AsString(v);
return 1; return 1;
} }

View file

@ -261,7 +261,7 @@ getcodec(PyObject *self, PyObject *encoding)
const MultibyteCodec *codec; const MultibyteCodec *codec;
const char *enc; const char *enc;
if (!PyBytes_Check(encoding)) { if (!PyString_Check(encoding)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"encoding name must be a string."); "encoding name must be a string.");
return NULL; return NULL;
@ -271,7 +271,7 @@ getcodec(PyObject *self, PyObject *encoding)
if (cofunc == NULL) if (cofunc == NULL)
return NULL; return NULL;
enc = PyBytes_AS_STRING(encoding); enc = PyString_AS_STRING(encoding);
for (codec = codec_list; codec->encoding[0]; codec++) for (codec = codec_list; codec->encoding[0]; codec++)
if (strcmp(codec->encoding, enc) == 0) if (strcmp(codec->encoding, enc) == 0)
break; break;

View file

@ -85,7 +85,7 @@ internal_error_callback(const char *errors)
else if (strcmp(errors, "replace") == 0) else if (strcmp(errors, "replace") == 0)
return ERROR_REPLACE; return ERROR_REPLACE;
else else
return PyBytes_FromString(errors); return PyString_FromString(errors);
} }
static PyObject * static PyObject *
@ -93,8 +93,8 @@ call_error_callback(PyObject *errors, PyObject *exc)
{ {
PyObject *args, *cb, *r; PyObject *args, *cb, *r;
assert(PyBytes_Check(errors)); assert(PyString_Check(errors));
cb = PyCodec_LookupError(PyBytes_AS_STRING(errors)); cb = PyCodec_LookupError(PyString_AS_STRING(errors));
if (cb == NULL) if (cb == NULL)
return NULL; return NULL;
@ -129,7 +129,7 @@ codecctx_errors_get(MultibyteStatefulCodecContext *self)
return self->errors; return self->errors;
} }
return PyBytes_FromString(errors); return PyString_FromString(errors);
} }
static int static int
@ -138,12 +138,12 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
{ {
PyObject *cb; PyObject *cb;
if (!PyBytes_Check(value)) { if (!PyString_Check(value)) {
PyErr_SetString(PyExc_TypeError, "errors must be a string"); PyErr_SetString(PyExc_TypeError, "errors must be a string");
return -1; return -1;
} }
cb = internal_error_callback(PyBytes_AS_STRING(value)); cb = internal_error_callback(PyString_AS_STRING(value));
if (cb == NULL) if (cb == NULL)
return -1; return -1;
@ -166,15 +166,15 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
Py_ssize_t orgpos, orgsize; Py_ssize_t orgpos, orgsize;
orgpos = (Py_ssize_t)((char *)buf->outbuf - orgpos = (Py_ssize_t)((char *)buf->outbuf -
PyBytes_AS_STRING(buf->outobj)); PyString_AS_STRING(buf->outobj));
orgsize = PyBytes_GET_SIZE(buf->outobj); orgsize = PyString_GET_SIZE(buf->outobj);
if (_PyBytes_Resize(&buf->outobj, orgsize + ( if (_PyString_Resize(&buf->outobj, orgsize + (
esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1) esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1)
return -1; return -1;
buf->outbuf = (unsigned char *)PyBytes_AS_STRING(buf->outobj) +orgpos; buf->outbuf = (unsigned char *)PyString_AS_STRING(buf->outobj) +orgpos;
buf->outbuf_end = (unsigned char *)PyBytes_AS_STRING(buf->outobj) buf->outbuf_end = (unsigned char *)PyString_AS_STRING(buf->outobj)
+ PyBytes_GET_SIZE(buf->outobj); + PyString_GET_SIZE(buf->outobj);
return 0; return 0;
} }
@ -322,10 +322,10 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto errorexit; goto errorexit;
} }
retstrsize = PyBytes_GET_SIZE(retstr); retstrsize = PyString_GET_SIZE(retstr);
REQUIRE_ENCODEBUFFER(buf, retstrsize); REQUIRE_ENCODEBUFFER(buf, retstrsize);
memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize); memcpy(buf->outbuf, PyString_AS_STRING(retstr), retstrsize);
buf->outbuf += retstrsize; buf->outbuf += retstrsize;
newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
@ -468,16 +468,16 @@ multibytecodec_encode(MultibyteCodec *codec,
Py_ssize_t finalsize, r = 0; Py_ssize_t finalsize, r = 0;
if (datalen == 0) if (datalen == 0)
return PyBytes_FromString(""); return PyString_FromString("");
buf.excobj = NULL; buf.excobj = NULL;
buf.inbuf = buf.inbuf_top = *data; buf.inbuf = buf.inbuf_top = *data;
buf.inbuf_end = buf.inbuf_top + datalen; buf.inbuf_end = buf.inbuf_top + datalen;
buf.outobj = PyBytes_FromStringAndSize(NULL, datalen * 2 + 16); buf.outobj = PyString_FromStringAndSize(NULL, datalen * 2 + 16);
if (buf.outobj == NULL) if (buf.outobj == NULL)
goto errorexit; goto errorexit;
buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj); buf.outbuf = (unsigned char *)PyString_AS_STRING(buf.outobj);
buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj); buf.outbuf_end = buf.outbuf + PyString_GET_SIZE(buf.outobj);
while (buf.inbuf < buf.inbuf_end) { while (buf.inbuf < buf.inbuf_end) {
Py_ssize_t inleft, outleft; Py_ssize_t inleft, outleft;
@ -512,10 +512,10 @@ multibytecodec_encode(MultibyteCodec *codec,
} }
finalsize = (Py_ssize_t)((char *)buf.outbuf - finalsize = (Py_ssize_t)((char *)buf.outbuf -
PyBytes_AS_STRING(buf.outobj)); PyString_AS_STRING(buf.outobj));
if (finalsize != PyBytes_GET_SIZE(buf.outobj)) if (finalsize != PyString_GET_SIZE(buf.outobj))
if (_PyBytes_Resize(&buf.outobj, finalsize) == -1) if (_PyString_Resize(&buf.outobj, finalsize) == -1)
goto errorexit; goto errorexit;
Py_XDECREF(buf.excobj); Py_XDECREF(buf.excobj);
@ -1222,35 +1222,35 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if (cres == NULL) if (cres == NULL)
goto errorexit; goto errorexit;
if (!PyBytes_Check(cres)) { if (!PyString_Check(cres)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"stream function returned a " "stream function returned a "
"non-string object"); "non-string object");
goto errorexit; goto errorexit;
} }
endoffile = (PyBytes_GET_SIZE(cres) == 0); endoffile = (PyString_GET_SIZE(cres) == 0);
if (self->pendingsize > 0) { if (self->pendingsize > 0) {
PyObject *ctr; PyObject *ctr;
char *ctrdata; char *ctrdata;
rsize = PyBytes_GET_SIZE(cres) + self->pendingsize; rsize = PyString_GET_SIZE(cres) + self->pendingsize;
ctr = PyBytes_FromStringAndSize(NULL, rsize); ctr = PyString_FromStringAndSize(NULL, rsize);
if (ctr == NULL) if (ctr == NULL)
goto errorexit; goto errorexit;
ctrdata = PyBytes_AS_STRING(ctr); ctrdata = PyString_AS_STRING(ctr);
memcpy(ctrdata, self->pending, self->pendingsize); memcpy(ctrdata, self->pending, self->pendingsize);
memcpy(ctrdata + self->pendingsize, memcpy(ctrdata + self->pendingsize,
PyBytes_AS_STRING(cres), PyString_AS_STRING(cres),
PyBytes_GET_SIZE(cres)); PyString_GET_SIZE(cres));
Py_DECREF(cres); Py_DECREF(cres);
cres = ctr; cres = ctr;
self->pendingsize = 0; self->pendingsize = 0;
} }
rsize = PyBytes_GET_SIZE(cres); rsize = PyString_GET_SIZE(cres);
if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres), if (decoder_prepare_buffer(&buf, PyString_AS_STRING(cres),
rsize) != 0) rsize) != 0)
goto errorexit; goto errorexit;
@ -1585,7 +1585,7 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
if (pwrt == NULL) if (pwrt == NULL)
return NULL; return NULL;
if (PyBytes_Size(pwrt) > 0) { if (PyString_Size(pwrt) > 0) {
PyObject *wr; PyObject *wr;
wr = PyObject_CallMethod(self->stream, "write", "O", pwrt); wr = PyObject_CallMethod(self->stream, "write", "O", pwrt);
if (wr == NULL) { if (wr == NULL) {

View file

@ -111,7 +111,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
return NULL; return NULL;
retry: retry:
compressedBuffer = PyBytes_FromStringAndSize(NULL, frameBufferSize); compressedBuffer = PyString_FromStringAndSize(NULL, frameBufferSize);
if (compressedBuffer == NULL) if (compressedBuffer == NULL)
return NULL; return NULL;
@ -120,7 +120,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
if (clCompressImage(compressionScheme, width, height, originalFormat, if (clCompressImage(compressionScheme, width, height, originalFormat,
compressionRatio, (void *) frameBuffer, compressionRatio, (void *) frameBuffer,
&compressedBufferSize, &compressedBufferSize,
(void *) PyBytes_AsString(compressedBuffer)) (void *) PyString_AsString(compressedBuffer))
== FAILURE || error_handler_called) { == FAILURE || error_handler_called) {
Py_DECREF(compressedBuffer); Py_DECREF(compressedBuffer);
if (!error_handler_called) if (!error_handler_called)
@ -135,7 +135,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
} }
if (compressedBufferSize < frameBufferSize) if (compressedBufferSize < frameBufferSize)
_PyBytes_Resize(&compressedBuffer, compressedBufferSize); _PyString_Resize(&compressedBuffer, compressedBufferSize);
return compressedBuffer; return compressedBuffer;
} }
@ -155,14 +155,14 @@ cl_DecompressImage(PyObject *self, PyObject *args)
frameBufferSize = width * height * CL_BytesPerPixel(originalFormat); frameBufferSize = width * height * CL_BytesPerPixel(originalFormat);
frameBuffer = PyBytes_FromStringAndSize(NULL, frameBufferSize); frameBuffer = PyString_FromStringAndSize(NULL, frameBufferSize);
if (frameBuffer == NULL) if (frameBuffer == NULL)
return NULL; return NULL;
error_handler_called = 0; error_handler_called = 0;
if (clDecompressImage(compressionScheme, width, height, originalFormat, if (clDecompressImage(compressionScheme, width, height, originalFormat,
compressedBufferSize, compressedBuffer, compressedBufferSize, compressedBuffer,
(void *) PyBytes_AsString(frameBuffer)) (void *) PyString_AsString(frameBuffer))
== FAILURE || error_handler_called) { == FAILURE || error_handler_called) {
Py_DECREF(frameBuffer); Py_DECREF(frameBuffer);
if (!error_handler_called) if (!error_handler_called)
@ -236,14 +236,14 @@ clm_Compress(PyObject *self, PyObject *args)
if (error_handler_called) if (error_handler_called)
return NULL; return NULL;
data = PyBytes_FromStringAndSize(NULL, size); data = PyString_FromStringAndSize(NULL, size);
if (data == NULL) if (data == NULL)
return NULL; return NULL;
error_handler_called = 0; error_handler_called = 0;
if (clCompress(SELF->ob_compressorHdl, numberOfFrames, if (clCompress(SELF->ob_compressorHdl, numberOfFrames,
(void *) frameBuffer, &compressedBufferSize, (void *) frameBuffer, &compressedBufferSize,
(void *) PyBytes_AsString(data)) == FAILURE || (void *) PyString_AsString(data)) == FAILURE ||
error_handler_called) { error_handler_called) {
Py_DECREF(data); Py_DECREF(data);
if (!error_handler_called) if (!error_handler_called)
@ -252,7 +252,7 @@ clm_Compress(PyObject *self, PyObject *args)
} }
if (compressedBufferSize < size) if (compressedBufferSize < size)
if (_PyBytes_Resize(&data, compressedBufferSize)) if (_PyString_Resize(&data, compressedBufferSize))
return NULL; return NULL;
if (compressedBufferSize > size) { if (compressedBufferSize > size) {
@ -285,14 +285,14 @@ clm_Decompress(PyObject *self, PyObject *args)
if (error_handler_called) if (error_handler_called)
return NULL; return NULL;
data = PyBytes_FromStringAndSize(NULL, dataSize); data = PyString_FromStringAndSize(NULL, dataSize);
if (data == NULL) if (data == NULL)
return NULL; return NULL;
error_handler_called = 0; error_handler_called = 0;
if (clDecompress(SELF->ob_compressorHdl, numberOfFrames, if (clDecompress(SELF->ob_compressorHdl, numberOfFrames,
compressedDataSize, (void *) compressedData, compressedDataSize, (void *) compressedData,
(void *) PyBytes_AsString(data)) == FAILURE || (void *) PyString_AsString(data)) == FAILURE ||
error_handler_called) { error_handler_called) {
Py_DECREF(data); Py_DECREF(data);
if (!error_handler_called) if (!error_handler_called)
@ -514,7 +514,7 @@ clm_QueryParams(PyObject *self)
PyList_SetItem(list, i, Py_None); PyList_SetItem(list, i, Py_None);
} else } else
PyList_SetItem(list, i, PyList_SetItem(list, i,
PyBytes_FromString((char *) PVbuffer[i])); PyString_FromString((char *) PVbuffer[i]));
} }
PyMem_DEL(PVbuffer); PyMem_DEL(PVbuffer);
@ -563,7 +563,7 @@ clm_GetName(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
return PyBytes_FromString(name); return PyString_FromString(name);
} }
static PyObject * static PyObject *
@ -775,7 +775,7 @@ cl_QueryAlgorithms(PyObject *self, PyObject *args)
PyList_SetItem(list, i, Py_None); PyList_SetItem(list, i, Py_None);
} else } else
PyList_SetItem(list, i, PyList_SetItem(list, i,
PyBytes_FromString((char *) PVbuffer[i])); PyString_FromString((char *) PVbuffer[i]));
} }
PyMem_DEL(PVbuffer); PyMem_DEL(PVbuffer);
@ -818,7 +818,7 @@ cl_GetAlgorithmName(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
return PyBytes_FromString(name); return PyString_FromString(name);
} }
static PyObject * static PyObject *

View file

@ -947,7 +947,7 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
else else
result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg); result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);
if (result != NULL && result != Py_None && ! PyBytes_Check(result)) { if (result != NULL && result != Py_None && ! PyString_Check(result)) {
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must " PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
"return None or a string, not '%s'", "return None or a string, not '%s'",
Py_TYPE(result)->tp_name); Py_TYPE(result)->tp_name);
@ -1046,27 +1046,27 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
{ {
PyObject *temp; PyObject *temp;
assert(PyBytes_Check(repr)); assert(PyString_Check(repr));
assert(tzinfo); assert(tzinfo);
if (tzinfo == Py_None) if (tzinfo == Py_None)
return repr; return repr;
/* Get rid of the trailing ')'. */ /* Get rid of the trailing ')'. */
assert(PyBytes_AsString(repr)[PyBytes_Size(repr)-1] == ')'); assert(PyString_AsString(repr)[PyString_Size(repr)-1] == ')');
temp = PyBytes_FromStringAndSize(PyBytes_AsString(repr), temp = PyString_FromStringAndSize(PyString_AsString(repr),
PyBytes_Size(repr) - 1); PyString_Size(repr) - 1);
Py_DECREF(repr); Py_DECREF(repr);
if (temp == NULL) if (temp == NULL)
return NULL; return NULL;
repr = temp; repr = temp;
/* Append ", tzinfo=". */ /* Append ", tzinfo=". */
PyBytes_ConcatAndDel(&repr, PyBytes_FromString(", tzinfo=")); PyString_ConcatAndDel(&repr, PyString_FromString(", tzinfo="));
/* Append repr(tzinfo). */ /* Append repr(tzinfo). */
PyBytes_ConcatAndDel(&repr, PyObject_Repr(tzinfo)); PyString_ConcatAndDel(&repr, PyObject_Repr(tzinfo));
/* Add a closing paren. */ /* Add a closing paren. */
PyBytes_ConcatAndDel(&repr, PyBytes_FromString(")")); PyString_ConcatAndDel(&repr, PyString_FromString(")"));
return repr; return repr;
} }
@ -1092,7 +1092,7 @@ format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
DayNames[wday], MonthNames[GET_MONTH(date) - 1], DayNames[wday], MonthNames[GET_MONTH(date) - 1],
GET_DAY(date), hours, minutes, seconds, GET_DAY(date), hours, minutes, seconds,
GET_YEAR(date)); GET_YEAR(date));
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
/* Add an hours & minutes UTC offset string to buf. buf has no more than /* Add an hours & minutes UTC offset string to buf. buf has no more than
@ -1143,7 +1143,7 @@ make_freplacement(PyObject *object)
else else
sprintf(freplacement, "%06d", 0); sprintf(freplacement, "%06d", 0);
return PyBytes_FromStringAndSize(freplacement, strlen(freplacement)); return PyString_FromStringAndSize(freplacement, strlen(freplacement));
} }
/* I sure don't want to reproduce the strftime code from the time module, /* I sure don't want to reproduce the strftime code from the time module,
@ -1230,7 +1230,7 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
/* format utcoffset */ /* format utcoffset */
char buf[100]; char buf[100];
PyObject *tzinfo = get_tzinfo_member(object); PyObject *tzinfo = get_tzinfo_member(object);
zreplacement = PyBytes_FromString(""); zreplacement = PyString_FromString("");
if (zreplacement == NULL) goto Done; if (zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) { if (tzinfo != Py_None && tzinfo != NULL) {
assert(tzinfoarg != NULL); assert(tzinfoarg != NULL);
@ -1241,19 +1241,19 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
tzinfoarg) < 0) tzinfoarg) < 0)
goto Done; goto Done;
Py_DECREF(zreplacement); Py_DECREF(zreplacement);
zreplacement = PyBytes_FromString(buf); zreplacement = PyString_FromString(buf);
if (zreplacement == NULL) goto Done; if (zreplacement == NULL) goto Done;
} }
} }
assert(zreplacement != NULL); assert(zreplacement != NULL);
ptoappend = PyBytes_AS_STRING(zreplacement); ptoappend = PyString_AS_STRING(zreplacement);
ntoappend = PyBytes_GET_SIZE(zreplacement); ntoappend = PyString_GET_SIZE(zreplacement);
} }
else if (ch == 'Z') { else if (ch == 'Z') {
/* format tzname */ /* format tzname */
if (Zreplacement == NULL) { if (Zreplacement == NULL) {
PyObject *tzinfo = get_tzinfo_member(object); PyObject *tzinfo = get_tzinfo_member(object);
Zreplacement = PyBytes_FromString(""); Zreplacement = PyString_FromString("");
if (Zreplacement == NULL) goto Done; if (Zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) { if (tzinfo != Py_None && tzinfo != NULL) {
PyObject *temp; PyObject *temp;
@ -1261,7 +1261,7 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
temp = call_tzname(tzinfo, tzinfoarg); temp = call_tzname(tzinfo, tzinfoarg);
if (temp == NULL) goto Done; if (temp == NULL) goto Done;
if (temp != Py_None) { if (temp != Py_None) {
assert(PyBytes_Check(temp)); assert(PyString_Check(temp));
/* Since the tzname is getting /* Since the tzname is getting
* stuffed into the format, we * stuffed into the format, we
* have to double any % signs * have to double any % signs
@ -1275,7 +1275,7 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
Py_DECREF(temp); Py_DECREF(temp);
if (Zreplacement == NULL) if (Zreplacement == NULL)
goto Done; goto Done;
if (!PyBytes_Check(Zreplacement)) { if (!PyString_Check(Zreplacement)) {
PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string"); PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string");
goto Done; goto Done;
} }
@ -1285,8 +1285,8 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
} }
} }
assert(Zreplacement != NULL); assert(Zreplacement != NULL);
ptoappend = PyBytes_AS_STRING(Zreplacement); ptoappend = PyString_AS_STRING(Zreplacement);
ntoappend = PyBytes_GET_SIZE(Zreplacement); ntoappend = PyString_GET_SIZE(Zreplacement);
} }
else if (ch == 'f') { else if (ch == 'f') {
/* format microseconds */ /* format microseconds */
@ -1296,9 +1296,9 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
goto Done; goto Done;
} }
assert(freplacement != NULL); assert(freplacement != NULL);
assert(PyBytes_Check(freplacement)); assert(PyString_Check(freplacement));
ptoappend = PyBytes_AS_STRING(freplacement); ptoappend = PyString_AS_STRING(freplacement);
ntoappend = PyBytes_GET_SIZE(freplacement); ntoappend = PyString_GET_SIZE(freplacement);
} }
else { else {
/* percent followed by neither z nor Z */ /* percent followed by neither z nor Z */
@ -1319,10 +1319,10 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
PyErr_NoMemory(); PyErr_NoMemory();
goto Done; goto Done;
} }
if (_PyBytes_Resize(&newfmt, bigger) < 0) if (_PyString_Resize(&newfmt, bigger) < 0)
goto Done; goto Done;
totalnew = bigger; totalnew = bigger;
pnew = PyBytes_AsString(newfmt) + usednew; pnew = PyString_AsString(newfmt) + usednew;
} }
memcpy(pnew, ptoappend, ntoappend); memcpy(pnew, ptoappend, ntoappend);
pnew += ntoappend; pnew += ntoappend;
@ -1330,7 +1330,7 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
assert(usednew <= totalnew); assert(usednew <= totalnew);
} /* end while() */ } /* end while() */
if (_PyBytes_Resize(&newfmt, usednew) < 0) if (_PyString_Resize(&newfmt, usednew) < 0)
goto Done; goto Done;
{ {
PyObject *time = PyImport_ImportModuleNoBlock("time"); PyObject *time = PyImport_ImportModuleNoBlock("time");
@ -2008,18 +2008,18 @@ static PyObject *
delta_repr(PyDateTime_Delta *self) delta_repr(PyDateTime_Delta *self)
{ {
if (GET_TD_MICROSECONDS(self) != 0) if (GET_TD_MICROSECONDS(self) != 0)
return PyBytes_FromFormat("%s(%d, %d, %d)", return PyString_FromFormat("%s(%d, %d, %d)",
Py_TYPE(self)->tp_name, Py_TYPE(self)->tp_name,
GET_TD_DAYS(self), GET_TD_DAYS(self),
GET_TD_SECONDS(self), GET_TD_SECONDS(self),
GET_TD_MICROSECONDS(self)); GET_TD_MICROSECONDS(self));
if (GET_TD_SECONDS(self) != 0) if (GET_TD_SECONDS(self) != 0)
return PyBytes_FromFormat("%s(%d, %d)", return PyString_FromFormat("%s(%d, %d)",
Py_TYPE(self)->tp_name, Py_TYPE(self)->tp_name,
GET_TD_DAYS(self), GET_TD_DAYS(self),
GET_TD_SECONDS(self)); GET_TD_SECONDS(self));
return PyBytes_FromFormat("%s(%d)", return PyString_FromFormat("%s(%d)",
Py_TYPE(self)->tp_name, Py_TYPE(self)->tp_name,
GET_TD_DAYS(self)); GET_TD_DAYS(self));
} }
@ -2063,7 +2063,7 @@ delta_str(PyDateTime_Delta *self)
pbuf += n; pbuf += n;
} }
return PyBytes_FromStringAndSize(buf, pbuf - buf); return PyString_FromStringAndSize(buf, pbuf - buf);
Fail: Fail:
PyErr_SetString(PyExc_SystemError, "goofy result from PyOS_snprintf"); PyErr_SetString(PyExc_SystemError, "goofy result from PyOS_snprintf");
@ -2242,15 +2242,15 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */ /* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) == 1 && if (PyTuple_GET_SIZE(args) == 1 &&
PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) && PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
PyBytes_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE && PyString_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
MONTH_IS_SANE(PyBytes_AS_STRING(state)[2])) MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
{ {
PyDateTime_Date *me; PyDateTime_Date *me;
me = (PyDateTime_Date *) (type->tp_alloc(type, 0)); me = (PyDateTime_Date *) (type->tp_alloc(type, 0));
if (me != NULL) { if (me != NULL) {
char *pdata = PyBytes_AS_STRING(state); char *pdata = PyString_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE); memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
me->hashcode = -1; me->hashcode = -1;
} }
@ -2448,7 +2448,7 @@ date_repr(PyDateTime_Date *self)
type_name, type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self)); GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
static PyObject * static PyObject *
@ -2457,7 +2457,7 @@ date_isoformat(PyDateTime_Date *self)
char buffer[128]; char buffer[128];
isoformat_date(self, buffer, sizeof(buffer)); isoformat_date(self, buffer, sizeof(buffer));
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
/* str() calls the appropriate isoformat() method. */ /* str() calls the appropriate isoformat() method. */
@ -2508,9 +2508,9 @@ date_format(PyDateTime_Date *self, PyObject *args)
return NULL; return NULL;
/* Check for str or unicode */ /* Check for str or unicode */
if (PyBytes_Check(format)) { if (PyString_Check(format)) {
/* If format is zero length, return str(self) */ /* If format is zero length, return str(self) */
if (PyBytes_GET_SIZE(format) == 0) if (PyString_GET_SIZE(format) == 0)
return PyObject_Str((PyObject *)self); return PyObject_Str((PyObject *)self);
} else if (PyUnicode_Check(format)) { } else if (PyUnicode_Check(format)) {
/* If format is zero length, return str(self) */ /* If format is zero length, return str(self) */
@ -2653,7 +2653,7 @@ date_getstate(PyDateTime_Date *self)
{ {
return Py_BuildValue( return Py_BuildValue(
"(N)", "(N)",
PyBytes_FromStringAndSize((char *)self->data, PyString_FromStringAndSize((char *)self->data,
_PyDateTime_DATE_DATASIZE)); _PyDateTime_DATE_DATASIZE));
} }
@ -3109,9 +3109,9 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */ /* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) >= 1 && if (PyTuple_GET_SIZE(args) >= 1 &&
PyTuple_GET_SIZE(args) <= 2 && PyTuple_GET_SIZE(args) <= 2 &&
PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) && PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
PyBytes_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE && PyString_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
((unsigned char) (PyBytes_AS_STRING(state)[0])) < 24) ((unsigned char) (PyString_AS_STRING(state)[0])) < 24)
{ {
PyDateTime_Time *me; PyDateTime_Time *me;
char aware; char aware;
@ -3127,7 +3127,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
aware = (char)(tzinfo != Py_None); aware = (char)(tzinfo != Py_None);
me = (PyDateTime_Time *) (type->tp_alloc(type, aware)); me = (PyDateTime_Time *) (type->tp_alloc(type, aware));
if (me != NULL) { if (me != NULL) {
char *pdata = PyBytes_AS_STRING(state); char *pdata = PyString_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE); memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE);
me->hashcode = -1; me->hashcode = -1;
@ -3213,7 +3213,7 @@ time_repr(PyDateTime_Time *self)
else else
PyOS_snprintf(buffer, sizeof(buffer), PyOS_snprintf(buffer, sizeof(buffer),
"%s(%d, %d)", type_name, h, m); "%s(%d, %d)", type_name, h, m);
result = PyBytes_FromString(buffer); result = PyString_FromString(buffer);
if (result != NULL && HASTZINFO(self)) if (result != NULL && HASTZINFO(self))
result = append_keyword_tzinfo(result, self->tzinfo); result = append_keyword_tzinfo(result, self->tzinfo);
return result; return result;
@ -3240,7 +3240,7 @@ time_isoformat(PyDateTime_Time *self, PyObject *unused)
_PyDateTime_TIME_DATASIZE); _PyDateTime_TIME_DATASIZE);
isoformat_time(pdatetime, buf, sizeof(buf)); isoformat_time(pdatetime, buf, sizeof(buf));
result = PyBytes_FromString(buf); result = PyString_FromString(buf);
if (result == NULL || ! HASTZINFO(self) || self->tzinfo == Py_None) if (result == NULL || ! HASTZINFO(self) || self->tzinfo == Py_None)
return result; return result;
@ -3250,7 +3250,7 @@ time_isoformat(PyDateTime_Time *self, PyObject *unused)
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
PyBytes_ConcatAndDel(&result, PyBytes_FromString(buf)); PyString_ConcatAndDel(&result, PyString_FromString(buf));
return result; return result;
} }
@ -3364,7 +3364,7 @@ time_hash(PyDateTime_Time *self)
/* Reduce this to a hash of another object. */ /* Reduce this to a hash of another object. */
if (offset == 0) if (offset == 0)
temp = PyBytes_FromStringAndSize((char *)self->data, temp = PyString_FromStringAndSize((char *)self->data,
_PyDateTime_TIME_DATASIZE); _PyDateTime_TIME_DATASIZE);
else { else {
int hour; int hour;
@ -3452,7 +3452,7 @@ time_getstate(PyDateTime_Time *self)
PyObject *basestate; PyObject *basestate;
PyObject *result = NULL; PyObject *result = NULL;
basestate = PyBytes_FromStringAndSize((char *)self->data, basestate = PyString_FromStringAndSize((char *)self->data,
_PyDateTime_TIME_DATASIZE); _PyDateTime_TIME_DATASIZE);
if (basestate != NULL) { if (basestate != NULL) {
if (! HASTZINFO(self) || self->tzinfo == Py_None) if (! HASTZINFO(self) || self->tzinfo == Py_None)
@ -3639,9 +3639,9 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */ /* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) >= 1 && if (PyTuple_GET_SIZE(args) >= 1 &&
PyTuple_GET_SIZE(args) <= 2 && PyTuple_GET_SIZE(args) <= 2 &&
PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) && PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
PyBytes_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE && PyString_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
MONTH_IS_SANE(PyBytes_AS_STRING(state)[2])) MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
{ {
PyDateTime_DateTime *me; PyDateTime_DateTime *me;
char aware; char aware;
@ -3657,7 +3657,7 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
aware = (char)(tzinfo != Py_None); aware = (char)(tzinfo != Py_None);
me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware)); me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware));
if (me != NULL) { if (me != NULL) {
char *pdata = PyBytes_AS_STRING(state); char *pdata = PyString_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE); memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE);
me->hashcode = -1; me->hashcode = -1;
@ -4166,7 +4166,7 @@ datetime_repr(PyDateTime_DateTime *self)
GET_YEAR(self), GET_MONTH(self), GET_DAY(self), GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
DATE_GET_HOUR(self), DATE_GET_MINUTE(self)); DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
} }
baserepr = PyBytes_FromString(buffer); baserepr = PyString_FromString(buffer);
if (baserepr == NULL || ! HASTZINFO(self)) if (baserepr == NULL || ! HASTZINFO(self))
return baserepr; return baserepr;
return append_keyword_tzinfo(baserepr, self->tzinfo); return append_keyword_tzinfo(baserepr, self->tzinfo);
@ -4194,7 +4194,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
assert(cp != NULL); assert(cp != NULL);
*cp++ = sep; *cp++ = sep;
isoformat_time(self, cp, sizeof(buffer) - (cp - buffer)); isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
result = PyBytes_FromString(buffer); result = PyString_FromString(buffer);
if (result == NULL || ! HASTZINFO(self)) if (result == NULL || ! HASTZINFO(self))
return result; return result;
@ -4204,7 +4204,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
PyBytes_ConcatAndDel(&result, PyBytes_FromString(buffer)); PyString_ConcatAndDel(&result, PyString_FromString(buffer));
return result; return result;
} }
@ -4310,7 +4310,7 @@ datetime_hash(PyDateTime_DateTime *self)
/* Reduce this to a hash of another object. */ /* Reduce this to a hash of another object. */
if (n == OFFSET_NAIVE) if (n == OFFSET_NAIVE)
temp = PyBytes_FromStringAndSize( temp = PyString_FromStringAndSize(
(char *)self->data, (char *)self->data,
_PyDateTime_DATETIME_DATASIZE); _PyDateTime_DATETIME_DATASIZE);
else { else {
@ -4533,7 +4533,7 @@ datetime_getstate(PyDateTime_DateTime *self)
PyObject *basestate; PyObject *basestate;
PyObject *result = NULL; PyObject *result = NULL;
basestate = PyBytes_FromStringAndSize((char *)self->data, basestate = PyString_FromStringAndSize((char *)self->data,
_PyDateTime_DATETIME_DATASIZE); _PyDateTime_DATETIME_DATASIZE);
if (basestate != NULL) { if (basestate != NULL) {
if (! HASTZINFO(self) || self->tzinfo == Py_None) if (! HASTZINFO(self) || self->tzinfo == Py_None)

View file

@ -104,7 +104,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
drec = dbm_fetch(dp->di_dbm, krec); drec = dbm_fetch(dp->di_dbm, krec);
if ( drec.dptr == 0 ) { if ( drec.dptr == 0 ) {
PyErr_SetString(PyExc_KeyError, PyErr_SetString(PyExc_KeyError,
PyBytes_AS_STRING((PyBytesObject *)key)); PyString_AS_STRING((PyStringObject *)key));
return NULL; return NULL;
} }
if ( dbm_error(dp->di_dbm) ) { if ( dbm_error(dp->di_dbm) ) {
@ -112,7 +112,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
PyErr_SetString(DbmError, ""); PyErr_SetString(DbmError, "");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(drec.dptr, drec.dsize); return PyString_FromStringAndSize(drec.dptr, drec.dsize);
} }
static int static int
@ -136,7 +136,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
if ( dbm_delete(dp->di_dbm, krec) < 0 ) { if ( dbm_delete(dp->di_dbm, krec) < 0 ) {
dbm_clearerr(dp->di_dbm); dbm_clearerr(dp->di_dbm);
PyErr_SetString(PyExc_KeyError, PyErr_SetString(PyExc_KeyError,
PyBytes_AS_STRING((PyBytesObject *)v)); PyString_AS_STRING((PyStringObject *)v));
return -1; return -1;
} }
} else { } else {
@ -166,7 +166,7 @@ dbm_contains(register dbmobject *dp, PyObject *v)
{ {
datum key, val; datum key, val;
if (PyBytes_AsStringAndSize(v, (char **)&key.dptr, if (PyString_AsStringAndSize(v, (char **)&key.dptr,
(Py_ssize_t *)&key.dsize)) { (Py_ssize_t *)&key.dsize)) {
return -1; return -1;
} }
@ -222,7 +222,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
return NULL; return NULL;
for (key = dbm_firstkey(dp->di_dbm); key.dptr; for (key = dbm_firstkey(dp->di_dbm); key.dptr;
key = dbm_nextkey(dp->di_dbm)) { key = dbm_nextkey(dp->di_dbm)) {
item = PyBytes_FromStringAndSize(key.dptr, key.dsize); item = PyString_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) { if (item == NULL) {
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
@ -269,7 +269,7 @@ dbm_get(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
return PyBytes_FromStringAndSize(val.dptr, val.dsize); return PyString_FromStringAndSize(val.dptr, val.dsize);
else { else {
Py_INCREF(defvalue); Py_INCREF(defvalue);
return defvalue; return defvalue;
@ -292,16 +292,16 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
return PyBytes_FromStringAndSize(val.dptr, val.dsize); return PyString_FromStringAndSize(val.dptr, val.dsize);
if (defvalue == NULL) { if (defvalue == NULL) {
defvalue = PyBytes_FromStringAndSize(NULL, 0); defvalue = PyString_FromStringAndSize(NULL, 0);
if (defvalue == NULL) if (defvalue == NULL)
return NULL; return NULL;
} }
else else
Py_INCREF(defvalue); Py_INCREF(defvalue);
val.dptr = PyBytes_AS_STRING(defvalue); val.dptr = PyString_AS_STRING(defvalue);
val.dsize = PyBytes_GET_SIZE(defvalue); val.dsize = PyString_GET_SIZE(defvalue);
if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) { if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) {
dbm_clearerr(dp->di_dbm); dbm_clearerr(dp->di_dbm);
PyErr_SetString(DbmError, "cannot add item to database"); PyErr_SetString(DbmError, "cannot add item to database");
@ -404,7 +404,7 @@ initdbm(void) {
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
if (DbmError == NULL) if (DbmError == NULL)
DbmError = PyErr_NewException("dbm.error", NULL, NULL); DbmError = PyErr_NewException("dbm.error", NULL, NULL);
s = PyBytes_FromString(which_dbm); s = PyString_FromString(which_dbm);
if (s != NULL) { if (s != NULL) {
PyDict_SetItemString(d, "library", s); PyDict_SetItemString(d, "library", s);
Py_DECREF(s); Py_DECREF(s);

View file

@ -58,8 +58,8 @@ dl_sym(dlobject *xp, PyObject *args)
{ {
char *name; char *name;
PyUnivPtr *func; PyUnivPtr *func;
if (PyBytes_Check(args)) { if (PyString_Check(args)) {
name = PyBytes_AS_STRING(args); name = PyString_AS_STRING(args);
} else { } else {
PyErr_Format(PyExc_TypeError, "expected string, found %.200s", PyErr_Format(PyExc_TypeError, "expected string, found %.200s",
Py_TYPE(args)->tp_name); Py_TYPE(args)->tp_name);
@ -88,14 +88,14 @@ dl_call(dlobject *xp, PyObject *args)
return NULL; return NULL;
} }
name = PyTuple_GetItem(args, 0); name = PyTuple_GetItem(args, 0);
if (!PyBytes_Check(name)) { if (!PyString_Check(name)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"function name must be a string"); "function name must be a string");
return NULL; return NULL;
} }
func = (long (*)(long, long, long, long, long, func = (long (*)(long, long, long, long, long,
long, long, long, long, long)) long, long, long, long, long))
dlsym(xp->dl_handle, PyBytes_AsString(name)); dlsym(xp->dl_handle, PyString_AsString(name));
if (func == NULL) { if (func == NULL) {
PyErr_SetString(PyExc_ValueError, dlerror()); PyErr_SetString(PyExc_ValueError, dlerror());
return NULL; return NULL;
@ -109,8 +109,8 @@ dl_call(dlobject *xp, PyObject *args)
PyObject *v = PyTuple_GetItem(args, i); PyObject *v = PyTuple_GetItem(args, i);
if (PyInt_Check(v)) if (PyInt_Check(v))
alist[i-1] = PyInt_AsLong(v); alist[i-1] = PyInt_AsLong(v);
else if (PyBytes_Check(v)) else if (PyString_Check(v))
alist[i-1] = (long)PyBytes_AsString(v); alist[i-1] = (long)PyString_AsString(v);
else if (v == Py_None) else if (v == Py_None)
alist[i-1] = (long) ((char *)NULL); alist[i-1] = (long) ((char *)NULL);
else { else {

View file

@ -21,7 +21,7 @@ static PyMethodDef errno_methods[] = {
static void static void
_inscode(PyObject *d, PyObject *de, char *name, int code) _inscode(PyObject *d, PyObject *de, char *name, int code)
{ {
PyObject *u = PyBytes_FromString(name); PyObject *u = PyString_FromString(name);
PyObject *v = PyInt_FromLong((long) code); PyObject *v = PyInt_FromLong((long) code);
/* Don't bother checking for errors; they'll be caught at the end /* Don't bother checking for errors; they'll be caught at the end

View file

@ -55,7 +55,7 @@ fcntl_fcntl(PyObject *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError); PyErr_SetFromErrno(PyExc_IOError);
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(buf, len); return PyString_FromStringAndSize(buf, len);
} }
PyErr_Clear(); PyErr_Clear();
@ -164,7 +164,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
return PyInt_FromLong(ret); return PyInt_FromLong(ret);
} }
else { else {
return PyBytes_FromStringAndSize(buf, len); return PyString_FromStringAndSize(buf, len);
} }
} }
@ -185,7 +185,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError); PyErr_SetFromErrno(PyExc_IOError);
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(buf, len); return PyString_FromStringAndSize(buf, len);
} }
PyErr_Clear(); PyErr_Clear();

View file

@ -324,7 +324,7 @@ generic_getattr(genericobject *g, char *name)
/* "label" is an exception, getmember only works for char pointers, /* "label" is an exception, getmember only works for char pointers,
not for char arrays */ not for char arrays */
if (strcmp(name, "label") == 0) if (strcmp(name, "label") == 0)
return PyBytes_FromString(g->ob_generic->label); return PyString_FromString(g->ob_generic->label);
return PyMember_Get((char *)g->ob_generic, generic_memberlist, name); return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
} }
@ -343,12 +343,12 @@ generic_setattr(genericobject *g, char *name, PyObject *v)
/* "label" is an exception: setmember doesn't set strings; /* "label" is an exception: setmember doesn't set strings;
and FORMS wants you to call a function to set the label */ and FORMS wants you to call a function to set the label */
if (strcmp(name, "label") == 0) { if (strcmp(name, "label") == 0) {
if (!PyBytes_Check(v)) { if (!PyString_Check(v)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"label attr must be string"); "label attr must be string");
return -1; return -1;
} }
fl_set_object_label(g->ob_generic, PyBytes_AsString(v)); fl_set_object_label(g->ob_generic, PyString_AsString(v));
return 0; return 0;
} }
@ -369,7 +369,7 @@ generic_repr(genericobject *g)
char buf[100]; char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>", PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
g, g->ob_generic->objclass); g, g->ob_generic->objclass);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static PyTypeObject GenericObjecttype = { static PyTypeObject GenericObjecttype = {
@ -530,7 +530,7 @@ call_forms_Rstr (char * (*func)(FL_OBJECT *), FL_OBJECT *obj)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString (str); return PyString_FromString (str);
} }
/* int func (object) */ /* int func (object) */
@ -628,7 +628,7 @@ get_browser_line(genericobject *g, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString (str); return PyString_FromString (str);
} }
static PyObject * static PyObject *
@ -1594,7 +1594,7 @@ form_repr(formobject *f)
char buf[100]; char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>", PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
f, f->ob_form->window); f, f->ob_form->window);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static PyTypeObject Formtype = { static PyTypeObject Formtype = {
@ -2027,7 +2027,7 @@ forms_show_input(PyObject *f, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString(str); return PyString_FromString(str);
} }
static PyObject * static PyObject *
@ -2046,7 +2046,7 @@ forms_file_selector(PyObject *f, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString(str); return PyString_FromString(str);
} }
@ -2061,7 +2061,7 @@ forms_file_selector_func(PyObject *args, char *(*func)(void))
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString(str); return PyString_FromString(str);
} }
static PyObject * static PyObject *

View file

@ -66,7 +66,7 @@ fh_getfontname(fhobject *self)
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname"); PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(fontname, len); return PyString_FromStringAndSize(fontname, len);
} }
static PyObject * static PyObject *
@ -79,7 +79,7 @@ fh_getcomment(fhobject *self)
PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment"); PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(comment, len); return PyString_FromStringAndSize(comment, len);
} }
static PyObject * static PyObject *
@ -200,7 +200,7 @@ clientproc(char *fontname)
PyObject *v; PyObject *v;
if (fontlist == NULL) if (fontlist == NULL)
return; return;
v = PyBytes_FromString(fontname); v = PyString_FromString(fontname);
if (v == NULL) if (v == NULL)
err = -1; err = -1;
else { else {
@ -240,7 +240,7 @@ fm_setpath(PyObject *self, PyObject *args)
static PyObject * static PyObject *
fm_fontpath(PyObject *self) fm_fontpath(PyObject *self)
{ {
return PyBytes_FromString(fmfontpath()); return PyString_FromString(fmfontpath());
} }
static PyMethodDef fm_methods[] = { static PyMethodDef fm_methods[] = {

View file

@ -639,8 +639,8 @@ debug_instance(char *msg, PyInstanceObject *inst)
char *cname; char *cname;
/* simple version of instance_repr */ /* simple version of instance_repr */
PyObject *classname = inst->in_class->cl_name; PyObject *classname = inst->in_class->cl_name;
if (classname != NULL && PyBytes_Check(classname)) if (classname != NULL && PyString_Check(classname))
cname = PyBytes_AsString(classname); cname = PyString_AsString(classname);
else else
cname = "?"; cname = "?";
PySys_WriteStderr("gc: %.100s <%.100s instance at %p>\n", PySys_WriteStderr("gc: %.100s <%.100s instance at %p>\n",
@ -754,7 +754,7 @@ collect(int generation)
double t1 = 0.0; double t1 = 0.0;
if (delstr == NULL) { if (delstr == NULL) {
delstr = PyBytes_InternFromString("__del__"); delstr = PyString_InternFromString("__del__");
if (delstr == NULL) if (delstr == NULL)
Py_FatalError("gc couldn't allocate \"__del__\""); Py_FatalError("gc couldn't allocate \"__del__\"");
} }
@ -898,7 +898,7 @@ collect(int generation)
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
if (gc_str == NULL) if (gc_str == NULL)
gc_str = PyBytes_FromString("garbage collection"); gc_str = PyString_FromString("garbage collection");
PyErr_WriteUnraisable(gc_str); PyErr_WriteUnraisable(gc_str);
Py_FatalError("unexpected exception during garbage collection"); Py_FatalError("unexpected exception during garbage collection");
} }

View file

@ -128,10 +128,10 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
drec = gdbm_fetch(dp->di_dbm, krec); drec = gdbm_fetch(dp->di_dbm, krec);
if (drec.dptr == 0) { if (drec.dptr == 0) {
PyErr_SetString(PyExc_KeyError, PyErr_SetString(PyExc_KeyError,
PyBytes_AS_STRING((PyBytesObject *)key)); PyString_AS_STRING((PyStringObject *)key));
return NULL; return NULL;
} }
v = PyBytes_FromStringAndSize(drec.dptr, drec.dsize); v = PyString_FromStringAndSize(drec.dptr, drec.dsize);
free(drec.dptr); free(drec.dptr);
return v; return v;
} }
@ -155,7 +155,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
if (w == NULL) { if (w == NULL) {
if (gdbm_delete(dp->di_dbm, krec) < 0) { if (gdbm_delete(dp->di_dbm, krec) < 0) {
PyErr_SetString(PyExc_KeyError, PyErr_SetString(PyExc_KeyError,
PyBytes_AS_STRING((PyBytesObject *)v)); PyString_AS_STRING((PyStringObject *)v));
return -1; return -1;
} }
} }
@ -188,14 +188,14 @@ dbm_contains(register dbmobject *dp, PyObject *arg)
"GDBM object has already been closed"); "GDBM object has already been closed");
return -1; return -1;
} }
if (!PyBytes_Check(arg)) { if (!PyString_Check(arg)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"gdbm key must be string, not %.100s", "gdbm key must be string, not %.100s",
arg->ob_type->tp_name); arg->ob_type->tp_name);
return -1; return -1;
} }
key.dptr = PyBytes_AS_STRING(arg); key.dptr = PyString_AS_STRING(arg);
key.dsize = PyBytes_GET_SIZE(arg); key.dsize = PyString_GET_SIZE(arg);
return gdbm_exists(dp->di_dbm, key); return gdbm_exists(dp->di_dbm, key);
} }
@ -255,7 +255,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
key = gdbm_firstkey(dp->di_dbm); key = gdbm_firstkey(dp->di_dbm);
while (key.dptr) { while (key.dptr) {
item = PyBytes_FromStringAndSize(key.dptr, key.dsize); item = PyString_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) { if (item == NULL) {
free(key.dptr); free(key.dptr);
Py_DECREF(v); Py_DECREF(v);
@ -306,7 +306,7 @@ dbm_firstkey(register dbmobject *dp, PyObject *unused)
check_dbmobject_open(dp); check_dbmobject_open(dp);
key = gdbm_firstkey(dp->di_dbm); key = gdbm_firstkey(dp->di_dbm);
if (key.dptr) { if (key.dptr) {
v = PyBytes_FromStringAndSize(key.dptr, key.dsize); v = PyString_FromStringAndSize(key.dptr, key.dsize);
free(key.dptr); free(key.dptr);
return v; return v;
} }
@ -338,7 +338,7 @@ dbm_nextkey(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp); check_dbmobject_open(dp);
nextkey = gdbm_nextkey(dp->di_dbm, key); nextkey = gdbm_nextkey(dp->di_dbm, key);
if (nextkey.dptr) { if (nextkey.dptr) {
v = PyBytes_FromStringAndSize(nextkey.dptr, nextkey.dsize); v = PyString_FromStringAndSize(nextkey.dptr, nextkey.dsize);
free(nextkey.dptr); free(nextkey.dptr);
return v; return v;
} }
@ -541,7 +541,7 @@ initgdbm(void) {
DbmError = PyErr_NewException("gdbm.error", NULL, NULL); DbmError = PyErr_NewException("gdbm.error", NULL, NULL);
if (DbmError != NULL) { if (DbmError != NULL) {
PyDict_SetItemString(d, "error", DbmError); PyDict_SetItemString(d, "error", DbmError);
s = PyBytes_FromString(dbmmodule_open_flags); s = PyString_FromString(dbmmodule_open_flags);
PyDict_SetItemString(d, "open_flags", s); PyDict_SetItemString(d, "open_flags", s);
Py_DECREF(s); Py_DECREF(s);
} }

View file

@ -593,7 +593,7 @@ gl_lrectwrite(PyObject *self, PyObject *args)
#if 0 #if 0
/* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */ /* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
if (!PyBytes_Check(s) || PyBytes_Size(s) != pixcount*sizeof(long)) { if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"string arg to lrectwrite has wrong size"); "string arg to lrectwrite has wrong size");
return NULL; return NULL;
@ -623,10 +623,10 @@ gl_lrectread(PyObject *self, PyObject *args)
if (!PyArg_GetShort(args, 4, 3, &y2)) if (!PyArg_GetShort(args, 4, 3, &y2))
return NULL; return NULL;
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
parray = PyBytes_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (parray == NULL) if (parray == NULL)
return NULL; /* No memory */ return NULL; /* No memory */
lrectread(x1, y1, x2, y2, (unsigned long *) PyBytes_AsString(parray)); lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray));
return parray; return parray;
} }
@ -642,10 +642,10 @@ gl_readdisplay(PyObject *self, PyObject *args)
if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) ) if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
return 0; return 0;
size = (long)(x2+1-x1) * (long)(y2+1-y1); size = (long)(x2+1-x1) * (long)(y2+1-y1);
rv = PyBytes_FromStringAndSize((char *)NULL, size*sizeof(long)); rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
if ( rv == NULL ) if ( rv == NULL )
return NULL; return NULL;
parray = (unsigned long *)PyBytes_AsString(rv); parray = (unsigned long *)PyString_AsString(rv);
size_ret = readdisplay(x1, y1, x2, y2, parray, hints); size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
if ( size_ret != size ) { if ( size_ret != size ) {
printf("gl_readdisplay: got %ld pixels, expected %ld\n", printf("gl_readdisplay: got %ld pixels, expected %ld\n",
@ -700,16 +700,16 @@ gl_packrect(PyObject *self, PyObject *args)
pixcount = width*height; pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) * packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor); ((height+packfactor-1)/packfactor);
if (PyBytes_Size(unpacked) != pixcount*sizeof(long)) { if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"string arg to packrect has wrong size"); "string arg to packrect has wrong size");
return NULL; return NULL;
} }
packed = PyBytes_FromStringAndSize((char *)NULL, packedcount); packed = PyString_FromStringAndSize((char *)NULL, packedcount);
if (packed == NULL) if (packed == NULL)
return NULL; return NULL;
parray = (unsigned long *) PyBytes_AsString(unpacked); parray = (unsigned long *) PyString_AsString(unpacked);
p = (unsigned char *) PyBytes_AsString(packed); p = (unsigned char *) PyString_AsString(packed);
for (y = 0; y < height; y += packfactor, parray += packfactor*width) { for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
for (x = 0; x < width; x += packfactor) { for (x = 0; x < width; x += packfactor) {
pixel = parray[x]; pixel = parray[x];
@ -758,16 +758,16 @@ gl_unpackrect(PyObject *self, PyObject *args)
pixcount = width*height; pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) * packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor); ((height+packfactor-1)/packfactor);
if (PyBytes_Size(packed) != packedcount) { if (PyString_Size(packed) != packedcount) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"string arg to unpackrect has wrong size"); "string arg to unpackrect has wrong size");
return NULL; return NULL;
} }
unpacked = PyBytes_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (unpacked == NULL) if (unpacked == NULL)
return NULL; return NULL;
parray = (unsigned long *) PyBytes_AsString(unpacked); parray = (unsigned long *) PyString_AsString(unpacked);
p = (unsigned char *) PyBytes_AsString(packed); p = (unsigned char *) PyString_AsString(packed);
if (packfactor == 1 && width*height > 0) { if (packfactor == 1 && width*height > 0) {
/* Just expand bytes to longs */ /* Just expand bytes to longs */
register int x = width * height; register int x = width * height;
@ -799,7 +799,7 @@ gl_gversion(PyObject *self, PyObject *args)
{ {
char buf[20]; char buf[20];
gversion(buf); gversion(buf);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }

View file

@ -47,7 +47,7 @@ mkgrent(struct group *p)
return NULL; return NULL;
} }
for (member = p->gr_mem; *member != NULL; member++) { for (member = p->gr_mem; *member != NULL; member++) {
PyObject *x = PyBytes_FromString(*member); PyObject *x = PyString_FromString(*member);
if (x == NULL || PyList_Append(w, x) != 0) { if (x == NULL || PyList_Append(w, x) != 0) {
Py_XDECREF(x); Py_XDECREF(x);
Py_DECREF(w); Py_DECREF(w);
@ -58,13 +58,13 @@ mkgrent(struct group *p)
} }
#define SET(i,val) PyStructSequence_SET_ITEM(v, i, val) #define SET(i,val) PyStructSequence_SET_ITEM(v, i, val)
SET(setIndex++, PyBytes_FromString(p->gr_name)); SET(setIndex++, PyString_FromString(p->gr_name));
#ifdef __VMS #ifdef __VMS
SET(setIndex++, Py_None); SET(setIndex++, Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);
#else #else
if (p->gr_passwd) if (p->gr_passwd)
SET(setIndex++, PyBytes_FromString(p->gr_passwd)); SET(setIndex++, PyString_FromString(p->gr_passwd));
else { else {
SET(setIndex++, Py_None); SET(setIndex++, Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -113,7 +113,7 @@ grp_getgrnam(PyObject *self, PyObject *pyo_name)
py_str_name = PyObject_Str(pyo_name); py_str_name = PyObject_Str(pyo_name);
if (!py_str_name) if (!py_str_name)
return NULL; return NULL;
name = PyBytes_AS_STRING(py_str_name); name = PyString_AS_STRING(py_str_name);
if ((p = getgrnam(name)) == NULL) { if ((p = getgrnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name); PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name);

View file

@ -54,7 +54,7 @@ imageop_backward_compatible(void)
return 1; return 1;
if (bcos == NULL) { if (bcos == NULL) {
/* cache string object for future use */ /* cache string object for future use */
bcos = PyBytes_FromString("backward_compatible"); bcos = PyString_FromString("backward_compatible");
if (bcos == NULL) if (bcos == NULL)
return 1; return 1;
} }
@ -97,11 +97,11 @@ imageop_crop(PyObject *self, PyObject *args)
xstep = (newx1 < newx2)? 1 : -1; xstep = (newx1 < newx2)? 1 : -1;
ystep = (newy1 < newy2)? 1 : -1; ystep = (newy1 < newy2)? 1 : -1;
rv = PyBytes_FromStringAndSize(NULL, rv = PyString_FromStringAndSize(NULL,
(abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size); (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (char *)PyBytes_AsString(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (Py_Int32 *)ncp; nlp = (Py_Int32 *)ncp;
newy2 += ystep; newy2 += ystep;
@ -150,10 +150,10 @@ imageop_scale(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, newx*newy*size); rv = PyString_FromStringAndSize(NULL, newx*newy*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (char *)PyBytes_AsString(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (Py_Int32 *)ncp; nlp = (Py_Int32 *)ncp;
for( iy = 0; iy < newy; iy++ ) { for( iy = 0; iy < newy; iy++ ) {
@ -195,10 +195,10 @@ imageop_tovideo(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, len); rv = PyString_FromStringAndSize(NULL, len);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
if ( width == 1 ) { if ( width == 1 ) {
memcpy(ncp, cp, maxx); /* Copy first line */ memcpy(ncp, cp, maxx); /* Copy first line */
@ -245,10 +245,10 @@ imageop_grey2mono(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len+7)/8); rv = PyString_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
ovalue = 0; ovalue = 0;
@ -286,10 +286,10 @@ imageop_grey2grey4(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len+1)/2); rv = PyString_FromStringAndSize(NULL, (len+1)/2);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
@ -325,10 +325,10 @@ imageop_grey2grey2(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len+3)/4); rv = PyString_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
@ -363,10 +363,10 @@ imageop_dither2mono(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len+7)/8); rv = PyString_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
ovalue = 0; ovalue = 0;
@ -409,10 +409,10 @@ imageop_dither2grey2(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, (len+3)/4); rv = PyString_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 1; pos = 1;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
@ -449,10 +449,10 @@ imageop_mono2grey(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
@ -486,10 +486,10 @@ imageop_grey22grey(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
@ -522,10 +522,10 @@ imageop_grey42grey(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
@ -559,10 +559,10 @@ imageop_rgb2rgb8(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
/* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */ /* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */
@ -603,10 +603,10 @@ imageop_rgb82rgb(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
/* Bits in source: RRRBBGGG /* Bits in source: RRRBBGGG
@ -653,10 +653,10 @@ imageop_rgb2grey(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
if (backward_compatible) { if (backward_compatible) {
@ -698,10 +698,10 @@ imageop_grey2rgb(PyObject *self, PyObject *args)
return 0; return 0;
} }
rv = PyBytes_FromStringAndSize(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)PyBytes_AsString(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
value = *cp++; value = *cp++;

View file

@ -130,12 +130,12 @@ imgfile_read(PyObject *self, PyObject *args)
} }
if ( zsize == 3 ) zsize = 4; if ( zsize == 3 ) zsize = 4;
rv = PyBytes_FromStringAndSize((char *)NULL, xsize*ysize*zsize); rv = PyString_FromStringAndSize((char *)NULL, xsize*ysize*zsize);
if ( rv == NULL ) { if ( rv == NULL ) {
iclose(image); iclose(image);
return NULL; return NULL;
} }
cdatap = PyBytes_AsString(rv); cdatap = PyString_AsString(rv);
idatap = (long *)cdatap; idatap = (long *)cdatap;
if (top_to_bottom) { if (top_to_bottom) {
@ -319,7 +319,7 @@ imgfile_readscaled(PyObject *self, PyObject *args)
} }
if ( zsize == 3 ) zsize = 4; if ( zsize == 3 ) zsize = 4;
rv = PyBytes_FromStringAndSize(NULL, xwtd*ywtd*zsize); rv = PyString_FromStringAndSize(NULL, xwtd*ywtd*zsize);
if ( rv == NULL ) { if ( rv == NULL ) {
iclose(image); iclose(image);
return NULL; return NULL;
@ -328,7 +328,7 @@ imgfile_readscaled(PyObject *self, PyObject *args)
xfac = (float)xsize/(float)xwtd; xfac = (float)xsize/(float)xwtd;
yfac = (float)ysize/(float)ywtd; yfac = (float)ysize/(float)ywtd;
PyFPE_END_PROTECT(yfac) PyFPE_END_PROTECT(yfac)
cdatap = PyBytes_AsString(rv); cdatap = PyString_AsString(rv);
idatap = (long *)cdatap; idatap = (long *)cdatap;
if ( extended ) { if ( extended ) {

View file

@ -2904,12 +2904,12 @@ count_repr(countobject *lz)
PyObject *result; PyObject *result;
if (lz->cnt != PY_SSIZE_T_MAX) if (lz->cnt != PY_SSIZE_T_MAX)
return PyBytes_FromFormat("count(%zd)", lz->cnt); return PyString_FromFormat("count(%zd)", lz->cnt);
cnt_repr = PyObject_Repr(lz->long_cnt); cnt_repr = PyObject_Repr(lz->long_cnt);
if (cnt_repr == NULL) if (cnt_repr == NULL)
return NULL; return NULL;
result = PyBytes_FromFormat("count(%s)", PyBytes_AS_STRING(cnt_repr)); result = PyString_FromFormat("count(%s)", PyString_AS_STRING(cnt_repr));
Py_DECREF(cnt_repr); Py_DECREF(cnt_repr);
return result; return result;
} }
@ -3221,11 +3221,11 @@ repeat_repr(repeatobject *ro)
return NULL; return NULL;
if (ro->cnt == -1) if (ro->cnt == -1)
result = PyBytes_FromFormat("repeat(%s)", result = PyString_FromFormat("repeat(%s)",
PyBytes_AS_STRING(objrepr)); PyString_AS_STRING(objrepr));
else else
result = PyBytes_FromFormat("repeat(%s, %zd)", result = PyString_FromFormat("repeat(%s, %zd)",
PyBytes_AS_STRING(objrepr), ro->cnt); PyString_AS_STRING(objrepr), ro->cnt);
Py_DECREF(objrepr); Py_DECREF(objrepr);
return result; return result;
} }

View file

@ -162,17 +162,17 @@ lad_read(lad_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size)) if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL; return NULL;
rv = PyBytes_FromStringAndSize(NULL, size); rv = PyString_FromStringAndSize(NULL, size);
if (rv == NULL) if (rv == NULL)
return NULL; return NULL;
cp = PyBytes_AS_STRING(rv); cp = PyString_AS_STRING(rv);
if ((count = read(self->x_fd, cp, size)) < 0) { if ((count = read(self->x_fd, cp, size)) < 0) {
PyErr_SetFromErrno(LinuxAudioError); PyErr_SetFromErrno(LinuxAudioError);
Py_DECREF(rv); Py_DECREF(rv);
return NULL; return NULL;
} }
self->x_icount += count; self->x_icount += count;
_PyBytes_Resize(&rv, count); _PyString_Resize(&rv, count);
return rv; return rv;
} }

View file

@ -196,7 +196,7 @@ static int RunMainFromImporter(char *filename)
{ {
PyObject *argv0 = NULL, *importer = NULL; PyObject *argv0 = NULL, *importer = NULL;
if ((argv0 = PyBytes_FromString(filename)) && if ((argv0 = PyString_FromString(filename)) &&
(importer = PyImport_GetImporter(argv0)) && (importer = PyImport_GetImporter(argv0)) &&
(importer->ob_type != &PyNullImporter_Type)) (importer->ob_type != &PyNullImporter_Type))
{ {

View file

@ -80,7 +80,7 @@ md5_digest(md5object *self)
mdContext = self->md5; mdContext = self->md5;
md5_finish(&mdContext, aDigest); md5_finish(&mdContext, aDigest);
return PyBytes_FromStringAndSize((char *)aDigest, 16); return PyString_FromStringAndSize((char *)aDigest, 16);
} }
PyDoc_STRVAR(digest_doc, PyDoc_STRVAR(digest_doc,
@ -113,7 +113,7 @@ md5_hexdigest(md5object *self)
c = (c>9) ? c+'a'-10 : c + '0'; c = (c>9) ? c+'a'-10 : c + '0';
hexdigest[j++] = c; hexdigest[j++] = c;
} }
return PyBytes_FromStringAndSize((char*)hexdigest, 32); return PyString_FromStringAndSize((char*)hexdigest, 32);
} }
@ -165,7 +165,7 @@ md5_get_digest_size(PyObject *self, void *closure)
static PyObject * static PyObject *
md5_get_name(PyObject *self, void *closure) md5_get_name(PyObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize("MD5", 3); return PyString_FromStringAndSize("MD5", 3);
} }
static PyGetSetDef md5_getseters[] = { static PyGetSetDef md5_getseters[] = {

View file

@ -222,7 +222,7 @@ mmap_read_line_method(mmap_object *self,
else else
++eol; /* we're interested in the position after the ++eol; /* we're interested in the position after the
newline. */ newline. */
result = PyBytes_FromStringAndSize(start, (eol - start)); result = PyString_FromStringAndSize(start, (eol - start));
self->pos += (eol - start); self->pos += (eol - start);
return result; return result;
} }
@ -700,7 +700,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "mmap index out of range"); PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(self->data + i, 1); return PyString_FromStringAndSize(self->data + i, 1);
} }
static PyObject * static PyObject *
@ -718,7 +718,7 @@ mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
else if ((size_t)ihigh > self->size) else if ((size_t)ihigh > self->size)
ihigh = self->size; ihigh = self->size;
return PyBytes_FromStringAndSize(self->data + ilow, ihigh-ilow); return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
} }
static PyObject * static PyObject *
@ -736,7 +736,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
"mmap index out of range"); "mmap index out of range");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(self->data + i, 1); return PyString_FromStringAndSize(self->data + i, 1);
} }
else if (PySlice_Check(item)) { else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelen; Py_ssize_t start, stop, step, slicelen;
@ -747,9 +747,9 @@ mmap_subscript(mmap_object *self, PyObject *item)
} }
if (slicelen <= 0) if (slicelen <= 0)
return PyBytes_FromStringAndSize("", 0); return PyString_FromStringAndSize("", 0);
else if (step == 1) else if (step == 1)
return PyBytes_FromStringAndSize(self->data + start, return PyString_FromStringAndSize(self->data + start,
slicelen); slicelen);
else { else {
char *result_buf = (char *)PyMem_Malloc(slicelen); char *result_buf = (char *)PyMem_Malloc(slicelen);
@ -762,7 +762,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
cur += step, i++) { cur += step, i++) {
result_buf[i] = self->data[cur]; result_buf[i] = self->data[cur];
} }
result = PyBytes_FromStringAndSize(result_buf, result = PyString_FromStringAndSize(result_buf,
slicelen); slicelen);
PyMem_Free(result_buf); PyMem_Free(result_buf);
return result; return result;
@ -815,19 +815,19 @@ mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v
"mmap object doesn't support slice deletion"); "mmap object doesn't support slice deletion");
return -1; return -1;
} }
if (! (PyBytes_Check(v)) ) { if (! (PyString_Check(v)) ) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap slice assignment must be a string"); "mmap slice assignment must be a string");
return -1; return -1;
} }
if (PyBytes_Size(v) != (ihigh - ilow)) { if (PyString_Size(v) != (ihigh - ilow)) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap slice assignment is wrong size"); "mmap slice assignment is wrong size");
return -1; return -1;
} }
if (!is_writeable(self)) if (!is_writeable(self))
return -1; return -1;
buf = PyBytes_AsString(v); buf = PyString_AsString(v);
memcpy(self->data + ilow, buf, ihigh-ilow); memcpy(self->data + ilow, buf, ihigh-ilow);
return 0; return 0;
} }
@ -847,14 +847,14 @@ mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
"mmap object doesn't support item deletion"); "mmap object doesn't support item deletion");
return -1; return -1;
} }
if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) { if (! (PyString_Check(v) && PyString_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap assignment must be single-character string"); "mmap assignment must be single-character string");
return -1; return -1;
} }
if (!is_writeable(self)) if (!is_writeable(self))
return -1; return -1;
buf = PyBytes_AsString(v); buf = PyString_AsString(v);
self->data[i] = buf[0]; self->data[i] = buf[0];
return 0; return 0;
} }
@ -882,14 +882,14 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
"mmap object doesn't support item deletion"); "mmap object doesn't support item deletion");
return -1; return -1;
} }
if (!PyBytes_Check(value) || PyBytes_Size(value) != 1) { if (!PyString_Check(value) || PyString_Size(value) != 1) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap assignment must be single-character string"); "mmap assignment must be single-character string");
return -1; return -1;
} }
if (!is_writeable(self)) if (!is_writeable(self))
return -1; return -1;
buf = PyBytes_AsString(value); buf = PyString_AsString(value);
self->data[i] = buf[0]; self->data[i] = buf[0];
return 0; return 0;
} }
@ -906,12 +906,12 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
"mmap object doesn't support slice deletion"); "mmap object doesn't support slice deletion");
return -1; return -1;
} }
if (!PyBytes_Check(value)) { if (!PyString_Check(value)) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap slice assignment must be a string"); "mmap slice assignment must be a string");
return -1; return -1;
} }
if (PyBytes_Size(value) != slicelen) { if (PyString_Size(value) != slicelen) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap slice assignment is wrong size"); "mmap slice assignment is wrong size");
return -1; return -1;
@ -922,7 +922,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
if (slicelen == 0) if (slicelen == 0)
return 0; return 0;
else if (step == 1) { else if (step == 1) {
const char *buf = PyBytes_AsString(value); const char *buf = PyString_AsString(value);
if (buf == NULL) if (buf == NULL)
return -1; return -1;
@ -931,7 +931,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
} }
else { else {
Py_ssize_t cur, i; Py_ssize_t cur, i;
const char *buf = PyBytes_AsString(value); const char *buf = PyString_AsString(value);
if (buf == NULL) if (buf == NULL)
return -1; return -1;

View file

@ -115,8 +115,8 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
if (invallen > 0 && inval[invallen-1] == '\0') if (invallen > 0 && inval[invallen-1] == '\0')
invallen--; invallen--;
} }
key = PyBytes_FromStringAndSize(inkey, inkeylen); key = PyString_FromStringAndSize(inkey, inkeylen);
val = PyBytes_FromStringAndSize(inval, invallen); val = PyString_FromStringAndSize(inval, invallen);
if (key == NULL || val == NULL) { if (key == NULL || val == NULL) {
/* XXX error -- don't know how to handle */ /* XXX error -- don't know how to handle */
PyErr_Clear(); PyErr_Clear();
@ -146,7 +146,7 @@ nis_get_default_domain (PyObject *self)
if ((err = yp_get_default_domain(&domain)) != 0) if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err); return nis_error(err);
res = PyBytes_FromStringAndSize (domain, strlen(domain)); res = PyString_FromStringAndSize (domain, strlen(domain));
return res; return res;
} }
@ -178,7 +178,7 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict)
len--; len--;
if (err != 0) if (err != 0)
return nis_error(err); return nis_error(err);
res = PyBytes_FromStringAndSize (match, len); res = PyString_FromStringAndSize (match, len);
free (match); free (match);
return res; return res;
} }
@ -398,7 +398,7 @@ nis_maps (PyObject *self, PyObject *args, PyObject *kwdict)
if ((list = PyList_New(0)) == NULL) if ((list = PyList_New(0)) == NULL)
return NULL; return NULL;
for (maps = maps; maps; maps = maps->next) { for (maps = maps; maps; maps = maps->next) {
PyObject *str = PyBytes_FromString(maps->map); PyObject *str = PyString_FromString(maps->map);
if (!str || PyList_Append(list, str) < 0) if (!str || PyList_Append(list, str) < 0)
{ {
Py_DECREF(list); Py_DECREF(list);

View file

@ -508,19 +508,19 @@ dotted_getattr(PyObject *obj, PyObject *attr)
} }
#endif #endif
if (!PyBytes_Check(attr)) { if (!PyString_Check(attr)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"attribute name must be a string"); "attribute name must be a string");
return NULL; return NULL;
} }
s = PyBytes_AS_STRING(attr); s = PyString_AS_STRING(attr);
Py_INCREF(obj); Py_INCREF(obj);
for (;;) { for (;;) {
PyObject *newobj, *str; PyObject *newobj, *str;
p = strchr(s, '.'); p = strchr(s, '.');
str = p ? PyBytes_FromStringAndSize(s, (p-s)) : str = p ? PyString_FromStringAndSize(s, (p-s)) :
PyBytes_FromString(s); PyString_FromString(s);
if (str == NULL) { if (str == NULL) {
Py_DECREF(obj); Py_DECREF(obj);
return NULL; return NULL;

View file

@ -366,10 +366,10 @@ oss_read(oss_audio_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size)) if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL; return NULL;
rv = PyBytes_FromStringAndSize(NULL, size); rv = PyString_FromStringAndSize(NULL, size);
if (rv == NULL) if (rv == NULL)
return NULL; return NULL;
cp = PyBytes_AS_STRING(rv); cp = PyString_AS_STRING(rv);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
count = read(self->fd, cp, size); count = read(self->fd, cp, size);
@ -381,7 +381,7 @@ oss_read(oss_audio_t *self, PyObject *args)
return NULL; return NULL;
} }
self->icount += count; self->icount += count;
_PyBytes_Resize(&rv, count); _PyString_Resize(&rv, count);
return rv; return rv;
} }
@ -811,20 +811,20 @@ oss_getattr(oss_audio_t *self, char *name)
Py_INCREF(rval); Py_INCREF(rval);
} }
else if (strcmp(name, "name") == 0) { else if (strcmp(name, "name") == 0) {
rval = PyBytes_FromString(self->devicename); rval = PyString_FromString(self->devicename);
} }
else if (strcmp(name, "mode") == 0) { else if (strcmp(name, "mode") == 0) {
/* No need for a "default" in this switch: from newossobject(), /* No need for a "default" in this switch: from newossobject(),
self->mode can only be one of these three values. */ self->mode can only be one of these three values. */
switch(self->mode) { switch(self->mode) {
case O_RDONLY: case O_RDONLY:
rval = PyBytes_FromString("r"); rval = PyString_FromString("r");
break; break;
case O_RDWR: case O_RDWR:
rval = PyBytes_FromString("rw"); rval = PyString_FromString("rw");
break; break;
case O_WRONLY: case O_WRONLY:
rval = PyBytes_FromString("w"); rval = PyString_FromString("w");
break; break;
} }
} }
@ -913,12 +913,12 @@ build_namelists (PyObject *module)
if (labels == NULL || names == NULL) if (labels == NULL || names == NULL)
goto error2; goto error2;
for (i = 0; i < num_controls; i++) { for (i = 0; i < num_controls; i++) {
s = PyBytes_FromString(control_labels[i]); s = PyString_FromString(control_labels[i]);
if (s == NULL) if (s == NULL)
goto error2; goto error2;
PyList_SET_ITEM(labels, i, s); PyList_SET_ITEM(labels, i, s);
s = PyBytes_FromString(control_names[i]); s = PyString_FromString(control_names[i]);
if (s == NULL) if (s == NULL)
goto error2; goto error2;
PyList_SET_ITEM(names, i, s); PyList_SET_ITEM(names, i, s);

View file

@ -105,14 +105,14 @@ node2tuple(node *n, /* node to convert */
} }
if (TYPE(n) == encoding_decl) if (TYPE(n) == encoding_decl)
(void) addelem(v, i+1, PyBytes_FromString(STR(n))); (void) addelem(v, i+1, PyString_FromString(STR(n)));
return (v); return (v);
} }
else if (ISTERMINAL(TYPE(n))) { else if (ISTERMINAL(TYPE(n))) {
PyObject *result = mkseq(2 + lineno + col_offset); PyObject *result = mkseq(2 + lineno + col_offset);
if (result != NULL) { if (result != NULL) {
(void) addelem(result, 0, PyInt_FromLong(TYPE(n))); (void) addelem(result, 0, PyInt_FromLong(TYPE(n)));
(void) addelem(result, 1, PyBytes_FromString(STR(n))); (void) addelem(result, 1, PyString_FromString(STR(n)));
if (lineno == 1) if (lineno == 1)
(void) addelem(result, 2, PyInt_FromLong(n->n_lineno)); (void) addelem(result, 2, PyInt_FromLong(n->n_lineno));
if (col_offset == 1) if (col_offset == 1)
@ -689,7 +689,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
temp = PySequence_GetItem(elem, 1); temp = PySequence_GetItem(elem, 1);
if (temp == NULL) if (temp == NULL)
return 0; return 0;
if (!PyBytes_Check(temp)) { if (!PyString_Check(temp)) {
PyErr_Format(parser_error, PyErr_Format(parser_error,
"second item in terminal node must be a string," "second item in terminal node must be a string,"
" found %s", " found %s",
@ -714,10 +714,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
Py_DECREF(o); Py_DECREF(o);
} }
} }
len = PyBytes_GET_SIZE(temp) + 1; len = PyString_GET_SIZE(temp) + 1;
strn = (char *)PyObject_MALLOC(len); strn = (char *)PyObject_MALLOC(len);
if (strn != NULL) if (strn != NULL)
(void) memcpy(strn, PyBytes_AS_STRING(temp), len); (void) memcpy(strn, PyString_AS_STRING(temp), len);
Py_DECREF(temp); Py_DECREF(temp);
} }
else if (!ISNONTERMINAL(type)) { else if (!ISNONTERMINAL(type)) {
@ -800,10 +800,10 @@ build_node_tree(PyObject *tuple)
} }
if (res && encoding) { if (res && encoding) {
Py_ssize_t len; Py_ssize_t len;
len = PyBytes_GET_SIZE(encoding) + 1; len = PyString_GET_SIZE(encoding) + 1;
res->n_str = (char *)PyObject_MALLOC(len); res->n_str = (char *)PyObject_MALLOC(len);
if (res->n_str != NULL) if (res->n_str != NULL)
(void) memcpy(res->n_str, PyBytes_AS_STRING(encoding), len); (void) memcpy(res->n_str, PyString_AS_STRING(encoding), len);
Py_DECREF(encoding); Py_DECREF(encoding);
Py_DECREF(tuple); Py_DECREF(tuple);
} }

View file

@ -375,12 +375,12 @@ convertenviron(void)
char *p = strchr(*e, '='); char *p = strchr(*e, '=');
if (p == NULL) if (p == NULL)
continue; continue;
k = PyBytes_FromStringAndSize(*e, (int)(p-*e)); k = PyString_FromStringAndSize(*e, (int)(p-*e));
if (k == NULL) { if (k == NULL) {
PyErr_Clear(); PyErr_Clear();
continue; continue;
} }
v = PyBytes_FromString(p+1); v = PyString_FromString(p+1);
if (v == NULL) { if (v == NULL) {
PyErr_Clear(); PyErr_Clear();
Py_DECREF(k); Py_DECREF(k);
@ -400,13 +400,13 @@ convertenviron(void)
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH); rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */ if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
PyObject *v = PyBytes_FromString(buffer); PyObject *v = PyString_FromString(buffer);
PyDict_SetItemString(d, "BEGINLIBPATH", v); PyDict_SetItemString(d, "BEGINLIBPATH", v);
Py_DECREF(v); Py_DECREF(v);
} }
rc = DosQueryExtLIBPATH(buffer, END_LIBPATH); rc = DosQueryExtLIBPATH(buffer, END_LIBPATH);
if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */ if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */
PyObject *v = PyBytes_FromString(buffer); PyObject *v = PyString_FromString(buffer);
PyDict_SetItemString(d, "ENDLIBPATH", v); PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v); Py_DECREF(v);
} }
@ -1598,7 +1598,7 @@ posix_ttyname(PyObject *self, PyObject *args)
#endif #endif
if (ret == NULL) if (ret == NULL)
return posix_error(); return posix_error();
return PyBytes_FromString(ret); return PyString_FromString(ret);
} }
#endif #endif
@ -1620,7 +1620,7 @@ posix_ctermid(PyObject *self, PyObject *noargs)
#endif #endif
if (ret == NULL) if (ret == NULL)
return posix_error(); return posix_error();
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
#endif #endif
@ -1968,7 +1968,7 @@ posix_getcwd(PyObject *self, PyObject *noargs)
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (res == NULL) if (res == NULL)
return posix_error(); return posix_error();
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
@ -2174,7 +2174,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* Skip over . and .. */ /* Skip over . and .. */
if (strcmp(FileData.cFileName, ".") != 0 && if (strcmp(FileData.cFileName, ".") != 0 &&
strcmp(FileData.cFileName, "..") != 0) { strcmp(FileData.cFileName, "..") != 0) {
v = PyBytes_FromString(FileData.cFileName); v = PyString_FromString(FileData.cFileName);
if (v == NULL) { if (v == NULL) {
Py_DECREF(d); Py_DECREF(d);
d = NULL; d = NULL;
@ -2262,7 +2262,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* Leave Case of Name Alone -- In Native Form */ /* Leave Case of Name Alone -- In Native Form */
/* (Removed Forced Lowercasing Code) */ /* (Removed Forced Lowercasing Code) */
v = PyBytes_FromString(namebuf); v = PyString_FromString(namebuf);
if (v == NULL) { if (v == NULL) {
Py_DECREF(d); Py_DECREF(d);
d = NULL; d = NULL;
@ -2312,7 +2312,7 @@ posix_listdir(PyObject *self, PyObject *args)
(NAMLEN(ep) == 1 || (NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2))) (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
continue; continue;
v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep)); v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep));
if (v == NULL) { if (v == NULL) {
Py_DECREF(d); Py_DECREF(d);
d = NULL; d = NULL;
@ -2397,7 +2397,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
return PyUnicode_Decode(outbuf, strlen(outbuf), return PyUnicode_Decode(outbuf, strlen(outbuf),
Py_FileSystemDefaultEncoding, NULL); Py_FileSystemDefaultEncoding, NULL);
} }
return PyBytes_FromString(outbuf); return PyString_FromString(outbuf);
} /* end of posix__getfullpathname */ } /* end of posix__getfullpathname */
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
@ -3062,7 +3062,7 @@ posix_execve(PyObject *self, PyObject *args)
/* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */ /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) { if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif #endif
len = PyBytes_Size(key) + PyBytes_Size(val) + 2; len = PyString_Size(key) + PyString_Size(val) + 2;
p = PyMem_NEW(char, len); p = PyMem_NEW(char, len);
if (p == NULL) { if (p == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
@ -3292,7 +3292,7 @@ posix_spawnve(PyObject *self, PyObject *args)
{ {
goto fail_2; goto fail_2;
} }
len = PyBytes_Size(key) + PyBytes_Size(val) + 2; len = PyString_Size(key) + PyString_Size(val) + 2;
p = PyMem_NEW(char, len); p = PyMem_NEW(char, len);
if (p == NULL) { if (p == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
@ -3525,7 +3525,7 @@ posix_spawnvpe(PyObject *self, PyObject *args)
{ {
goto fail_2; goto fail_2;
} }
len = PyBytes_Size(key) + PyBytes_Size(val) + 2; len = PyString_Size(key) + PyString_Size(val) + 2;
p = PyMem_NEW(char, len); p = PyMem_NEW(char, len);
if (p == NULL) { if (p == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
@ -3895,7 +3895,7 @@ posix_getlogin(PyObject *self, PyObject *noargs)
"unable to determine login name"); "unable to determine login name");
} }
else else
result = PyBytes_FromString(name); result = PyString_FromString(name);
errno = old_errno; errno = old_errno;
return result; return result;
@ -5884,7 +5884,7 @@ posix_readlink(PyObject *self, PyObject *args)
return posix_error_with_allocated_filename(path); return posix_error_with_allocated_filename(path);
PyMem_Free(path); PyMem_Free(path);
v = PyBytes_FromStringAndSize(buf, n); v = PyString_FromStringAndSize(buf, n);
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
if (arg_is_unicode) { if (arg_is_unicode) {
PyObject *w; PyObject *w;
@ -6289,18 +6289,18 @@ posix_read(PyObject *self, PyObject *args)
errno = EINVAL; errno = EINVAL;
return posix_error(); return posix_error();
} }
buffer = PyBytes_FromStringAndSize((char *)NULL, size); buffer = PyString_FromStringAndSize((char *)NULL, size);
if (buffer == NULL) if (buffer == NULL)
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
n = read(fd, PyBytes_AsString(buffer), size); n = read(fd, PyString_AsString(buffer), size);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (n < 0) { if (n < 0) {
Py_DECREF(buffer); Py_DECREF(buffer);
return posix_error(); return posix_error();
} }
if (n != size) if (n != size)
_PyBytes_Resize(&buffer, n); _PyString_Resize(&buffer, n);
return buffer; return buffer;
} }
@ -6647,11 +6647,11 @@ posix_putenv(PyObject *self, PyObject *args)
/* XXX This can leak memory -- not easy to fix :-( */ /* XXX This can leak memory -- not easy to fix :-( */
len = strlen(s1) + strlen(s2) + 2; len = strlen(s1) + strlen(s2) + 2;
/* len includes space for a trailing \0; the size arg to /* len includes space for a trailing \0; the size arg to
PyBytes_FromStringAndSize does not count that */ PyString_FromStringAndSize does not count that */
newstr = PyBytes_FromStringAndSize(NULL, (int)len - 1); newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
if (newstr == NULL) if (newstr == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
newenv = PyBytes_AS_STRING(newstr); newenv = PyString_AS_STRING(newstr);
PyOS_snprintf(newenv, len, "%s=%s", s1, s2); PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
if (putenv(newenv)) { if (putenv(newenv)) {
Py_DECREF(newstr); Py_DECREF(newstr);
@ -6727,7 +6727,7 @@ posix_strerror(PyObject *self, PyObject *args)
"strerror() argument out of range"); "strerror() argument out of range");
return NULL; return NULL;
} }
return PyBytes_FromString(message); return PyString_FromString(message);
} }
@ -7009,7 +7009,7 @@ posix_tempnam(PyObject *self, PyObject *args)
#endif #endif
if (name == NULL) if (name == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
result = PyBytes_FromString(name); result = PyString_FromString(name);
free(name); free(name);
return result; return result;
} }
@ -7066,7 +7066,7 @@ posix_tmpnam(PyObject *self, PyObject *noargs)
Py_XDECREF(err); Py_XDECREF(err);
return NULL; return NULL;
} }
return PyBytes_FromString(buffer); return PyString_FromString(buffer);
} }
#endif #endif
@ -7095,13 +7095,13 @@ conv_confname(PyObject *arg, int *valuep, struct constdef *table,
*valuep = PyInt_AS_LONG(arg); *valuep = PyInt_AS_LONG(arg);
return 1; return 1;
} }
if (PyBytes_Check(arg)) { if (PyString_Check(arg)) {
/* look up the value in the table using a binary search */ /* look up the value in the table using a binary search */
size_t lo = 0; size_t lo = 0;
size_t mid; size_t mid;
size_t hi = tablesize; size_t hi = tablesize;
int cmp; int cmp;
char *confname = PyBytes_AS_STRING(arg); char *confname = PyString_AS_STRING(arg);
while (lo < hi) { while (lo < hi) {
mid = (lo + hi) / 2; mid = (lo + hi) / 2;
cmp = strcmp(confname, table[mid].name); cmp = strcmp(confname, table[mid].name);
@ -7431,12 +7431,12 @@ posix_confstr(PyObject *self, PyObject *args)
} }
else { else {
if ((unsigned int)len >= sizeof(buffer)) { if ((unsigned int)len >= sizeof(buffer)) {
result = PyBytes_FromStringAndSize(NULL, len-1); result = PyString_FromStringAndSize(NULL, len-1);
if (result != NULL) if (result != NULL)
confstr(name, PyBytes_AS_STRING(result), len); confstr(name, PyString_AS_STRING(result), len);
} }
else else
result = PyBytes_FromStringAndSize(buffer, len-1); result = PyString_FromStringAndSize(buffer, len-1);
} }
} }
return result; return result;
@ -8225,11 +8225,11 @@ win32_urandom(PyObject *self, PyObject *args)
} }
/* Allocate bytes */ /* Allocate bytes */
result = PyBytes_FromStringAndSize(NULL, howMany); result = PyString_FromStringAndSize(NULL, howMany);
if (result != NULL) { if (result != NULL) {
/* Get random data */ /* Get random data */
if (! pCryptGenRandom(hCryptProv, howMany, (unsigned char*) if (! pCryptGenRandom(hCryptProv, howMany, (unsigned char*)
PyBytes_AS_STRING(result))) { PyString_AS_STRING(result))) {
Py_DECREF(result); Py_DECREF(result);
return win32_error("CryptGenRandom", NULL); return win32_error("CryptGenRandom", NULL);
} }
@ -8259,11 +8259,11 @@ vms_urandom(PyObject *self, PyObject *args)
"negative argument not allowed"); "negative argument not allowed");
/* Allocate bytes */ /* Allocate bytes */
result = PyBytes_FromStringAndSize(NULL, howMany); result = PyString_FromStringAndSize(NULL, howMany);
if (result != NULL) { if (result != NULL) {
/* Get random data */ /* Get random data */
if (RAND_pseudo_bytes((unsigned char*) if (RAND_pseudo_bytes((unsigned char*)
PyBytes_AS_STRING(result), PyString_AS_STRING(result),
howMany) < 0) { howMany) < 0) {
Py_DECREF(result); Py_DECREF(result);
return PyErr_Format(PyExc_ValueError, return PyErr_Format(PyExc_ValueError,

View file

@ -49,7 +49,7 @@ static void
sets(PyObject *v, int i, char* val) sets(PyObject *v, int i, char* val)
{ {
if (val) if (val)
PyStructSequence_SET_ITEM(v, i, PyBytes_FromString(val)); PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
else { else {
PyStructSequence_SET_ITEM(v, i, Py_None); PyStructSequence_SET_ITEM(v, i, Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);

View file

@ -153,7 +153,7 @@ get_handler_name(struct HandlerInfo *hinfo)
{ {
PyObject *name = hinfo->nameobj; PyObject *name = hinfo->nameobj;
if (name == NULL) { if (name == NULL) {
name = PyBytes_FromString(hinfo->name); name = PyString_FromString(hinfo->name);
hinfo->nameobj = name; hinfo->nameobj = name;
} }
Py_XINCREF(name); Py_XINCREF(name);
@ -205,7 +205,7 @@ conv_string_to_utf8(const XML_Char *str)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromString(str); return PyString_FromString(str);
} }
static PyObject * static PyObject *
@ -218,7 +218,7 @@ conv_string_len_to_utf8(const XML_Char *str, int len)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
return PyBytes_FromStringAndSize((const char *)str, len); return PyString_FromStringAndSize((const char *)str, len);
} }
/* Callback routines */ /* Callback routines */
@ -267,16 +267,16 @@ getcode(enum HandlerTypes slot, char* func_name, int lineno)
PyObject *filename = NULL; PyObject *filename = NULL;
if (handler_info[slot].tb_code == NULL) { if (handler_info[slot].tb_code == NULL) {
code = PyBytes_FromString(""); code = PyString_FromString("");
if (code == NULL) if (code == NULL)
goto failed; goto failed;
name = PyBytes_FromString(func_name); name = PyString_FromString(func_name);
if (name == NULL) if (name == NULL)
goto failed; goto failed;
nulltuple = PyTuple_New(0); nulltuple = PyTuple_New(0);
if (nulltuple == NULL) if (nulltuple == NULL)
goto failed; goto failed;
filename = PyBytes_FromString(__FILE__); filename = PyString_FromString(__FILE__);
handler_info[slot].tb_code = handler_info[slot].tb_code =
PyCode_New(0, /* argcount */ PyCode_New(0, /* argcount */
0, /* nlocals */ 0, /* nlocals */
@ -971,13 +971,13 @@ readinst(char *buf, int buf_size, PyObject *meth)
goto finally; goto finally;
/* XXX what to do if it returns a Unicode string? */ /* XXX what to do if it returns a Unicode string? */
if (!PyBytes_Check(str)) { if (!PyString_Check(str)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"read() did not return a string object (type=%.400s)", "read() did not return a string object (type=%.400s)",
Py_TYPE(str)->tp_name); Py_TYPE(str)->tp_name);
goto finally; goto finally;
} }
len = PyBytes_GET_SIZE(str); len = PyString_GET_SIZE(str);
if (len > buf_size) { if (len > buf_size) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"read() returned too much data: " "read() returned too much data: "
@ -985,7 +985,7 @@ readinst(char *buf, int buf_size, PyObject *meth)
buf_size, len); buf_size, len);
goto finally; goto finally;
} }
memcpy(buf, PyBytes_AsString(str), len); memcpy(buf, PyString_AsString(str), len);
finally: finally:
Py_XDECREF(arg); Py_XDECREF(arg);
Py_XDECREF(str); Py_XDECREF(str);
@ -1094,7 +1094,7 @@ xmlparse_GetInputContext(xmlparseobject *self, PyObject *unused)
= XML_GetInputContext(self->itself, &offset, &size); = XML_GetInputContext(self->itself, &offset, &size);
if (buffer != NULL) if (buffer != NULL)
return PyBytes_FromStringAndSize(buffer + offset, return PyString_FromStringAndSize(buffer + offset,
size - offset); size - offset);
else else
Py_RETURN_NONE; Py_RETURN_NONE;
@ -1511,7 +1511,7 @@ xmlparse_getattr(xmlparseobject *self, char *name)
#define APPEND(list, str) \ #define APPEND(list, str) \
do { \ do { \
PyObject *o = PyBytes_FromString(str); \ PyObject *o = PyString_FromString(str); \
if (o != NULL) \ if (o != NULL) \
PyList_Append(list, o); \ PyList_Append(list, o); \
Py_XDECREF(o); \ Py_XDECREF(o); \
@ -1862,7 +1862,7 @@ get_version_string(void)
while (rev[i] != ' ' && rev[i] != '\0') while (rev[i] != ' ' && rev[i] != '\0')
++i; ++i;
return PyBytes_FromStringAndSize(rev, i); return PyString_FromStringAndSize(rev, i);
} }
/* Initialization function for the module */ /* Initialization function for the module */
@ -1889,7 +1889,7 @@ PyMODINIT_FUNC
MODULE_INITFUNC(void) MODULE_INITFUNC(void)
{ {
PyObject *m, *d; PyObject *m, *d;
PyObject *errmod_name = PyBytes_FromString(MODULE_NAME ".errors"); PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors");
PyObject *errors_module; PyObject *errors_module;
PyObject *modelmod_name; PyObject *modelmod_name;
PyObject *model_module; PyObject *model_module;
@ -1899,7 +1899,7 @@ MODULE_INITFUNC(void)
if (errmod_name == NULL) if (errmod_name == NULL)
return; return;
modelmod_name = PyBytes_FromString(MODULE_NAME ".model"); modelmod_name = PyString_FromString(MODULE_NAME ".model");
if (modelmod_name == NULL) if (modelmod_name == NULL)
return; return;

View file

@ -421,7 +421,7 @@ add a line to the history buffer");
static PyObject * static PyObject *
get_completer_delims(PyObject *self, PyObject *noarg) get_completer_delims(PyObject *self, PyObject *noarg)
{ {
return PyBytes_FromString(rl_completer_word_break_characters); return PyString_FromString(rl_completer_word_break_characters);
} }
PyDoc_STRVAR(doc_get_completer_delims, PyDoc_STRVAR(doc_get_completer_delims,
@ -471,7 +471,7 @@ get_history_item(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:index", &idx)) if (!PyArg_ParseTuple(args, "i:index", &idx))
return NULL; return NULL;
if ((hist_ent = history_get(idx))) if ((hist_ent = history_get(idx)))
return PyBytes_FromString(hist_ent->line); return PyString_FromString(hist_ent->line);
else { else {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -503,7 +503,7 @@ return the current (not the maximum) length of history.");
static PyObject * static PyObject *
get_line_buffer(PyObject *self, PyObject *noarg) get_line_buffer(PyObject *self, PyObject *noarg)
{ {
return PyBytes_FromString(rl_line_buffer); return PyString_FromString(rl_line_buffer);
} }
PyDoc_STRVAR(doc_get_line_buffer, PyDoc_STRVAR(doc_get_line_buffer,
@ -676,7 +676,7 @@ on_completion_display_matches_hook(char **matches,
if (m == NULL) if (m == NULL)
goto error; goto error;
for (i = 0; i < num_matches; i++) { for (i = 0; i < num_matches; i++) {
s = PyBytes_FromString(matches[i+1]); s = PyString_FromString(matches[i+1]);
if (s == NULL) if (s == NULL)
goto error; goto error;
if (PyList_SetItem(m, i, s) == -1) if (PyList_SetItem(m, i, s) == -1)
@ -725,7 +725,7 @@ on_completion(const char *text, int state)
result = NULL; result = NULL;
} }
else { else {
char *s = PyBytes_AsString(r); char *s = PyString_AsString(r);
if (s == NULL) if (s == NULL)
goto error; goto error;
result = strdup(s); result = strdup(s);

View file

@ -1219,7 +1219,7 @@ kqueue_event_repr(kqueue_event_Object *s)
"data=0x%lx udata=%p>", "data=0x%lx udata=%p>",
(unsigned long)(s->e.ident), s->e.filter, s->e.flags, (unsigned long)(s->e.ident), s->e.filter, s->e.flags,
s->e.fflags, (long)(s->e.data), s->e.udata); s->e.fflags, (long)(s->e.data), s->e.udata);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
static int static int

View file

@ -432,7 +432,7 @@ SHA256_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp); SHAcopy(self, &temp);
sha_final(digest, &temp); sha_final(digest, &temp);
return PyBytes_FromStringAndSize((const char *)digest, self->digestsize); return PyString_FromStringAndSize((const char *)digest, self->digestsize);
} }
PyDoc_STRVAR(SHA256_hexdigest__doc__, PyDoc_STRVAR(SHA256_hexdigest__doc__,
@ -452,10 +452,10 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused)
sha_final(digest, &temp); sha_final(digest, &temp);
/* Create a new string */ /* Create a new string */
retval = PyBytes_FromStringAndSize(NULL, self->digestsize * 2); retval = PyString_FromStringAndSize(NULL, self->digestsize * 2);
if (!retval) if (!retval)
return NULL; return NULL;
hex_digest = PyBytes_AsString(retval); hex_digest = PyString_AsString(retval);
if (!hex_digest) { if (!hex_digest) {
Py_DECREF(retval); Py_DECREF(retval);
return NULL; return NULL;
@ -510,9 +510,9 @@ static PyObject *
SHA256_get_name(PyObject *self, void *closure) SHA256_get_name(PyObject *self, void *closure)
{ {
if (((SHAobject *)self)->digestsize == 32) if (((SHAobject *)self)->digestsize == 32)
return PyBytes_FromStringAndSize("SHA256", 6); return PyString_FromStringAndSize("SHA256", 6);
else else
return PyBytes_FromStringAndSize("SHA224", 6); return PyString_FromStringAndSize("SHA224", 6);
} }
static PyGetSetDef SHA_getseters[] = { static PyGetSetDef SHA_getseters[] = {

View file

@ -498,7 +498,7 @@ SHA512_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp); SHAcopy(self, &temp);
sha512_final(digest, &temp); sha512_final(digest, &temp);
return PyBytes_FromStringAndSize((const char *)digest, self->digestsize); return PyString_FromStringAndSize((const char *)digest, self->digestsize);
} }
PyDoc_STRVAR(SHA512_hexdigest__doc__, PyDoc_STRVAR(SHA512_hexdigest__doc__,
@ -518,10 +518,10 @@ SHA512_hexdigest(SHAobject *self, PyObject *unused)
sha512_final(digest, &temp); sha512_final(digest, &temp);
/* Create a new string */ /* Create a new string */
retval = PyBytes_FromStringAndSize(NULL, self->digestsize * 2); retval = PyString_FromStringAndSize(NULL, self->digestsize * 2);
if (!retval) if (!retval)
return NULL; return NULL;
hex_digest = PyBytes_AsString(retval); hex_digest = PyString_AsString(retval);
if (!hex_digest) { if (!hex_digest) {
Py_DECREF(retval); Py_DECREF(retval);
return NULL; return NULL;
@ -576,9 +576,9 @@ static PyObject *
SHA512_get_name(PyObject *self, void *closure) SHA512_get_name(PyObject *self, void *closure)
{ {
if (((SHAobject *)self)->digestsize == 64) if (((SHAobject *)self)->digestsize == 64)
return PyBytes_FromStringAndSize("SHA512", 6); return PyString_FromStringAndSize("SHA512", 6);
else else
return PyBytes_FromStringAndSize("SHA384", 6); return PyString_FromStringAndSize("SHA384", 6);
} }
static PyGetSetDef SHA_getseters[] = { static PyGetSetDef SHA_getseters[] = {

View file

@ -380,7 +380,7 @@ SHA_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp); SHAcopy(self, &temp);
sha_final(digest, &temp); sha_final(digest, &temp);
return PyBytes_FromStringAndSize((const char *)digest, sizeof(digest)); return PyString_FromStringAndSize((const char *)digest, sizeof(digest));
} }
PyDoc_STRVAR(SHA_hexdigest__doc__, PyDoc_STRVAR(SHA_hexdigest__doc__,
@ -400,10 +400,10 @@ SHA_hexdigest(SHAobject *self, PyObject *unused)
sha_final(digest, &temp); sha_final(digest, &temp);
/* Create a new string */ /* Create a new string */
retval = PyBytes_FromStringAndSize(NULL, sizeof(digest) * 2); retval = PyString_FromStringAndSize(NULL, sizeof(digest) * 2);
if (!retval) if (!retval)
return NULL; return NULL;
hex_digest = PyBytes_AsString(retval); hex_digest = PyString_AsString(retval);
if (!hex_digest) { if (!hex_digest) {
Py_DECREF(retval); Py_DECREF(retval);
return NULL; return NULL;
@ -463,7 +463,7 @@ SHA_get_digest_size(PyObject *self, void *closure)
static PyObject * static PyObject *
SHA_get_name(PyObject *self, void *closure) SHA_get_name(PyObject *self, void *closure)
{ {
return PyBytes_FromStringAndSize("SHA1", 4); return PyString_FromStringAndSize("SHA1", 4);
} }
static PyGetSetDef SHA_getseters[] = { static PyGetSetDef SHA_getseters[] = {

View file

@ -911,7 +911,7 @@ makeipaddr(struct sockaddr *addr, int addrlen)
set_gaierror(error); set_gaierror(error);
return NULL; return NULL;
} }
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
@ -955,7 +955,7 @@ makebdaddr(bdaddr_t *bdaddr)
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
bdaddr->b[5], bdaddr->b[4], bdaddr->b[3], bdaddr->b[5], bdaddr->b[4], bdaddr->b[3],
bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]); bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
#endif #endif
@ -1002,14 +1002,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
#ifdef linux #ifdef linux
if (a->sun_path[0] == 0) { /* Linux abstract namespace */ if (a->sun_path[0] == 0) { /* Linux abstract namespace */
addrlen -= offsetof(struct sockaddr_un, sun_path); addrlen -= offsetof(struct sockaddr_un, sun_path);
return PyBytes_FromStringAndSize(a->sun_path, return PyString_FromStringAndSize(a->sun_path,
addrlen); addrlen);
} }
else else
#endif /* linux */ #endif /* linux */
{ {
/* regular NULL-terminated string */ /* regular NULL-terminated string */
return PyBytes_FromString(a->sun_path); return PyString_FromString(a->sun_path);
} }
} }
#endif /* AF_UNIX */ #endif /* AF_UNIX */
@ -1362,7 +1362,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
addr = (struct sockaddr_sco *)addr_ret; addr = (struct sockaddr_sco *)addr_ret;
_BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
straddr = PyBytes_AsString(args); straddr = PyString_AsString(args);
if (straddr == NULL) { if (straddr == NULL) {
PyErr_SetString(socket_error, "getsockaddrarg: " PyErr_SetString(socket_error, "getsockaddrarg: "
"wrong format"); "wrong format");
@ -1854,16 +1854,16 @@ sock_getsockopt(PySocketSockObject *s, PyObject *args)
"getsockopt buflen out of range"); "getsockopt buflen out of range");
return NULL; return NULL;
} }
buf = PyBytes_FromStringAndSize((char *)NULL, buflen); buf = PyString_FromStringAndSize((char *)NULL, buflen);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
res = getsockopt(s->sock_fd, level, optname, res = getsockopt(s->sock_fd, level, optname,
(void *)PyBytes_AS_STRING(buf), &buflen); (void *)PyString_AS_STRING(buf), &buflen);
if (res < 0) { if (res < 0) {
Py_DECREF(buf); Py_DECREF(buf);
return s->errorhandler(); return s->errorhandler();
} }
_PyBytes_Resize(&buf, buflen); _PyString_Resize(&buf, buflen);
return buf; return buf;
#endif /* __BEOS__ */ #endif /* __BEOS__ */
} }
@ -2386,12 +2386,12 @@ sock_recv(PySocketSockObject *s, PyObject *args)
} }
/* Allocate a new string. */ /* Allocate a new string. */
buf = PyBytes_FromStringAndSize((char *) 0, recvlen); buf = PyString_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
/* Call the guts */ /* Call the guts */
outlen = sock_recv_guts(s, PyBytes_AS_STRING(buf), recvlen, flags); outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags);
if (outlen < 0) { if (outlen < 0) {
/* An error occurred, release the string and return an /* An error occurred, release the string and return an
error. */ error. */
@ -2401,7 +2401,7 @@ sock_recv(PySocketSockObject *s, PyObject *args)
if (outlen != recvlen) { if (outlen != recvlen) {
/* We did not read as many bytes as we anticipated, resize the /* We did not read as many bytes as we anticipated, resize the
string if possible and be succesful. */ string if possible and be succesful. */
if (_PyBytes_Resize(&buf, outlen) < 0) if (_PyString_Resize(&buf, outlen) < 0)
/* Oopsy, not so succesful after all. */ /* Oopsy, not so succesful after all. */
return NULL; return NULL;
} }
@ -2560,11 +2560,11 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
return NULL; return NULL;
} }
buf = PyBytes_FromStringAndSize((char *) 0, recvlen); buf = PyString_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
outlen = sock_recvfrom_guts(s, PyBytes_AS_STRING(buf), outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf),
recvlen, flags, &addr); recvlen, flags, &addr);
if (outlen < 0) { if (outlen < 0) {
goto finally; goto finally;
@ -2573,7 +2573,7 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
if (outlen != recvlen) { if (outlen != recvlen) {
/* We did not read as many bytes as we anticipated, resize the /* We did not read as many bytes as we anticipated, resize the
string if possible and be succesful. */ string if possible and be succesful. */
if (_PyBytes_Resize(&buf, outlen) < 0) if (_PyString_Resize(&buf, outlen) < 0)
/* Oopsy, not so succesful after all. */ /* Oopsy, not so succesful after all. */
goto finally; goto finally;
} }
@ -2941,7 +2941,7 @@ sock_repr(PySocketSockObject *s)
(long)s->sock_fd, s->sock_family, (long)s->sock_fd, s->sock_family,
s->sock_type, s->sock_type,
s->sock_proto); s->sock_proto);
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
@ -3057,7 +3057,7 @@ socket_gethostname(PyObject *self, PyObject *unused)
if (res < 0) if (res < 0)
return set_error(); return set_error();
buf[sizeof buf - 1] = '\0'; buf[sizeof buf - 1] = '\0';
return PyBytes_FromString(buf); return PyString_FromString(buf);
} }
PyDoc_STRVAR(gethostname_doc, PyDoc_STRVAR(gethostname_doc,
@ -3143,7 +3143,7 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
if (h->h_aliases) { if (h->h_aliases) {
for (pch = h->h_aliases; *pch != NULL; pch++) { for (pch = h->h_aliases; *pch != NULL; pch++) {
int status; int status;
tmp = PyBytes_FromString(*pch); tmp = PyString_FromString(*pch);
if (tmp == NULL) if (tmp == NULL)
goto err; goto err;
@ -3432,7 +3432,7 @@ socket_getservbyport(PyObject *self, PyObject *args)
PyErr_SetString(socket_error, "port/proto not found"); PyErr_SetString(socket_error, "port/proto not found");
return NULL; return NULL;
} }
return PyBytes_FromString(sp->s_name); return PyString_FromString(sp->s_name);
} }
PyDoc_STRVAR(getservbyport_doc, PyDoc_STRVAR(getservbyport_doc,
@ -3734,7 +3734,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
if (inet_aton != NULL) { if (inet_aton != NULL) {
#endif #endif
if (inet_aton(ip_addr, &buf)) if (inet_aton(ip_addr, &buf))
return PyBytes_FromStringAndSize((char *)(&buf), return PyString_FromStringAndSize((char *)(&buf),
sizeof(buf)); sizeof(buf));
PyErr_SetString(socket_error, PyErr_SetString(socket_error,
@ -3763,7 +3763,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
} }
return PyBytes_FromStringAndSize((char *) &packed_addr, return PyString_FromStringAndSize((char *) &packed_addr,
sizeof(packed_addr)); sizeof(packed_addr));
#ifdef USE_INET_ATON_WEAKLINK #ifdef USE_INET_ATON_WEAKLINK
@ -3797,7 +3797,7 @@ socket_inet_ntoa(PyObject *self, PyObject *args)
memcpy(&packed_addr, packed_str, addr_len); memcpy(&packed_addr, packed_str, addr_len);
return PyBytes_FromString(inet_ntoa(packed_addr)); return PyString_FromString(inet_ntoa(packed_addr));
} }
#ifdef HAVE_INET_PTON #ifdef HAVE_INET_PTON
@ -3840,11 +3840,11 @@ socket_inet_pton(PyObject *self, PyObject *args)
"illegal IP address string passed to inet_pton"); "illegal IP address string passed to inet_pton");
return NULL; return NULL;
} else if (af == AF_INET) { } else if (af == AF_INET) {
return PyBytes_FromStringAndSize(packed, return PyString_FromStringAndSize(packed,
sizeof(struct in_addr)); sizeof(struct in_addr));
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
} else if (af == AF_INET6) { } else if (af == AF_INET6) {
return PyBytes_FromStringAndSize(packed, return PyString_FromStringAndSize(packed,
sizeof(struct in6_addr)); sizeof(struct in6_addr));
#endif #endif
} else { } else {
@ -3871,7 +3871,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
char ip[INET_ADDRSTRLEN + 1]; char ip[INET_ADDRSTRLEN + 1];
#endif #endif
/* Guarantee NUL-termination for PyBytes_FromString() below */ /* Guarantee NUL-termination for PyString_FromString() below */
memset((void *) &ip[0], '\0', sizeof(ip)); memset((void *) &ip[0], '\0', sizeof(ip));
if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) { if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) {
@ -3903,7 +3903,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
PyErr_SetFromErrno(socket_error); PyErr_SetFromErrno(socket_error);
return NULL; return NULL;
} else { } else {
return PyBytes_FromString(retval); return PyString_FromString(retval);
} }
/* NOTREACHED */ /* NOTREACHED */
@ -3944,9 +3944,9 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); idna = PyObject_CallMethod(hobj, "encode", "s", "idna");
if (!idna) if (!idna)
return NULL; return NULL;
hptr = PyBytes_AsString(idna); hptr = PyString_AsString(idna);
} else if (PyBytes_Check(hobj)) { } else if (PyString_Check(hobj)) {
hptr = PyBytes_AsString(hobj); hptr = PyString_AsString(hobj);
} else { } else {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"getaddrinfo() argument 1 must be string or None"); "getaddrinfo() argument 1 must be string or None");
@ -3955,8 +3955,8 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
if (PyInt_Check(pobj)) { if (PyInt_Check(pobj)) {
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj)); PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
pptr = pbuf; pptr = pbuf;
} else if (PyBytes_Check(pobj)) { } else if (PyString_Check(pobj)) {
pptr = PyBytes_AsString(pobj); pptr = PyString_AsString(pobj);
} else if (pobj == Py_None) { } else if (pobj == Py_None) {
pptr = (char *)NULL; pptr = (char *)NULL;
} else { } else {

View file

@ -60,7 +60,7 @@ static void
sets(PyObject *v, int i, char* val) sets(PyObject *v, int i, char* val)
{ {
if (val) if (val)
PyStructSequence_SET_ITEM(v, i, PyBytes_FromString(val)); PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
else { else {
PyStructSequence_SET_ITEM(v, i, Py_None); PyStructSequence_SET_ITEM(v, i, Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);

View file

@ -47,7 +47,7 @@ split_whitespace(char *s, Py_ssize_t len, Py_ssize_t maxsplit)
i = i+1; i = i+1;
} }
if (j < i) { if (j < i) {
item = PyBytes_FromStringAndSize(s+j, i-j); item = PyString_FromStringAndSize(s+j, i-j);
if (item == NULL) if (item == NULL)
goto finally; goto finally;
@ -61,7 +61,7 @@ split_whitespace(char *s, Py_ssize_t len, Py_ssize_t maxsplit)
i = i+1; i = i+1;
} }
if (maxsplit && (countsplit >= maxsplit) && i < len) { if (maxsplit && (countsplit >= maxsplit) && i < len) {
item = PyBytes_FromStringAndSize( item = PyString_FromStringAndSize(
s+i, len - i); s+i, len - i);
if (item == NULL) if (item == NULL)
goto finally; goto finally;
@ -122,7 +122,7 @@ strop_splitfields(PyObject *self, PyObject *args)
i = j = 0; i = j = 0;
while (i+n <= len) { while (i+n <= len) {
if (s[i] == sub[0] && (n == 1 || memcmp(s+i, sub, n) == 0)) { if (s[i] == sub[0] && (n == 1 || memcmp(s+i, sub, n) == 0)) {
item = PyBytes_FromStringAndSize(s+j, i-j); item = PyString_FromStringAndSize(s+j, i-j);
if (item == NULL) if (item == NULL)
goto fail; goto fail;
err = PyList_Append(list, item); err = PyList_Append(list, item);
@ -137,7 +137,7 @@ strop_splitfields(PyObject *self, PyObject *args)
else else
i++; i++;
} }
item = PyBytes_FromStringAndSize(s+j, len-j); item = PyString_FromStringAndSize(s+j, len-j);
if (item == NULL) if (item == NULL)
goto fail; goto fail;
err = PyList_Append(list, item); err = PyList_Append(list, item);
@ -189,7 +189,7 @@ strop_joinfields(PyObject *self, PyObject *args)
if (seqlen == 1) { if (seqlen == 1) {
/* Optimization if there's only one item */ /* Optimization if there's only one item */
PyObject *item = PySequence_GetItem(seq, 0); PyObject *item = PySequence_GetItem(seq, 0);
if (item && !PyBytes_Check(item)) { if (item && !PyString_Check(item)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings"); "first argument must be sequence of strings");
Py_DECREF(item); Py_DECREF(item);
@ -198,9 +198,9 @@ strop_joinfields(PyObject *self, PyObject *args)
return item; return item;
} }
if (!(res = PyBytes_FromStringAndSize((char*)NULL, sz))) if (!(res = PyString_FromStringAndSize((char*)NULL, sz)))
return NULL; return NULL;
p = PyBytes_AsString(res); p = PyString_AsString(res);
/* optimize for lists, since it's the most common case. all others /* optimize for lists, since it's the most common case. all others
* (tuples and arbitrary sequences) just use the sequence abstract * (tuples and arbitrary sequences) just use the sequence abstract
@ -209,29 +209,29 @@ strop_joinfields(PyObject *self, PyObject *args)
if (PyList_Check(seq)) { if (PyList_Check(seq)) {
for (i = 0; i < seqlen; i++) { for (i = 0; i < seqlen; i++) {
PyObject *item = PyList_GET_ITEM(seq, i); PyObject *item = PyList_GET_ITEM(seq, i);
if (!PyBytes_Check(item)) { if (!PyString_Check(item)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings"); "first argument must be sequence of strings");
Py_DECREF(res); Py_DECREF(res);
return NULL; return NULL;
} }
slen = PyBytes_GET_SIZE(item); slen = PyString_GET_SIZE(item);
while (reslen + slen + seplen >= sz) { while (reslen + slen + seplen >= sz) {
if (_PyBytes_Resize(&res, sz * 2) < 0) if (_PyString_Resize(&res, sz * 2) < 0)
return NULL; return NULL;
sz *= 2; sz *= 2;
p = PyBytes_AsString(res) + reslen; p = PyString_AsString(res) + reslen;
} }
if (i > 0) { if (i > 0) {
memcpy(p, sep, seplen); memcpy(p, sep, seplen);
p += seplen; p += seplen;
reslen += seplen; reslen += seplen;
} }
memcpy(p, PyBytes_AS_STRING(item), slen); memcpy(p, PyString_AS_STRING(item), slen);
p += slen; p += slen;
reslen += slen; reslen += slen;
} }
_PyBytes_Resize(&res, reslen); _PyString_Resize(&res, reslen);
return res; return res;
} }
@ -245,33 +245,33 @@ strop_joinfields(PyObject *self, PyObject *args)
/* This is now type safe */ /* This is now type safe */
for (i = 0; i < seqlen; i++) { for (i = 0; i < seqlen; i++) {
PyObject *item = getitemfunc(seq, i); PyObject *item = getitemfunc(seq, i);
if (!item || !PyBytes_Check(item)) { if (!item || !PyString_Check(item)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings"); "first argument must be sequence of strings");
Py_DECREF(res); Py_DECREF(res);
Py_XDECREF(item); Py_XDECREF(item);
return NULL; return NULL;
} }
slen = PyBytes_GET_SIZE(item); slen = PyString_GET_SIZE(item);
while (reslen + slen + seplen >= sz) { while (reslen + slen + seplen >= sz) {
if (_PyBytes_Resize(&res, sz * 2) < 0) { if (_PyString_Resize(&res, sz * 2) < 0) {
Py_DECREF(item); Py_DECREF(item);
return NULL; return NULL;
} }
sz *= 2; sz *= 2;
p = PyBytes_AsString(res) + reslen; p = PyString_AsString(res) + reslen;
} }
if (i > 0) { if (i > 0) {
memcpy(p, sep, seplen); memcpy(p, sep, seplen);
p += seplen; p += seplen;
reslen += seplen; reslen += seplen;
} }
memcpy(p, PyBytes_AS_STRING(item), slen); memcpy(p, PyString_AS_STRING(item), slen);
p += slen; p += slen;
reslen += slen; reslen += slen;
Py_DECREF(item); Py_DECREF(item);
} }
_PyBytes_Resize(&res, reslen); _PyString_Resize(&res, reslen);
return res; return res;
} }
@ -369,7 +369,7 @@ do_strip(PyObject *args, int striptype)
Py_ssize_t len, i, j; Py_ssize_t len, i, j;
if (PyBytes_AsStringAndSize(args, &s, &len)) if (PyString_AsStringAndSize(args, &s, &len))
return NULL; return NULL;
i = 0; i = 0;
@ -392,7 +392,7 @@ do_strip(PyObject *args, int striptype)
return args; return args;
} }
else else
return PyBytes_FromStringAndSize(s+i, j-i); return PyString_FromStringAndSize(s+i, j-i);
} }
@ -450,12 +450,12 @@ strop_lower(PyObject *self, PyObject *args)
int changed; int changed;
WARN; WARN;
if (PyBytes_AsStringAndSize(args, &s, &n)) if (PyString_AsStringAndSize(args, &s, &n))
return NULL; return NULL;
newstr = PyBytes_FromStringAndSize(NULL, n); newstr = PyString_FromStringAndSize(NULL, n);
if (newstr == NULL) if (newstr == NULL)
return NULL; return NULL;
s_new = PyBytes_AsString(newstr); s_new = PyString_AsString(newstr);
changed = 0; changed = 0;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++); int c = Py_CHARMASK(*s++);
@ -489,12 +489,12 @@ strop_upper(PyObject *self, PyObject *args)
int changed; int changed;
WARN; WARN;
if (PyBytes_AsStringAndSize(args, &s, &n)) if (PyString_AsStringAndSize(args, &s, &n))
return NULL; return NULL;
newstr = PyBytes_FromStringAndSize(NULL, n); newstr = PyString_FromStringAndSize(NULL, n);
if (newstr == NULL) if (newstr == NULL)
return NULL; return NULL;
s_new = PyBytes_AsString(newstr); s_new = PyString_AsString(newstr);
changed = 0; changed = 0;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++); int c = Py_CHARMASK(*s++);
@ -529,12 +529,12 @@ strop_capitalize(PyObject *self, PyObject *args)
int changed; int changed;
WARN; WARN;
if (PyBytes_AsStringAndSize(args, &s, &n)) if (PyString_AsStringAndSize(args, &s, &n))
return NULL; return NULL;
newstr = PyBytes_FromStringAndSize(NULL, n); newstr = PyString_FromStringAndSize(NULL, n);
if (newstr == NULL) if (newstr == NULL)
return NULL; return NULL;
s_new = PyBytes_AsString(newstr); s_new = PyString_AsString(newstr);
changed = 0; changed = 0;
if (0 < n) { if (0 < n) {
int c = Py_CHARMASK(*s++); int c = Py_CHARMASK(*s++);
@ -610,12 +610,12 @@ strop_expandtabs(PyObject *self, PyObject *args)
} }
/* Second pass: create output string and fill it */ /* Second pass: create output string and fill it */
out = PyBytes_FromStringAndSize(NULL, i+j); out = PyString_FromStringAndSize(NULL, i+j);
if (out == NULL) if (out == NULL)
return NULL; return NULL;
i = 0; i = 0;
q = PyBytes_AS_STRING(out); q = PyString_AS_STRING(out);
for (p = string; p < e; p++) { for (p = string; p < e; p++) {
if (*p == '\t') { if (*p == '\t') {
@ -695,12 +695,12 @@ strop_swapcase(PyObject *self, PyObject *args)
int changed; int changed;
WARN; WARN;
if (PyBytes_AsStringAndSize(args, &s, &n)) if (PyString_AsStringAndSize(args, &s, &n))
return NULL; return NULL;
newstr = PyBytes_FromStringAndSize(NULL, n); newstr = PyString_FromStringAndSize(NULL, n);
if (newstr == NULL) if (newstr == NULL)
return NULL; return NULL;
s_new = PyBytes_AsString(newstr); s_new = PyString_AsString(newstr);
changed = 0; changed = 0;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++); int c = Py_CHARMASK(*s++);
@ -898,10 +898,10 @@ strop_maketrans(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
result = PyBytes_FromStringAndSize((char *)NULL, 256); result = PyString_FromStringAndSize((char *)NULL, 256);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
c = (unsigned char *) PyBytes_AS_STRING((PyBytesObject *)result); c = (unsigned char *) PyString_AS_STRING((PyStringObject *)result);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
c[i]=(unsigned char)i; c[i]=(unsigned char)i;
for (i = 0; i < fromlen; i++) for (i = 0; i < fromlen; i++)
@ -942,12 +942,12 @@ strop_translate(PyObject *self, PyObject *args)
} }
table = table1; table = table1;
inlen = PyBytes_GET_SIZE(input_obj); inlen = PyString_GET_SIZE(input_obj);
result = PyBytes_FromStringAndSize((char *)NULL, inlen); result = PyString_FromStringAndSize((char *)NULL, inlen);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
output_start = output = PyBytes_AsString(result); output_start = output = PyString_AsString(result);
input = PyBytes_AsString(input_obj); input = PyString_AsString(input_obj);
if (dellen == 0) { if (dellen == 0) {
/* If no deletions are required, use faster code */ /* If no deletions are required, use faster code */
@ -983,7 +983,7 @@ strop_translate(PyObject *self, PyObject *args)
} }
/* Fix the size of the resulting string */ /* Fix the size of the resulting string */
if (inlen > 0) if (inlen > 0)
_PyBytes_Resize(&result, output - output_start); _PyString_Resize(&result, output - output_start);
return result; return result;
} }
@ -1169,7 +1169,7 @@ strop_replace(PyObject *self, PyObject *args)
Py_XINCREF(newstr); Py_XINCREF(newstr);
} }
else { else {
newstr = PyBytes_FromStringAndSize(new_s, out_len); newstr = PyString_FromStringAndSize(new_s, out_len);
PyMem_FREE(new_s); PyMem_FREE(new_s);
} }
return newstr; return newstr;
@ -1222,7 +1222,7 @@ initstrop(void)
if (isspace(c)) if (isspace(c))
buf[n++] = c; buf[n++] = c;
} }
s = PyBytes_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) if (s)
PyModule_AddObject(m, "whitespace", s); PyModule_AddObject(m, "whitespace", s);
@ -1232,7 +1232,7 @@ initstrop(void)
if (islower(c)) if (islower(c))
buf[n++] = c; buf[n++] = c;
} }
s = PyBytes_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) if (s)
PyModule_AddObject(m, "lowercase", s); PyModule_AddObject(m, "lowercase", s);
@ -1242,7 +1242,7 @@ initstrop(void)
if (isupper(c)) if (isupper(c))
buf[n++] = c; buf[n++] = c;
} }
s = PyBytes_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) if (s)
PyModule_AddObject(m, "uppercase", s); PyModule_AddObject(m, "uppercase", s);
} }

Some files were not shown because too many files have changed in this diff Show more