]> granicus.if.org Git - python/commitdiff
Clean up references to the no longer existing PyString_ APIs in our docs.
authorGregory P. Smith <greg@krypto.org>
Fri, 22 Mar 2013 20:43:30 +0000 (13:43 -0700)
committerGregory P. Smith <greg@krypto.org>
Fri, 22 Mar 2013 20:43:30 +0000 (13:43 -0700)
Doc/c-api/intro.rst
Doc/c-api/memory.rst
Doc/extending/newtypes.rst
Doc/faq/extending.rst

index 6464fe7d37bc63db82f0a216694b797c14706ba8..bc3a7521327f1fcace6ed6e4d1f77a486857bf6c 100644 (file)
@@ -210,7 +210,7 @@ error handling for the moment; a better way to code this is shown below)::
    t = PyTuple_New(3);
    PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
    PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
-   PyTuple_SetItem(t, 2, PyString_FromString("three"));
+   PyTuple_SetItem(t, 2, PyUnicode_FromString("three"));
 
 Here, :c:func:`PyLong_FromLong` returns a new reference which is immediately
 stolen by :c:func:`PyTuple_SetItem`.  When you want to keep using an object
index 54655719045faa6564e217349aac7a059efc1ada..8afa56ac6ce39f35bfdf642e2f2a7fc8d89fe32a 100644 (file)
@@ -61,7 +61,7 @@ example::
    if (buf == NULL)
        return PyErr_NoMemory();
    ...Do some I/O operation involving buf...
-   res = PyString_FromString(buf);
+   res = PyBytes_FromString(buf);
    free(buf); /* malloc'ed */
    return res;
 
@@ -169,7 +169,7 @@ I/O buffer is allocated from the Python heap by using the first function set::
    if (buf == NULL)
        return PyErr_NoMemory();
    /* ...Do some I/O operation involving buf... */
-   res = PyString_FromString(buf);
+   res = PyBytes_FromString(buf);
    PyMem_Free(buf); /* allocated with PyMem_Malloc */
    return res;
 
@@ -181,7 +181,7 @@ The same code using the type-oriented function set::
    if (buf == NULL)
        return PyErr_NoMemory();
    /* ...Do some I/O operation involving buf... */
-   res = PyString_FromString(buf);
+   res = PyBytes_FromString(buf);
    PyMem_Del(buf); /* allocated with PyMem_New */
    return res;
 
index 3001415188b9e43e43cf2a2224c34e23a7cbdec5..3d68251dce709c85dfb552dba32e251737832c24 100644 (file)
@@ -287,14 +287,14 @@ strings, so we provide a new method::
 
        self = (Noddy *)type->tp_alloc(type, 0);
        if (self != NULL) {
-           self->first = PyString_FromString("");
+           self->first = PyUnicode_FromString("");
            if (self->first == NULL)
              {
                Py_DECREF(self);
                return NULL;
              }
 
-           self->last = PyString_FromString("");
+           self->last = PyUnicode_FromString("");
            if (self->last == NULL)
              {
                Py_DECREF(self);
@@ -449,7 +449,7 @@ concatenation of the first and last names. ::
        PyObject *args, *result;
 
        if (format == NULL) {
-           format = PyString_FromString("%s %s");
+           format = PyUnicode_FromString("%s %s");
            if (format == NULL)
                return NULL;
        }
@@ -468,7 +468,7 @@ concatenation of the first and last names. ::
        if (args == NULL)
            return NULL;
 
-       result = PyString_Format(format, args);
+       result = PyUnicode_Format(format, args);
        Py_DECREF(args);
 
        return result;
@@ -557,9 +557,9 @@ getting and setting the :attr:`first` attribute::
        return -1;
      }
 
-     if (! PyString_Check(value)) {
+     if (! PyUnicode_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
-                       "The first attribute value must be a string");
+                       "The first attribute value must be a str");
        return -1;
      }
 
@@ -1022,8 +1022,8 @@ example::
    static PyObject *
    newdatatype_repr(newdatatypeobject * obj)
    {
-       return PyString_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
-                                  obj->obj_UnderlyingDatatypePtr->size);
+       return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
+                                   obj->obj_UnderlyingDatatypePtr->size);
    }
 
 If no :attr:`tp_repr` handler is specified, the interpreter will supply a
@@ -1042,8 +1042,8 @@ Here is a simple example::
    static PyObject *
    newdatatype_str(newdatatypeobject * obj)
    {
-       return PyString_FromFormat("Stringified_newdatatype{{size:\%d}}",
-                                  obj->obj_UnderlyingDatatypePtr->size);
+       return PyUnicode_FromFormat("Stringified_newdatatype{{size:\%d}}",
+                                   obj->obj_UnderlyingDatatypePtr->size);
    }
 
 
@@ -1364,11 +1364,10 @@ Here is a desultory example of the implementation of the call function. ::
        if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
            return NULL;
        }
-       result = PyString_FromFormat(
+       result = PyUnicode_FromFormat(
            "Returning -- value: [\%d] arg1: [\%s] arg2: [\%s] arg3: [\%s]\n",
            obj->obj_UnderlyingDatatypePtr->size,
            arg1, arg2, arg3);
-       printf("\%s", PyString_AS_STRING(result));
        return result;
    }
 
index 7c684a092948ed32366ec57f4e8fe8f97f32d741..f862151f2305300e49fd38e9572ea86b9e299161 100644 (file)
@@ -82,18 +82,20 @@ returns its length and :c:func:`PyTuple_GetItem` returns the item at a specified
 index.  Lists have similar functions, :c:func:`PyListSize` and
 :c:func:`PyList_GetItem`.
 
-For strings, :c:func:`PyString_Size` returns its length and
-:c:func:`PyString_AsString` a pointer to its value.  Note that Python strings may
-contain null bytes so C's :c:func:`strlen` should not be used.
+For bytes, :c:func:`PyBytes_Size` returns its length and
+:c:func:`PyBytes_AsStringAndSize` provides a pointer to its value and its
+length.  Note that Python bytes objects may contain null bytes so C's
+:c:func:`strlen` should not be used.
 
 To test the type of an object, first make sure it isn't *NULL*, and then use
-:c:func:`PyString_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
+:c:func:`PyBytes_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
 
 There is also a high-level API to Python objects which is provided by the
 so-called 'abstract' interface -- read ``Include/abstract.h`` for further
 details.  It allows interfacing with any kind of Python sequence using calls
-like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.)  as well as
-many other useful protocols.
+like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well
+as many other useful protocols such as numbers (:c:func:`PyNumber_Index` et.
+al.) and mappings in the PyMapping APIs.
 
 
 How do I use Py_BuildValue() to create a tuple of arbitrary length?