summaryrefslogtreecommitdiff
path: root/src/if_python.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-05-12 18:44:48 +0200
committerBram Moolenaar <Bram@vim.org>2013-05-12 18:44:48 +0200
commit971db4679940fd2f06733e8a1513215f9e1943a4 (patch)
tree566ecdc2f8d5cb86bc82160c190c20765da589ee /src/if_python.c
parent3b9abb6cc20d3077b6fd239fb59dee8c75fa599b (diff)
downloadvim-git-971db4679940fd2f06733e8a1513215f9e1943a4.tar.gz
updated for version 7.3.937v7.3.937
Problem: More can be shared between Python 2 and 3. Solution: Move code to if_py_both.h. (ZyX)
Diffstat (limited to 'src/if_python.c')
-rw-r--r--src/if_python.c109
1 files changed, 9 insertions, 100 deletions
diff --git a/src/if_python.c b/src/if_python.c
index 4eb9a4d96..addb674c2 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -619,6 +619,9 @@ static int initialised = 0;
#define DESTRUCTOR_FINISH(self) Py_DECREF(self);
+#define WIN_PYTHON_REF(win) win->w_python_ref
+#define BUF_PYTHON_REF(buf) buf->b_python_ref
+
static PyObject *OutputGetattr(PyObject *, char *);
static PyObject *BufferGetattr(PyObject *, char *);
static PyObject *WindowGetattr(PyObject *, char *);
@@ -1054,42 +1057,6 @@ static PySequenceMethods BufferAsSeq = {
*/
static PyObject *
-BufferNew(buf_T *buf)
-{
- /* We need to handle deletion of buffers underneath us.
- * If we add a "b_python_ref" field to the buf_T structure,
- * then we can get at it in buf_freeall() in vim. We then
- * need to create only ONE Python object per buffer - if
- * we try to create a second, just INCREF the existing one
- * and return it. The (single) Python object referring to
- * the buffer is stored in "b_python_ref".
- * Question: what to do on a buf_freeall(). We'll probably
- * have to either delete the Python object (DECREF it to
- * zero - a bad idea, as it leaves dangling refs!) or
- * set the buf_T * value to an invalid value (-1?), which
- * means we need checks in all access functions... Bah.
- */
-
- BufferObject *self;
-
- if (buf->b_python_ref != NULL)
- {
- self = buf->b_python_ref;
- Py_INCREF(self);
- }
- else
- {
- self = PyObject_NEW(BufferObject, &BufferType);
- if (self == NULL)
- return NULL;
- self->buf = buf;
- buf->b_python_ref = self;
- }
-
- return (PyObject *)(self);
-}
-
- static PyObject *
BufferGetattr(PyObject *self, char *name)
{
PyObject *r;
@@ -1107,30 +1074,6 @@ BufferGetattr(PyObject *self, char *name)
/******************/
static PyInt
-BufferLength(PyObject *self)
-{
- /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
- if (CheckBuffer((BufferObject *)(self)))
- return -1; /* ??? */
-
- return (((BufferObject *)(self))->buf->b_ml.ml_line_count);
-}
-
- static PyObject *
-BufferItem(PyObject *self, PyInt n)
-{
- return RBItem((BufferObject *)(self), n, 1,
- (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
-}
-
- static PyObject *
-BufferSlice(PyObject *self, PyInt lo, PyInt hi)
-{
- return RBSlice((BufferObject *)(self), lo, hi, 1,
- (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
-}
-
- static PyInt
BufferAssItem(PyObject *self, PyInt n, PyObject *val)
{
return RBAsItem((BufferObject *)(self), n, val, 1,
@@ -1217,40 +1160,6 @@ static PySequenceMethods BufListAsSeq = {
*/
static PyObject *
-WindowNew(win_T *win)
-{
- /* We need to handle deletion of windows underneath us.
- * If we add a "w_python_ref" field to the win_T structure,
- * then we can get at it in win_free() in vim. We then
- * need to create only ONE Python object per window - if
- * we try to create a second, just INCREF the existing one
- * and return it. The (single) Python object referring to
- * the window is stored in "w_python_ref".
- * On a win_free() we set the Python object's win_T* field
- * to an invalid value. We trap all uses of a window
- * object, and reject them if the win_T* field is invalid.
- */
-
- WindowObject *self;
-
- if (win->w_python_ref)
- {
- self = win->w_python_ref;
- Py_INCREF(self);
- }
- else
- {
- self = PyObject_NEW(WindowObject, &WindowType);
- if (self == NULL)
- return NULL;
- self->win = win;
- win->w_python_ref = self;
- }
-
- return (PyObject *)(self);
-}
-
- static PyObject *
WindowGetattr(PyObject *self, char *name)
{
PyObject *r;
@@ -1289,11 +1198,11 @@ static PySequenceMethods WinListAsSeq = {
void
python_buffer_free(buf_T *buf)
{
- if (buf->b_python_ref != NULL)
+ if (BUF_PYTHON_REF(buf) != NULL)
{
- BufferObject *bp = buf->b_python_ref;
+ BufferObject *bp = BUF_PYTHON_REF(buf);
bp->buf = INVALID_BUFFER_VALUE;
- buf->b_python_ref = NULL;
+ BUF_PYTHON_REF(buf) = NULL;
}
}
@@ -1301,11 +1210,11 @@ python_buffer_free(buf_T *buf)
void
python_window_free(win_T *win)
{
- if (win->w_python_ref != NULL)
+ if (WIN_PYTHON_REF(win) != NULL)
{
- WindowObject *wp = win->w_python_ref;
+ WindowObject *wp = WIN_PYTHON_REF(win);
wp->win = INVALID_WINDOW_VALUE;
- win->w_python_ref = NULL;
+ WIN_PYTHON_REF(win) = NULL;
}
}
#endif