Skip to content

Commit cb6178c

Browse files
committed
Phase 122: Complete LuaT enum class refactoring
Fixed all remaining type mismatches from lu_byte to LuaT: - Updated operator new signatures in all GC classes to use LuaT - Changed luaC_newobj/luaC_newobjdt to accept LuaT instead of lu_byte - Updated Table method return types (get, getInt, getShortStr, getStr) - Fixed local variables in ltable.cpp, ldump.cpp, lstate.cpp - Added iscollectable(LuaT) overload for type-safe bit checking - Updated macros in gc_marking.cpp and gc_weak.cpp to use iscollectable() - Changed createstrobj parameter from lu_byte to LuaT All files now use LuaT enum class instead of lu_byte for variant tags. Build successful with zero warnings!
1 parent 47a3120 commit cb6178c

File tree

13 files changed

+36
-35
lines changed

13 files changed

+36
-35
lines changed

src/core/lstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
272272
lua_lock(L);
273273
luaC_checkGC(L);
274274
/* create new thread */
275-
o = luaC_newobjdt(L, LUA_TTHREAD, sizeof(LX), lxOffset());
275+
o = luaC_newobjdt(L, LuaT::THREAD, sizeof(LX), lxOffset());
276276
L1 = gco2th(o);
277277
/* anchor it on L stack */
278278
setthvalue2s(L, L->getTop().p, L1);

src/memory/gc/gc_marking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static inline void linkgclistThread(lua_State* th, GCObject*& p) {
8383
** Access to collectable objects in table array part
8484
*/
8585
#define gcvalarr(t, i) \
86-
((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr)
86+
(iscollectable(*(t)->getArrayTag(i)) ? (t)->getArrayVal(i)->gc : nullptr)
8787

8888

8989
/*

src/memory/gc/gc_weak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
/* Access to collectable objects in array part of tables */
4040
#define gcvalarr(t,i) \
41-
((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr)
41+
(iscollectable(*(t)->getArrayTag(i)) ? (t)->getArrayVal(i)->gc : nullptr)
4242

4343
/* Note: gcvalueN and valiswhite are now in lgc.h */
4444
/* Note: markkey and markvalue are defined in gc_marking.h */

src/memory/lgc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void luaC_barrierback_ (lua_State *L, GCObject *o) {
219219
** create a new collectable object (with given type, size, and offset)
220220
** and link it to 'allgc' list.
221221
*/
222-
GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, size_t offset) {
222+
GCObject *luaC_newobjdt (lua_State *L, LuaT tt, size_t sz, size_t offset) {
223223
global_State *g = G(L);
224224
char *p = cast_charp(luaM_newobject(L, novariant(tt), sz));
225225
GCObject *o = reinterpret_cast<GCObject*>(p + offset);
@@ -234,7 +234,7 @@ GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, size_t offset) {
234234
/*
235235
** create a new collectable object with no offset.
236236
*/
237-
GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) {
237+
GCObject *luaC_newobj (lua_State *L, LuaT tt, size_t sz) {
238238
return luaC_newobjdt(L, tt, sz, 0);
239239
}
240240

src/memory/lgc.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ LUAI_FUNC void luaC_step (lua_State *L);
387387
LUAI_FUNC void luaC_runtilstate (lua_State *L, GCState state, int fast);
388388
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
389389
LUAI_FUNC void propagateall (global_State *g); /* used by GCCollector */
390-
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz);
391-
LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz,
390+
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, LuaT tt, size_t sz);
391+
LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, LuaT tt, size_t sz,
392392
size_t offset);
393393
LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
394394
LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);
@@ -411,37 +411,37 @@ LUAI_FUNC void freeobj (lua_State *L, GCObject *o);
411411
*/
412412

413413
// CClosure placement new operator
414-
inline void* CClosure::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) {
414+
inline void* CClosure::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) {
415415
return luaC_newobj(L, tt, size + extra);
416416
}
417417

418418
// LClosure placement new operator
419-
inline void* LClosure::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) {
419+
inline void* LClosure::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) {
420420
return luaC_newobj(L, tt, size + extra);
421421
}
422422

423423
// Udata placement new operator
424-
inline void* Udata::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) {
424+
inline void* Udata::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) {
425425
return luaC_newobj(L, tt, size + extra);
426426
}
427427

