Merged in py3k-buffer branch to main line.  All objects now use the buffer protocol in PEP 3118.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 5ee3347..157ea1c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8108,57 +8108,26 @@
     (objobjargproc)0,			/* mp_ass_subscript */
 };
 
-static Py_ssize_t
-unicode_buffer_getreadbuf(PyUnicodeObject *self,
-			  Py_ssize_t index,
-			  const void **ptr)
-{
-    if (index != 0) {
-        PyErr_SetString(PyExc_SystemError,
-			"accessing non-existent unicode segment");
-        return -1;
-    }
-    *ptr = (void *) self->str;
-    return PyUnicode_GET_DATA_SIZE(self);
-}
-
-static Py_ssize_t
-unicode_buffer_getwritebuf(PyUnicodeObject *self, Py_ssize_t index,
-			   const void **ptr)
-{
-    PyErr_SetString(PyExc_TypeError,
-		    "cannot use unicode as modifiable buffer");
-    return -1;
-}
 
 static int
-unicode_buffer_getsegcount(PyUnicodeObject *self,
-			   Py_ssize_t *lenp)
+unicode_buffer_getbuffer(PyUnicodeObject *self, PyBuffer *view, int flags)
 {
-    if (lenp)
-        *lenp = PyUnicode_GET_DATA_SIZE(self);
-    return 1;
-}
 
-static Py_ssize_t
-unicode_buffer_getcharbuf(PyUnicodeObject *self,
-			  Py_ssize_t index,
-			  const void **ptr)
-{
-    PyObject *str;
-
-    if (index != 0) {
-        PyErr_SetString(PyExc_SystemError,
-			"accessing non-existent unicode segment");
-        return -1;
+    if (flags & PyBUF_CHARACTER) {
+        PyObject *str;
+        
+        str = _PyUnicode_AsDefaultEncodedString((PyObject *)self, NULL);
+        if (str == NULL) return -1;
+        return PyBuffer_FillInfo(view, (void *)PyString_AS_STRING(str),
+                                 PyString_GET_SIZE(str), 1, flags);
     }
-    str = _PyUnicode_AsDefaultEncodedString((PyObject *)self, NULL);
-    if (str == NULL)
-	return -1;
-    *ptr = (void *) PyString_AS_STRING(str);
-    return PyString_GET_SIZE(str);
+    else {
+        return PyBuffer_FillInfo(view, (void *)self->str, 
+                                 PyUnicode_GET_DATA_SIZE(self), 1, flags);
+    }
 }
 
+
 /* Helpers for PyUnicode_Format() */
 
 static PyObject *
@@ -8853,10 +8822,8 @@
 }
 
 static PyBufferProcs unicode_as_buffer = {
-    (readbufferproc) unicode_buffer_getreadbuf,
-    (writebufferproc) unicode_buffer_getwritebuf,
-    (segcountproc) unicode_buffer_getsegcount,
-    (charbufferproc) unicode_buffer_getcharbuf,
+    (getbufferproc) unicode_buffer_getbuffer,
+    NULL,
 };
 
 static PyObject *