@@ -82,7 +82,12 @@ termios_tcgetattr_impl(PyObject *module, int fd)
82
82
{
83
83
termiosmodulestate * state = PyModule_GetState (module );
84
84
struct termios mode ;
85
- if (tcgetattr (fd , & mode ) == -1 ) {
85
+ int r ;
86
+
87
+ Py_BEGIN_ALLOW_THREADS
88
+ r = tcgetattr (fd , & mode );
89
+ Py_END_ALLOW_THREADS
90
+ if (r == -1 ) {
86
91
return PyErr_SetFromErrno (state -> TermiosError );
87
92
}
88
93
@@ -169,7 +174,12 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
169
174
/* Get the old mode, in case there are any hidden fields... */
170
175
termiosmodulestate * state = PyModule_GetState (module );
171
176
struct termios mode ;
172
- if (tcgetattr (fd , & mode ) == -1 ) {
177
+ int r ;
178
+
179
+ Py_BEGIN_ALLOW_THREADS
180
+ r = tcgetattr (fd , & mode );
181
+ Py_END_ALLOW_THREADS
182
+ if (r == -1 ) {
173
183
return PyErr_SetFromErrno (state -> TermiosError );
174
184
}
175
185
@@ -211,7 +221,12 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
211
221
return PyErr_SetFromErrno (state -> TermiosError );
212
222
if (cfsetospeed (& mode , (speed_t ) ospeed ) == -1 )
213
223
return PyErr_SetFromErrno (state -> TermiosError );
214
- if (tcsetattr (fd , when , & mode ) == -1 )
224
+
225
+ Py_BEGIN_ALLOW_THREADS
226
+ r = tcsetattr (fd , when , & mode );
227
+ Py_END_ALLOW_THREADS
228
+
229
+ if (r == -1 )
215
230
return PyErr_SetFromErrno (state - > TermiosError );
216
231
217
232
Py_RETURN_NONE ;
@@ -235,7 +250,13 @@ termios_tcsendbreak_impl(PyObject *module, int fd, int duration)
235
250
/*[clinic end generated code: output=5945f589b5d3ac66 input=dc2f32417691f8ed]*/
236
251
{
237
252
termiosmodulestate * state = PyModule_GetState (module );
238
- if (tcsendbreak (fd , duration ) == -1 ) {
253
+ int r ;
254
+
255
+ Py_BEGIN_ALLOW_THREADS
256
+ r = tcsendbreak (fd , duration );
257
+ Py_END_ALLOW_THREADS
258
+
259
+ if (r == -1 ) {
239
260
return PyErr_SetFromErrno (state -> TermiosError );
240
261
}
241
262
@@ -256,7 +277,13 @@ termios_tcdrain_impl(PyObject *module, int fd)
256
277
/*[clinic end generated code: output=5fd86944c6255955 input=c99241b140b32447]*/
257
278
{
258
279
termiosmodulestate * state = PyModule_GetState (module );
259
- if (tcdrain (fd ) == -1 ) {
280
+ int r ;
281
+
282
+ Py_BEGIN_ALLOW_THREADS
283
+ r = tcdrain (fd );
284
+ Py_END_ALLOW_THREADS
285
+
286
+ if (r == -1 ) {
260
287
return PyErr_SetFromErrno (state -> TermiosError );
261
288
}
262
289
@@ -282,7 +309,13 @@ termios_tcflush_impl(PyObject *module, int fd, int queue)
282
309
/*[clinic end generated code: output=2424f80312ec2f21 input=0f7d08122ddc07b5]*/
283
310
{
284
311
termiosmodulestate * state = PyModule_GetState (module );
285
- if (tcflush (fd , queue ) == -1 ) {
312
+ int r ;
313
+
314
+ Py_BEGIN_ALLOW_THREADS
315
+ r = tcflush (fd , queue );
316
+ Py_END_ALLOW_THREADS
317
+
318
+ if (r == -1 ) {
286
319
return PyErr_SetFromErrno (state -> TermiosError );
287
320
}
288
321
@@ -308,7 +341,13 @@ termios_tcflow_impl(PyObject *module, int fd, int action)
308
341
/*[clinic end generated code: output=afd10928e6ea66eb input=c6aff0640b6efd9c]*/
309
342
{
310
343
termiosmodulestate * state = PyModule_GetState (module );
311
- if (tcflow (fd , action ) == -1 ) {
344
+ int r ;
345
+
346
+ Py_BEGIN_ALLOW_THREADS
347
+ r = tcflow (fd , action );
348
+ Py_END_ALLOW_THREADS
349
+
350
+ if (r == -1 ) {
312
351
return PyErr_SetFromErrno (state -> TermiosError );
313
352
}
314
353
@@ -333,7 +372,13 @@ termios_tcgetwinsize_impl(PyObject *module, int fd)
333
372
#if defined(TIOCGWINSZ )
334
373
termiosmodulestate * state = PyModule_GetState (module );
335
374
struct winsize w ;
336
- if (ioctl (fd , TIOCGWINSZ , & w ) == -1 ) {
375
+ int r ;
376
+
377
+ Py_BEGIN_ALLOW_THREADS
378
+ r = ioctl (fd , TIOCGWINSZ , & w );
379
+ Py_END_ALLOW_THREADS
380
+
381
+ if (r == -1 ) {
337
382
return PyErr_SetFromErrno (state -> TermiosError );
338
383
}
339
384
@@ -352,7 +397,12 @@ termios_tcgetwinsize_impl(PyObject *module, int fd)
352
397
#elif defined(TIOCGSIZE )
353
398
termiosmodulestate * state = PyModule_GetState (module );
354
399
struct ttysize s ;
355
- if (ioctl (fd , TIOCGSIZE , & s ) == -1 ) {
400
+ int r ;
401
+
402
+ Py_BEGIN_ALLOW_THREADS
403
+ r = ioctl (fd , TIOCGSIZE , & s );
404
+ Py_END_ALLOW_THREADS
405
+ if (r == -1 ) {
356
406
return PyErr_SetFromErrno (state -> TermiosError );
357
407
}
358
408
@@ -433,15 +483,25 @@ termios_tcsetwinsize_impl(PyObject *module, int fd, PyObject *winsz)
433
483
return NULL ;
434
484
}
435
485
436
- if (ioctl (fd , TIOCSWINSZ , & w ) == -1 ) {
486
+ int r ;
487
+ Py_BEGIN_ALLOW_THREADS
488
+ r = ioctl (fd , TIOCSWINSZ , & w );
489
+ Py_END_ALLOW_THREADS
490
+
491
+ if (r == -1 ) {
437
492
return PyErr_SetFromErrno (state -> TermiosError );
438
493
}
439
494
440
495
Py_RETURN_NONE ;
441
496
#elif defined(TIOCGSIZE ) && defined(TIOCSSIZE )
442
497
struct ttysize s ;
498
+ int r ;
443
499
/* Get the old ttysize because it might have more fields. */
444
- if (ioctl (fd , TIOCGSIZE , & s ) == -1 ) {
500
+ Py_BEGIN_ALLOW_THREADS
501
+ r = ioctl (fd , TIOCGSIZE , & s );
502
+ Py_END_ALLOW_THREADS
503
+
504
+ if (r == -1 ) {
445
505
return PyErr_SetFromErrno (state -> TermiosError );
446
506
}
447
507
@@ -453,7 +513,11 @@ termios_tcsetwinsize_impl(PyObject *module, int fd, PyObject *winsz)
453
513
return NULL ;
454
514
}
455
515
456
- if (ioctl (fd , TIOCSSIZE , & s ) == -1 ) {
516
+ Py_BEGIN_ALLOW_THREADS
517
+ r = ioctl (fd , TIOCSSIZE , & s );
518
+ Py_END_ALLOW_THREADS
519
+
520
+ if (r == -1 ) {
457
521
return PyErr_SetFromErrno (state -> TermiosError );
458
522
}
459
523
0 commit comments