[pygobject/py3k] Use bytes rather than bytearray and use PYGLIB_ macro prefix



commit 4f1246c03cecc28b2e8661d5b6181a3e88fa7e58
Author: John Ehresman <jpe wingware com>
Date:   Thu Apr 15 17:53:45 2010 -0400

    Use bytes rather than bytearray and use PYGLIB_ macro prefix

 gio/ginputstream.override        |   20 ++++++++++----------
 gio/gmemoryinputstream.override  |   12 ++++++------
 gio/gmemoryoutputstream.override |    2 +-
 glib/pygiochannel.c              |   14 +++++++-------
 glib/pyglib-python-compat.h      |   20 ++++++++++----------
 5 files changed, 34 insertions(+), 34 deletions(-)
---
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index 917f13a..97fb406 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -47,7 +47,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
     if (!pygio_check_cancellable(pycancellable, &cancellable))
         return NULL;
 
-    v = _PyByteArray_FromStringAndSize((char *)NULL, buffersize);
+    v = PYGLIB_PyBytes_FromStringAndSize((char *)NULL, buffersize);
     if (v == NULL)
         return NULL;
 
@@ -57,7 +57,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
             pyg_begin_allow_threads;
             errno = 0;
             chunksize = g_input_stream_read(G_INPUT_STREAM(self->obj),
-                                            _PyByteArray_AsString(v) + bytesread,
+                                            PYGLIB_PyBytes_AsString(v) + bytesread,
                                             buffersize - bytesread, cancellable,
                                             &error);
             pyg_end_allow_threads;
@@ -81,7 +81,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
 
             if (count < 0) {
 		buffersize += BUFSIZE;
-		if (_PyByteArray_Resize(&v, buffersize) < 0)
+		if (PYGLIB_PyBytes_Resize(&v, buffersize) < 0)
 		    return NULL;
 	    }
             else {
@@ -91,7 +91,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
         }
 
     if (bytesread != buffersize)
-        _PyByteArray_Resize(&v, bytesread);
+        PYGLIB_PyBytes_Resize(&v, bytesread);
 
     return v;
 }
@@ -119,7 +119,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
     if (!pygio_check_cancellable(pycancellable, &cancellable))
         return NULL;
 
-    v = _PyByteArray_FromStringAndSize((char *)NULL, buffersize);
+    v = PYGLIB_PyBytes_FromStringAndSize((char *)NULL, buffersize);
     if (v == NULL)
         return NULL;
 
@@ -129,7 +129,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
             pyg_begin_allow_threads;
             errno = 0;
             g_input_stream_read_all(G_INPUT_STREAM(self->obj),
-				    _PyByteArray_AsString(v) + bytesread,
+				    PYGLIB_PyBytes_AsString(v) + bytesread,
 				    buffersize - bytesread,
 				    &chunksize,
 				    cancellable, &error);
@@ -148,7 +148,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
 
             if (count < 0) {
 		buffersize += BUFSIZE;
-		if (_PyByteArray_Resize(&v, buffersize) < 0)
+		if (PYGLIB_PyBytes_Resize(&v, buffersize) < 0)
 		    return NULL;
 	    }
             else {
@@ -158,7 +158,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
         }
 
     if (bytesread != buffersize)
-        _PyByteArray_Resize(&v, bytesread);
+        PYGLIB_PyBytes_Resize(&v, bytesread);
 
     return v;
 }
@@ -241,10 +241,10 @@ _wrap_g_input_stream_read_finish(PyGObject *self,
         return NULL;
 
     if (bytesread == 0)
-        return _PyByteArray_FromStringAndSize("", 0);
+        return PYGLIB_PyBytes_FromStringAndSize("", 0);
 
     notify = pygio_notify_get_attached(result);
-    return _PyByteArray_FromStringAndSize(notify->buffer, bytesread);
+    return PYGLIB_PyBytes_FromStringAndSize(notify->buffer, bytesread);
 }
 %%
 override g_input_stream_close_async kwargs
