10
10
11
11
/* Standard definitions */
12
12
#include "Python.h"
13
+ #include "pycore_pyatomic_ft_wrappers.h"
13
14
#include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv()
14
15
15
16
#include <errno.h> // errno
@@ -199,7 +200,7 @@ disable_bracketed_paste(void)
199
200
/* Exported function to send one line to readline's init file parser */
200
201
201
202
/*[clinic input]
202
- @critical_section module
203
+ @critical_section
203
204
readline.parse_and_bind
204
205
205
206
string: object
@@ -234,7 +235,7 @@ readline_parse_and_bind_impl(PyObject *module, PyObject *string)
234
235
/* Exported function to parse a readline init file */
235
236
236
237
/*[clinic input]
237
- @critical_section module
238
+ @critical_section
238
239
readline.read_init_file
239
240
240
241
filename as filename_obj: object = None
@@ -266,7 +267,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
266
267
/* Exported function to load a readline history file */
267
268
268
269
/*[clinic input]
269
- @critical_section module
270
+ @critical_section
270
271
readline.read_history_file
271
272
272
273
filename as filename_obj: object = None
@@ -299,6 +300,7 @@ static int _history_length = -1; /* do not truncate history by default */
299
300
/* Exported function to save a readline history file */
300
301
301
302
/*[clinic input]
303
+ @critical_section
302
304
readline.write_history_file
303
305
304
306
filename as filename_obj: object = None
@@ -325,8 +327,9 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
325
327
filename = NULL ;
326
328
}
327
329
errno = err = write_history (filename );
328
- if (!err && _history_length >= 0 )
329
- history_truncate_file (filename , _history_length );
330
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED (_history_length );
331
+ if (!err && history_length >= 0 )
332
+ history_truncate_file (filename , history_length );
330
333
Py_XDECREF (filename_bytes );
331
334
errno = err ;
332
335
if (errno )
@@ -338,6 +341,7 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
338
341
/* Exported function to save part of a readline history file */
339
342
340
343
/*[clinic input]
344
+ @critical_section
341
345
readline.append_history_file
342
346
343
347
nelements: int
@@ -373,8 +377,9 @@ readline_append_history_file_impl(PyObject *module, int nelements,
373
377
}
374
378
errno = err = append_history (
375
379
nelements - libedit_append_replace_history_offset , filename );
376
- if (!err && _history_length >= 0 )
377
- history_truncate_file (filename , _history_length );
380
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED (_history_length );
381
+ if (!err && history_length >= 0 )
382
+ history_truncate_file (filename , history_length );
378
383
Py_XDECREF (filename_bytes );
379
384
errno = err ;
380
385
if (errno )
@@ -401,7 +406,7 @@ static PyObject *
401
406
readline_set_history_length_impl (PyObject * module , int length )
402
407
/*[clinic end generated code: output=e161a53e45987dc7 input=b8901bf16488b760]*/
403
408
{
404
- _history_length = length ;
409
+ FT_ATOMIC_STORE_INT_RELAXED ( _history_length , length ) ;
405
410
Py_RETURN_NONE ;
406
411
}
407
412
@@ -417,7 +422,8 @@ static PyObject *
417
422
readline_get_history_length_impl (PyObject * module )
418
423
/*[clinic end generated code: output=83a2eeae35b6d2b9 input=5dce2eeba4327817]*/
419
424
{
420
- return PyLong_FromLong (_history_length );
425
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED (_history_length );
426
+ return PyLong_FromLong (history_length );
421
427
}
422
428
423
429
/* Generic hook function setter */
@@ -577,7 +583,7 @@ readline_get_endidx_impl(PyObject *module)
577
583
/* Set the tab-completion word-delimiters that readline uses */
578
584
579
585
/*[clinic input]
580
- @critical_section module
586
+ @critical_section
581
587
readline.set_completer_delims
582
588
583
589
string: object
@@ -650,7 +656,7 @@ _py_free_history_entry_lock_held(HIST_ENTRY *entry)
650
656
#endif
651
657
652
658
/*[clinic input]
653
- @critical_section module
659
+ @critical_section
654
660
readline.remove_history_item
655
661
656
662
pos as entry_number: int
@@ -683,7 +689,7 @@ readline_remove_history_item_impl(PyObject *module, int entry_number)
683
689
}
684
690
685
691
/*[clinic input]
686
- @critical_section module
692
+ @critical_section
687
693
readline.replace_history_item
688
694
689
695
pos as entry_number: int
@@ -730,7 +736,7 @@ readline_replace_history_item_impl(PyObject *module, int entry_number,
730
736
/* Add a line to the history buffer */
731
737
732
738
/*[clinic input]
733
- @critical_section module
739
+ @critical_section
734
740
readline.add_history
735
741
736
742
string: object
@@ -778,7 +784,7 @@ readline_set_auto_history_impl(PyObject *module,
778
784
/* Get the tab-completion word-delimiters that readline uses */
779
785
780
786
/*[clinic input]
781
- @critical_section module
787
+ @critical_section
782
788
readline.get_completer_delims
783
789
784
790
Get the word delimiters for completion.
@@ -853,7 +859,7 @@ _py_get_history_length_lock_held(void)
853
859
/* Exported function to get any element of history */
854
860
855
861
/*[clinic input]
856
- @critical_section module
862
+ @critical_section
857
863
readline.get_history_item
858
864
859
865
index as idx: int
@@ -897,7 +903,7 @@ readline_get_history_item_impl(PyObject *module, int idx)
897
903
/* Exported function to get current length of history */
898
904
899
905
/*[clinic input]
900
- @critical_section module
906
+ @critical_section
901
907
readline.get_current_history_length
902
908
903
909
Return the current (not the maximum) length of history.
@@ -913,7 +919,7 @@ readline_get_current_history_length_impl(PyObject *module)
913
919
/* Exported function to read the current line buffer */
914
920
915
921
/*[clinic input]
916
- @critical_section module
922
+ @critical_section
917
923
readline.get_line_buffer
918
924
919
925
Return the current contents of the line buffer.
@@ -931,7 +937,7 @@ readline_get_line_buffer_impl(PyObject *module)
931
937
/* Exported function to clear the current history */
932
938
933
939
/*[clinic input]
934
- @critical_section module
940
+ @critical_section
935
941
readline.clear_history
936
942
937
943
Clear the current readline history.
@@ -950,7 +956,7 @@ readline_clear_history_impl(PyObject *module)
950
956
/* Exported function to insert text into the line buffer */
951
957
952
958
/*[clinic input]
953
- @critical_section module
959
+ @critical_section
954
960
readline.insert_text
955
961
956
962
string: object
@@ -975,7 +981,7 @@ readline_insert_text_impl(PyObject *module, PyObject *string)
975
981
/* Redisplay the line buffer */
976
982
977
983
/*[clinic input]
978
- @critical_section module
984
+ @critical_section
979
985
readline.redisplay
980
986
981
987
Change what's displayed on the screen to reflect contents of the line buffer.
0 commit comments