Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0df4888
feature: add option to disable forward slash escaping
Mar 9, 2020
5c25e6f
support lua 5.2 with LUA_COMPAT_ALL
leafo Sep 22, 2019
dbfac1a
support lua 5.3 with LUA_COMPAT_5_1
leafo Sep 22, 2019
3cdf14a
Lua 5.2+ unpack support
leafo Sep 22, 2019
dcd5c25
Lua 5.2+ maxn support
leafo Sep 22, 2019
f5cf829
use macro instead of header defines for Lua 5.2+ support
leafo Sep 22, 2019
6534a23
see what happens if we run tests on github actions
leafo Sep 22, 2019
cfa855d
fail if tests are blocked
leafo Sep 22, 2019
d3685e3
build after tests, so tests can do their own build test
leafo Sep 22, 2019
e55b93f
use local lua for makefile build
leafo Sep 22, 2019
7f21cad
tell cmake where lua is
leafo Sep 22, 2019
0d0c406
make tests fail when they fail
leafo Sep 22, 2019
3882fac
add one_of testing to avoid hash table ordering causing test to fail
leafo Sep 22, 2019
96187b4
support error message testing for modern versions of lua
leafo Sep 22, 2019
5dd400b
use different header path for luajit make builds
leafo Sep 22, 2019
701fda3
attempting to fix luajit cmake build
leafo Sep 22, 2019
206cb29
cmake doesn't support finding luajit, so skip it
leafo Sep 22, 2019
760db1b
attempt to run openresty perl tests
leafo Sep 22, 2019
fde219d
bring cppcheck back
leafo Sep 22, 2019
c3bc1a1
ignore dtoa.c for cppcheck, don't share lua headers (breaks due to de…
leafo Sep 22, 2019
dbcfb92
run with gcc and clang
leafo Sep 22, 2019
461c7ef
write sort_json, use it on perl tests to prevent hash table ordering …
leafo Sep 22, 2019
f8e36f8
added -g by default.
agentzh Jul 10, 2020
62fe224
Update CI (#68)
leafo Jan 8, 2021
891962b
bump version to 2.1.0.9
leafo Feb 6, 2021
4b350c5
travis-ci: remove clang compiler mode from travis to save credits. (#72)
xiaocang Jul 8, 2021
3d93d29
doc: minor tweak in README.md (#71)
ali-ghazi78 Sep 23, 2021
8dadbca
bugfix: fixed a possible division by zero bugs found by cppcheck. (#75)
xiaocang Oct 18, 2021
f416d26
bugfix: fixed bugs suspected by cppcheck: shift signed 32-bit value b…
xiaocang Oct 19, 2021
96e6e0c
bumped version to 2.1.0.10. (#79)
xiaocang Dec 10, 2021
0f3dda3
bugfix: windows luarocks make doesn't export cjson.safe.
andrewvmail Oct 26, 2021
92cebdc
bugfix: empty_array can not work on Apple because csjon did not compa…
dndx Jan 13, 2022
91c3363
add lua 5.4 to test suite
leafo Oct 17, 2022
6f38a95
bumped version to 2.1.0.11. (#86)
xiaocang Jan 19, 2023
1dff61d
optimization: add void to functions with no arguments to prevent comp…
zhuizhuhaomeng Feb 22, 2023
de93a78
feature: Add option to skip invalid value types.
zhuizhuhaomeng Feb 22, 2023
41eee74
Add updated netlib dtoa.c from https://netlib.sandia.gov/fp/dtoa.c
zhuizhuhaomeng Feb 22, 2023
881accc
bumped version to 2.1.0.12.
zhuizhuhaomeng Feb 22, 2023
2bfad8f
Bugfix: Lua cjson integer overflow issues (CVE-2022-24834) (#94)
zhuizhuhaomeng Jul 20, 2023
68019ea
Feat(CI): Add automated builds (#1)
magicaldave Oct 16, 2023
c6ffa11
Feat(CI): Add macOS builds & Dreamweave LuaJIT (#2)
magicaldave Oct 18, 2023
5dae577
Feat(CI): Fix Windows builds by building in gcc (#3)
magicaldave Oct 20, 2023
bffdffe
Test(CI): Make phoenix build it
magicaldave Oct 20, 2023
9e75dee
Merge branch 'master' of github.com:DreamWeave-MP/lua-cjson
magicaldave Oct 20, 2023
4ca1190
Revert "Test(CI): Make phoenix build it"
HotaruBlaze Oct 24, 2023
be218a6
Merge pull request #6 from DreamWeave-MP/revert-self-hosted
magicaldave Oct 25, 2023
d20576d
bugfix: bus error or SIGSEGV caused by encode not keep buffer.
hyw0810 Mar 1, 2024
c92ecda
feature: Lua 5.3 + 5.4 integer support, with CI and conflicts fixed.
hishamhm Jun 11, 2024
42ee52e
doc: update location of cjson documentation.
mrthehud Jun 21, 2024
b0b4c58
doc: add comment for dtoa.c.
zhuizhuhaomeng Jun 11, 2024
91ca29d
doc: added doc for encode_skip_unsupported_value_types.
zhuizhuhaomeng Aug 1, 2024
cd944c1
gugfix: fixed Makefile.
zhuizhuhaomeng Oct 16, 2025
35bac3c
bugfix: fix truncation of decoded numbers outside lua_Integer's range…
jamessan Oct 30, 2025
e6daf3c
bumped to to v2.1.0.16
zhuizhuhaomeng Jan 19, 2026
3c64e22
Fixed: worning for explicit pointer to int conversion.
dvdvideo1234 Jan 19, 2026
ea05d06
feature: add option to indent encoded output.
skewb1k Jan 19, 2026
a71470d
Merge remote-tracking branch 'openresty/master'
magicaldave Jan 21, 2026
74c23b4
FIX: Bump action versions
magicaldave Jan 21, 2026
bfbeef9
CLEANUP: Remove the build_typeb stuff as that seems to be pointless f…
magicaldave Jan 21, 2026
b055030
FIX: We ship luajit2 now
magicaldave Jan 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/cjson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CJSON-Main

on:
workflow_dispatch:
push:
branches:
- 'master'
pull_request:
branches: [ master ]

jobs:
CJSON_MASTER:
strategy:
matrix:
target_system: [ ubuntu-22.04, windows-2022, macos-11 ]
runs-on: ${{ matrix.target_system }}
env:
BUILD_EXT: ${{ matrix.target_system == 'windows-2022' && '.dll' || '.so' }}
BUILD_DIR: ${{ matrix.target_system == 'windows-2022' && 'D:/a/lua-cjson/lua-cjson' || '/home/runner/work/lua-cjson/lua-cjson' }}

steps:
- uses: actions/checkout@v4

- uses: msys2/setup-msys2@v2
if: runner.os == 'Windows'
with:
msystem: UCRT64
update: true
install: git mingw-w64-ucrt-x86_64-gcc

- name: Prime ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ matrix.target_system }}
max-size: 1000M

- name: Cache LuaJIT
id: cache-Lua
uses: actions/cache@v3
with:
path: |
LuaJIT
key: ${{ runner.os }}-Lua

- name: Get Deps (LuaJIT)
shell: bash
if: steps.cache-Lua.outputs.cache-hit != 'true'
run: |
curl -o LuaJIT.7z -L https://github.com/DreamWeave-MP/luajit2/releases/download/Stable-CI/LuaJIT-${{ runner.os }}.7z
7z x -y LuaJIT.7z -oLuaJIT/

- name: Configure
if: runner.os != 'Windows'
shell: bash
run: |
LUA_DIR=LuaJIT/ cmake .

- name: Configure
if: runner.os == 'Windows'
shell: bash
run: |
LUA_DIR=LuaJIT/ CC=$(which gcc) cmake . -G 'MinGW Makefiles'

- name: Build
run: |
cmake --build .

- name: Prep Release
run: |
mv cjson${{ env.BUILD_EXT }} cjson-${{ runner.os }}${{ env.BUILD_EXT }}

- name: Upload Release
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@v2
with:
tag_name: Stable-CI
files: cjson-${{ runner.os }}${{ env.BUILD_EXT }}
body: |
CI Build for Dreamweave IO2 fork

- name: Upload Artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v6
with:
name: cjson-${{ runner.os }}
path: cjson-${{ runner.os }}${{ env.BUILD_EXT }}
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: test

on: [push, pull_request]

jobs:
test:
strategy:
fail-fast: false
matrix:
cc: ["gcc", "clang"]
luaVersion: ["5.1", "5.2", "5.3", "5.4", "luajit", "luajit-openresty"]
include:
- luaVersion: "luajit"
runtestArgs: "LUA_INCLUDE_DIR=.lua/include/luajit-2.1"
runtestEnv: "SKIP_CMAKE=1"
- luaVersion: "luajit-openresty"
runtestArgs: "LUA_INCLUDE_DIR=.lua/include/luajit-2.1"
runtestEnv: "SKIP_CMAKE=1"

runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@master

- uses: leafo/gh-actions-lua@master
env:
CC: ${{ matrix.cc }}
with:
luaVersion: ${{ matrix.luaVersion }}
luaCompileFlags: CC=${{ matrix.cc }}

- uses: leafo/gh-actions-luarocks@master

- name: runtests.sh
env:
CC: ${{ matrix.cc }}
run: |
LUA_DIR=.lua ${{ matrix.runtestEnv }} ./runtests.sh PREFIX=.lua ${{ matrix.runtestArgs }}

- name: setup prove
env:
CC: ${{ matrix.cc }}
run: |
make PREFIX=.lua ${{ matrix.runtestArgs }}
sudo apt-get update
sudo apt-get install -q valgrind libipc-run3-perl cppcheck cpanminus
sudo cpanm --notest Test::Base Test::LongString

- name: cppcheck
run: cppcheck -i .lua/ -i .install/ -i dtoa.c --force --error-exitcode=1 --enable=warning --inline-suppr .

- name: prove
run: LUA_BIN=lua prove -Itests tests

- name: prove (valgrind)
run: LUA_BIN=lua TEST_LUA_USE_VALGRIND=1 prove -Itests tests

- name: build
run: |
luarocks make

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.html
*.o
*.so
*.a
notes
packages
tags
Expand Down
17 changes: 12 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
sudo: required
dist: trusty
dist: Focal

os: linux

language: c

compiler:
- gcc
- clang

addons:
apt:
Expand All @@ -18,6 +17,7 @@ addons:
- libipc-run3-perl
- lua5.1
- lua5.1-dev
- cmake

cache:
apt: true
Expand All @@ -27,10 +27,11 @@ env:
- JOBS=3
- LUAROCKS_VER=2.4.2
matrix:
#- LUA=1 LUA_DIR=/usr LUA_INCLUDE_DIR=$LUA_DIR/include/lua5.1
#- LUA=1 LUA_DIR=/usr LUA_INCLUDE_DIR=$LUA_DIR/include/lua5.1
- LUAJIT=1 LUA_DIR=/usr/local LUA_INCLUDE_DIR=$LUA_DIR/include/luajit-2.1 LUA_SUFFIX=--lua-suffix=jit

install:
- sudo ln -s /usr/bin/cmake /usr/local/bin/cmake
- if [ -n "$LUAJIT" ]; then git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git; fi
- if [ -n "$LUAJIT" ]; then cd ./luajit2; fi
- if [ -n "$LUAJIT" ]; then make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1); fi
Expand All @@ -47,8 +48,14 @@ install:
- cd ..

script:
- cppcheck -i ./luajit2 -i --force --error-exitcode=1 --enable=warning . > build.log 2>&1 || (cat build.log && exit 1)
- sh runtests.sh
- cppcheck -i ./luajit2 --force --error-exitcode=1 --enable=warning . > build.log 2>&1 || (cat build.log && exit 1)
- bash runtests.sh
- make
- prove -Itests tests
- TEST_LUA_USE_VALGRIND=1 prove -Itests tests > build.log 2>&1; export e=$?
- cat build.log
- grep -E '^==[0-9]+==' build.log; if [ "$?" == 0 ]; then exit 1; else exit $e; fi
- cmake -DUSE_INTERNAL_FPCONV=1 .
- make
- prove -Itests tests
- TEST_LUA_USE_VALGRIND=1 prove -Itests tests > build.log 2>&1; export e=$?
Expand Down
36 changes: 36 additions & 0 deletions CI/get_luajit.Linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -euo pipefail

print_help() {
echo "usage: $0 [group]..."
echo
echo " available groups: "${!GROUPED_DEPS[@]}""
}

declare -rA GROUPED_DEPS=(
# Common dependencies for building OpenMW.
[openmw-deps]="
libluajit-5.1-dev
"
)

if [[ $# -eq 0 ]]; then
>&2 print_help
exit 1
fi

deps=()
for group in "$@"; do
if [[ ! -v GROUPED_DEPS[$group] ]]; then
>&2 echo "error: unknown group ${group}"
exit 1
fi
deps+=(${GROUPED_DEPS[$group]})
done

export APT_CACHE_DIR="${PWD}/apt-cache"
set -x
mkdir -pv "$APT_CACHE_DIR"
apt-get update -yq
apt-get -q -o dir::cache::archives="$APT_CACHE_DIR" install -y --no-install-recommends "${deps[@]}"
52 changes: 52 additions & 0 deletions CI/get_luajit.windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
set -e

download() {
if [ $# -lt 3 ]; then
echo "Invalid parameters to download."
return 1
fi

NAME=$1
shift

echo "$NAME..."

while [ $# -gt 1 ]; do
URL=$1
FILE=$2
shift
shift

if ! [ -f $FILE ]; then
printf " Downloading $FILE... "

if [ -z $VERBOSE ]; then
RET=0
curl --silent --fail --retry 10 -Ly 5 -o $FILE $URL || RET=$?
else
RET=0
curl --fail --retry 10 -Ly 5 -o $FILE $URL || RET=$?
fi

if [ $RET -ne 0 ]; then
echo "Failed!"
wrappedExit $RET
else
echo "Done."
fi
else
echo " $FILE exists, skipping."
fi
done

if [ $# -ne 0 ]; then
echo "Missing parameter."
fi
}

download "LuaJIT v2.1.0-beta3-452-g7a0cf5fd" \
"https://gitlab.com/OpenMW/openmw-deps/-/raw/main/windows/LuaJIT-v2.1.0-beta3-452-g7a0cf5fd-msvc2019-win64.7z" \
"LuaJIT-v2.1.0-beta3-452-g7a0cf5fd-msvc2019-win64.7z"

echo "Extracting LuaJIT . . ."
eval 7z x -y LuaJIT-v2.1.0-beta3-452-g7a0cf5fd-msvc2019-win64.7z -o./LuaJIT
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Windows: set LUA_DIR=c:\lua51

project(lua-cjson C)
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8.12)

option(USE_INTERNAL_FPCONV "Use internal strtod() / g_fmt() code for performance")
option(MULTIPLE_THREADS "Support multi-threaded apps with internal fpconv - recommended" ON)
Expand All @@ -15,7 +15,9 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

find_package(Lua51 REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)

find_package(LuaJit REQUIRED)
include_directories(${LUA_INCLUDE_DIR})

if(NOT USE_INTERNAL_FPCONV)
Expand Down Expand Up @@ -68,6 +70,13 @@ else()
set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
endif()

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-Dinline=__inline)
add_definitions(-Dsnprintf=_snprintf)
add_definitions(-Dstrncasecmp=_strnicmp)
endif()

add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
set_target_properties(cjson PROPERTIES PREFIX "")
target_link_libraries(cjson ${_MODULE_LINK})
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LUA_VERSION = 5.1
TARGET = cjson.so
PREFIX = /usr/local
#CFLAGS = -g -Wall -pedantic -fno-inline
CFLAGS = -O3 -Wall -pedantic -DNDEBUG
CFLAGS = -O3 -Wall -pedantic -DNDEBUG -g
CJSON_CFLAGS = -fpic
CJSON_LDFLAGS = -shared
LUA_INCLUDE_DIR ?= $(PREFIX)/include
Expand Down Expand Up @@ -84,20 +84,20 @@ OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS)

.PHONY: all clean install install-extra doc

.SUFFIXES: .html .txt
.SUFFIXES: .html .adoc

.c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(BUILD_CFLAGS) -o $@ $<

.txt.html:
.adoc.html:
$(ASCIIDOC) -n -a toc $<

all: $(TARGET)

doc: manual.html performance.html

$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) $(CJSON_LDFLAGS) -o $@ $(OBJS)
$(CC) -o $@ $(LDFLAGS) $(CJSON_LDFLAGS) $(OBJS)

install: $(TARGET)
mkdir -p $(DESTDIR)$(LUA_CMODULE_DIR)
Expand Down
Loading