428428
// TString placement new operator
429-
inline void* TString::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) {
429+
inline void* TString::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) {
430430
return luaC_newobj(L, tt, size + extra);
431431
}
432432

433433
// Proto placement new operator
434-
inline void* Proto::operator new(size_t size, lua_State* L, lu_byte tt) {
434+
inline void* Proto::operator new(size_t size, lua_State* L, LuaT tt) {
435435
return luaC_newobj(L, tt, size);
436436
}
437437

438438
// UpVal placement new operator
439-
inline void* UpVal::operator new(size_t size, lua_State* L, lu_byte tt) {
439+
inline void* UpVal::operator new(size_t size, lua_State* L, LuaT tt) {
440440
return luaC_newobj(L, tt, size);
441441
}
442442

443443
// Table placement new operator
444-
inline void* Table::operator new(size_t size, lua_State* L, lu_byte tt) {
444+
inline void* Table::operator new(size_t size, lua_State* L, LuaT tt) {
445445
return luaC_newobj(L, tt, size);
446446
}
447447

src/objects/lfunc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class UpVal : public GCBase<UpVal> {
8787
~UpVal() noexcept = default;
8888

8989
// Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h)
90-
static void* operator new(size_t size, lua_State* L, lu_byte tt);
90+
static void* operator new(size_t size, lua_State* L, LuaT tt);
9191

9292
// Disable regular new/delete (must use placement new with GC)
9393
static void* operator new(size_t) = delete;
@@ -144,7 +144,7 @@ class CClosure : public GCBase<CClosure> {
144144

145145
public:
146146
// Member placement new operator for GC allocation (defined in lgc.h)
147-
static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0);
147+
static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0);
148148

149149
// Constructor
150150
CClosure(int nupvals);
@@ -182,7 +182,7 @@ class LClosure : public GCBase<LClosure> {
182182

183183
public:
184184
// Member placement new operator for GC allocation (defined in lgc.h)
185-
static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0);
185+
static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0);
186186

187187
// Constructor
188188
LClosure(int nupvals);

src/objects/lobject_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class GCBase: public GCObject {
302302
};
303303

304304
constexpr bool iscollectable(const TValue* o) noexcept { return (static_cast<int>(rawtt(o)) & BIT_ISCOLLECTABLE) != 0; }
305+
constexpr bool iscollectable(LuaT tag) noexcept { return (static_cast<int>(tag) & BIT_ISCOLLECTABLE) != 0; }
305306

306307
constexpr bool TValue::isCollectable() const noexcept { return (static_cast<int>(tt_) & BIT_ISCOLLECTABLE) != 0; }
307308

@@ -381,7 +382,7 @@ class Udata : public GCBase<Udata> {
381382
}
382383

383384
// Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h)
384-
static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0);
385+
static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0);
385386

386387
// Disable regular new/delete (must use placement new with GC)
387388
static void* operator new(size_t) = delete;

src/objects/lproto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Proto : public GCBase<Proto> {
248248
~Proto() noexcept = default;
249249

250250
// Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h)
251-
static void* operator new(size_t size, lua_State* L, lu_byte tt);
251+
static void* operator new(size_t size, lua_State* L, LuaT tt);
252252

253253
// Disable regular new/delete (must use placement new with GC)
254254
static void* operator new(size_t) = delete;

src/objects/lstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void TString::init(lua_State* L) {
146146
** creates a new string object
147147
** Phase 50: Now uses placement new to call constructor
148148
*/
149-
static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag,
149+
static TString *createstrobj (lua_State *L, size_t totalsize, LuaT tag,
150150
unsigned h) {
151151
// For TString, we need to allocate exactly totalsize bytes, not sizeof(TString)
152152
// For short strings: totalsize = contentsOffset() + string_length + 1

src/objects/lstring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TString : public GCBase<TString> {
9999

100100
// Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h)
101101
// Note: For TString, this may allocate less than sizeof(TString) for short strings!
102-
static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0);
102+
static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0);
103103

104104
// Disable regular new/delete (must use placement new with GC)
105105
static void* operator new(size_t) = delete;

0 commit comments

Comments
 (0)