Changeset 73616 in vbox for trunk/src/VBox/Runtime/common/misc
- Timestamp:
- Aug 10, 2018 1:43:18 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/json.cpp
r72955 r73616 1289 1289 { 1290 1290 PRTJSONVALINT pThis = hJsonVal; 1291 AssertPtrReturn(pThis, RTJSONVALTYPE_INVALID); 1292 1291 1293 if (pThis == NIL_RTJSONVAL) 1292 1294 return RTJSONVALTYPE_INVALID; 1293 AssertPtrReturn(pThis, RTJSONVALTYPE_INVALID);1294 1295 1295 1296 return pThis->enmType; 1296 1297 } 1297 1298 1299 1300 #define AssertJsonTypeReturn(pJson, enmExpectedType, ret) do { \ 1301 AssertPtrReturn((pJson), (ret)); \ 1302 AssertReturn((pJson) != NIL_RTJSONVAL, (ret)); \ 1303 AssertReturn((pJson)->enmType == (enmExpectedType), (ret)); \ 1304 } while (0) 1305 1306 #define RTJSON_TYPECHECK(pJson, enmExpectedType) do { \ 1307 if (RT_UNLIKELY((pJson) == NIL_RTJSONVAL)) \ 1308 return VERR_INVALID_HANDLE; \ 1309 if ((pJson)->enmType != (enmExpectedType)) \ 1310 return VERR_JSON_VALUE_INVALID_TYPE; \ 1311 } while (0) 1312 1313 1314 #define RTJSON_TYPECHECK_CONTAINER(pJson) do { \ 1315 if (RT_UNLIKELY((pJson) == NIL_RTJSONVAL)) \ 1316 return VERR_INVALID_HANDLE; \ 1317 if ( (pJson)->enmType != RTJSONVALTYPE_ARRAY \ 1318 && (pJson)->enmType != RTJSONVALTYPE_OBJECT) \ 1319 return VERR_JSON_VALUE_INVALID_TYPE; \ 1320 } while (0) 1321 1322 1298 1323 RTDECL(const char *) RTJsonValueGetString(RTJSONVAL hJsonVal) 1299 1324 { 1300 1325 PRTJSONVALINT pThis = hJsonVal; 1301 AssertReturn(pThis != NIL_RTJSONVAL, NULL); 1302 AssertReturn(pThis->enmType == RTJSONVALTYPE_STRING, NULL); 1326 AssertJsonTypeReturn(pThis, RTJSONVALTYPE_STRING, NULL); 1303 1327 1304 1328 return pThis->Type.String.pszStr; 1305 1329 } 1306 1330 1331 1307 1332 RTDECL(int) RTJsonValueQueryString(RTJSONVAL hJsonVal, const char **ppszStr) 1308 1333 { 1309 1334 PRTJSONVALINT pThis = hJsonVal; 1335 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1310 1336 AssertPtrReturn(ppszStr, VERR_INVALID_POINTER); 1311 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1312 AssertReturn(pThis->enmType == RTJSONVALTYPE_STRING, VERR_JSON_VALUE_INVALID_TYPE); 1313 1337 1338 RTJSON_TYPECHECK(pThis, RTJSONVALTYPE_STRING); 1314 1339 *ppszStr = pThis->Type.String.pszStr; 1315 1340 return VINF_SUCCESS; … … 1319 1344 { 1320 1345 PRTJSONVALINT pThis = hJsonVal; 1346 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1321 1347 AssertPtrReturn(pi64Num, VERR_INVALID_POINTER); 1322 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1323 AssertReturn(pThis->enmType == RTJSONVALTYPE_NUMBER, VERR_JSON_VALUE_INVALID_TYPE); 1324 1348 1349 RTJSON_TYPECHECK(pThis, RTJSONVALTYPE_NUMBER); 1325 1350 *pi64Num = pThis->Type.Number.i64Num; 1326 1351 return VINF_SUCCESS; … … 1330 1355 { 1331 1356 PRTJSONVALINT pThis = hJsonVal; 1357 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1332 1358 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 1333 1359 AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER); 1334 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1335 AssertReturn(pThis->enmType == RTJSONVALTYPE_OBJECT, VERR_JSON_VALUE_INVALID_TYPE);1360 1361 RTJSON_TYPECHECK(pThis, RTJSONVALTYPE_OBJECT); 1336 1362 1337 1363 int rc = VERR_NOT_FOUND; … … 1407 1433 { 1408 1434 PRTJSONVALINT pThis = hJsonVal; 1409 AssertReturn(pThis != NIL_RTJSONVAL, 0); 1410 AssertReturn(pThis->enmType == RTJSONVALTYPE_ARRAY, 0); 1435 AssertJsonTypeReturn(pThis, RTJSONVALTYPE_ARRAY, 0); 1411 1436 1412 1437 return pThis->Type.Array.cItems; … … 1416 1441 { 1417 1442 PRTJSONVALINT pThis = hJsonVal; 1443 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1418 1444 AssertPtrReturn(pcItems, VERR_INVALID_POINTER); 1419 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1420 AssertReturn(pThis->enmType == RTJSONVALTYPE_ARRAY, VERR_JSON_VALUE_INVALID_TYPE); 1421 1445 1446 RTJSON_TYPECHECK(pThis, RTJSONVALTYPE_ARRAY); 1422 1447 *pcItems = pThis->Type.Array.cItems; 1423 1448 return VINF_SUCCESS; … … 1427 1452 { 1428 1453 PRTJSONVALINT pThis = hJsonVal; 1454 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1429 1455 AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER); 1430 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1431 AssertReturn(pThis->enmType == RTJSONVALTYPE_ARRAY, VERR_JSON_VALUE_INVALID_TYPE); 1432 AssertReturn(idx < pThis->Type.Array.cItems, VERR_OUT_OF_RANGE); 1456 1457 RTJSON_TYPECHECK(pThis, RTJSONVALTYPE_ARRAY); 1458 if (RT_UNLIKELY(idx >= pThis->Type.Array.cItems)) 1459 return VERR_OUT_OF_RANGE; 1433 1460 1434 1461 RTJsonValueRetain(pThis->Type.Array.papItems[idx]); … … 1440 1467 { 1441 1468 PRTJSONVALINT pThis = hJsonVal; 1469 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1442 1470 AssertPtrReturn(phJsonIt, VERR_INVALID_POINTER); 1443 AssertReturn(pThis != NIL_RTJSONVAL, VERR_INVALID_HANDLE); 1444 AssertReturn(pThis->enmType == RTJSONVALTYPE_ARRAY || pThis->enmType == RTJSONVALTYPE_OBJECT, 1445 VERR_JSON_VALUE_INVALID_TYPE); 1471 1472 RTJSON_TYPECHECK_CONTAINER(pThis); 1446 1473 1447 1474 PRTJSONITINT pIt = (PRTJSONITINT)RTMemTmpAllocZ(sizeof(RTJSONITINT)); … … 1460 1487 { 1461 1488 PRTJSONITINT pIt = hJsonIt; 1489 AssertPtrReturn(pIt, VERR_INVALID_HANDLE); 1462 1490 AssertReturn(pIt != NIL_RTJSONIT, VERR_INVALID_HANDLE); 1463 1491 AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER); … … 1500 1528 { 1501 1529 PRTJSONITINT pIt = hJsonIt; 1530 AssertPtrReturn(pIt, VERR_INVALID_HANDLE); 1502 1531 AssertReturn(pIt != NIL_RTJSONIT, VERR_INVALID_HANDLE); 1503 1532 … … 1529 1558 { 1530 1559 PRTJSONITINT pThis = hJsonIt; 1560 AssertPtrReturnVoid(pThis); 1561 1531 1562 if (pThis == NIL_RTJSONIT) 1532 1563 return; 1533 AssertPtrReturnVoid(pThis);1534 1564 1535 1565 RTJsonValueRelease(pThis->pJsonVal); 1536 1566 RTMemTmpFree(pThis); 1537 1567 } 1538
Note:
See TracChangeset
for help on using the changeset viewer.