Skip to content

Commit c92ecda

Browse files
hishamhmmpxqi7chencloudwut0350
authored
feature: Lua 5.3 + 5.4 integer support, with CI and conflicts fixed.
Co-Authored-By: Hisham Muhammad <[email protected]> Co-authored-by: Mark Pulford <[email protected]> Co-authored-by: ichenq <[email protected]> Co-authored-by: Cloud Wu <[email protected]> Co-authored-by: caijietao <[email protected]> Co-authored-by: actboy168 <[email protected]> Co-authored-by: wudeng <[email protected]> Co-authored-by: caiyiheng <[email protected]>
1 parent d20576d commit c92ecda

File tree

15 files changed

+236
-73
lines changed

15 files changed

+236
-73
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runtestArgs: "LUA_INCLUDE_DIR=.lua/include/luajit-2.1"
1818
runtestEnv: "SKIP_CMAKE=1"
1919

20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-24.04
2121

2222
steps:
2323
- uses: actions/checkout@master
@@ -47,7 +47,7 @@ jobs:
4747
sudo cpanm --notest Test::Base Test::LongString
4848
4949
- name: cppcheck
50-
run: cppcheck -i .lua/ -i .install/ -i dtoa.c --force --error-exitcode=1 --enable=warning .
50+
run: cppcheck -i .lua/ -i .install/ -i dtoa.c --force --error-exitcode=1 --enable=warning --inline-suppr .
5151

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.html
22
*.o
33
*.so
4+
*.a
45
notes
56
packages
67
tags

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ else()
6868
set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
6969
endif()
7070

71+
if(MSVC)
72+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
73+
add_definitions(-Dinline=__inline)
74+
add_definitions(-Dsnprintf=_snprintf)
75+
add_definitions(-Dstrncasecmp=_strnicmp)
76+
endif()
77+
7178
add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
7279
set_target_properties(cjson PROPERTIES PREFIX "")
7380
target_link_libraries(cjson ${_MODULE_LINK})

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LUA_CMODULE_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
2323
LUA_MODULE_DIR ?= $(PREFIX)/share/lua/$(LUA_VERSION)
2424
LUA_BIN_DIR ?= $(PREFIX)/bin
2525

26+
AR= $(CC) -o
27+
2628
##### Platform overrides #####
2729
##
2830
## Tweak one of the platform sections below to suit your situation.
@@ -84,20 +86,20 @@ OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS)
8486

8587
.PHONY: all clean install install-extra doc
8688

87-
.SUFFIXES: .html .txt
89+
.SUFFIXES: .html .adoc
8890

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

92-
.txt.html:
94+
.adoc.html:
9395
$(ASCIIDOC) -n -a toc $<
9496

9597
all: $(TARGET)
9698

9799
doc: manual.html performance.html
98100

99101
$(TARGET): $(OBJS)
100-
$(CC) $(LDFLAGS) $(CJSON_LDFLAGS) -o $@ $(OBJS)
102+
$(AR) $@ $(LDFLAGS) $(CJSON_LDFLAGS) $(OBJS)
101103

102104
install: $(TARGET)
103105
mkdir -p $(DESTDIR)$(LUA_CMODULE_DIR)

build-packages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Build packages. Use current checked out version, or a specific tag/commit.
66

77
# Files requiring a version bump
8-
VERSION_FILES="lua-cjson-2.1devel-1.rockspec lua-cjson.spec lua_cjson.c manual.txt runtests.sh tests/test.lua"
8+
VERSION_FILES="lua-cjson-2.1devel-1.rockspec lua-cjson.spec lua_cjson.c manual.adoc runtests.sh tests/test.lua"
99

1010
[ "$1" ] && BRANCH="$1" || BRANCH="`git describe --match '[1-3].[0-9]*'`"
1111
VERSION="`git describe --match '[1-3].[0-9]*' $BRANCH`"

