1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
diff --git a/src/ieee1284module.c b/src/ieee1284module.c
index 23c1f29..c6d6928 100644
--- a/src/ieee1284module.c
+++ b/src/ieee1284module.c
@@ -52,33 +52,32 @@ Parport_dealloc (ParportObject *self)
{
if (self->port)
ieee1284_unref (self->port);
-
- self->ob_type->tp_free ((PyObject *) self);
+ Py_TYPE(self)->tp_free((PyObject *) self);
}
static PyObject *
Parport_getname (ParportObject *self, void *closure)
{
- return PyString_FromString (self->port->name);
+ return PyBytes_FromString (self->port->name);
}
static PyObject *
Parport_getbase_addr (ParportObject *self, void *closure)
{
- return PyInt_FromLong (self->port->base_addr);
+ return PyLong_FromLong (self->port->base_addr);
}
static PyObject *
Parport_gethibase_addr (ParportObject *self, void *closure)
{
- return PyInt_FromLong (self->port->hibase_addr);
+ return PyLong_FromLong (self->port->hibase_addr);
}
static PyObject *
Parport_getfilename (ParportObject *self, void *closure)
{
if (self->port->filename)
- return PyString_FromString (self->port->filename);
+ return PyBytes_FromString (self->port->filename);
Py_INCREF (Py_None);
return Py_None;
@@ -168,7 +167,7 @@ Parport_get_deviceid (ParportObject *self, PyObject *args)
return NULL;
}
- return PyString_FromStringAndSize (buffer, r);
+ return PyBytes_FromStringAndSize (buffer, r);
}
static PyObject *
@@ -186,7 +185,7 @@ Parport_open (ParportObject *self, PyObject *args)
return NULL;
}
- return PyInt_FromLong (capabilities);
+ return PyLong_FromLong (capabilities);
}
static PyObject *
@@ -198,7 +197,7 @@ Parport_get_irq_fd (ParportObject *self)
return NULL;
}
- return PyInt_FromLong (fd);
+ return PyLong_FromLong (fd);
}
static PyObject *
@@ -213,7 +212,7 @@ Parport_clear_irq (ParportObject *self)
return NULL;
}
- return PyInt_FromLong (portcount);
+ return PyLong_FromLong (portcount);
}
static PyObject *
@@ -259,7 +258,7 @@ Parport_read_data (ParportObject *self)
return NULL;
}
- return PyInt_FromLong (r);
+ return PyLong_FromLong (r);
}
static PyObject *
@@ -301,7 +300,7 @@ Parport_read_status (ParportObject *self)
return NULL;
}
- return PyInt_FromLong (r);
+ return PyLong_FromLong (r);
}
static PyObject *
@@ -335,7 +334,7 @@ Parport_read_control (ParportObject *self)
return NULL;
}
- return PyInt_FromLong (r);
+ return PyLong_FromLong (r);
}
static PyObject *
@@ -452,7 +451,7 @@ Parport_##x (ParportObject *self, PyObject *args) \
return NULL; \
} \
\
- ret = PyString_FromStringAndSize (buffer, got); \
+ ret = PyBytes_FromStringAndSize (buffer, got); \
free (buffer); \
return ret; \
}
@@ -480,7 +479,7 @@ Parport_##x (ParportObject *self, PyObject *args) \
return NULL; \
} \
\
- return PyInt_FromLong (wrote); \
+ return PyLong_FromLong (wrote); \
}
#define WRITE_METHOD(x) \
@@ -581,44 +580,53 @@ WRITE_METHOD(ecp_write_addr)
static PyTypeObject ParportType = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "ieee1284.Parport", /* tp_name */
- sizeof (ParportObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)Parport_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- "parallel port object", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- Parport_methods, /* tp_methods */
- 0, /* tp_members */
- Parport_getseters, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Parport_init, /* tp_init */
- 0, /* tp_alloc */
- Parport_new, /* tp_new */
+ "ieee1284.Parport", /* const char *tp_name; */
+ sizeof (ParportObject), /* Py_ssize_t tp_basicsize */
+ 0, /* Py_ssize_t tp_itemsize; */
+ (destructor)Parport_dealloc, /* destructor tp_dealloc; */
+ 0, /* printfunc tp_print; */
+ 0, /* getattrfunc tp_getattr; */
+ 0, /* setattrfunc tp_setattr; */
+ 0, /* PyAsyncMethods *tp_as_async; */
+ 0, /* reprfunc tp_repr; */
+ 0, /* PyNumberMethods *tp_as_number; */
+ 0, /* PySequenceMethods *tp_as_sequence; */
+ 0, /* PyMappingMethods *tp_as_mapping; */
+ 0, /* hashfunc tp_hash; */
+ 0, /* ternaryfunc tp_call; */
+ 0, /* reprfunc tp_str; */
+ 0, /* getattrofunc tp_getattro; */
+ 0, /* setattrofunc tp_setattro; */
+ 0, /* PyBufferProcs *tp_as_buffer; */
+ Py_TPFLAGS_DEFAULT, /* unsigned long tp_flags; */
+ "parallel port object", /* const char *tp_doc; */
+ 0, /* traverseproc tp_traverse; */
+ 0, /* inquiry tp_clear; */
+ 0, /* richcmpfunc tp_richcompare; */
+ 0, /* Py_ssize_t tp_weaklistoffset; */
+ 0, /* getiterfunc tp_iter; */
+ 0, /* iternextfunc tp_iternext; */
+ Parport_methods, /* struct PyMethodDef *tp_methods; */
+ 0, /* struct PyMemberDef *tp_members; */
+ Parport_getseters, /* struct PyGetSetDef *tp_getset; */
+ 0, /* struct _typeobject *tp_base; */
+ 0, /* PyObject *tp_dict; */
+ 0, /* descrgetfunc tp_descr_get; */
+ 0, /* descrsetfunc tp_descr_set; */
+ 0, /* Py_ssize_t tp_dictoffset; */
+ (initproc)Parport_init, /* initproc tp_init; */
+ 0, /* allocfunc tp_alloc; */
+ Parport_new, /* newfunc tp_new; */
+ 0, /* freefunc tp_free; */
+ 0, /* inquiry tp_is_gc; */
+ 0, /* PyObject *tp_bases; */
+ 0, /* PyObject *tp_mro; */
+ 0, /* PyObject *tp_cache; */
+ 0, /* PyObject *tp_subclasses; */
+ 0, /* PyObject *tp_weaklist; */
+ 0, /* destructor tp_del; */
+ 0, /* unsigned int tp_version_tag; */
+ 0 /* destructor tp_finalize; */
};
static PyObject *
@@ -672,18 +680,30 @@ static PyMethodDef Ieee1284Methods[] = {
{NULL, NULL, 0, NULL}
};
+static struct PyModuleDef Ieee1284Module = {
+ PyModuleDef_HEAD_INIT,
+ "ieee1284",
+ NULL, /* documentation */
+ -1,
+ Ieee1284Methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
#ifndef PyMODINIT_FUNC
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
-initieee1284 (void)
+PyInit_ieee1284module (void)
{
- PyObject *m = Py_InitModule ("ieee1284", Ieee1284Methods);
+ PyObject *m = PyModule_Create (&Ieee1284Module);
PyObject *d = PyModule_GetDict (m);
PyObject *c;
if (PyType_Ready (&ParportType) < 0)
- return;
+ return NULL;
PyModule_AddObject (m, "Parport", (PyObject *) &ParportType);
@@ -693,7 +713,7 @@ initieee1284 (void)
#define CONSTANT(x) \
do { \
- c = PyInt_FromLong (x); \
+ c = PyLong_FromLong (x); \
PyDict_SetItemString (d, #x, c); \
Py_DECREF (c); \
} while (0)
@@ -740,4 +760,6 @@ initieee1284 (void)
CONSTANT (F1284_SWE);
CONSTANT (F1284_RLE);
CONSTANT (F1284_FASTEPP);
+
+ return m;
}
|