ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

GCC 5.4.0 gives unexpected read errors #104

Open lnkuiper opened 1 year ago

lnkuiper commented 1 year ago

Describe the bug I get YYJSON_READ_ERROR_UNEXPECTED_END when reading this (and other JSON):

{
    "firstName": "John",
    "lastName": "Smith",
    "isAlive": true,
    "age": 25,
    "address": {
      "streetAddress": "21 2nd Street",
      "city": "New York",
      "state": "NY",
      "postalCode": "10021-3100"
    },
    "phoneNumbers": [
      {
        "type": "home",
        "number": "212 555-1234"
      },
      {
        "type": "office",
        "number": "646 555-4567"
      }
    ],
    "children": [],
    "spouse": null
}

Your environment

Additional context I have changed some #defines and found that disabling this piece of code (e.g., by changing 4 to 6 so it is not triggered for GCC 5.4) solves the problem.

/** unlikely for compiler */
#ifndef yyjson_unlikely
#   if yyjson_has_builtin(__builtin_expect) || YYJSON_GCC_VER >= 4
#       define yyjson_unlikely(expr) __builtin_expect(!!(expr), 0)
#   else
#       define yyjson_unlikely(expr) (expr)
#   endif
#endif

It seems to work properly in our GCC 4.8 builds though, so maybe it's best to set it to:

YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5
ibireme commented 1 year ago

Thanks~ I've made the changes as you suggested, I'll look into the specific reasons later.