dtoa.c

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,12 +1533,18 @@ ThInfo {
15331533
set_max_dtoa_threads(unsigned int n)
15341534
{
15351535
size_t L;
1536+
ThInfo *newTI1;
15361537

15371538
if (n > maxthreads) {
15381539
L = n*sizeof(ThInfo);
15391540
if (TI1) {
1540-
TI1 = (ThInfo*)REALLOC(TI1, L);
1541-
memset(TI1 + maxthreads, 0, (n-maxthreads)*sizeof(ThInfo));
1541+
newTI1 = (ThInfo*)REALLOC(TI1, L);
1542+
if (newTI1) {
1543+
TI1 = newTI1;
1544+
memset(TI1 + maxthreads, 0, (n-maxthreads)*sizeof(ThInfo));
1545+
}
1546+
else
1547+
return;
15421548
}
15431549
else {
15441550
TI1 = (ThInfo*)MALLOC(L);
@@ -1871,7 +1877,7 @@ mult(Bigint *a, Bigint *b MTd)
18711877
#else
18721878
#ifdef Pack_32
18731879
for(; xb < xbe; xb++, xc0++) {
1874-
if (y = *xb & 0xffff) {
1880+
if ((y = *xb & 0xffff)) {
18751881
x = xa;
18761882
xc = xc0;
18771883
carry = 0;
@@ -1885,7 +1891,7 @@ mult(Bigint *a, Bigint *b MTd)
18851891
while(x < xae);
18861892
*xc = carry;
18871893
}
1888-
if (y = *xb >> 16) {
1894+
if ((y = *xb >> 16)) {
18891895
x = xa;
18901896
xc = xc0;
18911897
carry = 0;
@@ -2718,13 +2724,14 @@ enum { /* rounding values: same as FLT_ROUNDS */
27182724
};
27192725

27202726
void
2721-
gethex( const char **sp, U *rvp, int rounding, int sign MTd)
2727+
gethex(const char **sp, U *rvp, int rounding, int sign MTd)
27222728
{
27232729
Bigint *b;
2730+
char d;
27242731
const unsigned char *decpt, *s0, *s, *s1;
27252732
Long e, e1;
27262733
ULong L, lostbits, *x;
2727-
int big, denorm, esign, havedig, k, n, nbits, up, zret;
2734+
int big, denorm, esign, havedig, k, n, nb, nbits, nz, up, zret;
27282735
#ifdef IBM
27292736
int j;
27302737
#endif
@@ -2742,6 +2749,9 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
27422749
#endif
27432750
#endif /*}}*/
27442751
};
2752+
#ifdef IEEE_Arith
2753+
int check_denorm = 0;
2754+
#endif
27452755
#ifdef USE_LOCALE
27462756
int i;
27472757
#ifdef NO_LOCALE_CACHE
@@ -2893,7 +2903,7 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
28932903
k++;
28942904
b = Balloc(k MTa);
28952905
x = b->x;
2896-
n = 0;
2906+
havedig = n = nz = 0;
28972907
L = 0;
28982908
#ifdef USE_LOCALE
28992909
for(i = 0; decimalpoint[i+1]; ++i);
@@ -2908,22 +2918,28 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29082918
if (*--s1 == '.')
29092919
continue;
29102920
#endif
2921+
if ((d = hexdig[*s1]))
2922+
havedig = 1;
2923+
else if (!havedig) {
2924+
e += 4;
2925+
continue;
2926+
}
29112927
if (n == ULbits) {
29122928
*x++ = L;
29132929
L = 0;
29142930
n = 0;
29152931
}
2916-
L |= (hexdig[*s1] & 0x0f) << n;
2932+
L |= (d & 0x0f) << n;
29172933
n += 4;
29182934
}
29192935
*x++ = L;
29202936
b->wds = n = x - b->x;
2921-
n = ULbits*n - hi0bits(L);
2937+
nb = ULbits*n - hi0bits(L);
29222938
nbits = Nbits;
29232939
lostbits = 0;
29242940
x = b->x;
2925-
if (n > nbits) {
2926-
n -= nbits;
2941+
if (nb > nbits) {
2942+
n = nb - nbits;
29272943
if (any_on(b,n)) {
29282944
lostbits = 1;
29292945
k = n - 1;
@@ -2936,8 +2952,8 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29362952
rshift(b, n);
29372953
e += n;
29382954
}
2939-
else if (n < nbits) {
2940-
n = nbits - n;
2955+
else if (nb < nbits) {
2956+
n = nbits - nb;
29412957
b = lshift(b, n MTa);
29422958
e -= n;
29432959
x = b->x;
@@ -2992,12 +3008,49 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29923008
return;
29933009
}
29943010
k = n - 1;
3011+
#ifdef IEEE_Arith
3012+
if (!k) {
3013+
switch(rounding) {
3014+
case Round_near:
3015+
if (((b->x[0] & 3) == 3) || (lostbits && (b->x[0] & 1))) {
3016+
multadd(b, 1, 1 MTa);
3017+
emin_check:
3018+
if (b->x[1] == (1 << (Exp_shift + 1))) {
3019+
rshift(b,1);
3020+
e = emin;
3021+
goto normal;
3022+
}
3023+
}
3024+
break;
3025+
case Round_up:
3026+
if (!sign && (lostbits || (b->x[0] & 1))) {
3027+
incr_denorm:
3028+
multadd(b, 1, 2 MTa);
3029+
check_denorm = 1;
3030+
lostbits = 0;
3031+
goto emin_check;
3032+
}
3033+
break;
3034+
case Round_down:
3035+
if (sign && (lostbits || (b->x[0] & 1)))
3036+
goto incr_denorm;
3037+
break;
3038+
}
3039+
}
3040+
#endif
29953041
if (lostbits)
29963042
lostbits = 1;
29973043
else if (k > 0)
29983044
lostbits = any_on(b,k);
3045+
#ifdef IEEE_Arith
3046+
else if (check_denorm)
3047+
goto no_lostbits;
3048+
#endif
29993049
if (x[k>>kshift] & 1 << (k & kmask))
30003050
lostbits |= 2;
3051+
#ifdef IEEE_Arith
3052+
no_lostbits:
3053+
#endif
30013054
nbits -= n;
30023055
rshift(b,n);
30033056
e = emin;
@@ -3022,16 +3075,9 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
30223075
k = b->wds;
30233076
b = increment(b MTa);
30243077
x = b->x;
3025-
if (denorm) {
3026-
#if 0
3027-
if (nbits == Nbits - 1
3028-
&& x[nbits >> kshift] & 1 << (nbits & kmask))
3029-
denorm = 0; /* not currently used */
3030-
#endif
3031-
}
3032-
else if (b->wds > k
3078+
if (!denorm && (b->wds > k
30333079
|| ((n = nbits & kmask) !=0
3034-
&& hi0bits(x[k-1]) < 32-n)) {
3080+
&& hi0bits(x[k-1]) < 32-n))) {
30353081
rshift(b,1);
30363082
if (++e > Emax)
30373083
goto ovfl;
@@ -3041,8 +3087,10 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
30413087
#ifdef IEEE_Arith
30423088
if (denorm)
30433089
word0(rvp) = b->wds > 1 ? b->x[1] & ~0x100000 : 0;
3044-
else
3090+
else {
3091+
normal:
30453092
word0(rvp) = (b->x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20);
3093+
}
30463094
word1(rvp) = b->x[0];
30473095
#endif
30483096
#ifdef IBM
@@ -3409,6 +3457,7 @@ bigcomp(U *rv, const char *s0, BCinfo *bc MTd)
34093457
if ((j = ((word0(rv) & Exp_mask) >> Exp_shift) - bc->scale) <= 0) {
34103458
i = 1 - j;
34113459
if (i <= 31) {
3460+
/* cppcheck-suppress integerOverflowCond */
34123461
if (word1(rv) & (0x1 << i))
34133462
goto odd;
34143463
}
@@ -3619,10 +3668,11 @@ fpconv_strtod(const char *s00, char **se)
36193668
c = *++s;
36203669
if (c > '0' && c <= '9') {
36213670
L = c - '0';
3622-
s1 = s;
3623-
while((c = *++s) >= '0' && c <= '9')
3624-
L = 10*L + c - '0';
3625-
if (s - s1 > 8 || L > 19999)
3671+
while((c = *++s) >= '0' && c <= '9') {
3672+
if (L <= 19999)
3673+
L = 10*L + c - '0';
3674+
}
3675+
if (L > 19999)
36263676
/* Avoid confusion from exponents
36273677
* so large that e might overflow.
36283678
*/
@@ -4884,6 +4934,7 @@ nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, int n MTd)
48844934
s0 = rv_alloc(n MTa);
48854935
else if (s0len <= n) {
48864936
rv = 0;
4937+
/* cppcheck-suppress nullPointerArithmetic */
48874938
t = rv + n;
48884939
goto rve_chk;
48894940
}
@@ -5237,9 +5288,11 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
52375288
#ifndef SET_INEXACT
52385289
#ifdef Check_FLT_ROUNDS
52395290
try_quick = Rounding == 1;
5291+
#else
5292+
try_quick = 1;
52405293
#endif
52415294
#endif /*SET_INEXACT*/
5242-
#endif
5295+
#endif /*USE_BF96*/
52435296

52445297
if (mode > 5) {
52455298
mode -= 4;
@@ -5281,6 +5334,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
52815334
else if (blen <= i) {
52825335
buf = 0;
52835336
if (rve)
5337+
/* cppcheck-suppress nullPointerArithmetic */
52845338
*rve = buf + i;
52855339
return buf;
52865340
}
@@ -5469,6 +5523,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
54695523
res3 = p10->b1 * dbhi + (tv3 & 0xffffffffull);
54705524
res = p10->b0 * dbhi + (tv3>>32) + (res3>>32);
54715525
be += p10->e - 0x3fe;
5526+
/* cppcheck-suppress integerOverflowCond */
54725527
eulp = j1 = be - 54 + ulpadj;
54735528
if (!(res & 0x8000000000000000ull)) {
54745529
--be;

fpconv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
130130
/* Duplicate number into buffer */
131131
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
132132
/* Handle unusually large numbers */
133-
buf = malloc(buflen + 1);
133+
buf = (char *)malloc(buflen + 1);
134134
if (!buf) {
135135
fprintf(stderr, "Out of memory");
136136
abort();

lua-cjson-2.1.0.12-1.rockspec renamed to lua-cjson-2.1.0.14-1.rockspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package = "lua-cjson"
2-
version = "2.1.0.11-1"
2+
version = "2.1.0.14-1"
33

44
source = {
55
url = "git+https://github.com/openresty/lua-cjson",
6-
tag = "2.1.0.11",
6+
tag = "2.1.0.14",
77
}
88

99
description = {

lua-cjson.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ rm -rf "$RPM_BUILD_ROOT"
5050

5151
%files
5252
%defattr(-,root,root,-)
53-
%doc LICENSE NEWS performance.html performance.txt manual.html manual.txt rfc4627.txt THANKS
53+
%doc LICENSE NEWS performance.html performance.adoc manual.html manual.adoc rfc4627.txt THANKS
5454
%{lualibdir}/*
5555
%{luadatadir}/*
5656
%{_bindir}/*

0 commit comments

Comments
 (0)