Skip to content

Commit 235dd0d

Browse files
committed
Migrate lstring
1 parent 77bd7c4 commit 235dd0d

File tree

10 files changed

+388
-257
lines changed

10 files changed

+388
-257
lines changed

build/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fn main() {
2323
.file("build/loslib.c")
2424
.file("build/lparser.c")
2525
.file("build/lstate.c")
26-
.file("build/lstring.c")
2726
.file("build/lstrlib.c")
2827
.file("build/ltable.c")
2928
.file("build/ltablib.c")

build/lstring.c

Lines changed: 0 additions & 248 deletions
This file was deleted.

src/lgc.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use std::mem;
66

7-
use libc::c_int;
7+
use libc::{c_int, size_t};
88

99
use crate::lfunc::upisopen;
1010
use crate::lfunc::UpVal;
@@ -127,7 +127,10 @@ pub unsafe fn isdead(g: *mut global_State, v: *mut GCObject) -> bool {
127127
isdeadm(otherwhite(g), (*v).marked)
128128
}
129129

130-
// #define changewhite(x) ((x)->marked ^= WHITEBITS)
130+
pub unsafe fn changewhite(x: *mut GCObject) {
131+
(*x).marked ^= WHITEBITS;
132+
}
133+
131134
// #define gray2black(x) l_setbit((x)->marked, BLACKBIT)
132135

133136
// #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
@@ -165,5 +168,7 @@ pub unsafe fn luaC_upvalbarrier(L: *mut lua_State, uv: *mut UpVal) {
165168
}
166169

167170
extern "C" {
168-
fn luaC_upvalbarrier_(L: *mut lua_State, uv: *mut UpVal);
171+
pub fn luaC_upvalbarrier_(L: *mut lua_State, uv: *mut UpVal);
172+
pub fn luaC_fix(L: *mut lua_State, o: *mut GCObject);
173+
pub fn luaC_newobj(L: *mut lua_State, tt: c_int, sz: size_t) -> *mut GCObject;
169174
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) mod llimits;
1616
pub(crate) mod lmem;
1717
pub(crate) mod lobject;
1818
pub(crate) mod lopcodes;
19+
pub(crate) mod lstring;
1920
pub(crate) mod ltemp;
2021
pub(crate) mod ltm;
2122
pub(crate) mod lvm;

src/llimits.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ pub union L_Umaxalign {
2424
*/
2525
pub type Instruction = c_uint;
2626

27+
/*
28+
** Maximum length for short strings, that is, strings that are
29+
** internalized. (Cannot be smaller than reserved words or tags for
30+
** metamethods, as these strings must be internalized;
31+
** #("function") = 8, #("__newindex") = 10.)
32+
*/
33+
pub const LUAI_MAXSHORTLEN: usize = 40;
34+
35+
/*
36+
** Initial size for the string table (must be power of 2).
37+
** The Lua core alone registers ~50 strings (reserved words +
38+
** metaevent keys + a few others). Libraries would typically add
39+
** a few dozens more.
40+
*/
41+
pub const MINSTRTABSIZE: usize = 128;
42+
2743
/*
2844
** Size of cache for strings in the API. 'N' is the number of
2945
** sets (better be a prime) and "M" is the size of each set (M == 1
@@ -32,6 +48,9 @@ pub type Instruction = c_uint;
3248
pub const STRCACHE_N: usize = 53;
3349
pub const STRCACHE_M: usize = 2;
3450

51+
/* minimum size for string buffer */
52+
pub const LUA_MINBUFFER: usize = 32;
53+
3554
/*
3655
@@ LUA_IDSIZE gives the maximum size for the description of the source
3756
@@ of a function in debug information.

src/lmem.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ pub unsafe fn luaM_new<T>(L: *mut lua_State) -> *mut T {
3333
luaM_realloc_(L, ptr::null_mut(), 0, size_of::<T>()) as *mut T
3434
}
3535

36+
pub unsafe fn luaM_reallocvector<T>(L: *mut lua_State, v: &mut *mut T, oldn: usize, n: usize) {
37+
*v = luaM_realloc_(
38+
L,
39+
*v as *mut c_void,
40+
oldn * size_of::<T>(),
41+
n * size_of::<T>(),
42+
) as *mut T;
43+
}
44+
3645
/*
3746
** About the realloc function:
3847
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);

0 commit comments

Comments
 (0)