vim.eval('recursive object') do not return recursive object. It returns
deeply nested object instead and each object do not point same object.
The attached patch fixes this problem.
Steps To Reproduce:
let x = {}
let x.x = x
let y = []
call add(y, y)
python <<EOF
import vim
x = vim.eval('x')
y = vim.eval('y')
print x is x['x']
print y is y[0]
print x
print y
EOF
Actual Results:
False
False
{'x': {'x': {...}}}
[[[...]]]
Expected Results:
True
True
{'x': {...}}
[[...]]
--
Yukihiro Nakadaira - [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: src/if_python.c
===================================================================
--- src/if_python.c (revision 1308)
+++ src/if_python.c (working copy)
@@ -1151,14 +1151,20 @@
/* Check if we run into a recursive loop. The item must be in lookupDict
* then and we can use it again. */
- sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U, (long_u)our_tv);
- result = PyDict_GetItemString(lookupDict, ptrBuf);
- if (result != NULL)
- Py_INCREF(result);
- else if (our_tv->v_type == VAR_STRING)
+ if (our_tv->v_type == VAR_LIST || our_tv->v_type == VAR_DICT)
{
+ sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U, (long_u)our_tv->vval.v_list);
+ result = PyDict_GetItemString(lookupDict, ptrBuf);
+ if (result != NULL)
+ {
+ Py_INCREF(result);
+ return result;
+ }
+ }
+
+ if (our_tv->v_type == VAR_STRING)
+ {
result = Py_BuildValue("s", our_tv->vval.v_string);
- PyDict_SetItemString(lookupDict, ptrBuf, result);
}
else if (our_tv->v_type == VAR_NUMBER)
{
@@ -1167,7 +1173,6 @@
/* For backwards compatibility numbers are stored as strings. */
sprintf(buf, "%ld", (long)our_tv->vval.v_number);
result = Py_BuildValue("s", buf);
- PyDict_SetItemString(lookupDict, ptrBuf, result);
}
# ifdef FEAT_FLOAT
else if (our_tv->v_type == VAR_FLOAT)
@@ -1176,7 +1181,6 @@
sprintf(buf, "%f", our_tv->vval.v_float);
result = Py_BuildValue("s", buf);
- PyDict_SetItemString(lookupDict, ptrBuf, result);
}
# endif
else if (our_tv->v_type == VAR_LIST)
@@ -1185,10 +1189,11 @@
listitem_T *curr;
result = PyList_New(0);
- PyDict_SetItemString(lookupDict, ptrBuf, result);
if (list != NULL)
{
+ PyDict_SetItemString(lookupDict, ptrBuf, result);
+
for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
{
newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
@@ -1200,7 +1205,6 @@
else if (our_tv->v_type == VAR_DICT)
{
result = PyDict_New();
- PyDict_SetItemString(lookupDict, ptrBuf, result);
if (our_tv->vval.v_dict != NULL)
{
@@ -1209,6 +1213,8 @@
hashitem_T *hi;
dictitem_T *di;
+ PyDict_SetItemString(lookupDict, ptrBuf, result);
+
for (hi = ht->ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))