Changeset 391 for python/trunk/Doc/c-api/file.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/c-api/file.rst
r2 r391 8 8 .. index:: object: file 9 9 10 Python's built-in file objects are implemented entirely on the :c type:`FILE\*`10 Python's built-in file objects are implemented entirely on the :c:type:`FILE\*` 11 11 support from the C standard library. This is an implementation detail and may 12 12 change in future releases of Python. 13 13 14 14 15 .. c type:: PyFileObject15 .. c:type:: PyFileObject 16 16 17 This subtype of :c type:`PyObject` represents a Python file object.17 This subtype of :c:type:`PyObject` represents a Python file object. 18 18 19 19 20 .. c var:: PyTypeObject PyFile_Type20 .. c:var:: PyTypeObject PyFile_Type 21 21 22 22 .. index:: single: FileType (in module types) 23 23 24 This instance of :c type:`PyTypeObject` represents the Python file type. This is24 This instance of :c:type:`PyTypeObject` represents the Python file type. This is 25 25 exposed to Python programs as ``file`` and ``types.FileType``. 26 26 27 27 28 .. c function:: int PyFile_Check(PyObject *p)28 .. c:function:: int PyFile_Check(PyObject *p) 29 29 30 Return true if its argument is a :c type:`PyFileObject` or a subtype of31 :c type:`PyFileObject`.30 Return true if its argument is a :c:type:`PyFileObject` or a subtype of 31 :c:type:`PyFileObject`. 32 32 33 33 .. versionchanged:: 2.2 … … 35 35 36 36 37 .. c function:: int PyFile_CheckExact(PyObject *p)37 .. c:function:: int PyFile_CheckExact(PyObject *p) 38 38 39 Return true if its argument is a :c type:`PyFileObject`, but not a subtype of40 :c type:`PyFileObject`.39 Return true if its argument is a :c:type:`PyFileObject`, but not a subtype of 40 :c:type:`PyFileObject`. 41 41 42 42 .. versionadded:: 2.2 43 43 44 44 45 .. c function:: PyObject* PyFile_FromString(char *filename, char *mode)45 .. c:function:: PyObject* PyFile_FromString(char *filename, char *mode) 46 46 47 47 .. index:: single: fopen() … … 49 49 On success, return a new file object that is opened on the file given by 50 50 *filename*, with a file mode given by *mode*, where *mode* has the same 51 semantics as the standard C routine :c func:`fopen`. On failure, return *NULL*.51 semantics as the standard C routine :c:func:`fopen`. On failure, return *NULL*. 52 52 53 53 54 .. c function:: PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*))54 .. c:function:: PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*)) 55 55 56 Create a new :c type:`PyFileObject` from the already-open standard C file56 Create a new :c:type:`PyFileObject` from the already-open standard C file 57 57 pointer, *fp*. The function *close* will be called when the file should be 58 closed. Return *NULL* on failure. 58 closed. Return *NULL* and close the file using *close* on failure. 59 *close* is optional and can be set to *NULL*. 59 60 60 61 61 .. c function:: FILE* PyFile_AsFile(PyObject \*p)62 .. c:function:: FILE* PyFile_AsFile(PyObject \*p) 62 63 63 Return the file object associated with *p* as a :c type:`FILE\*`.64 Return the file object associated with *p* as a :c:type:`FILE\*`. 64 65 65 If the caller will ever use the returned :c type:`FILE\*` object while66 the GIL is released it must also call the :cfunc:`PyFile_IncUseCount` and67 :c func:`PyFile_DecUseCount` functions described below as appropriate.66 If the caller will ever use the returned :c:type:`FILE\*` object while 67 the :term:`GIL` is released it must also call the :c:func:`PyFile_IncUseCount` and 68 :c:func:`PyFile_DecUseCount` functions described below as appropriate. 68 69 69 70 70 .. c function:: void PyFile_IncUseCount(PyFileObject \*p)71 .. c:function:: void PyFile_IncUseCount(PyFileObject \*p) 71 72 72 73 Increments the PyFileObject's internal use count to indicate 73 that the underlying :c type:`FILE\*` is being used.74 that the underlying :c:type:`FILE\*` is being used. 74 75 This prevents Python from calling f_close() on it from another thread. 75 Callers of this must call :c func:`PyFile_DecUseCount` when they are76 finished with the :c type:`FILE\*`. Otherwise the file object will76 Callers of this must call :c:func:`PyFile_DecUseCount` when they are 77 finished with the :c:type:`FILE\*`. Otherwise the file object will 77 78 never be closed by Python. 78 79 79 The GILmust be held while calling this function.80 The :term:`GIL` must be held while calling this function. 80 81 81 The suggested use is to call this after :cfunc:`PyFile_AsFile` just before 82 you release the GIL. 82 The suggested use is to call this after :c:func:`PyFile_AsFile` and before 83 you release the GIL:: 84 85 FILE *fp = PyFile_AsFile(p); 86 PyFile_IncUseCount(p); 87 /* ... */ 88 Py_BEGIN_ALLOW_THREADS 89 do_something(fp); 90 Py_END_ALLOW_THREADS 91 /* ... */ 92 PyFile_DecUseCount(p); 83 93 84 94 .. versionadded:: 2.6 85 95 86 96 87 .. c function:: void PyFile_DecUseCount(PyFileObject \*p)97 .. c:function:: void PyFile_DecUseCount(PyFileObject \*p) 88 98 89 99 Decrements the PyFileObject's internal unlocked_count member to 90 indicate that the caller is done with its own use of the :c type:`FILE\*`.91 This may only be called to undo a prior call to :c func:`PyFile_IncUseCount`.100 indicate that the caller is done with its own use of the :c:type:`FILE\*`. 101 This may only be called to undo a prior call to :c:func:`PyFile_IncUseCount`. 92 102 93 The GIL must be held while calling this function. 103 The :term:`GIL` must be held while calling this function (see the example 104 above). 94 105 95 106 .. versionadded:: 2.6 96 107 97 108 98 .. c function:: PyObject* PyFile_GetLine(PyObject *p, int n)109 .. c:function:: PyObject* PyFile_GetLine(PyObject *p, int n) 99 110 100 111 .. index:: single: EOFError (built-in exception) 101 112 102 113 Equivalent to ``p.readline([n])``, this function reads one line from the 103 object *p*. *p* may be a file object or any object with a :meth:`readline` 114 object *p*. *p* may be a file object or any object with a 115 :meth:`~io.IOBase.readline` 104 116 method. If *n* is ``0``, exactly one line is read, regardless of the length of 105 117 the line. If *n* is greater than ``0``, no more than *n* bytes will be read … … 110 122 111 123 112 .. c function:: PyObject* PyFile_Name(PyObject *p)124 .. c:function:: PyObject* PyFile_Name(PyObject *p) 113 125 114 126 Return the name of the file specified by *p* as a string object. 115 127 116 128 117 .. c function:: void PyFile_SetBufSize(PyFileObject *p, int n)129 .. c:function:: void PyFile_SetBufSize(PyFileObject *p, int n) 118 130 119 131 .. index:: single: setvbuf() 120 132 121 Available on systems with :c func:`setvbuf` only. This should only be called133 Available on systems with :c:func:`setvbuf` only. This should only be called 122 134 immediately after file object creation. 123 135 124 136 125 .. c function:: int PyFile_SetEncoding(PyFileObject *p, const char *enc)137 .. c:function:: int PyFile_SetEncoding(PyFileObject *p, const char *enc) 126 138 127 139 Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0 … … 131 143 132 144 133 .. c function:: int PyFile_SetEncodingAndErrors(PyFileObject *p, const char *enc, *errors)145 .. c:function:: int PyFile_SetEncodingAndErrors(PyFileObject *p, const char *enc, *errors) 134 146 135 147 Set the file's encoding for Unicode output to *enc*, and its error … … 139 151 140 152 141 .. c function:: int PyFile_SoftSpace(PyObject *p, int newflag)153 .. c:function:: int PyFile_SoftSpace(PyObject *p, int newflag) 142 154 143 155 .. index:: single: softspace (file attribute) … … 153 165 154 166 155 .. c function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)167 .. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags) 156 168 157 169 .. index:: single: Py_PRINT_RAW … … 163 175 164 176 165 .. c function:: int PyFile_WriteString(const char *s, PyObject *p)177 .. c:function:: int PyFile_WriteString(const char *s, PyObject *p) 166 178 167 179 Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on
Note:
See TracChangeset
for help on using the changeset viewer.