zserge / jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
MIT License
3.64k stars 778 forks source link

Allow JSMN_API to be defined by the user (e. g. for Windows DLLs). #198

Open lx-s opened 4 years ago

lx-s commented 4 years ago

To make jsmn part of a shared Windows-DLL, jsmn's functions have to be marked __declspec(dllexport) / __declscpec(dllimport). Functions marked as extern are - contrary to unix - not automatically exported.

Making JSMN_API user-definable (with a default fallback) makes writing wrapper such as these possible:

jsmn_dll_wrapper.c:

#ifdef _WIN32
#   define JSMN_API __declspec(dllexport)
#endif
#define JSMN_STRICT
#include "jsmn.h"

jsmn_dll_wrapper.h

#ifdef _WIN32
#  ifdef EXPORTS
#     define JSMN_API __declspec(dllexport)
#  else
#     define JSMN_API __declspec(dllimport)
#  endif
#endif
#define JSMN_HEADER
#include "jsmn.h"
#undef JSMN_HEADER