preserve
[clinic start generated code]*/
+#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(readline_parse_and_bind__doc__,
#define READLINE_PARSE_AND_BIND_METHODDEF \
{"parse_and_bind", (PyCFunction)readline_parse_and_bind, METH_O, readline_parse_and_bind__doc__},
+static PyObject *
+readline_parse_and_bind_impl(PyObject *module, PyObject *string);
+
+static PyObject *
+readline_parse_and_bind(PyObject *module, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_parse_and_bind_impl(module, string);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+
PyDoc_STRVAR(readline_read_init_file__doc__,
"read_init_file($module, filename=None, /)\n"
"--\n"
}
filename_obj = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_read_init_file_impl(module, filename_obj);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
filename_obj = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_read_history_file_impl(module, filename_obj);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
filename_obj = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_write_history_file_impl(module, filename_obj);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
filename_obj = args[1];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_append_history_file_impl(module, nelements, filename_obj);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
function = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_set_completion_display_matches_hook_impl(module, function);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
function = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_set_startup_hook_impl(module, function);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
function = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_set_pre_input_hook_impl(module, function);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
#define READLINE_SET_COMPLETER_DELIMS_METHODDEF \
{"set_completer_delims", (PyCFunction)readline_set_completer_delims, METH_O, readline_set_completer_delims__doc__},
+static PyObject *
+readline_set_completer_delims_impl(PyObject *module, PyObject *string);
+
+static PyObject *
+readline_set_completer_delims(PyObject *module, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_set_completer_delims_impl(module, string);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+
PyDoc_STRVAR(readline_remove_history_item__doc__,
"remove_history_item($module, pos, /)\n"
"--\n"
if (entry_number == -1 && PyErr_Occurred()) {
goto exit;
}
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_remove_history_item_impl(module, entry_number);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
goto exit;
}
line = args[1];
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_replace_history_item_impl(module, entry_number, line);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
#define READLINE_ADD_HISTORY_METHODDEF \
{"add_history", (PyCFunction)readline_add_history, METH_O, readline_add_history__doc__},
+static PyObject *
+readline_add_history_impl(PyObject *module, PyObject *string);
+
+static PyObject *
+readline_add_history(PyObject *module, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_add_history_impl(module, string);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+
PyDoc_STRVAR(readline_set_auto_history__doc__,
"set_auto_history($module, enabled, /)\n"
"--\n"
static PyObject *
readline_get_completer_delims(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return readline_get_completer_delims_impl(module);
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_get_completer_delims_impl(module);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
}
PyDoc_STRVAR(readline_set_completer__doc__,
}
function = args[0];
skip_optional:
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_set_completer_impl(module, function);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
if (idx == -1 && PyErr_Occurred()) {
goto exit;
}
+ Py_BEGIN_CRITICAL_SECTION(module);
return_value = readline_get_history_item_impl(module, idx);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
static PyObject *
readline_get_current_history_length(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return readline_get_current_history_length_impl(module);
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_get_current_history_length_impl(module);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
}
PyDoc_STRVAR(readline_get_line_buffer__doc__,
static PyObject *
readline_get_line_buffer(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return readline_get_line_buffer_impl(module);
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_get_line_buffer_impl(module);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
}
#if defined(HAVE_RL_COMPLETION_APPEND_CHARACTER)
static PyObject *
readline_clear_history(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return readline_clear_history_impl(module);
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_clear_history_impl(module);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
}
#endif /* defined(HAVE_RL_COMPLETION_APPEND_CHARACTER) */
#define READLINE_INSERT_TEXT_METHODDEF \
{"insert_text", (PyCFunction)readline_insert_text, METH_O, readline_insert_text__doc__},
+static PyObject *
+readline_insert_text_impl(PyObject *module, PyObject *string);
+
+static PyObject *
+readline_insert_text(PyObject *module, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_insert_text_impl(module, string);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+
PyDoc_STRVAR(readline_redisplay__doc__,
"redisplay($module, /)\n"
"--\n"
static PyObject *
readline_redisplay(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return readline_redisplay_impl(module);
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(module);
+ return_value = readline_redisplay_impl(module);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
}
#ifndef READLINE_APPEND_HISTORY_FILE_METHODDEF
#ifndef READLINE_CLEAR_HISTORY_METHODDEF
#define READLINE_CLEAR_HISTORY_METHODDEF
#endif /* !defined(READLINE_CLEAR_HISTORY_METHODDEF) */
-/*[clinic end generated code: output=358ab465285c7949 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=88d9812b6caa2102 input=a9049054013a1b77]*/
/* Standard definitions */
#include "Python.h"
+#include "pycore_pyatomic_ft_wrappers.h"
#include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv()
#include <errno.h> // errno
/* Exported function to send one line to readline's init file parser */
/*[clinic input]
+@critical_section
readline.parse_and_bind
string: object
[clinic start generated code]*/
static PyObject *
-readline_parse_and_bind(PyObject *module, PyObject *string)
-/*[clinic end generated code: output=1a1ede8afb9546c1 input=8a28a00bb4d61eec]*/
+readline_parse_and_bind_impl(PyObject *module, PyObject *string)
+/*[clinic end generated code: output=828d9b6630d434f5 input=cefdc0f9f62f9fcc]*/
{
char *copy;
PyObject *encoded = encode(string);
/* Exported function to parse a readline init file */
/*[clinic input]
+@critical_section
readline.read_init_file
filename as filename_obj: object = None
static PyObject *
readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
-/*[clinic end generated code: output=8e059b676142831e input=4c80c473e448139d]*/
+/*[clinic end generated code: output=8e059b676142831e input=62b767adfab6cc15]*/
{
PyObject *filename_bytes;
if (filename_obj != Py_None) {
/* Exported function to load a readline history file */
/*[clinic input]
+@critical_section
readline.read_history_file
filename as filename_obj: object = None
static PyObject *
readline_read_history_file_impl(PyObject *module, PyObject *filename_obj)
-/*[clinic end generated code: output=66a951836fb54fbb input=3d29d755b7e6932e]*/
+/*[clinic end generated code: output=66a951836fb54fbb input=5d86fd7813172a67]*/
{
PyObject *filename_bytes;
if (filename_obj != Py_None) {
/* Exported function to save a readline history file */
/*[clinic input]
+@critical_section
readline.write_history_file
filename as filename_obj: object = None
static PyObject *
readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
-/*[clinic end generated code: output=fbcad13d8ef59ae6 input=28a8e062fe363703]*/
+/*[clinic end generated code: output=fbcad13d8ef59ae6 input=34aaada95120cfaa]*/
{
PyObject *filename_bytes;
const char *filename;
filename = NULL;
}
errno = err = write_history(filename);
- if (!err && _history_length >= 0)
- history_truncate_file(filename, _history_length);
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED(_history_length);
+ if (!err && history_length >= 0)
+ history_truncate_file(filename, history_length);
Py_XDECREF(filename_bytes);
errno = err;
if (errno)
/* Exported function to save part of a readline history file */
/*[clinic input]
+@critical_section
readline.append_history_file
nelements: int
static PyObject *
readline_append_history_file_impl(PyObject *module, int nelements,
PyObject *filename_obj)
-/*[clinic end generated code: output=5df06fc9da56e4e4 input=784b774db3a4b7c5]*/
+/*[clinic end generated code: output=5df06fc9da56e4e4 input=78a6061a8d3a0275]*/
{
if (nelements < 0)
{
}
errno = err = append_history(
nelements - libedit_append_replace_history_offset, filename);
- if (!err && _history_length >= 0)
- history_truncate_file(filename, _history_length);
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED(_history_length);
+ if (!err && history_length >= 0)
+ history_truncate_file(filename, history_length);
Py_XDECREF(filename_bytes);
errno = err;
if (errno)
readline_set_history_length_impl(PyObject *module, int length)
/*[clinic end generated code: output=e161a53e45987dc7 input=b8901bf16488b760]*/
{
- _history_length = length;
+ FT_ATOMIC_STORE_INT_RELAXED(_history_length, length);
Py_RETURN_NONE;
}
readline_get_history_length_impl(PyObject *module)
/*[clinic end generated code: output=83a2eeae35b6d2b9 input=5dce2eeba4327817]*/
{
- return PyLong_FromLong(_history_length);
+ int history_length = FT_ATOMIC_LOAD_INT_RELAXED(_history_length);
+ return PyLong_FromLong(history_length);
}
/* Generic hook function setter */
}
/*[clinic input]
+@critical_section
readline.set_completion_display_matches_hook
function: object = None
static PyObject *
readline_set_completion_display_matches_hook_impl(PyObject *module,
PyObject *function)
-/*[clinic end generated code: output=516e5cb8db75a328 input=4f0bfd5ab0179a26]*/
+/*[clinic end generated code: output=516e5cb8db75a328 input=ea4191e4a07d28d3]*/
{
readlinestate *state = get_readline_state(module);
PyObject *result = set_hook("completion_display_matches_hook",
}
/*[clinic input]
+@critical_section
readline.set_startup_hook
function: object = None
static PyObject *
readline_set_startup_hook_impl(PyObject *module, PyObject *function)
-/*[clinic end generated code: output=02cd0e0c4fa082ad input=7783b4334b26d16d]*/
+/*[clinic end generated code: output=02cd0e0c4fa082ad input=11fce34992f1125e]*/
{
readlinestate *state = get_readline_state(module);
return set_hook("startup_hook", &state->startup_hook,
/* Set pre-input hook */
/*[clinic input]
+@critical_section
readline.set_pre_input_hook
function: object = None
static PyObject *
readline_set_pre_input_hook_impl(PyObject *module, PyObject *function)
-/*[clinic end generated code: output=fe1a96505096f464 input=4f3eaeaf7ce1fdbe]*/
+/*[clinic end generated code: output=fe1a96505096f464 input=96d3d5ff4a0c7c28]*/
{
readlinestate *state = get_readline_state(module);
return set_hook("pre_input_hook", &state->pre_input_hook,
/* Set the tab-completion word-delimiters that readline uses */
/*[clinic input]
+@critical_section
readline.set_completer_delims
string: object
[clinic start generated code]*/
static PyObject *
-readline_set_completer_delims(PyObject *module, PyObject *string)
-/*[clinic end generated code: output=4305b266106c4f1f input=ae945337ebd01e20]*/
+readline_set_completer_delims_impl(PyObject *module, PyObject *string)
+/*[clinic end generated code: output=017e48e9704a2f64 input=6c87bb1cbed7fcf1]*/
{
char *break_chars;
PyObject *encoded = encode(string);
return PyErr_NoMemory();
}
-/* _py_free_history_entry: Utility function to free a history entry. */
+/* _py_free_history_entry_lock_held: Utility function to free a history entry. */
#if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0500
takes care of the timestamp. */
static void
-_py_free_history_entry(HIST_ENTRY *entry)
+_py_free_history_entry_lock_held(HIST_ENTRY *entry)
{
histdata_t data = free_history_entry(entry);
free(data);
/* No free_history_entry function; free everything manually. */
static void
-_py_free_history_entry(HIST_ENTRY *entry)
+_py_free_history_entry_lock_held(HIST_ENTRY *entry)
{
if (entry->line)
free((void *)entry->line);
#endif
/*[clinic input]
+@critical_section
readline.remove_history_item
pos as entry_number: int
static PyObject *
readline_remove_history_item_impl(PyObject *module, int entry_number)
-/*[clinic end generated code: output=ab114f029208c7e8 input=f248beb720ff1838]*/
+/*[clinic end generated code: output=ab114f029208c7e8 input=847d7cc7e7c25852]*/
{
HIST_ENTRY *entry;
return NULL;
}
/* free memory allocated for the history entry */
- _py_free_history_entry(entry);
+ _py_free_history_entry_lock_held(entry);
Py_RETURN_NONE;
}
/*[clinic input]
+@critical_section
readline.replace_history_item
pos as entry_number: int
static PyObject *
readline_replace_history_item_impl(PyObject *module, int entry_number,
PyObject *line)
-/*[clinic end generated code: output=f8cec2770ca125eb input=368bb66fe5ee5222]*/
+/*[clinic end generated code: output=f8cec2770ca125eb input=b44c8dcdc2dd87fe]*/
{
PyObject *encoded;
HIST_ENTRY *old_entry;
return NULL;
}
/* free memory allocated for the old history entry */
- _py_free_history_entry(old_entry);
+ _py_free_history_entry_lock_held(old_entry);
Py_RETURN_NONE;
}
/* Add a line to the history buffer */
/*[clinic input]
+@critical_section
readline.add_history
string: object
[clinic start generated code]*/
static PyObject *
-readline_add_history(PyObject *module, PyObject *string)
-/*[clinic end generated code: output=b107b7e8106e803d input=e57c1cf6bc68d7e3]*/
+readline_add_history_impl(PyObject *module, PyObject *string)
+/*[clinic end generated code: output=89047062042ac344 input=faa7053b8612513b]*/
{
PyObject *encoded = encode(string);
if (encoded == NULL) {
/* Get the tab-completion word-delimiters that readline uses */
/*[clinic input]
+@critical_section
readline.get_completer_delims
Get the word delimiters for completion.
static PyObject *
readline_get_completer_delims_impl(PyObject *module)
-/*[clinic end generated code: output=6b060280fa68ef43 input=e36eb14fb8a1f08a]*/
+/*[clinic end generated code: output=6b060280fa68ef43 input=80583cdf8176bcdd]*/
{
return decode(rl_completer_word_break_characters);
}
/* Set the completer function */
/*[clinic input]
+@critical_section
readline.set_completer
function: object = None
static PyObject *
readline_set_completer_impl(PyObject *module, PyObject *function)
-/*[clinic end generated code: output=171a2a60f81d3204 input=51e81e13118eb877]*/
+/*[clinic end generated code: output=171a2a60f81d3204 input=97f539d8d0bfcb95]*/
{
readlinestate *state = get_readline_state(module);
return set_hook("completer", &state->completer, function);
* See issue #8065.*/
static int
-_py_get_history_length(void)
+_py_get_history_length_lock_held(void)
{
HISTORY_STATE *hist_st = history_get_history_state();
int length = hist_st->length;
/* Exported function to get any element of history */
/*[clinic input]
+@critical_section
readline.get_history_item
index as idx: int
static PyObject *
readline_get_history_item_impl(PyObject *module, int idx)
-/*[clinic end generated code: output=83d3e53ea5f34b3d input=8adf5c80e6c7ff2b]*/
+/*[clinic end generated code: output=83d3e53ea5f34b3d input=2835b50c7bde705f]*/
{
HIST_ENTRY *hist_ent;
* use 0-based indexes, while readline and newer
* versions of libedit use 1-based indexes.
*/
- int length = _py_get_history_length();
+ int length = _py_get_history_length_lock_held();
idx = idx - 1 + libedit_history_start;
/* Exported function to get current length of history */
/*[clinic input]
+@critical_section
readline.get_current_history_length
Return the current (not the maximum) length of history.
static PyObject *
readline_get_current_history_length_impl(PyObject *module)
-/*[clinic end generated code: output=436b294f12ba1e3f input=9cb3f431a68d071f]*/
+/*[clinic end generated code: output=436b294f12ba1e3f input=22e9fd0abbc2fd8d]*/
{
- return PyLong_FromLong((long)_py_get_history_length());
+ return PyLong_FromLong((long)_py_get_history_length_lock_held());
}
/* Exported function to read the current line buffer */
/*[clinic input]
+@critical_section
readline.get_line_buffer
Return the current contents of the line buffer.
static PyObject *
readline_get_line_buffer_impl(PyObject *module)
-/*[clinic end generated code: output=d22f9025ecad80e4 input=5f5fbc0d12c69412]*/
+/*[clinic end generated code: output=d22f9025ecad80e4 input=8e02e0fe081feece]*/
{
return decode(rl_line_buffer);
}
/* Exported function to clear the current history */
/*[clinic input]
+@critical_section
readline.clear_history
Clear the current readline history.
static PyObject *
readline_clear_history_impl(PyObject *module)
-/*[clinic end generated code: output=1f2dbb0dfa5d5ebb input=208962c4393f5d16]*/
+/*[clinic end generated code: output=1f2dbb0dfa5d5ebb input=b2c6b11551593053]*/
{
clear_history();
Py_RETURN_NONE;
/* Exported function to insert text into the line buffer */
/*[clinic input]
+@critical_section
readline.insert_text
string: object
[clinic start generated code]*/
static PyObject *
-readline_insert_text(PyObject *module, PyObject *string)
-/*[clinic end generated code: output=23d792821d320c19 input=bc96c3c848d5ccb5]*/
+readline_insert_text_impl(PyObject *module, PyObject *string)
+/*[clinic end generated code: output=4bf4e176f68750e0 input=2f401f4316df33c2]*/
{
PyObject *encoded = encode(string);
if (encoded == NULL) {
/* Redisplay the line buffer */
/*[clinic input]
+@critical_section
readline.redisplay
Change what's displayed on the screen to reflect contents of the line buffer.
static PyObject *
readline_redisplay_impl(PyObject *module)
-/*[clinic end generated code: output=a8b9725827c3c34b input=b485151058d75edc]*/
+/*[clinic end generated code: output=a8b9725827c3c34b input=5895fd014615ff58]*/
{
rl_redisplay();
Py_RETURN_NONE;
{
add_history("2");
HIST_ENTRY *old_entry = replace_history_entry(1, "X", NULL);
- _py_free_history_entry(old_entry);
+ _py_free_history_entry_lock_held(old_entry);
HIST_ENTRY *item = history_get(libedit_history_start);
if (item && item->line && strcmp(item->line, "X")) {
libedit_append_replace_history_offset = 0;
n = strlen(p);
if (should_auto_add_history && n > 0) {
const char *line;
- int length = _py_get_history_length();
+ int length = _py_get_history_length_lock_held();
if (length > 0) {
HIST_ENTRY *hist_ent;
if (using_libedit_emulation) {