Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Lua Json
Commits
cde7ad26
Commit
cde7ad26
authored
Jun 04, 2019
by
seny
Browse files
Remove inline storage
parent
7069e9a8
Changes
1
Show whitespace changes
Inline
Side-by-side
src/json-encode.c
View file @
cde7ad26
...
@@ -27,18 +27,16 @@
...
@@ -27,18 +27,16 @@
#define MAXSTACK 1000
/* Arbitrary stack size limit to check for recursion */
#define MAXSTACK 1000
/* Arbitrary stack size limit to check for recursion */
typedef
struct
{
typedef
struct
{
char
*
buf
,
data
[
1024
]
;
char
*
buf
;
size_t
pos
,
size
;
size_t
pos
,
size
;
}
Box
;
}
Box
;
static
char
*
resizeBox
(
lua_State
*
L
,
Box
*
box
,
size_t
size
)
{
static
char
*
resizeBox
(
lua_State
*
L
,
Box
*
box
,
size_t
size
)
{
void
*
ud
;
void
*
ud
;
lua_Alloc
allocf
=
lua_getallocf
(
L
,
&
ud
);
lua_Alloc
allocf
=
lua_getallocf
(
L
,
&
ud
);
int
dyn
=
box
->
buf
!=
box
->
data
;
/* Dynamically allocated? */
char
*
buf
=
allocf
(
ud
,
box
->
buf
,
box
->
size
,
size
);
char
*
buf
=
dyn
?
allocf
(
ud
,
box
->
buf
,
box
->
size
,
size
)
:
allocf
(
ud
,
0
,
0
,
size
);
if
(
!
size
)
return
0
;
if
(
!
size
)
return
0
;
if
(
!
buf
)
luaL_error
(
L
,
"cannot allocate buffer"
);
if
(
!
buf
)
luaL_error
(
L
,
"cannot allocate buffer"
);
if
(
!
dyn
)
memcpy
(
buf
,
box
->
buf
,
box
->
pos
);
box
->
buf
=
buf
;
box
->
buf
=
buf
;
box
->
size
=
size
;
box
->
size
=
size
;
return
buf
;
return
buf
;
...
@@ -51,14 +49,15 @@ static int m__gc(lua_State *L) {
...
@@ -51,14 +49,15 @@ static int m__gc(lua_State *L) {
static
Box
*
newBox
(
lua_State
*
L
)
{
static
Box
*
newBox
(
lua_State
*
L
)
{
Box
*
box
=
lua_newuserdata
(
L
,
sizeof
*
box
);
Box
*
box
=
lua_newuserdata
(
L
,
sizeof
*
box
);
box
->
buf
=
box
->
data
;
box
->
buf
=
0
;
box
->
pos
=
0
;
box
->
pos
=
0
;
box
->
size
=
sizeof
box
->
data
;
box
->
size
=
0
;
if
(
luaL_newmetatable
(
L
,
MODNAME
))
{
if
(
luaL_newmetatable
(
L
,
MODNAME
))
{
lua_pushcfunction
(
L
,
m__gc
);
lua_pushcfunction
(
L
,
m__gc
);
lua_setfield
(
L
,
-
2
,
"__gc"
);
lua_setfield
(
L
,
-
2
,
"__gc"
);
}
}
lua_setmetatable
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
resizeBox
(
L
,
box
,
100
);
return
box
;
return
box
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment