Mercurial > vim
comparison src/if_python.c @ 1786:b2f4319efde1 v7.2.084
updated for version 7.2-084
author | vimboss |
---|---|
date | Tue, 13 Jan 2009 17:11:05 +0000 |
parents | 06317850ad3a |
children | fc89a4f98a8b |
comparison
equal
deleted
inserted
replaced
1785:65c332f15dbf | 1786:b2f4319efde1 |
---|---|
1149 return result; | 1149 return result; |
1150 } | 1150 } |
1151 | 1151 |
1152 /* Check if we run into a recursive loop. The item must be in lookupDict | 1152 /* Check if we run into a recursive loop. The item must be in lookupDict |
1153 * then and we can use it again. */ | 1153 * then and we can use it again. */ |
1154 sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U, (long_u)our_tv); | 1154 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL) |
1155 result = PyDict_GetItemString(lookupDict, ptrBuf); | 1155 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL)) |
1156 if (result != NULL) | 1156 { |
1157 Py_INCREF(result); | 1157 sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U, |
1158 else if (our_tv->v_type == VAR_STRING) | 1158 our_tv->v_type == VAR_LIST ? (long_u)our_tv->vval.v_list |
1159 : (long_u)our_tv->vval.v_dict); | |
1160 result = PyDict_GetItemString(lookupDict, ptrBuf); | |
1161 if (result != NULL) | |
1162 { | |
1163 Py_INCREF(result); | |
1164 return result; | |
1165 } | |
1166 } | |
1167 | |
1168 if (our_tv->v_type == VAR_STRING) | |
1159 { | 1169 { |
1160 result = Py_BuildValue("s", our_tv->vval.v_string); | 1170 result = Py_BuildValue("s", our_tv->vval.v_string); |
1161 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1162 } | 1171 } |
1163 else if (our_tv->v_type == VAR_NUMBER) | 1172 else if (our_tv->v_type == VAR_NUMBER) |
1164 { | 1173 { |
1165 char buf[NUMBUFLEN]; | 1174 char buf[NUMBUFLEN]; |
1166 | 1175 |
1167 /* For backwards compatibility numbers are stored as strings. */ | 1176 /* For backwards compatibility numbers are stored as strings. */ |
1168 sprintf(buf, "%ld", (long)our_tv->vval.v_number); | 1177 sprintf(buf, "%ld", (long)our_tv->vval.v_number); |
1169 result = Py_BuildValue("s", buf); | 1178 result = Py_BuildValue("s", buf); |
1170 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1171 } | 1179 } |
1172 # ifdef FEAT_FLOAT | 1180 # ifdef FEAT_FLOAT |
1173 else if (our_tv->v_type == VAR_FLOAT) | 1181 else if (our_tv->v_type == VAR_FLOAT) |
1174 { | 1182 { |
1175 char buf[NUMBUFLEN]; | 1183 char buf[NUMBUFLEN]; |
1176 | 1184 |
1177 sprintf(buf, "%f", our_tv->vval.v_float); | 1185 sprintf(buf, "%f", our_tv->vval.v_float); |
1178 result = Py_BuildValue("s", buf); | 1186 result = Py_BuildValue("s", buf); |
1179 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1180 } | 1187 } |
1181 # endif | 1188 # endif |
1182 else if (our_tv->v_type == VAR_LIST) | 1189 else if (our_tv->v_type == VAR_LIST) |
1183 { | 1190 { |
1184 list_T *list = our_tv->vval.v_list; | 1191 list_T *list = our_tv->vval.v_list; |
1185 listitem_T *curr; | 1192 listitem_T *curr; |
1186 | 1193 |
1187 result = PyList_New(0); | 1194 result = PyList_New(0); |
1188 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1189 | 1195 |
1190 if (list != NULL) | 1196 if (list != NULL) |
1191 { | 1197 { |
1198 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1199 | |
1192 for (curr = list->lv_first; curr != NULL; curr = curr->li_next) | 1200 for (curr = list->lv_first; curr != NULL; curr = curr->li_next) |
1193 { | 1201 { |
1194 newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict); | 1202 newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict); |
1195 PyList_Append(result, newObj); | 1203 PyList_Append(result, newObj); |
1196 Py_DECREF(newObj); | 1204 Py_DECREF(newObj); |
1198 } | 1206 } |
1199 } | 1207 } |
1200 else if (our_tv->v_type == VAR_DICT) | 1208 else if (our_tv->v_type == VAR_DICT) |
1201 { | 1209 { |
1202 result = PyDict_New(); | 1210 result = PyDict_New(); |
1203 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1204 | 1211 |
1205 if (our_tv->vval.v_dict != NULL) | 1212 if (our_tv->vval.v_dict != NULL) |
1206 { | 1213 { |
1207 hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab; | 1214 hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab; |
1208 long_u todo = ht->ht_used; | 1215 long_u todo = ht->ht_used; |
1209 hashitem_T *hi; | 1216 hashitem_T *hi; |
1210 dictitem_T *di; | 1217 dictitem_T *di; |
1218 | |
1219 PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1211 | 1220 |
1212 for (hi = ht->ht_array; todo > 0; ++hi) | 1221 for (hi = ht->ht_array; todo > 0; ++hi) |
1213 { | 1222 { |
1214 if (!HASHITEM_EMPTY(hi)) | 1223 if (!HASHITEM_EMPTY(hi)) |
1215 { | 1224 { |