upgrading.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .. highlight:: c
  2. ******************
  3. Upgrading from 1.x
  4. ******************
  5. This chapter lists the backwards incompatible changes introduced in
  6. Jansson 2.0, and the steps that are needed for upgrading your code.
  7. **The incompatibilities are not dramatic.** The biggest change is that
  8. all decoding functions now require and extra parameter. Most programs
  9. can be modified to work with 2.0 by adding a ``0`` as the second
  10. parameter to all calls of :func:`json_loads()`, :func:`json_loadf()`
  11. and :func:`json_load_file()`.
  12. Compatibility
  13. =============
  14. Jansson 2.0 is backwards incompatible with the Jansson 1.x releases.
  15. It is ABI incompatible, i.e. all programs dynamically linking to the
  16. Jansson library need to be recompiled. It's also API incompatible,
  17. i.e. the source code of programs using Jansson 1.x may need
  18. modifications to make them compile against Jansson 2.0.
  19. All the 2.x releases are guaranteed to be backwards compatible for
  20. both ABI and API, so no recompilation or source changes are needed
  21. when upgrading from 2.x to 2.y.
  22. List of Incompatible Changes
  23. ============================
  24. **Decoding flags**
  25. For future needs, a ``flags`` parameter was added as the second
  26. parameter to all decoding functions, i.e. :func:`json_loads()`,
  27. :func:`json_loadf()` and :func:`json_load_file()`. All calls to
  28. these functions need to be changed by adding a ``0`` as the second
  29. argument. For example::
  30. /* old code */
  31. json_loads(input, &error);
  32. /* new code */
  33. json_loads(input, 0, &error);
  34. **Underlying type of JSON integers**
  35. The underlying C type of JSON integers has been changed from
  36. :type:`int` to the widest available signed integer type, i.e.
  37. :type:`long long` or :type:`long`, depending on whether
  38. :type:`long long` is supported on your system or not. This makes
  39. the whole 64-bit integer range available on most modern systems.
  40. ``jansson.h`` has a typedef :type:`json_int_t` to the underlying
  41. integer type. :type:`int` should still be used in most cases when
  42. dealing with smallish JSON integers, as the compiler handles
  43. implicit type coercion. Only when the full 64-bit range is needed,
  44. :type:`json_int_t` should be explicitly used.
  45. **Maximum encoder indentation depth**
  46. The maximum argument of the ``JSON_INDENT()`` macro has been
  47. changed from 255 to 31, to free up bits from the ``flags``
  48. parameter of :func:`json_dumps()`, :func:`json_dumpf()` and
  49. :func:`json_dump_file()`. If your code uses a bigger indentation
  50. than 31, it needs to be changed.
  51. **Unsigned integers in API functions**
  52. Version 2.0 unifies unsigned integer usage in the API. All uses of
  53. :type:`unsigned int` and :type:`unsigned long` have been replaced
  54. with :type:`size_t`. This includes flags, container sizes, etc.
  55. This should not require source code changes, as both
  56. :type:`unsigned int` and :type:`unsigned long` are usually
  57. compatible with :type:`size_t`.