# HG changeset patch
# User ZyX <[email protected]>
# Date 1367162056 -14400
# Branch python-extended-2
# Node ID 5a313de268b20a15b0121ff3696d7ded2e570ab9
# Parent 76f0957fb04d08fc04dd44ca2c78db13c9e992d4
Make vim work on python-2.2:
- Use PyObject_IsTrue in place of PyBool_Check
The former is not present in python-2.2
- Fix thread saving in python-2.2
- Make test run without SyntaxErrors under python-2.2
diff -r 76f0957fb04d -r 5a313de268b2 src/if_py_both.h
--- a/src/if_py_both.h Sun Apr 28 04:27:42 2013 +0400
+++ b/src/if_py_both.h Sun Apr 28 19:14:16 2013 +0400
@@ -696,13 +696,7 @@
}
else
{
- if (!PyBool_Check(val))
- {
- PyErr_SetString(PyExc_TypeError, _("Only boolean objects are
allowed"));
- return -1;
- }
-
- if (val == Py_True)
+ if (PyObject_IsTrue(val))
this->dict->dv_lock = VAR_LOCKED;
else
this->dict->dv_lock = 0;
@@ -1202,13 +1196,7 @@
}
else
{
- if (!PyBool_Check(val))
- {
- PyErr_SetString(PyExc_TypeError, _("Only boolean objects are
allowed"));
- return -1;
- }
-
- if (val == Py_True)
+ if (PyObject_IsTrue(val))
this->list->lv_lock = VAR_LOCKED;
else
this->list->lv_lock = 0;
@@ -1484,14 +1472,8 @@
if (flags & SOPT_BOOL)
{
- if (!PyBool_Check(valObject))
- {
- PyErr_SetString(PyExc_ValueError, "Object must be boolean");
- return -1;
- }
-
- r = set_option_value_for(key, (valObject == Py_True), NULL, opt_flags,
- this->opt_type, this->from);
+ r = set_option_value_for(key, PyObject_IsTrue(valObject), NULL,
+ opt_flags, this->opt_type, this->from);
}
else if (flags & SOPT_NUM)
{
diff -r 76f0957fb04d -r 5a313de268b2 src/if_python.c
--- a/src/if_python.c Sun Apr 28 04:27:42 2013 +0400
+++ b/src/if_python.c Sun Apr 28 19:14:16 2013 +0400
@@ -229,6 +229,7 @@
# define _Py_TrueStruct (*dll__Py_TrueStruct)
# define PyObject_Init dll__PyObject_Init
# define PyObject_GetIter dll_PyObject_GetIter
+# define PyObject_IsTrue dll_PyObject_IsTrue
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
# define PyType_IsSubtype dll_PyType_IsSubtype
# endif
@@ -324,6 +325,7 @@
static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *);
static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *);
static PyObject* (*dll_PyObject_GetIter)(PyObject *);
+static int (*dll_PyObject_IsTrue)(PyObject *);
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
static iternextfunc dll__PyObject_NextNotImplemented;
# endif
@@ -459,6 +461,7 @@
{"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New},
{"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init},
{"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter},
+ {"PyObject_IsTrue", (PYTHON_PROC*)&dll_PyObject_IsTrue},
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
{"_PyObject_NextNotImplemented",
(PYTHON_PROC*)&dll__PyObject_NextNotImplemented},
# endif
@@ -787,7 +790,10 @@
* so the following does both: unlock GIL and save thread state in TLS
* without deleting thread state
*/
- PyEval_SaveThread();
+#ifndef PY_CAN_RECURSE
+ saved_python_thread =
+#endif
+ PyEval_SaveThread();
initialised = 1;
}
diff -r 76f0957fb04d -r 5a313de268b2 src/if_python3.c
--- a/src/if_python3.c Sun Apr 28 04:27:42 2013 +0400
+++ b/src/if_python3.c Sun Apr 28 19:14:16 2013 +0400
@@ -156,6 +156,7 @@
# define PyMapping_Items py3_PyMapping_Items
# define PyIter_Next py3_PyIter_Next
# define PyObject_GetIter py3_PyObject_GetIter
+# define PyObject_IsTrue py3_PyObject_IsTrue
# define PyModule_GetDict py3_PyModule_GetDict
#undef PyRun_SimpleString
# define PyRun_SimpleString py3_PyRun_SimpleString
@@ -264,6 +265,7 @@
static PyObject* (*py3_PyDict_New)(void);
static PyObject* (*py3_PyIter_Next)(PyObject *);
static PyObject* (*py3_PyObject_GetIter)(PyObject *);
+static int (*py3_PyObject_IsTrue)(PyObject *);
static PyObject* (*py3_Py_BuildValue)(char *, ...);
static int (*py3_PyType_Ready)(PyTypeObject *type);
static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject
*item);
@@ -392,6 +394,7 @@
{"PyMapping_Items", (PYTHON_PROC*)&py3_PyMapping_Items},
{"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next},
{"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
+ {"PyObject_IsTrue", (PYTHON_PROC*)&py3_PyObject_IsTrue},
{"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
{"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
{"PyType_Ready", (PYTHON_PROC*)&py3_PyType_Ready},
diff -r 76f0957fb04d -r 5a313de268b2 src/testdir/test86.in
--- a/src/testdir/test86.in Sun Apr 28 04:27:42 2013 +0400
+++ b/src/testdir/test86.in Sun Apr 28 19:14:16 2013 +0400
@@ -183,38 +183,21 @@
: $put ='[0.0, 0.0]'
:endif
:let messages=[]
-:py <<EOF
+py <<EOF
d=vim.bindeval('{}')
m=vim.bindeval('messages')
-try:
- d['abc']
-except Exception as e:
- m.extend([e.__class__.__name__])
+def em(expr, g=globals(), l=locals()):
+ try:
+ exec(expr, g, l)
+ except:
+ m.extend([sys.exc_type.__name__])
-try:
- d['abc']="\0"
-except Exception as e:
- m.extend([e.__class__.__name__])
-
-try:
- d['abc']=vim
-except Exception as e:
- m.extend([e.__class__.__name__])
-
-try:
- d['']=1
-except Exception as e:
- m.extend([e.__class__.__name__])
-
-try:
- d['a\0b']=1
-except Exception as e:
- m.extend([e.__class__.__name__])
-
-try:
- d[b'a\0b']=1
-except Exception as e:
- m.extend([e.__class__.__name__])
+em('d["abc"]')
+em('d["abc"]="\\0"')
+em('d["abc"]=vim')
+em('d[""]=1')
+em('d["a\\0b"]=1')
+em('d[u"a\\0b"]=1')
EOF
:$put =messages
:unlet messages
@@ -394,14 +377,14 @@
def e(s, g=globals(), l=locals()):
try:
exec(s, g, l)
- except Exception as e:
- vim.command('throw ' + repr(e.__class__.__name__))
+ except:
+ vim.command('throw ' + repr(sys.exc_type.__name__))
def ev(s, g=globals(), l=locals()):
try:
return eval(s, g, l)
- except Exception as e:
- vim.command('throw ' + repr(e.__class__.__name__))
+ except:
+ vim.command('throw ' + repr(sys.exc_type.__name__))
return 0
EOF
:function E(s)
diff -r 76f0957fb04d -r 5a313de268b2 src/testdir/test86.ok
--- a/src/testdir/test86.ok Sun Apr 28 04:27:42 2013 +0400
+++ b/src/testdir/test86.ok Sun Apr 28 19:14:16 2013 +0400
@@ -82,7 +82,6 @@
bar
>>> paste
p/gopts1: False
- inv: 2! ValueError
p/wopts1! KeyError
inv: 2! KeyError
wopts1! KeyError
@@ -224,7 +223,6 @@
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
@@ -280,7 +278,6 @@
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
diff -r 76f0957fb04d -r 5a313de268b2 src/testdir/test87.ok
--- a/src/testdir/test87.ok Sun Apr 28 04:27:42 2013 +0400
+++ b/src/testdir/test87.ok Sun Apr 28 19:14:16 2013 +0400
@@ -71,7 +71,6 @@
bar
>>> paste
p/gopts1: False
- inv: 2! ValueError
p/wopts1! KeyError
inv: 2! KeyError
wopts1! KeyError
@@ -213,7 +212,6 @@
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
@@ -269,7 +267,6 @@
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -cr vim.76f0957fb04d/src/if_py_both.h vim.5a313de268b2/src/if_py_both.h
*** vim.76f0957fb04d/src/if_py_both.h 2013-04-28 20:35:07.182783459 +0400
--- vim.5a313de268b2/src/if_py_both.h 2013-04-28 20:35:07.194783339 +0400
***************
*** 696,708 ****
}
else
{
! if (!PyBool_Check(val))
! {
! PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
! return -1;
! }
!
! if (val == Py_True)
this->dict->dv_lock = VAR_LOCKED;
else
this->dict->dv_lock = 0;
--- 696,702 ----
}
else
{
! if (PyObject_IsTrue(val))
this->dict->dv_lock = VAR_LOCKED;
else
this->dict->dv_lock = 0;
***************
*** 1202,1214 ****
}
else
{
! if (!PyBool_Check(val))
! {
! PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
! return -1;
! }
!
! if (val == Py_True)
this->list->lv_lock = VAR_LOCKED;
else
this->list->lv_lock = 0;
--- 1196,1202 ----
}
else
{
! if (PyObject_IsTrue(val))
this->list->lv_lock = VAR_LOCKED;
else
this->list->lv_lock = 0;
***************
*** 1484,1497 ****
if (flags & SOPT_BOOL)
{
! if (!PyBool_Check(valObject))
! {
! PyErr_SetString(PyExc_ValueError, "Object must be boolean");
! return -1;
! }
!
! r = set_option_value_for(key, (valObject == Py_True), NULL, opt_flags,
! this->opt_type, this->from);
}
else if (flags & SOPT_NUM)
{
--- 1472,1479 ----
if (flags & SOPT_BOOL)
{
! r = set_option_value_for(key, PyObject_IsTrue(valObject), NULL,
! opt_flags, this->opt_type, this->from);
}
else if (flags & SOPT_NUM)
{
diff -cr vim.76f0957fb04d/src/if_python3.c vim.5a313de268b2/src/if_python3.c
*** vim.76f0957fb04d/src/if_python3.c 2013-04-28 20:35:07.185783429 +0400
--- vim.5a313de268b2/src/if_python3.c 2013-04-28 20:35:07.198783299 +0400
***************
*** 156,161 ****
--- 156,162 ----
# define PyMapping_Items py3_PyMapping_Items
# define PyIter_Next py3_PyIter_Next
# define PyObject_GetIter py3_PyObject_GetIter
+ # define PyObject_IsTrue py3_PyObject_IsTrue
# define PyModule_GetDict py3_PyModule_GetDict
#undef PyRun_SimpleString
# define PyRun_SimpleString py3_PyRun_SimpleString
***************
*** 264,269 ****
--- 265,271 ----
static PyObject* (*py3_PyDict_New)(void);
static PyObject* (*py3_PyIter_Next)(PyObject *);
static PyObject* (*py3_PyObject_GetIter)(PyObject *);
+ static int (*py3_PyObject_IsTrue)(PyObject *);
static PyObject* (*py3_Py_BuildValue)(char *, ...);
static int (*py3_PyType_Ready)(PyTypeObject *type);
static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
***************
*** 392,397 ****
--- 394,400 ----
{"PyMapping_Items", (PYTHON_PROC*)&py3_PyMapping_Items},
{"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next},
{"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
+ {"PyObject_IsTrue", (PYTHON_PROC*)&py3_PyObject_IsTrue},
{"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
{"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
{"PyType_Ready", (PYTHON_PROC*)&py3_PyType_Ready},
diff -cr vim.76f0957fb04d/src/if_python.c vim.5a313de268b2/src/if_python.c
*** vim.76f0957fb04d/src/if_python.c 2013-04-28 20:35:07.188783399 +0400
--- vim.5a313de268b2/src/if_python.c 2013-04-28 20:35:07.201783269 +0400
***************
*** 229,234 ****
--- 229,235 ----
# define _Py_TrueStruct (*dll__Py_TrueStruct)
# define PyObject_Init dll__PyObject_Init
# define PyObject_GetIter dll_PyObject_GetIter
+ # define PyObject_IsTrue dll_PyObject_IsTrue
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
# define PyType_IsSubtype dll_PyType_IsSubtype
# endif
***************
*** 324,329 ****
--- 325,331 ----
static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *);
static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *);
static PyObject* (*dll_PyObject_GetIter)(PyObject *);
+ static int (*dll_PyObject_IsTrue)(PyObject *);
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
static iternextfunc dll__PyObject_NextNotImplemented;
# endif
***************
*** 459,464 ****
--- 461,467 ----
{"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New},
{"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init},
{"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter},
+ {"PyObject_IsTrue", (PYTHON_PROC*)&dll_PyObject_IsTrue},
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
{"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented},
# endif
***************
*** 787,793 ****
* so the following does both: unlock GIL and save thread state in TLS
* without deleting thread state
*/
! PyEval_SaveThread();
initialised = 1;
}
--- 790,799 ----
* so the following does both: unlock GIL and save thread state in TLS
* without deleting thread state
*/
! #ifndef PY_CAN_RECURSE
! saved_python_thread =
! #endif
! PyEval_SaveThread();
initialised = 1;
}
diff -cr vim.76f0957fb04d/src/testdir/test86.in vim.5a313de268b2/src/testdir/test86.in
*** vim.76f0957fb04d/src/testdir/test86.in 2013-04-28 20:35:07.183783450 +0400
--- vim.5a313de268b2/src/testdir/test86.in 2013-04-28 20:35:07.195783330 +0400
***************
*** 183,220 ****
: $put ='[0.0, 0.0]'
:endif
:let messages=[]
! :py <<EOF
d=vim.bindeval('{}')
m=vim.bindeval('messages')
! try:
! d['abc']
! except Exception as e:
! m.extend([e.__class__.__name__])
!
! try:
! d['abc']="\0"
! except Exception as e:
! m.extend([e.__class__.__name__])
!
! try:
! d['abc']=vim
! except Exception as e:
! m.extend([e.__class__.__name__])
!
! try:
! d['']=1
! except Exception as e:
! m.extend([e.__class__.__name__])
!
! try:
! d['a\0b']=1
! except Exception as e:
! m.extend([e.__class__.__name__])
!
! try:
! d[b'a\0b']=1
! except Exception as e:
! m.extend([e.__class__.__name__])
EOF
:$put =messages
:unlet messages
--- 183,203 ----
: $put ='[0.0, 0.0]'
:endif
:let messages=[]
! py <<EOF
d=vim.bindeval('{}')
m=vim.bindeval('messages')
! def em(expr, g=globals(), l=locals()):
! try:
! exec(expr, g, l)
! except:
! m.extend([sys.exc_type.__name__])
!
! em('d["abc"]')
! em('d["abc"]="\\0"')
! em('d["abc"]=vim')
! em('d[""]=1')
! em('d["a\\0b"]=1')
! em('d[u"a\\0b"]=1')
EOF
:$put =messages
:unlet messages
***************
*** 394,407 ****
def e(s, g=globals(), l=locals()):
try:
exec(s, g, l)
! except Exception as e:
! vim.command('throw ' + repr(e.__class__.__name__))
def ev(s, g=globals(), l=locals()):
try:
return eval(s, g, l)
! except Exception as e:
! vim.command('throw ' + repr(e.__class__.__name__))
return 0
EOF
:function E(s)
--- 377,390 ----
def e(s, g=globals(), l=locals()):
try:
exec(s, g, l)
! except:
! vim.command('throw ' + repr(sys.exc_type.__name__))
def ev(s, g=globals(), l=locals()):
try:
return eval(s, g, l)
! except:
! vim.command('throw ' + repr(sys.exc_type.__name__))
return 0
EOF
:function E(s)
diff -cr vim.76f0957fb04d/src/testdir/test86.ok vim.5a313de268b2/src/testdir/test86.ok
*** vim.76f0957fb04d/src/testdir/test86.ok 2013-04-28 20:35:07.183783450 +0400
--- vim.5a313de268b2/src/testdir/test86.ok 2013-04-28 20:35:07.196783319 +0400
***************
*** 82,88 ****
bar
>>> paste
p/gopts1: False
- inv: 2! ValueError
p/wopts1! KeyError
inv: 2! KeyError
wopts1! KeyError
--- 82,87 ----
***************
*** 224,230 ****
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
--- 223,228 ----
***************
*** 280,286 ****
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
--- 278,283 ----
diff -cr vim.76f0957fb04d/src/testdir/test87.ok vim.5a313de268b2/src/testdir/test87.ok
*** vim.76f0957fb04d/src/testdir/test87.ok 2013-04-28 20:35:07.180783480 +0400
--- vim.5a313de268b2/src/testdir/test87.ok 2013-04-28 20:35:07.192783359 +0400
***************
*** 71,77 ****
bar
>>> paste
p/gopts1: False
- inv: 2! ValueError
p/wopts1! KeyError
inv: 2! KeyError
wopts1! KeyError
--- 71,76 ----
***************
*** 213,219 ****
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
--- 212,217 ----
***************
*** 269,275 ****
wopts2! KeyError
wopts3! KeyError
p/bopts1: False
- inv: 2! ValueError
G: 0
W: 1:0 2:1 3:0 4:1
B: 1:0 2:1 3:0 4:1
--- 267,272 ----