Fixup LROT_MASKs for all modules.

Search-and-replace considered harmful. I completely missed the need to
explicitly declare "fast" tag functions (__xyz) in the mask field to
LROT_BEGIN()/LROT_END() when I brought over the 5.1+5.3 support.
Without those flags set properly, the LVM doesn't even bother going
looking for those methods, which in this case led to garbage collection
not calling the __gc functions, among other horrible things.

Mea culpa.
This commit is contained in:
Johny Mattsson 2021-09-16 17:45:04 +10:00
parent 5e52a9e200
commit ea968de6f8
15 changed files with 40 additions and 38 deletions

View File

@ -45,9 +45,11 @@
static ROTable_entry LOCK_IN_SECTION(s) rt ## _entries[] = {
#define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \
const ROTable rt ## _ROTable = { \
(GCObject *)1, LUA_TROTABLE, LROT_MARKED, \
cast(lu_byte, ~(f)), (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \
cast(Table *, mt), cast(ROTable_entry *, rt ## _entries) };
.next = (GCObject *)1, .tt = LUA_TROTABLE, .marked = LROT_MARKED, \
.flags = cast(lu_byte, ~(f)), \
.lsizenode = (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \
.metatable = cast(Table *, mt), \
.entry = cast(ROTable_entry *, rt ## _entries) };
#define LROT_BREAK(rt) };
#define LROT_MASK(m) cast(lu_byte, 1<<TM_ ## m)

View File

@ -153,12 +153,12 @@ static int crypto_hash_gc(lua_State* L) {
}
// The following table defines methods of the hasher object
LROT_BEGIN(crypto_hasher, NULL, 0)
LROT_BEGIN(crypto_hasher, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY(__gc, crypto_hash_gc)
LROT_TABENTRY(__index, crypto_hasher)
LROT_FUNCENTRY(update, crypto_hash_update)
LROT_FUNCENTRY(finalize, crypto_hash_finalize)
LROT_END(crypto_hasher, NULL, 0)
LROT_END(crypto_hasher, NULL, LROT_MASK_GC_INDEX)
// This table defines the functions of the crypto module:
LROT_BEGIN(crypto, NULL, 0)

View File

@ -549,7 +549,7 @@ static int file_chdir( lua_State *L )
}
#endif
LROT_BEGIN(file_obj, NULL, 0)
LROT_BEGIN(file_obj, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, file_obj_free )
LROT_TABENTRY ( __index, file_obj )
LROT_FUNCENTRY( close, file_close )
@ -559,7 +559,7 @@ LROT_BEGIN(file_obj, NULL, 0)
LROT_FUNCENTRY( writeline, file_writeline )
LROT_FUNCENTRY( seek, file_seek )
LROT_FUNCENTRY( flush, file_flush )
LROT_END(file_obj, NULL, 0)
LROT_END(file_obj, NULL, LROT_MASK_GC_INDEX)
// Module function map
LROT_BEGIN(file, NULL, 0)

View File

@ -790,7 +790,7 @@ LROT_BEGIN(http, NULL, 0)
LROT_FUNCENTRY(post, http_lapi_post)
LROT_END(http, NULL, 0)
LROT_BEGIN(http_context, NULL, 0)
LROT_BEGIN(http_context, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY(__gc, context_gc)
LROT_TABENTRY (__index, http_context)
LROT_FUNCENTRY(on, http_lapi_on)
@ -801,7 +801,7 @@ LROT_BEGIN(http_context, NULL, 0)
LROT_FUNCENTRY(setpostdata, http_lapi_setpostdata)
LROT_FUNCENTRY(close, context_close)
LROT_FUNCENTRY(ack, http_lapi_ack)
LROT_END(http_context, NULL, 0)
LROT_END(http_context, NULL, LROT_MASK_GC_INDEX)
static int luaopen_http(lua_State *L)
{

View File

@ -231,7 +231,7 @@ static int lledc_set_fade( lua_State *L ) {
}
// Module function map
LROT_BEGIN(ledc_channel, NULL, 0)
LROT_BEGIN(ledc_channel, NULL, LROT_MASK_INDEX)
LROT_TABENTRY ( __index, ledc_channel )
LROT_FUNCENTRY( getduty, lledc_get_duty )
LROT_FUNCENTRY( setduty, lledc_set_duty )
@ -246,7 +246,7 @@ LROT_BEGIN(ledc_channel, NULL, 0)
LROT_FUNCENTRY( fadewithtime, lledc_set_fade_with_time )
LROT_FUNCENTRY( fadewithstep, lledc_set_fade_with_step )
LROT_FUNCENTRY( fade, lledc_set_fade )
LROT_END(ledc_channel, NULL, 0)
LROT_END(ledc_channel, NULL, LROT_MASK_INDEX)
LROT_BEGIN(ledc, NULL, 0)
LROT_FUNCENTRY( newChannel, lledc_new_channel )

View File

@ -635,7 +635,7 @@ static int mqtt_new(lua_State* L) {
}
// map client methods to functions:
LROT_BEGIN(mqtt_metatable, NULL, 0)
LROT_BEGIN(mqtt_metatable, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY(__gc, mqtt_delete)
LROT_TABENTRY(__index, mqtt_metatable)
LROT_FUNCENTRY(connect, mqtt_connect)
@ -645,7 +645,7 @@ LROT_BEGIN(mqtt_metatable, NULL, 0)
LROT_FUNCENTRY(subscribe, mqtt_subscribe)
LROT_FUNCENTRY(unsubscribe, mqtt_unsubscribe)
LROT_FUNCENTRY(on, mqtt_on)
LROT_END(mqtt_metatable, NULL, 0)
LROT_END(mqtt_metatable, NULL, LROT_MASK_GC_INDEX)
// Module function map
LROT_BEGIN(mqtt, NULL, 0)

View File

@ -1108,15 +1108,15 @@ static void lerr_cb (lua_State *L, lnet_userdata *ud, err_t err)
// --- Tables
// Module function map
LROT_BEGIN(net_tcpserver, NULL, 0)
LROT_BEGIN(net_tcpserver, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, net_delete )
LROT_TABENTRY ( __index, net_tcpserver )
LROT_FUNCENTRY( listen, net_listen )
LROT_FUNCENTRY( getaddr, net_getaddr )
LROT_FUNCENTRY( close, net_close )
LROT_END(net_tcpserver, NULL, 0)
LROT_END(net_tcpserver, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(net_tcpsocket, NULL, 0)
LROT_BEGIN(net_tcpsocket, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, net_delete )
LROT_TABENTRY ( __index, net_tcpsocket )
LROT_FUNCENTRY( connect, net_connect )
@ -1126,9 +1126,9 @@ LROT_BEGIN(net_tcpsocket, NULL, 0)
LROT_FUNCENTRY( dns, net_dns )
LROT_FUNCENTRY( getpeer, net_getpeer )
LROT_FUNCENTRY( getaddr, net_getaddr )
LROT_END(net_tcpsocket, NULL, 0)
LROT_END(net_tcpsocket, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(net_udpsocket, NULL, 0)
LROT_BEGIN(net_udpsocket, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, net_delete )
LROT_TABENTRY ( __index, net_udpsocket )
LROT_FUNCENTRY( listen, net_listen )
@ -1137,7 +1137,7 @@ LROT_BEGIN(net_udpsocket, NULL, 0)
LROT_FUNCENTRY( send, net_send )
LROT_FUNCENTRY( dns, net_dns )
LROT_FUNCENTRY( getaddr, net_getaddr )
LROT_END(net_udpsocket, NULL, 0)
LROT_END(net_udpsocket, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(net_dns, NULL, 0)
LROT_FUNCENTRY( setdnsserver, net_setdnsserver )

View File

@ -678,7 +678,7 @@ static int pulsecnt_unregister(lua_State* L){
return 0;
}
LROT_BEGIN(pulsecnt_dyn, NULL, 0)
LROT_BEGIN(pulsecnt_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, pulsecnt_unregister )
LROT_TABENTRY ( __index, pulsecnt_dyn )
// LROT_FUNCENTRY( __tostring, pulsecnt_tostring )
@ -693,7 +693,7 @@ LROT_BEGIN(pulsecnt_dyn, NULL, 0)
LROT_FUNCENTRY( setFilter, pulsecnt_set_filter )
LROT_FUNCENTRY( rawSetEventVal, pulsecnt_set_event_value )
LROT_FUNCENTRY( rawGetEventVal, pulsecnt_get_event_value )
LROT_END(pulsecnt_dyn, NULL, 0)
LROT_END(pulsecnt_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(pulsecnt, NULL, 0)
LROT_FUNCENTRY( create, pulsecnt_create )

View File

@ -327,14 +327,14 @@ static int lsdmmc_umount( lua_State *L )
return luaL_error( L, err_msg );
}
LROT_BEGIN(sdmmc_card, NULL, 0)
LROT_BEGIN(sdmmc_card, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, sdmmc_card )
LROT_FUNCENTRY( read, lsdmmc_read )
LROT_FUNCENTRY( write, lsdmmc_write )
LROT_FUNCENTRY( get_info, lsdmmc_get_info )
LROT_FUNCENTRY( mount, lsdmmc_mount )
LROT_FUNCENTRY( umount, lsdmmc_umount )
LROT_END(sdmmc_card, NULL, 0)
LROT_END(sdmmc_card, NULL, LROT_MASK_INDEX)
LROT_BEGIN(sdmmc, NULL, 0)
LROT_FUNCENTRY( init, lsdmmc_init )

View File

@ -177,12 +177,12 @@ free_mem:
}
LROT_BEGIN(lspi_device, NULL, 0)
LROT_BEGIN(lspi_device, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lspi_device_free )
LROT_TABENTRY( __index, lspi_device )
LROT_FUNCENTRY( transfer, lspi_device_transfer )
LROT_FUNCENTRY( remove, lspi_device_free )
LROT_END(lspi_device, NULL, 0)
LROT_END(lspi_device, NULL, LROT_MASK_GC_INDEX)
// ****************************************************************************
@ -320,12 +320,12 @@ static int lspi_host_device( lua_State *L )
}
LROT_BEGIN(lspi_master, NULL, 0)
LROT_BEGIN(lspi_master, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lspi_host_free )
LROT_TABENTRY( __index, lspi_master )
LROT_FUNCENTRY( device, lspi_host_device )
LROT_FUNCENTRY( close, lspi_host_free )
LROT_END(lspi_master, NULL, 0)
LROT_END(lspi_master, NULL, LROT_MASK_GC_INDEX)
// ****************************************************************************

4
components/modules/tmr.c Executable file → Normal file
View File

@ -235,7 +235,7 @@ static int tmr_create( lua_State *L ) {
// Module function map
LROT_BEGIN(tmr_dyn, NULL, 0)
LROT_BEGIN(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, tmr_unregister )
LROT_TABENTRY ( __index, tmr_dyn )
LROT_FUNCENTRY( register, tmr_register )
@ -245,7 +245,7 @@ LROT_BEGIN(tmr_dyn, NULL, 0)
LROT_FUNCENTRY( unregister, tmr_unregister )
LROT_FUNCENTRY( interval, tmr_interval)
LROT_FUNCENTRY( state, tmr_state )
LROT_END(tmr_dyn, NULL, 0)
LROT_END(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(tmr, NULL, 0)
LROT_FUNCENTRY( create, tmr_create )

View File

@ -589,7 +589,7 @@ static int touch_unregister(lua_State* L) {
return 0;
}
LROT_BEGIN(touch_dyn, NULL, 0)
LROT_BEGIN(touch_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, touch_unregister )
LROT_TABENTRY ( __index, touch_dyn )
// LROT_FUNCENTRY( __tostring, touch_tostring )
@ -598,7 +598,7 @@ LROT_BEGIN(touch_dyn, NULL, 0)
LROT_FUNCENTRY( intrDisable, touch_intrDisable )
LROT_FUNCENTRY( setThres, touch_setThres )
LROT_FUNCENTRY( setTriggerMode, touch_setTriggerMode )
LROT_END(touch_dyn, NULL, 0)
LROT_END(touch_dyn, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(touch, NULL, 0)
LROT_FUNCENTRY( create, touch_create )

View File

@ -558,8 +558,8 @@ static int lu8g2_updateDisplayArea( lua_State *L )
}
LROT_BEGIN(lu8g2_display, NULL, 0)
//LROT_FUNCENTRY( __gc, lu8g2_display_free )
LROT_BEGIN(lu8g2_display, NULL, LROT_MASK_INDEX)
//LROT_FUNCENTRY( __gc, lu8g2_display_free ) // update LROT_MASK if enabled
LROT_TABENTRY( __index, lu8g2_display )
LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer )
LROT_FUNCENTRY( drawBox, lu8g2_drawBox )
@ -602,7 +602,7 @@ LROT_BEGIN(lu8g2_display, NULL, 0)
LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave )
LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay )
LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea )
LROT_END(lu8g2_display, NULL, 0)
LROT_END(lu8g2_display, NULL, LROT_MASK_INDEX)
uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);

View File

@ -678,7 +678,7 @@ UCG_DISPLAY_TABLE
// Module function map
LROT_BEGIN(lucg_display, NULL, 0)
LROT_BEGIN(lucg_display, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY( __gc, lucg_close_display )
LROT_TABENTRY( __index, lucg_display )
LROT_FUNCENTRY( begin, lucg_begin )
@ -724,7 +724,7 @@ LROT_BEGIN(lucg_display, NULL, 0)
LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange )
LROT_FUNCENTRY( undoRotate, lucg_undoRotate )
LROT_FUNCENTRY( undoScale, lucg_undoScale )
LROT_END(lucg_display, NULL, 0)
LROT_END(lucg_display, NULL, LROT_MASK_GC_INDEX)
LROT_BEGIN(lucg, NULL, 0)
LROT_TABENTRY( __metatable, lucg )

View File

@ -497,7 +497,7 @@ static int ws2812_buffer_tostring(lua_State* L) {
return 1;
}
LROT_BEGIN(ws2812_buffer, NULL, 0)
LROT_BEGIN(ws2812_buffer, NULL, LROT_MASK_INDEX)
LROT_FUNCENTRY( __concat, ws2812_buffer_concat )
LROT_TABENTRY ( __index, ws2812_buffer )
LROT_FUNCENTRY( __tostring, ws2812_buffer_tostring )
@ -512,7 +512,7 @@ LROT_BEGIN(ws2812_buffer, NULL, 0)
LROT_FUNCENTRY( shift, ws2812_buffer_shift )
LROT_FUNCENTRY( size, ws2812_buffer_size )
LROT_FUNCENTRY( sub, ws2812_buffer_sub )
LROT_END(ws2812_buffer, NULL, 0)
LROT_END(ws2812_buffer, NULL, LROT_MASK_INDEX)
LROT_BEGIN(ws2812, NULL, 0)
LROT_FUNCENTRY( newBuffer, ws2812_new_buffer )