static PyObject * get_history_item(PyObject *self, PyObject *args) { int idx = 0; HIST_ENTRY *hist_ent; if (!PyArg_ParseTuple(args, "i:get_history_item", &idx)) return NULL; #ifdef __APPLE__ if (using_libedit_emulation) { /* Older versions of libedit's readline emulation * use 0-based indexes, while readline and newer * versions of libedit use 1-based indexes. */ int length = _py_get_history_length(); idx = idx - 1 + libedit_history_start; /* * Apple's readline emulation crashes when * the index is out of range, therefore * test for that and fail gracefully. */ if (idx < (0 + libedit_history_start) || idx >= (length + libedit_history_start)) { Py_RETURN_NONE; } } #endif /* __APPLE__ */ if ((hist_ent = history_get(idx))) return decode(hist_ent->line); else { Py_RETURN_NONE; } }
static PyObject * get_history_item(PyObject *self, PyObject *args) { int idx = 0; HIST_ENTRY *hist_ent; if (!PyArg_ParseTuple(args, "i:index", &idx)) return NULL; #ifdef __APPLE__ if (using_libedit_emulation) { /* Libedit emulation uses 0-based indexes, * the real one uses 1-based indexes, * adjust the index to ensure that Python * code doesn't have to worry about the * difference. */ int length = _py_get_history_length(); idx --; /* * Apple's readline emulation crashes when * the index is out of range, therefore * test for that and fail gracefully. */ if (idx < 0 || idx >= length) { Py_RETURN_NONE; } } #endif /* __APPLE__ */ if ((hist_ent = history_get(idx))) return PyUnicode_FromString(hist_ent->line); else { Py_RETURN_NONE; } }
static PyObject * get_current_history_length(PyObject *self, PyObject *noarg) { return PyLong_FromLong((long)_py_get_history_length()); }