Skip to content
Permalink
Browse files

SAPI: Mark all Lua API functions requiring envlock

  • Loading branch information
kwolekr committed Oct 26, 2015
1 parent 3936a5e commit 54f1267c2c87daea769966c694777a2e5977f870
@@ -36,10 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "emerge.h"
#include "pathfinder.h"

#define GET_ENV_PTR ServerEnvironment* env = \
dynamic_cast<ServerEnvironment*>(getEnv(L)); \
if (env == NULL) return 0

///////////////////////////////////////////////////////////////////////////////


@@ -658,7 +654,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
// returns world-specific PerlinNoise
int ModApiEnvMod::l_get_perlin(lua_State *L)
{
GET_ENV_PTR;
GET_ENV_PTR_NO_MAP_LOCK;

NoiseParams params;

@@ -684,7 +680,7 @@ int ModApiEnvMod::l_get_perlin(lua_State *L)
// returns world-specific PerlinNoiseMap
int ModApiEnvMod::l_get_perlin_map(lua_State *L)
{
GET_ENV_PTR;
GET_ENV_PTR_NO_MAP_LOCK;

NoiseParams np;
if (!read_noiseparams(L, 1, &np))
@@ -945,6 +941,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L)
// get_us_time()
int ModApiEnvMod::l_get_us_time(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
lua_pushnumber(L, porting::getTimeUs());
return 1;
}
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define API_FCT(name) registerFunction(L, #name, l_##name,top)
#define ASYNC_API_FCT(name) engine.registerFunction(#name, l_##name)

#define MAP_LOCK_REQUIRED
#define NO_MAP_LOCK_REQUIRED

/*
@@ -45,4 +46,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
*/

#define GET_ENV_PTR_NO_MAP_LOCK \
ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \
if (env == NULL) \
return 0

#define GET_ENV_PTR \
MAP_LOCK_REQUIRED; \
GET_ENV_PTR_NO_MAP_LOCK

#endif /* L_INTERNAL_H_ */
@@ -491,6 +491,7 @@ int ModApiInventory::l_get_inventory(lua_State *L)
std::string type = checkstringfield(L, 1, "type");

if(type == "node"){
MAP_LOCK_REQUIRED;
lua_getfield(L, 1, "pos");
v3s16 pos = check_v3s16(L, -1);
loc.setNodeMeta(pos);
@@ -514,7 +515,7 @@ int ModApiInventory::l_get_inventory(lua_State *L)
InvRef::create(L, loc);
else
lua_pushnil(L);
return 1;
return 1;
// END NO_MAP_LOCK_REQUIRED;
}
}
@@ -454,6 +454,8 @@ size_t get_biome_list(lua_State *L, int index,
// returns the biome id used in biomemap
int ModApiMapgen::l_get_biome_id(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

const char *biome_str = lua_tostring(L, 1);
if (!biome_str)
return 0;
@@ -463,7 +465,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
if (!bmgr)
return 0;

Biome *biome = (Biome *) bmgr->getByName(biome_str);
Biome *biome = (Biome *)bmgr->getByName(biome_str);

if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
@@ -478,6 +480,8 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
// returns the requested object used during map generation
int ModApiMapgen::l_get_mapgen_object(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

const char *mgobjstr = lua_tostring(L, 1);

int mgobjint;
@@ -588,6 +592,8 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)

int ModApiMapgen::l_get_mapgen_params(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

MapgenParams *params = &getServer(L)->getEmergeManager()->params;

lua_newtable(L);
@@ -616,6 +622,8 @@ int ModApiMapgen::l_get_mapgen_params(lua_State *L)
// set mapgen parameters
int ModApiMapgen::l_set_mapgen_params(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

if (!lua_istable(L, 1))
return 0;

@@ -664,6 +672,8 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
// set global config values for noise parameters
int ModApiMapgen::l_set_noiseparams(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

const char *name = luaL_checkstring(L, 1);

NoiseParams np;
@@ -681,6 +691,8 @@ int ModApiMapgen::l_set_noiseparams(lua_State *L)
// get_noiseparams(name)
int ModApiMapgen::l_get_noiseparams(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

std::string name = luaL_checkstring(L, 1);

NoiseParams np;
@@ -695,6 +707,8 @@ int ModApiMapgen::l_get_noiseparams(lua_State *L)
// set_gen_notify(flags, {deco_id_table})
int ModApiMapgen::l_set_gen_notify(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

u32 flags = 0, flagmask = 0;
EmergeManager *emerge = getServer(L)->getEmergeManager();

@@ -719,6 +733,8 @@ int ModApiMapgen::l_set_gen_notify(lua_State *L)
// get_gen_notify()
int ModApiMapgen::l_get_gen_notify(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

EmergeManager *emerge = getServer(L)->getEmergeManager();
push_flags_string(L, flagdesc_gennotify, emerge->gen_notify_on,
emerge->gen_notify_on);
@@ -738,6 +754,8 @@ int ModApiMapgen::l_get_gen_notify(lua_State *L)
// register_biome({lots of stuff})
int ModApiMapgen::l_register_biome(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

int index = 1;
luaL_checktype(L, index, LUA_TTABLE);

@@ -762,6 +780,8 @@ int ModApiMapgen::l_register_biome(lua_State *L)
// register_decoration({lots of stuff})
int ModApiMapgen::l_register_decoration(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

int index = 1;
luaL_checktype(L, index, LUA_TTABLE);

@@ -902,6 +922,8 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic
// register_ore({lots of stuff})
int ModApiMapgen::l_register_ore(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

int index = 1;
luaL_checktype(L, index, LUA_TTABLE);

@@ -1030,6 +1052,8 @@ int ModApiMapgen::l_register_ore(lua_State *L)
// register_schematic({schematic}, replacements={})
int ModApiMapgen::l_register_schematic(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;

StringMap replace_names;
@@ -1055,6 +1079,8 @@ int ModApiMapgen::l_register_schematic(lua_State *L)
// clear_registered_biomes()
int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
bmgr->clear();
return 0;
@@ -1064,6 +1090,8 @@ int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
// clear_registered_decorations()
int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr;
dmgr->clear();
return 0;
@@ -1073,6 +1101,8 @@ int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
// clear_registered_ores()
int ModApiMapgen::l_clear_registered_ores(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

OreManager *omgr = getServer(L)->getEmergeManager()->oremgr;
omgr->clear();
return 0;
@@ -1082,6 +1112,8 @@ int ModApiMapgen::l_clear_registered_ores(lua_State *L)
// clear_registered_schematics()
int ModApiMapgen::l_clear_registered_schematics(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

SchematicManager *smgr = getServer(L)->getEmergeManager()->schemmgr;
smgr->clear();
return 0;
@@ -1091,6 +1123,8 @@ int ModApiMapgen::l_clear_registered_schematics(lua_State *L)
// generate_ores(vm, p1, p2, [ore_id])
int ModApiMapgen::l_generate_ores(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

EmergeManager *emerge = getServer(L)->getEmergeManager();

Mapgen mg;
@@ -1115,6 +1149,8 @@ int ModApiMapgen::l_generate_ores(lua_State *L)
// generate_decorations(vm, p1, p2, [deco_id])
int ModApiMapgen::l_generate_decorations(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

EmergeManager *emerge = getServer(L)->getEmergeManager();

Mapgen mg;
@@ -1139,6 +1175,8 @@ int ModApiMapgen::l_generate_decorations(lua_State *L)
// create_schematic(p1, p2, probability_list, filename, y_slice_prob_list)
int ModApiMapgen::l_create_schematic(lua_State *L)
{
MAP_LOCK_REQUIRED;

INodeDefManager *ndef = getServer(L)->getNodeDefManager();

const char *filename = luaL_checkstring(L, 4);
@@ -1202,6 +1240,8 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
// place_schematic(p, schematic, rotation, replacement)
int ModApiMapgen::l_place_schematic(lua_State *L)
{
MAP_LOCK_REQUIRED;

Map *map = &(getEnv(L)->getMap());
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;

@@ -1240,6 +1280,8 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
// serialize_schematic(schematic, format, options={...})
int ModApiMapgen::l_serialize_schematic(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;

//// Read options
@@ -82,6 +82,8 @@ int NodeMetaRef::gc_object(lua_State *L) {
// get_string(self, name)
int NodeMetaRef::l_get_string(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = luaL_checkstring(L, 2);

@@ -98,6 +100,8 @@ int NodeMetaRef::l_get_string(lua_State *L)
// set_string(self, name, var)
int NodeMetaRef::l_set_string(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = luaL_checkstring(L, 2);
size_t len = 0;
@@ -115,6 +119,8 @@ int NodeMetaRef::l_set_string(lua_State *L)
// get_int(self, name)
int NodeMetaRef::l_get_int(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);

@@ -131,6 +137,8 @@ int NodeMetaRef::l_get_int(lua_State *L)
// set_int(self, name, var)
int NodeMetaRef::l_set_int(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
int a = lua_tointeger(L, 3);
@@ -147,6 +155,8 @@ int NodeMetaRef::l_set_int(lua_State *L)
// get_float(self, name)
int NodeMetaRef::l_get_float(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);

@@ -163,6 +173,8 @@ int NodeMetaRef::l_get_float(lua_State *L)
// set_float(self, name, var)
int NodeMetaRef::l_set_float(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
float a = lua_tonumber(L, 3);
@@ -179,6 +191,8 @@ int NodeMetaRef::l_set_float(lua_State *L)
// get_inventory(self)
int NodeMetaRef::l_get_inventory(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
getmeta(ref, true); // try to ensure the metadata exists
InvRef::createNodeMeta(L, ref->m_p);
@@ -188,6 +202,8 @@ int NodeMetaRef::l_get_inventory(lua_State *L)
// to_table(self)
int NodeMetaRef::l_to_table(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);

NodeMetadata *meta = getmeta(ref, true);
@@ -230,6 +246,8 @@ int NodeMetaRef::l_to_table(lua_State *L)
// from_table(self, table)
int NodeMetaRef::l_from_table(lua_State *L)
{
MAP_LOCK_REQUIRED;

NodeMetaRef *ref = checkobject(L, 1);
int base = 2;

0 comments on commit 54f1267

Please sign in to comment.