summarylogtreecommitdiffstats
path: root/python3.patch
blob: febfc8b639db03f461222c5231e86e6c4ac2eea3 (plain)
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
--- a/language/python/gpibinter.c	2014-12-13 12:27:49.000000000 +0200
+++ b/language/python/gpibinter.c	2015-03-12 17:20:57.712141182 +0200
@@ -98,7 +98,7 @@
 		_SetGpibError("find");
 		return NULL;
 	}
-	return PyInt_FromLong(ud);
+	return PyLong_FromLong(ud);
 }
 
 static char gpib_dev__doc__[] =
@@ -126,7 +126,7 @@
 		_SetGpibError("dev");
 		return NULL;
 	}
-	return PyInt_FromLong(ud);
+	return PyLong_FromLong(ud);
 }
 
 
@@ -149,7 +149,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(result);
+	return PyLong_FromLong(result);
 }
 
 
@@ -177,7 +177,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_listener__doc__[] =
@@ -220,7 +220,7 @@
 	   No copying needed, more efficient. (yes, this is legal, see
 	   http://www.python.org/doc/current/api/stringObjects.html) */
 
-	retval = PyString_FromStringAndSize(NULL, len);
+	retval = PyUnicode_FromStringAndSize(NULL, len);
 	if(retval == NULL)
 	{
 		PyErr_SetString(GpibError, "Read Error: can't get Memory.");
@@ -228,7 +228,7 @@
 	}
 
 	Py_BEGIN_ALLOW_THREADS
-	sta = ibrd(device, PyString_AS_STRING(retval), len);
+	sta = ibrd(device, PyUnicode_AS_UNICODE(retval), len);
 	Py_END_ALLOW_THREADS
 
 	if( sta & ERR )
@@ -238,7 +238,7 @@
 		return NULL;
 	}
 
-	_PyString_Resize(&retval, ThreadIbcntl());
+	PyUnicode_Resize(&retval, ThreadIbcntl());
 	return retval;
 }
 
@@ -265,7 +265,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_write_async__doc__[] =
@@ -291,7 +291,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 
@@ -318,7 +318,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_remote_enable__doc__[] =
@@ -343,7 +343,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 
@@ -368,7 +368,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 
@@ -393,7 +393,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 
@@ -418,7 +418,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 
@@ -443,7 +443,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_wait__doc__[] =
@@ -468,7 +468,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_timeout__doc__[] =
@@ -492,7 +492,7 @@
 		_SetGpibError("tmo");
 		return NULL;
 	}
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_serial_poll__doc__[] =
@@ -541,7 +541,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromLong(sta);
+	return PyLong_FromLong(sta);
 }
 
 static char gpib_ibsta__doc__[] =
@@ -550,7 +550,7 @@
 
 static PyObject* gpib_ibsta(PyObject *self, PyObject *args)
 {
-	return PyInt_FromLong(ThreadIbsta());
+	return PyLong_FromLong(ThreadIbsta());
 }
 
 static char gpib_ibcnt__doc__[] =
@@ -559,7 +559,7 @@
 
 static PyObject* gpib_ibcnt(PyObject *self, PyObject *args)
 {
-	return PyInt_FromLong(ThreadIbcntl());
+	return PyLong_FromLong(ThreadIbcntl());
 }
 
 /* List of methods defined in the module */
@@ -598,13 +598,24 @@
 	"As in the C API, all functions return the value of ibsta,\n"
 	"except where otherwise specified.";
 
-void initgpib(void)
+static struct PyModuleDef moduledef = {
+	PyModuleDef_HEAD_INIT,
+	"gpib",
+	gpib_module_documentation,
+	-1,
+	gpib_methods,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+};
+
+PyMODINIT_FUNC PyInit_gpib(void)
 {
 	PyObject *m;
 
 	/* Create the module and add the functions */
-	m = Py_InitModule4("gpib", gpib_methods, gpib_module_documentation,
-		(PyObject*)NULL, PYTHON_API_VERSION);
+	m = PyModule_Create(&moduledef);
 
 	/* Add GpibError exception to the module */
 	GpibError = PyErr_NewException("gpib.GpibError", NULL, NULL);
@@ -697,4 +708,6 @@
 	/* Check for errors */
 	if (PyErr_Occurred())
 		Py_FatalError("can't initialize module gpib");
+
+	return m;
 }
 
--- a/language/python/Gpib.py	(original)
+++ b/language/python/Gpib.py	(refactored)
@@ -17,7 +17,7 @@
 
 	def __init__(self, name = 'gpib0', pad = None, sad = 0, timeout = 13, send_eoi = 1, eos_mode = 0):
 		self._own = False
-		if isinstance(name, basestring):
+		if isinstance(name, str):
 			self.id = gpib.find(name)
 			self._own = True
 		elif pad is None: