1010
1111/* Standard definitions */
1212#include "Python.h"
13+ #include "pycore_pyatomic_ft_wrappers.h"
1314#include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv()
1415
1516#include <errno.h> // errno
@@ -199,7 +200,7 @@ disable_bracketed_paste(void)
199200/* Exported function to send one line to readline's init file parser */
200201
201202/*[clinic input]
202- @critical_section module
203+ @critical_section
203204readline.parse_and_bind
204205
205206 string: object
@@ -234,7 +235,7 @@ readline_parse_and_bind_impl(PyObject *module, PyObject *string)
234235/* Exported function to parse a readline init file */
235236
236237/*[clinic input]
237- @critical_section module
238+ @critical_section
238239readline.read_init_file
239240
240241 filename as filename_obj: object = None
@@ -266,7 +267,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
266267/* Exported function to load a readline history file */
267268
268269/*[clinic input]
269- @critical_section module
270+ @critical_section
270271readline.read_history_file
271272
272273 filename as filename_obj: object = None
@@ -299,6 +300,7 @@ static int _history_length = -1; /* do not truncate history by default */
299300/* Exported function to save a readline history file */
300301
301302/*[clinic input]
303+ @critical_section
302304readline.write_history_file
303305
304306 filename as filename_obj: object = None
@@ -325,8 +327,9 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
325327 filename = NULL ;
326328 }
327329 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 );
330333 Py_XDECREF (filename_bytes );
331334 errno = err ;
332335 if (errno )
@@ -338,6 +341,7 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
338341/* Exported function to save part of a readline history file */
339342
340343/*[clinic input]
344+ @critical_section
341345readline.append_history_file
342346
343347 nelements: int
@@ -373,8 +377,9 @@ readline_append_history_file_impl(PyObject *module, int nelements,
373377 }
374378 errno = err = append_history (
375379 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 );
378383 Py_XDECREF (filename_bytes );
379384 errno = err ;
380385 if (errno )
@@ -401,7 +406,7 @@ static PyObject *
401406readline_set_history_length_impl (PyObject * module , int length )
402407/*[clinic end generated code: output=e161a53e45987dc7 input=b8901bf16488b760]*/
403408{
404- _history_length = length ;
409+ FT_ATOMIC_STORE_INT_RELAXED ( _history_length , length ) ;
405410 Py_RETURN_NONE ;
406411}
407412
@@ -417,7 +422,8 @@ static PyObject *
417422readline_get_history_length_impl (PyObject * module )
418423/*[clinic end generated code: output=83a2eeae35b6d2b9 input=5dce2eeba4327817]*/
419424{
420- return PyLong_FromLong (_history_length );
425+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED (_history_length );
426+ return PyLong_FromLong (history_length );
421427}
422428
423429/* Generic hook function setter */
@@ -577,7 +583,7 @@ readline_get_endidx_impl(PyObject *module)
577583/* Set the tab-completion word-delimiters that readline uses */
578584
579585/*[clinic input]
580- @critical_section module
586+ @critical_section
581587readline.set_completer_delims
582588
583589 string: object
@@ -650,7 +656,7 @@ _py_free_history_entry_lock_held(HIST_ENTRY *entry)
650656#endif
651657
652658/*[clinic input]
653- @critical_section module
659+ @critical_section
654660readline.remove_history_item
655661
656662 pos as entry_number: int
@@ -683,7 +689,7 @@ readline_remove_history_item_impl(PyObject *module, int entry_number)
683689}
684690
685691/*[clinic input]
686- @critical_section module
692+ @critical_section
687693readline.replace_history_item
688694
689695 pos as entry_number: int
@@ -730,7 +736,7 @@ readline_replace_history_item_impl(PyObject *module, int entry_number,
730736/* Add a line to the history buffer */
731737
732738/*[clinic input]
733- @critical_section module
739+ @critical_section
734740readline.add_history
735741
736742 string: object
@@ -778,7 +784,7 @@ readline_set_auto_history_impl(PyObject *module,
778784/* Get the tab-completion word-delimiters that readline uses */
779785
780786/*[clinic input]
781- @critical_section module
787+ @critical_section
782788readline.get_completer_delims
783789
784790Get the word delimiters for completion.
@@ -853,7 +859,7 @@ _py_get_history_length_lock_held(void)
853859/* Exported function to get any element of history */
854860
855861/*[clinic input]
856- @critical_section module
862+ @critical_section
857863readline.get_history_item
858864
859865 index as idx: int
@@ -897,7 +903,7 @@ readline_get_history_item_impl(PyObject *module, int idx)
897903/* Exported function to get current length of history */
898904
899905/*[clinic input]
900- @critical_section module
906+ @critical_section
901907readline.get_current_history_length
902908
903909Return the current (not the maximum) length of history.
@@ -913,7 +919,7 @@ readline_get_current_history_length_impl(PyObject *module)
913919/* Exported function to read the current line buffer */
914920
915921/*[clinic input]
916- @critical_section module
922+ @critical_section
917923readline.get_line_buffer
918924
919925Return the current contents of the line buffer.
@@ -931,7 +937,7 @@ readline_get_line_buffer_impl(PyObject *module)
931937/* Exported function to clear the current history */
932938
933939/*[clinic input]
934- @critical_section module
940+ @critical_section
935941readline.clear_history
936942
937943Clear the current readline history.
@@ -950,7 +956,7 @@ readline_clear_history_impl(PyObject *module)
950956/* Exported function to insert text into the line buffer */
951957
952958/*[clinic input]
953- @critical_section module
959+ @critical_section
954960readline.insert_text
955961
956962 string: object
@@ -975,7 +981,7 @@ readline_insert_text_impl(PyObject *module, PyObject *string)
975981/* Redisplay the line buffer */
976982
977983/*[clinic input]
978- @critical_section module
984+ @critical_section
979985readline.redisplay
980986
981987Change what's displayed on the screen to reflect contents of the line buffer.
0 commit comments