annotate Modules/xreadlinesmodule.c @ 17581:c1937faabb23 2.1

Added support for optional explanation parameter to the \versionadded macro. Refactored do_cmd_versionadded() and do_cmd_versionchanged() to do most of the work in a helper function, with the do_cmd_*() wrappers just supplying a portion of the replacement text.
author Fred Drake <fdrake@acm.org>
date Wed, 18 Apr 2001 17:29:14 +0000
parents f1a49eec7c2b
children 77871c499215
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #include "Python.h"
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 static char xreadlines_doc [] =
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 "xreadlines(f)\n\
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 \n\
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 Return an xreadlines object for the file f.";
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 typedef struct {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 PyObject_HEAD
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 PyObject *file;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 PyObject *lines;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 int lineslen;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 int lineno;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 int abslineno;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 } PyXReadlinesObject;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 staticforward PyTypeObject XReadlinesObject_Type;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 static void
15819
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
20 xreadlines_dealloc(PyXReadlinesObject *op)
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
21 {
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 Py_XDECREF(op->file);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 Py_XDECREF(op->lines);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 PyObject_DEL(op);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 /* A larger chunk size doesn't seem to make a difference */
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #define CHUNKSIZE 8192
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 static PyXReadlinesObject *
15819
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
31 newreadlinesobject(PyObject *file)
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
32 {
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 PyXReadlinesObject *op;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 op = PyObject_NEW(PyXReadlinesObject, &XReadlinesObject_Type);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 if (op == NULL)
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 return NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 Py_XINCREF(file);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 op->file = file;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 op->lines = NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 op->abslineno = op->lineno = op->lineslen = 0;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 return op;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 static PyObject *
15819
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
45 xreadlines(PyObject *self, PyObject *args)
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
46 {
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 PyObject *file;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 PyXReadlinesObject *ret;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 if (!PyArg_ParseTuple(args, "O:xreadlines", &file))
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 return NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 ret = newreadlinesobject(file);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 return (PyObject*)ret;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
15819
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
56 static PyObject *
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
57 xreadlines_item(PyXReadlinesObject *a, int i)
79770ca15c5a Conform the new module to /the/ C style.
Thomas Wouters <thomas@python.org>
parents: 15791
diff changeset
58 {
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 if (i != a->abslineno) {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 PyErr_SetString(PyExc_RuntimeError,
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 "xreadlines object accessed out of order");
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 return NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 if (a->lineno >= a->lineslen) {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 Py_XDECREF(a->lines);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 a->lines = PyObject_CallMethod(a->file, "readlines", "(i)",
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 CHUNKSIZE);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if (a->lines == NULL)
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 return NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 a->lineno = 0;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if ((a->lineslen = PySequence_Size(a->lines)) < 0)
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 return NULL;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 a->abslineno++;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 return PySequence_GetItem(a->lines, a->lineno++);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 }
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 static PySequenceMethods xreadlines_as_sequence = {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 0, /*sq_length*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 0, /*sq_concat*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 0, /*sq_repeat*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 (intargfunc)xreadlines_item, /*sq_item*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 };
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static PyTypeObject XReadlinesObject_Type = {
16008
4c856a180458 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 15819
diff changeset
86 PyObject_HEAD_INIT(NULL)
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 0,
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 "xreadlines",
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 sizeof(PyXReadlinesObject) + PyGC_HEAD_SIZE,
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 0,
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 (destructor)xreadlines_dealloc, /*tp_dealloc*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 0, /*tp_print*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 0, /*tp_getattr*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 0, /*tp_setattr*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 0, /*tp_compare*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 0, /*tp_repr*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 0, /*tp_as_number*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 &xreadlines_as_sequence, /*tp_as_sequence*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 0, /*tp_as_mapping*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 0, /*tp_hash*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 0, /*tp_call*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 0, /*tp_str*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 0, /*tp_getattro*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 0, /*tp_setattro*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 0, /*tp_as_buffer*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 Py_TPFLAGS_DEFAULT, /*tp_flags*/
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 0, /* tp_doc */
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 };
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
109
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 static PyMethodDef xreadlines_methods[] = {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 {"xreadlines", xreadlines, METH_VARARGS, xreadlines_doc},
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 {NULL, NULL}
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 };
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
15791
4854ee585e0d Assorted xreadlines problems:
Tim Peters <tim.peters@gmail.com>
parents: 15778
diff changeset
115 DL_EXPORT(void)
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 initxreadlines(void)
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 {
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 PyObject *m;
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
16008
4c856a180458 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 15819
diff changeset
120 XReadlinesObject_Type.ob_type = &PyType_Type;
15778
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 m = Py_InitModule("xreadlines", xreadlines_methods);
b5a37bf9d12d Jeff Epler's xreadlines module, with slight reformatting and some
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }