Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Make sure the TH1 'info exists' sub-command preserves the existing interp error stack trace. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
9765b03759ff95c506b6b5777c6849ba |
User & Date: | mistachkin 2014-01-09 19:11:06 |
Context
2014-01-09
| ||
19:37 | Enforce minimum version requirement for SQLite of 3.8.2. ... (check-in: aee29225 user: mistachkin tags: trunk) | |
19:20 | Merge TH1 'info exists' fix from trunk. ... (check-in: 03504c62 user: mistachkin tags: branch-1.28) | |
19:11 | Make sure the TH1 'info exists' sub-command preserves the existing interp error stack trace. ... (check-in: 9765b037 user: mistachkin tags: trunk) | |
15:03 | Updates to the change-log. ... (check-in: ad2dd568 user: drh tags: trunk) | |
Changes
Changes to src/th.c.
︙ | ︙ | |||
1058 1059 1060 1061 1062 1063 1064 | ** arrayok is true an array name is Ok. */ static Th_Variable *thFindValue( Th_Interp *interp, const char *zVar, /* Pointer to variable name */ int nVar, /* Number of bytes at nVar */ int create, /* If true, create the variable if not found */ | | > | 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | ** arrayok is true an array name is Ok. */ static Th_Variable *thFindValue( Th_Interp *interp, const char *zVar, /* Pointer to variable name */ int nVar, /* Number of bytes at nVar */ int create, /* If true, create the variable if not found */ int arrayok, /* If true, an array is Ok. Otherwise array==error */ int noerror /* If false, set interpreter result to error message */ ){ const char *zOuter; int nOuter; const char *zInner; int nInner; int isGlobal; |
︙ | ︙ | |||
1091 1092 1093 1094 1095 1096 1097 | pValue = Th_Malloc(interp, sizeof(Th_Variable)); pValue->nRef = 1; pEntry->pData = (void *)pValue; } if( zInner ){ if( pValue->zData ){ | > | > | 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | pValue = Th_Malloc(interp, sizeof(Th_Variable)); pValue->nRef = 1; pEntry->pData = (void *)pValue; } if( zInner ){ if( pValue->zData ){ if( !noerror ){ Th_ErrorMessage(interp, "variable is a scalar:", zOuter, nOuter); } return 0; } if( !pValue->pHash ){ if( !create ){ goto no_such_var; } pValue->pHash = Th_HashNew(interp); |
︙ | ︙ | |||
1113 1114 1115 1116 1117 1118 1119 | assert(create); pValue = Th_Malloc(interp, sizeof(Th_Variable)); pValue->nRef = 1; pEntry->pData = (void *)pValue; } }else{ if( pValue->pHash && !arrayok ){ | > | > > | > | | | | 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 | assert(create); pValue = Th_Malloc(interp, sizeof(Th_Variable)); pValue->nRef = 1; pEntry->pData = (void *)pValue; } }else{ if( pValue->pHash && !arrayok ){ if( !noerror ){ Th_ErrorMessage(interp, "variable is an array:", zOuter, nOuter); } return 0; } } return pValue; no_such_var: if( !noerror ){ Th_ErrorMessage(interp, "no such variable:", zVar, nVar); } return 0; } /* ** String (zVar, nVar) must contain the name of a scalar variable or ** array member. Look up the variable, store its current value in ** the interpreter result and return TH_OK. ** ** If the named variable does not exist, return TH_ERROR and leave ** an error message in the interpreter result. */ int Th_GetVar(Th_Interp *interp, const char *zVar, int nVar){ Th_Variable *pValue; pValue = thFindValue(interp, zVar, nVar, 0, 0, 0); if( !pValue ){ return TH_ERROR; } if( !pValue->zData ){ Th_ErrorMessage(interp, "no such variable:", zVar, nVar); return TH_ERROR; } return Th_SetResult(interp, pValue->zData, pValue->nData); } /* ** Return true if variable (zVar, nVar) exists. */ int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ Th_Variable *pValue = thFindValue(interp, zVar, nVar, 0, 0, 1); return pValue && pValue->zData; } /* ** String (zVar, nVar) must contain the name of a scalar variable or ** array member. If the variable does not exist it is created. The ** variable is set to the value supplied in string (zValue, nValue). ** ** If (zVar, nVar) refers to an existing array, TH_ERROR is returned ** and an error message left in the interpreter result. */ int Th_SetVar( Th_Interp *interp, const char *zVar, int nVar, const char *zValue, int nValue ){ Th_Variable *pValue; pValue = thFindValue(interp, zVar, nVar, 1, 0, 0); if( !pValue ){ return TH_ERROR; } if( nValue<0 ){ nValue = th_strlen(zValue); } |
︙ | ︙ | |||
1216 1217 1218 1219 1220 1221 1222 | pFrame = getFrame(interp, iFrame); if( !pFrame ){ return TH_ERROR; } pSavedFrame = interp->pFrame; interp->pFrame = pFrame; | | | 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 | pFrame = getFrame(interp, iFrame); if( !pFrame ){ return TH_ERROR; } pSavedFrame = interp->pFrame; interp->pFrame = pFrame; pValue = thFindValue(interp, zLink, nLink, 1, 1, 0); interp->pFrame = pSavedFrame; pEntry = Th_HashFind(interp, interp->pFrame->paVar, zLocal, nLocal, 1); if( pEntry->pData ){ Th_ErrorMessage(interp, "variable exists:", zLocal, nLocal); return TH_ERROR; } |
︙ | ︙ | |||
1239 1240 1241 1242 1243 1244 1245 | ** an array, or an array member. If the identified variable exists, it ** is deleted and TH_OK returned. Otherwise, an error message is left ** in the interpreter result and TH_ERROR is returned. */ int Th_UnsetVar(Th_Interp *interp, const char *zVar, int nVar){ Th_Variable *pValue; | | | 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | ** an array, or an array member. If the identified variable exists, it ** is deleted and TH_OK returned. Otherwise, an error message is left ** in the interpreter result and TH_ERROR is returned. */ int Th_UnsetVar(Th_Interp *interp, const char *zVar, int nVar){ Th_Variable *pValue; pValue = thFindValue(interp, zVar, nVar, 0, 1, 0); if( !pValue ){ return TH_ERROR; } Th_Free(interp, pValue->zData); pValue->zData = 0; if( pValue->pHash ){ |
︙ | ︙ |
Changes to test/th1.test.
︙ | ︙ | |||
130 131 132 133 134 135 136 137 138 139 140 141 142 143 | fossil test-th-eval "set var 1; expr {\$var+0}" test th1-info-exists-4 {$RESULT eq {1}} ############################################################################### fossil test-th-eval "set var 1; unset var; expr {\$var+0}" test th1-info-exists-5 {$RESULT eq {TH_ERROR: no such variable: var}} ############################################################################### fossil test-th-eval "set var 1; unset var" test th1-unset-1 {$RESULT eq {var}} ############################################################################### | > > > > > | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | fossil test-th-eval "set var 1; expr {\$var+0}" test th1-info-exists-4 {$RESULT eq {1}} ############################################################################### fossil test-th-eval "set var 1; unset var; expr {\$var+0}" test th1-info-exists-5 {$RESULT eq {TH_ERROR: no such variable: var}} ############################################################################### fossil test-th-eval "catch {bad}; info exists var; set th_stack_trace" test th1-info-exists-6 {$RESULT eq {bad}} ############################################################################### fossil test-th-eval "set var 1; unset var" test th1-unset-1 {$RESULT eq {var}} ############################################################################### |
︙ | ︙ |