Browse code

bytecode: fixed issue with older versions of g++

Kevin Lin authored on 2014/06/04 00:19:01
Showing 3 changed files
... ...
@@ -227,7 +227,7 @@ static int cli_bytecode_context_reset(struct cli_bc_ctx *ctx)
227 227
     ctx->nmaps = 0;
228 228
 
229 229
 #if HAVE_JSON
230
-    free(ctx->jsonobjs);
230
+    free((json_object**)(ctx->jsonobjs));
231 231
     ctx->jsonobjs = NULL;
232 232
     ctx->njsonobjs = 0;
233 233
 #endif
... ...
@@ -1547,10 +1547,10 @@ int32_t cli_bcapi_json_is_active(struct cli_bc_ctx *ctx )
1547 1547
 static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx) {
1548 1548
 #if HAVE_JSON 
1549 1549
     unsigned n = ctx->njsonobjs + 1;
1550
-    json_object **j;
1550
+    json_object **j, jobjs = (json_object**)(ctx->jsonobjs);
1551 1551
     cli_ctx *cctx = (cli_ctx *)ctx->ctx;
1552 1552
 
1553
-    j = cli_realloc(ctx->jsonobjs, sizeof(*ctx->jsonobjs)*n);
1553
+    j = cli_realloc(jobjs, sizeof(*jobjs)*n);
1554 1554
     if (!j) { /* memory allocation failure */
1555 1555
         cli_event_error_oom(EV, 0);
1556 1556
         return -1;
... ...
@@ -1578,7 +1578,7 @@ int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t* name, in
1578 1578
 {
1579 1579
 #if HAVE_JSON
1580 1580
     unsigned n;
1581
-    json_object **j, *jobj;
1581
+    json_object **j, *jobj, **jobjs = (json_object**)(ctx->jsonobjs);
1582 1582
     char *namep;
1583 1583
 
1584 1584
     INIT_JSON_OBJS(ctx);
... ...
@@ -1593,7 +1593,7 @@ int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t* name, in
1593 1593
     }
1594 1594
 
1595 1595
     n = ctx->njsonobjs + 1;
1596
-    jobj = ctx->jsonobjs[objid];
1596
+    jobj = jobjs[objid];
1597 1597
     if (!jobj) /* shouldn't be possible */
1598 1598
         return -1;
1599 1599
     namep = (char*)cli_malloc(sizeof(char)*(name_len+1));
... ...
@@ -1608,7 +1608,7 @@ int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t* name, in
1608 1608
         return 0;
1609 1609
     }
1610 1610
 
1611
-    j = cli_realloc(ctx->jsonobjs, sizeof(*ctx->jsonobjs)*n);
1611
+    j = cli_realloc(jobjs, sizeof(*jobjs)*n);
1612 1612
     if (!j) { /* memory allocation failure */
1613 1613
         free(namep);
1614 1614
         cli_event_error_oom(EV, 0);
... ...
@@ -1631,6 +1631,7 @@ int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid)
1631 1631
 {
1632 1632
 #if HAVE_JSON
1633 1633
     enum json_type type;
1634
+    json_object **jobjs = (json_object**)(ctx->jsonobjs);
1634 1635
 
1635 1636
     INIT_JSON_OBJS(ctx);
1636 1637
     if (objid < 0 || objid >= ctx->njsonobjs) {
... ...
@@ -1638,7 +1639,7 @@ int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid)
1638 1638
         return -1;
1639 1639
     }
1640 1640
 
1641
-    type = json_object_get_type(ctx->jsonobjs[objid]);
1641
+    type = json_object_get_type(jobjs[objid]);
1642 1642
     switch (type) {
1643 1643
     case json_type_null:
1644 1644
         return JSON_TYPE_NULL;
... ...
@@ -1668,6 +1669,7 @@ int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid)
1668 1668
 {
1669 1669
 #if HAVE_JSON
1670 1670
     enum json_type type;
1671
+    json_object **jobjs = (json_object**)(ctx->jsonobjs);
1671 1672
 
1672 1673
     INIT_JSON_OBJS(ctx);
1673 1674
     if (objid < 0 || objid >= ctx->njsonobjs) {
... ...
@@ -1675,12 +1677,12 @@ int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid)
1675 1675
         return -1;
1676 1676
     }
1677 1677
 
1678
-    type = json_object_get_type(ctx->jsonobjs[objid]);
1678
+    type = json_object_get_type(jobjs[objid]);
1679 1679
     if (type != json_type_array) {
1680 1680
         return -2; /* error code for not an array */
1681 1681
     }
1682 1682
 
1683
-    return json_object_array_length(ctx->jsonobjs[objid]);
1683
+    return json_object_array_length(jobjs[objid]);
1684 1684
 #else
1685 1685
     cli_dbgmsg("bytecode api: libjson is not enabled!\n");
1686 1686
     return -1;
... ...
@@ -1693,7 +1695,7 @@ int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_
1693 1693
     enum json_type type;
1694 1694
     unsigned n;
1695 1695
     int length;
1696
-    json_object **j, *jarr = NULL, *jobj = NULL;
1696
+    json_object **j, *jarr = NULL, *jobj = NULL, **jobjs = (json_object**)(ctx->jsonobjs);
1697 1697
 
1698 1698
     INIT_JSON_OBJS(ctx);
1699 1699
     if (objid < 0 || objid >= ctx->njsonobjs) {
... ...
@@ -1701,7 +1703,7 @@ int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_
1701 1701
         return -1;
1702 1702
     }
1703 1703
 
1704
-    jarr = ctx->jsonobjs[objid];
1704
+    jarr = jobjs[objid];
1705 1705
     if (!jarr) /* shouldn't be possible */
1706 1706
         return -1;
1707 1707
 
... ...
@@ -1719,7 +1721,7 @@ int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_
1719 1719
             return 0;
1720 1720
         }
