[Python-Dev] Re: [Python-checkins] python/dist/src/Modules readline.c, 2.72, 2.73

Michael Hudson mwh at python.net
Mon Aug 16 14:40:50 CEST 2004


montanaro at users.sourceforge.net writes:

> Update of /cvsroot/python/python/dist/src/Modules
> In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28578/Modules
>
> Modified Files:
> 	readline.c 
> Log Message:
> Add get_history_item and replace_history_item functions to the readline
> module.  Closes patch #675551.  My apologies to Michal Vitecek for taking so
> long to process this.

A few small quibbles...

>
> Index: readline.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v
> retrieving revision 2.72
> retrieving revision 2.73
> diff -C2 -d -r2.72 -r2.73
> *** readline.c	8 Jul 2004 15:28:18 -0000	2.72
> --- readline.c	15 Aug 2004 14:31:57 -0000	2.73
> ***************
> *** 295,298 ****
> --- 295,363 ----
>   set the readline word delimiters for tab-completion");
>   
> + static PyObject *
> + py_remove_history(PyObject *self, PyObject *args)
> + {
> +         int entry_number;
> +         HIST_ENTRY *entry;
> + 
> +         if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number))
> +                 return NULL;
> +         entry = remove_history(entry_number);
> +         if (!entry) {
> +                 char buf[80];
> +                 PyOS_snprintf(buf, sizeof(buf),
> +                               "No history item at position %i",
> +                               entry_number);
> +                 PyErr_SetString(PyExc_ValueError, buf);
> +                 return NULL;
> +         }

What's wrong with PyErr_Format()?

> +         /* free memory allocated for the history entry */
> +         if (entry->line)
> +                 free(entry->line);
> +         if (entry->data)
> +                 free(entry->data);
> +         free(entry);
> + 
> +         Py_INCREF(Py_None);
> +         return Py_None;
> + }
> + 
> + PyDoc_STRVAR(doc_remove_history,
> + "remove_history(pos) -> None\n\
     ^^^^^^^^^^^^^^
This isn't the name in the PyMethodDef at the end...

[snippity]

The same comments apply to the other function, too.

>   /* Add a line to the history buffer */
> ***************
> *** 494,497 ****
> --- 559,564 ----
>   	 METH_VARARGS, doc_set_completer_delims},
>   	{"add_history", py_add_history, METH_VARARGS, doc_add_history},
> +         {"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
              ^^^^^^^^^^^^^^^^^^^
> +         {"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
>   	{"get_completer_delims", get_completer_delims,
>   	 METH_NOARGS, doc_get_completer_delims},

Cheers,
mwh

-- 
  <dash> it's like a bicycle
  <dash> but with internet                      -- from Twisted.Quotes


More information about the Python-Dev mailing list