diff --git a/gio/gmemoryinputstream.override b/gio/gmemoryinputstream.override
index 32b7a00..a38dc96 100644
--- a/gio/gmemoryinputstream.override
+++ b/gio/gmemoryinputstream.override
@@ -38,14 +38,14 @@ _wrap_g_memory_input_stream_add_data(PyGObject *self,
         char *copy;
         int length;
 
-        if (!_PyByteArray_Check(data)) {
+        if (!PYGLIB_PyBytes_Check(data)) {
             PyErr_SetString(PyExc_TypeError, "data must be a bytes instance or None");
             return NULL;
         }
 
-        length = _PyByteArray_Size(data);
+        length = PYGLIB_PyBytes_Size(data);
         copy = g_malloc(length);
-        memcpy(copy, _PyByteArray_AsString(data), length);
+        memcpy(copy, PYGLIB_PyBytes_AsString(data), length);
 
         g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(self->obj),
                                        copy, length, (GDestroyNotify) g_free);
@@ -74,14 +74,14 @@ _wrap_g_memory_input_stream_new_from_data(PyGObject *self,
         char *copy;
         int length;
 
-        if (!_PyByteArray_Check(data)) {
+        if (!PYGLIB_PyBytes_Check(data)) {
             PyErr_SetString(PyExc_TypeError, "data must be a string or None");
             return NULL;
         }
 
-        length = _PyByteArray_Size(data);
+        length = PYGLIB_PyBytes_Size(data);
         copy = g_malloc(length);
-        memcpy(copy, _PyByteArray_AsString(data), length);
+        memcpy(copy, PYGLIB_PyBytes_AsString(data), length);
 
         stream = g_memory_input_stream_new_from_data(copy, length,
                                                       (GDestroyNotify) g_free);
diff --git a/gio/gmemoryoutputstream.override b/gio/gmemoryoutputstream.override
index e95df0a..6041ca6 100644
--- a/gio/gmemoryoutputstream.override
+++ b/gio/gmemoryoutputstream.override
@@ -40,6 +40,6 @@ static PyObject *
 _wrap_g_memory_output_stream_get_data(PyGObject *self)
 {
     GMemoryOutputStream *stream = G_MEMORY_OUTPUT_STREAM(self->obj);
-    return _PyByteArray_FromStringAndSize(g_memory_output_stream_get_data(stream),
+    return PYGLIB_PyBytes_FromStringAndSize(g_memory_output_stream_get_data(stream),
 				      g_seekable_tell(G_SEEKABLE(stream)));
 }
diff --git a/glib/pygiochannel.c b/glib/pygiochannel.c
index d01dd40..544d3dd 100644
--- a/glib/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -204,16 +204,16 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
         }
 	
 	if ( ret_obj == NULL ) {
-	    ret_obj = _PyByteArray_FromStringAndSize((char *)NULL, buf_size);
+	    ret_obj = PYGLIB_PyBytes_FromStringAndSize((char *)NULL, buf_size);
 	    if (ret_obj == NULL)
 		goto failure;
 	}
-	else if (buf_size + total_read > _PyByteArray_Size(ret_obj)) {
-	    if (_PyByteArray_Resize(&ret_obj, buf_size + total_read) == -1)
+	else if (buf_size + total_read > PYGLIB_PyBytes_Size(ret_obj)) {
+	    if (PYGLIB_PyBytes_Resize(&ret_obj, buf_size + total_read) == -1)
 		goto failure;
 	}
        
-        buf = _PyByteArray_AsString(ret_obj) + total_read;
+        buf = PYGLIB_PyBytes_AsString(ret_obj) + total_read;
 
         pyglib_unblock_threads();
         status = g_io_channel_read_chars(self->channel, buf, buf_size, 
@@ -225,8 +225,8 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
 	total_read += single_read;
     }
 	
-    if ( total_read != _PyByteArray_Size(ret_obj) ) {
-	if (_PyByteArray_Resize(&ret_obj, total_read) == -1)
+    if ( total_read != PYGLIB_PyBytes_Size(ret_obj) ) {
+	if (PYGLIB_PyBytes_Resize(&ret_obj, total_read) == -1)
 	    goto failure;
     }
     
@@ -237,7 +237,7 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
     {
 	PyObject *unicode_obj;
 	
-	unicode_obj = PyUnicode_FromString(PyByteArray_AS_STRING(ret_obj));
+	unicode_obj = PyUnicode_FromString(PyBytes_AS_STRING(ret_obj));
 	if (unicode_obj == NULL)
 	    goto failure;
 	Py_DECREF(ret_obj);
diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h
index a422893..bea7d6b 100644
--- a/glib/pyglib-python-compat.h
+++ b/glib/pyglib-python-compat.h
@@ -95,11 +95,11 @@ static int _pyglib_init_##modname(PyObject *module)
 #define _PyUnicode_GET_SIZE PyString_GET_SIZE
 #define _PyUnicode_Type PyString_Type
 
-#define _PyByteArray_FromStringAndSize PyString_FromStringAndSize
-#define _PyByteArray_Resize _PyString_Resize
-#define _PyByteArray_AsString PyString_AsString
-#define _PyByteArray_Size PyString_Size
-#define _PyByteArray_Check PyString_Check
+#define PYGLIB_PyBytes_FromStringAndSize PyString_FromStringAndSize
+#define PYGLIB_PyBytes_Resize _PyString_Resize
+#define PYGLIB_PyBytes_AsString PyString_AsString
+#define PYGLIB_PyBytes_Size PyString_Size
+#define PYGLIB_PyBytes_Check PyString_Check
 
 #define _PyLong_Check PyInt_Check
 #define _PyLong_FromLong PyInt_FromLong
@@ -190,11 +190,11 @@ PyTypeObject symbol = {                                 \
 #define _PyLongObject PyLongObject
 #define _PyLong_Type PyLong_Type
 
-#define _PyByteArray_FromStringAndSize PyByteArray_FromStringAndSize
-#define _PyByteArray_Resize(o, len) PyByteArray_Resize(*o, len)
-#define _PyByteArray_AsString PyByteArray_AsString
-#define _PyByteArray_Size PyByteArray_Size
-#define _PyByteArray_Check PyByteArray_Check
+#define PYGLIB_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
+#define PYGLIB_PyBytes_Resize(o, len) _PyBytes_Resize(o, len)
+#define PYGLIB_PyBytes_AsString PyBytes_AsString
+#define PYGLIB_PyBytes_Size PyBytes_Size
+#define PYGLIB_PyBytes_Check PyBytes_Check
 
 #endif
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]