1721 1721
 
1722
-        j = cli_realloc(ctx->jsonobjs, sizeof(*ctx->jsonobjs)*n);
1722
+        j = cli_realloc(jobjs, sizeof(*jobjs)*n);
1723 1723
         if (!j) { /* memory allocation failure */
1724 1724
             cli_event_error_oom(EV, 0);
1725 1725
             return -1;
... ...
@@ -1743,7 +1745,7 @@ int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid)
1743 1743
 {
1744 1744
 #if HAVE_JSON
1745 1745
     enum json_type type;
1746
-    json_object *jobj;
1746
+    json_object *jobj, **jobjs = (json_object**)(ctx->jsonobjs);
1747 1747
     int32_t len;
1748 1748
     const char *jstr;
1749 1749
 
... ...
@@ -1753,7 +1755,7 @@ int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid)
1753 1753
         return -1;
1754 1754
     }
1755 1755
 
1756
-    jobj = ctx->jsonobjs[objid];
1756
+    jobj = jobjs[objid];
1757 1757
     if (!jobj) /* shouldn't be possible */
1758 1758
         return -1;
1759 1759
 
... ...
@@ -1777,7 +1779,7 @@ int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t* str, int32_t s
1777 1777
 {
1778 1778
 #if HAVE_JSON
1779 1779
     enum json_type type;
1780
-    json_object *jobj;
1780
+    json_object *jobj, **jobjs = (json_object**)(ctx->jsonobjs);
1781 1781
     int32_t len;
1782 1782
     const char *jstr;
1783 1783
 
... ...
@@ -1787,7 +1789,7 @@ int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t* str, int32_t s
1787 1787
         return -1;
1788 1788
     }
1789 1789
 
1790
-    jobj = ctx->jsonobjs[objid];
1790
+    jobj = jobjs[objid];
1791 1791
     if (!jobj) /* shouldn't be possible */
1792 1792
         return -1;
1793 1793
 
... ...
@@ -1821,7 +1823,7 @@ int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t* str, int32_t s
1821 1821
 int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid)
1822 1822
 {
1823 1823
 #if HAVE_JSON
1824
-    json_object *jobj;
1824
+    json_object *jobj, **jobjs = (json_object**)(ctx->jsonobjs);
1825 1825
 
1826 1826
     INIT_JSON_OBJS(ctx);
1827 1827
     if (objid < 0 || objid >= ctx->njsonobjs) {
... ...
@@ -1829,7 +1831,7 @@ int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid)
1829 1829
         return -1;
1830 1830
     }
1831 1831
 
1832
-    jobj = ctx->jsonobjs[objid];
1832
+    jobj = jobjs[objid];
1833 1833
     return json_object_get_boolean(jobj);
1834 1834
 #else
1835 1835
     cli_dbgmsg("bytecode api: libjson is not enabled!\n");
... ...
@@ -1840,7 +1842,7 @@ int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid)
1840 1840
 int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid)
1841 1841
 {
1842 1842
 #if HAVE_JSON
1843
-    json_object *jobj;
1843
+    json_object *jobj, **jobjs = (json_object**)(ctx->jsonobjs);
1844 1844
 
1845 1845
     INIT_JSON_OBJS(ctx);
1846 1846
     if (objid < 0 || objid >= ctx->njsonobjs) {
... ...
@@ -1848,7 +1850,7 @@ int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid)
1848 1848
         return -1;
1849 1849
     }
1850 1850
 
1851
-    jobj = ctx->jsonobjs[objid];
1851
+    jobj = jobjs[objid];
1852 1852
     return json_object_get_int(jobj);
1853 1853
 #else
1854 1854
     cli_dbgmsg("bytecode api: libjson is not enabled!\n");
... ...
@@ -32,9 +32,6 @@
32 32
 #include "mpool.h"
33 33
 #include "hashtab.h"
34 34
 #include "events.h"
35
-#if HAVE_JSON
36
-#include "json.h"
37
-#endif
38 35
 
39 36
 typedef uint32_t operand_t;
40 37
 typedef uint16_t bbid_t;
... ...
@@ -231,7 +228,7 @@ struct cli_bc_ctx {
231 231
     int on_jit;
232 232
     int no_diff;
233 233
 #if HAVE_JSON
234
-    json_object **jsonobjs;
234
+    void **jsonobjs;
235 235
     unsigned njsonobjs;
236 236
 #endif
237 237
 };