mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
updated for version 7.3.671
Problem: More Python code can be shared between Python 2 and 3. Solution: Move code to if_py_both.h. (ZyX)
This commit is contained in:
@@ -71,6 +71,31 @@ static struct PyMethodDef OutputMethods[] = {
|
|||||||
/* Output buffer management
|
/* Output buffer management
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
OutputSetattr(PyObject *self, char *name, PyObject *val)
|
||||||
|
{
|
||||||
|
if (val == NULL)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(name, "softspace") == 0)
|
||||||
|
{
|
||||||
|
if (!PyInt_Check(val))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
((OutputObject *)(self))->softspace = PyInt_AsLong(val);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
OutputWrite(PyObject *self, PyObject *args)
|
OutputWrite(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@@ -951,31 +951,6 @@ OutputGetattr(PyObject *self, char *name)
|
|||||||
return Py_FindMethod(OutputMethods, self, name);
|
return Py_FindMethod(OutputMethods, self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
OutputSetattr(PyObject *self, char *name, PyObject *val)
|
|
||||||
{
|
|
||||||
if (val == NULL)
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(name, "softspace") == 0)
|
|
||||||
{
|
|
||||||
if (!PyInt_Check(val))
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
((OutputObject *)(self))->softspace = PyInt_AsLong(val);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************/
|
/***************/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@@ -88,6 +88,9 @@ static void init_structs(void);
|
|||||||
#define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
|
#define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
|
||||||
#define PyString_FromString(repr) PyUnicode_FromString(repr)
|
#define PyString_FromString(repr) PyUnicode_FromString(repr)
|
||||||
#define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
|
#define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
|
||||||
|
#define PyInt_Check(obj) PyLong_Check(obj)
|
||||||
|
#define PyInt_FromLong(i) PyLong_FromLong(i)
|
||||||
|
#define PyInt_AsLong(obj) PyLong_AsLong(obj)
|
||||||
|
|
||||||
#if defined(DYNAMIC_PYTHON3) || defined(PROTO)
|
#if defined(DYNAMIC_PYTHON3) || defined(PROTO)
|
||||||
|
|
||||||
@@ -586,6 +589,11 @@ static int py3initialised = 0;
|
|||||||
*/
|
*/
|
||||||
#include "if_py_both.h"
|
#include "if_py_both.h"
|
||||||
|
|
||||||
|
#define GET_ATTR_STRING(name, nameobj) \
|
||||||
|
char *name = ""; \
|
||||||
|
if(PyUnicode_Check(nameobj)) \
|
||||||
|
name = _PyUnicode_AsString(nameobj)
|
||||||
|
|
||||||
#define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
|
#define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -923,9 +931,7 @@ ex_py3file(exarg_T *eap)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
OutputGetattro(PyObject *self, PyObject *nameobj)
|
OutputGetattro(PyObject *self, PyObject *nameobj)
|
||||||
{
|
{
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (strcmp(name, "softspace") == 0)
|
if (strcmp(name, "softspace") == 0)
|
||||||
return PyLong_FromLong(((OutputObject *)(self))->softspace);
|
return PyLong_FromLong(((OutputObject *)(self))->softspace);
|
||||||
@@ -936,30 +942,9 @@ OutputGetattro(PyObject *self, PyObject *nameobj)
|
|||||||
static int
|
static int
|
||||||
OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
|
OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
|
||||||
{
|
{
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (val == NULL)
|
return OutputSetattr(self, name, val);
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(name, "softspace") == 0)
|
|
||||||
{
|
|
||||||
if (!PyLong_Check(val))
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
((OutputObject *)(self))->softspace = PyLong_AsLong(val);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************/
|
/***************/
|
||||||
@@ -1091,9 +1076,7 @@ BufferGetattro(PyObject *self, PyObject*nameobj)
|
|||||||
{
|
{
|
||||||
BufferObject *this = (BufferObject *)(self);
|
BufferObject *this = (BufferObject *)(self);
|
||||||
|
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (CheckBuffer(this))
|
if (CheckBuffer(this))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1257,9 +1240,7 @@ RangeDestructor(PyObject *self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
RangeGetattro(PyObject *self, PyObject *nameobj)
|
RangeGetattro(PyObject *self, PyObject *nameobj)
|
||||||
{
|
{
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (strcmp(name, "start") == 0)
|
if (strcmp(name, "start") == 0)
|
||||||
return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
|
return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
|
||||||
@@ -1430,10 +1411,7 @@ WindowGetattro(PyObject *self, PyObject *nameobj)
|
|||||||
{
|
{
|
||||||
WindowObject *this = (WindowObject *)(self);
|
WindowObject *this = (WindowObject *)(self);
|
||||||
|
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
|
|
||||||
if (CheckWindow(this))
|
if (CheckWindow(this))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1461,10 +1439,7 @@ WindowGetattro(PyObject *self, PyObject *nameobj)
|
|||||||
static int
|
static int
|
||||||
WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
|
WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
|
||||||
{
|
{
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
|
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
return WindowSetattr(self, name, val);
|
return WindowSetattr(self, name, val);
|
||||||
}
|
}
|
||||||
@@ -1508,9 +1483,7 @@ static PyTypeObject CurrentType;
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
|
CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
|
||||||
{
|
{
|
||||||
char *name = "";
|
GET_ATTR_STRING(name, nameobj);
|
||||||
if (PyUnicode_Check(nameobj))
|
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (strcmp(name, "buffer") == 0)
|
if (strcmp(name, "buffer") == 0)
|
||||||
return (PyObject *)BufferNew(curbuf);
|
return (PyObject *)BufferNew(curbuf);
|
||||||
@@ -1681,9 +1654,8 @@ FunctionDestructor(PyObject *self)
|
|||||||
FunctionGetattro(PyObject *self, PyObject *nameobj)
|
FunctionGetattro(PyObject *self, PyObject *nameobj)
|
||||||
{
|
{
|
||||||
FunctionObject *this = (FunctionObject *)(self);
|
FunctionObject *this = (FunctionObject *)(self);
|
||||||
char *name = "";
|
|
||||||
if (PyUnicode_Check(nameobj))
|
GET_ATTR_STRING(name, nameobj);
|
||||||
name = _PyUnicode_AsString(nameobj);
|
|
||||||
|
|
||||||
if (strcmp(name, "name") == 0)
|
if (strcmp(name, "name") == 0)
|
||||||
return PyUnicode_FromString((char *)(this->name));
|
return PyUnicode_FromString((char *)(this->name));
|
||||||
|
@@ -719,6 +719,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
671,
|
||||||
/**/
|
/**/
|
||||||
670,
|
670,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user