From 37e9658f74f9421aaae5fe71f12eb2221f2d574a Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 18 Mar 2024 09:56:44 +0100 Subject: C++ migration: buildfixes Essentially, buildfixes when compiling as C++, plus properly marking public API as extern "C" --- src/cancel.h | 11 +++++--- src/compat.h | 11 +++++--- src/deep.c | 76 +++++++++++++++++++++++++------------------------- src/deep.h | 26 ++++++++--------- src/keeper.h | 12 +++++--- src/lanes.c | 8 +++--- src/lanes.h | 22 +++++++-------- src/lanes_private.h | 20 ++++++------- src/lanesconf.h | 17 +++++++++++ src/linda.c | 2 +- src/macros_and_utils.h | 14 +++++----- src/platform.h | 5 +--- src/state.c | 2 +- src/state.h | 6 +--- src/threading.h | 8 +----- src/tools.c | 2 +- src/tools.h | 6 +--- src/uniquekey.h | 5 +--- src/universe.c | 2 +- src/universe.h | 15 +++++----- 20 files changed, 135 insertions(+), 135 deletions(-) create mode 100644 src/lanesconf.h (limited to 'src') diff --git a/src/cancel.h b/src/cancel.h index c7c5433..bd6a1d0 100644 --- a/src/cancel.h +++ b/src/cancel.h @@ -1,9 +1,14 @@ -#if !defined( __LANES_CANCEL_H__) -#define __LANES_CANCEL_H__ 1 +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" #include "lualib.h" #include "lauxlib.h" +#ifdef __cplusplus +} +#endif // __cplusplus #include "uniquekey.h" #include "macros_and_utils.h" @@ -62,5 +67,3 @@ LUAG_FUNC( cancel_test); LUAG_FUNC( thread_cancel); // ################################################################################################ - -#endif // __LANES_CANCEL_H__ diff --git a/src/compat.h b/src/compat.h index e44f827..ed56cc6 100644 --- a/src/compat.h +++ b/src/compat.h @@ -1,9 +1,14 @@ -#if !defined( __COMPAT_H__) -#define __COMPAT_H__ 1 +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" #include "lualib.h" #include "lauxlib.h" +#ifdef __cplusplus +} +#endif // __cplusplus // try to detect if we are building against LuaJIT or MoonJIT #if defined(LUA_JITLIBNAME) @@ -92,5 +97,3 @@ int lua_setiuservalue( lua_State* L, int idx, int n); #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) #endif // LUA_VERSION_NUM == 504 - -#endif // __COMPAT_H__ diff --git a/src/deep.c b/src/deep.c index 9496477..58da457 100644 --- a/src/deep.c +++ b/src/deep.c @@ -97,8 +97,8 @@ static void get_deep_lookup( lua_State* L) REGISTRY_GET( L, DEEP_LOOKUP_KEY); // a {} if( !lua_isnil( L, -1)) { - lua_insert( L, -2); // {} a - lua_rawget( L, -2); // {} b + lua_insert( L, -2); // {} a + lua_rawget( L, -2); // {} b } lua_remove( L, -2); // a|b STACK_END( L, 1); @@ -173,7 +173,7 @@ static int deep_userdata_gc( lua_State* L) if( v == 0) { // retrieve wrapped __gc - lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? + lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? if( !lua_isnil( L, -1)) { lua_insert( L, -2); // __gc self @@ -213,12 +213,12 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in lua_rawget( L, -2); // DPC proxy if ( !lua_isnil( L, -1)) { - lua_remove( L, -2); // proxy + lua_remove( L, -2); // proxy return NULL; } else { - lua_pop( L, 1); // DPC + lua_pop( L, 1); // DPC } // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded @@ -231,7 +231,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in STACK_CHECK( L, 0); // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) - proxy = lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy + proxy = (DeepPrelude**) lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy ASSERT_L( proxy); *proxy = prelude; @@ -242,101 +242,101 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in if( lua_isnil( L, -1)) // // No metatable yet. { char const* modname; - int oldtop = lua_gettop( L); // DPC proxy nil - lua_pop( L, 1); // DPC proxy + int oldtop = lua_gettop( L); // DPC proxy nil + lua_pop( L, 1); // DPC proxy // 1 - make one and register it if( mode_ != eLM_ToKeeper) { - (void) prelude->idfunc( L, eDO_metatable); // DPC proxy metatable + (void) prelude->idfunc( L, eDO_metatable); // DPC proxy metatable if( lua_gettop( L) - oldtop != 0 || !lua_istable( L, -1)) { - lua_settop( L, oldtop); // DPC proxy X - lua_pop( L, 3); // + lua_settop( L, oldtop); // DPC proxy X + lua_pop( L, 3); // return "Bad idfunc(eOP_metatable): unexpected pushed value"; } // if the metatable contains a __gc, we will call it from our own - lua_getfield( L, -1, "__gc"); // DPC proxy metatable __gc + lua_getfield( L, -1, "__gc"); // DPC proxy metatable __gc } else { // keepers need a minimal metatable that only contains our own __gc - lua_newtable( L); // DPC proxy metatable - lua_pushnil( L); // DPC proxy metatable nil + lua_newtable( L); // DPC proxy metatable + lua_pushnil( L); // DPC proxy metatable nil } if( lua_isnil( L, -1)) { // Add our own '__gc' method - lua_pop( L, 1); // DPC proxy metatable - lua_pushcfunction( L, deep_userdata_gc); // DPC proxy metatable deep_userdata_gc + lua_pop( L, 1); // DPC proxy metatable + lua_pushcfunction( L, deep_userdata_gc); // DPC proxy metatable deep_userdata_gc } else { // Add our own '__gc' method wrapping the original - lua_pushcclosure( L, deep_userdata_gc, 1); // DPC proxy metatable deep_userdata_gc + lua_pushcclosure( L, deep_userdata_gc, 1); // DPC proxy metatable deep_userdata_gc } - lua_setfield( L, -2, "__gc"); // DPC proxy metatable + lua_setfield( L, -2, "__gc"); // DPC proxy metatable // Memorize for later rounds - lua_pushvalue( L, -1); // DPC proxy metatable metatable - lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc - set_deep_lookup( L); // DPC proxy metatable + lua_pushvalue( L, -1); // DPC proxy metatable metatable + lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc + set_deep_lookup( L); // DPC proxy metatable // 2 - cause the target state to require the module that exported the idfunc // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc { int oldtop_module = lua_gettop( L); - modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable + modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable // make sure the function pushed nothing on the stack! if( lua_gettop( L) - oldtop_module != 0) { - lua_pop( L, 3); // + lua_pop( L, 3); // return "Bad idfunc(eOP_module): should not push anything"; } } if( NULL != modname) // we actually got a module name { // L.registry._LOADED exists without having registered the 'package' library. - lua_getglobal( L, "require"); // DPC proxy metatable require() + lua_getglobal( L, "require"); // DPC proxy metatable require() // check that the module is already loaded (or being loaded, we are happy either way) if( lua_isfunction( L, -1)) { - lua_pushstring( L, modname); // DPC proxy metatable require() "module" - lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED + lua_pushstring( L, modname); // DPC proxy metatable require() "module" + lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED if( lua_istable( L, -1)) { bool_t alreadyloaded; - lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" - lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module + lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" + lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module alreadyloaded = lua_toboolean( L, -1); if( !alreadyloaded) // not loaded { int require_result; - lua_pop( L, 2); // DPC proxy metatable require() "module" + lua_pop( L, 2); // DPC proxy metatable require() "module" // require "modname" - require_result = lua_pcall( L, 1, 0, 0); // DPC proxy metatable error? + require_result = lua_pcall( L, 1, 0, 0); // DPC proxy metatable error? if( require_result != LUA_OK) { // failed, return the error message lua_pushfstring( L, "error while requiring '%s' identified by idfunc(eOP_module): ", modname); - lua_insert( L, -2); // DPC proxy metatable prefix error - lua_concat( L, 2); // DPC proxy metatable error + lua_insert( L, -2); // DPC proxy metatable prefix error + lua_concat( L, 2); // DPC proxy metatable error return lua_tostring( L, -1); } } else // already loaded, we are happy { - lua_pop( L, 4); // DPC proxy metatable + lua_pop( L, 4); // DPC proxy metatable } } else // no L.registry._LOADED; can this ever happen? { - lua_pop( L, 6); // + lua_pop( L, 6); // return "unexpected error while requiring a module identified by idfunc(eOP_module)"; } } else // a module name, but no require() function :-( { - lua_pop( L, 4); // + lua_pop( L, 4); // return "lanes receiving deep userdata should register the 'package' library"; } } @@ -386,7 +386,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) STACK_CHECK( L, 0); { int const oldtop = lua_gettop( L); - DeepPrelude* prelude = idfunc( L, eDO_new); + DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); if( prelude == NULL) { return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); @@ -473,7 +473,7 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui lua_pop( L, 1); // ... u [uv]* STACK_MID( L, nuv); - errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u + errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u // transfer all uservalues of the source in the destination { @@ -481,7 +481,7 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui while( nuv) { inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // u uv - lua_pop( L, 1); // ... u [uv]* + lua_pop( L, 1); // ... u [uv]* // this pops the value from the stack lua_setiuservalue( L2, clone_i, nuv); // u -- nuv; diff --git a/src/deep.h b/src/deep.h index 9b00b70..728aa2a 100644 --- a/src/deep.h +++ b/src/deep.h @@ -1,27 +1,25 @@ -#ifndef __LANES_DEEP_H__ -#define __LANES_DEEP_H__ 1 +#pragma once /* * public 'deep' API to be used by external modules if they want to implement Lanes-aware userdata * said modules will have to link against lanes (it is not really possible to separate the 'deep userdata' implementation from the rest of Lanes) */ +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" -#include "platform.h" +#ifdef __cplusplus +} +#endif // __cplusplus + +#include "lanesconf.h" #include "uniquekey.h" // forwards struct s_Universe; typedef struct s_Universe Universe; -#if !defined LANES_API // when deep is compiled standalone outside Lanes -#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) -#define LANES_API __declspec(dllexport) -#else -#define LANES_API -#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) -#endif // LANES_API - enum eLookupMode { eLM_LaneBody, // send the lane body directly from the source to the destination lane @@ -60,7 +58,5 @@ typedef struct s_DeepPrelude DeepPrelude; char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, int nuv_, LookupMode mode_); void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); -extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_); -extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); - -#endif // __LANES_DEEP_H__ +LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_); +LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); diff --git a/src/keeper.h b/src/keeper.h index d30aa36..33118be 100644 --- a/src/keeper.h +++ b/src/keeper.h @@ -1,7 +1,13 @@ -#if !defined( __keeper_h__) -#define __keeper_h__ 1 +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" +#ifdef __cplusplus +} +#endif // __cplusplus + #include "threading.h" #include "uniquekey.h" @@ -53,5 +59,3 @@ int keepercall_set( lua_State* L); int keepercall_count( lua_State* L); int keeper_call( Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, uint_t starting_index); - -#endif // __keeper_h__ \ No newline at end of file diff --git a/src/lanes.c b/src/lanes.c index 332a1b8..deee90c 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -790,7 +790,7 @@ LUAG_FUNC( set_debug_threadname) { DECLARE_CONST_UNIQUE_KEY( hidden_regkey, LG_set_debug_threadname); // C s_lane structure is a light userdata upvalue - Lane* s = lua_touserdata( L, lua_upvalueindex( 1)); + Lane* s = (Lane*) lua_touserdata( L, lua_upvalueindex( 1)); luaL_checktype( L, -1, LUA_TSTRING); // "name" lua_settop( L, 1); STACK_CHECK_ABS( L, 1); @@ -1225,7 +1225,7 @@ LUAG_FUNC( lane_new) // 's' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) // // a Lane full userdata needs a single uservalue - ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane + ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane { AllocatorDefinition* const allocD = &U->internal_allocator; s = *ud = (Lane*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); @@ -2074,7 +2074,7 @@ static void EnableCrashingOnCrashes( void) } #endif // PLATFORM_WIN32 -int LANES_API luaopen_lanes_core( lua_State* L) +LANES_API int luaopen_lanes_core( lua_State* L) { #if defined PLATFORM_WIN32 && !defined NDEBUG EnableCrashingOnCrashes(); @@ -2129,7 +2129,7 @@ static int default_luaopen_lanes( lua_State* L) } // call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application -void LANES_API luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) +LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) { STACK_CHECK( L, 0); // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded diff --git a/src/lanes.h b/src/lanes.h index 7e1a2e5..6e05cae 100644 --- a/src/lanes.h +++ b/src/lanes.h @@ -1,14 +1,14 @@ -#if !defined( __lanes_h__) -#define __lanes_h__ 1 +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" -#include "platform.h" +#ifdef __cplusplus +} +#endif // __cplusplus -#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) -#define LANES_API __declspec(dllexport) -#else -#define LANES_API -#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) +#include "lanesconf.h" #define LANES_VERSION_MAJOR 3 #define LANES_VERSION_MINOR 16 @@ -20,9 +20,7 @@ #define LANES_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>PATCH)))) #define LANES_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) -extern int LANES_API luaopen_lanes_core( lua_State* L); +LANES_API int luaopen_lanes_core( lua_State* L); // Call this to work with embedded Lanes instead of calling luaopen_lanes_core() -extern void LANES_API luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes); - -#endif // __lanes_h__ \ No newline at end of file +LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes); diff --git a/src/lanes_private.h b/src/lanes_private.h index 6717fe0..67c99f7 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h @@ -1,10 +1,15 @@ -#if !defined __lanes_private_h__ -#define __lanes_private_h__ 1 +#pragma once #include "uniquekey.h" #include "cancel.h" #include "universe.h" +enum ThreadStatus +{ + NORMAL, // normal master side state + KILLED // issued an OS kill +}; + // NOTE: values to be changed by either thread, during execution, without // locking, are marked "volatile" // @@ -49,11 +54,7 @@ struct s_Lane // lane status changes to DONE/ERROR_ST/CANCELLED. #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR - volatile enum - { - NORMAL, // normal master side state - KILLED // issued an OS kill - } mstatus; + volatile enum ThreadStatus mstatus; // // M: sets to NORMAL, if issued a kill changes to KILLED // S: not used @@ -84,13 +85,10 @@ static inline Lane* get_lane_from_registry( lua_State* L) STACK_GROW( L, 1); STACK_CHECK( L, 0); REGISTRY_GET( L, CANCEL_TEST_KEY); - s = lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil + s = (Lane*) lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil lua_pop( L, 1); STACK_END( L, 0); return s; } int push_thread_status( lua_State* L, Lane* s); - - -#endif // __lanes_private_h__ \ No newline at end of file diff --git a/src/lanesconf.h b/src/lanesconf.h new file mode 100644 index 0000000..fb4a601 --- /dev/null +++ b/src/lanesconf.h @@ -0,0 +1,17 @@ +#pragma once + +#include "platform.h" + +#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) +#ifdef __cplusplus +#define LANES_API extern "C" __declspec(dllexport) +#else +#define LANES_API extern __declspec(dllexport) +#endif // __cplusplus +#else +#ifdef __cplusplus +#define LANES_API extern "C" +#else +#define LANES_API extern +#endif // __cplusplus +#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) diff --git a/src/linda.c b/src/linda.c index 8b59790..eac6458 100644 --- a/src/linda.c +++ b/src/linda.c @@ -816,7 +816,7 @@ static void* linda_id( lua_State* L, DeepOp op_) case eDO_delete: { Keeper* K; - struct s_Linda* linda = lua_touserdata( L, 1); + struct s_Linda* linda = (struct s_Linda*) lua_touserdata( L, 1); ASSERT_L( linda); // Clean associated structures in the keeper state. diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 05a46b5..726fe64 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h @@ -1,11 +1,13 @@ -/* - * MACROS_AND_UTILS.H - */ -#ifndef MACROS_AND_UTILS_H -#define MACROS_AND_UTILS_H +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" #include "lualib.h" +#ifdef __cplusplus +} +#endif // __cplusplus // M$ compiler doesn't support 'inline' keyword in C files... #if defined( _MSC_VER) @@ -98,5 +100,3 @@ extern char const* debugspew_indent; } #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) - -#endif // MACROS_AND_UTILS_H diff --git a/src/platform.h b/src/platform.h index da5264e..ce621d9 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,5 +1,4 @@ -#ifndef __LANES_PLATFORM_H__ -#define __LANES_PLATFORM_H__ 1 +#pragma once #ifdef _WIN32_WCE #define PLATFORM_POCKETPC @@ -20,5 +19,3 @@ #else #error "Unknown platform!" #endif - -#endif // __LANES_PLATFORM_H__ diff --git a/src/state.c b/src/state.c index 21ca397..85ad31e 100644 --- a/src/state.c +++ b/src/state.c @@ -259,7 +259,7 @@ lua_State* create_state( Universe* U, lua_State* from_) lua_pushcclosure( from_, U->provide_allocator, 0); lua_call( from_, 0, 1); { - AllocatorDefinition* const def = lua_touserdata( from_, -1); + AllocatorDefinition* const def = (AllocatorDefinition*) lua_touserdata( from_, -1); L = lua_newstate( def->allocF, def->allocUD); } lua_pop( from_, 1); diff --git a/src/state.h b/src/state.h index e844405..0ffab02 100644 --- a/src/state.h +++ b/src/state.h @@ -1,7 +1,5 @@ -#ifndef __LANES_STATE_H__ -#define __LANES_STATE_H__ +#pragma once -//#include "lauxlib.h" #include "threading.h" #include "deep.h" @@ -18,5 +16,3 @@ lua_State* luaG_newstate( Universe* U, lua_State* _from, char const* libs); void initialize_on_state_create( Universe* U, lua_State* L); void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); - -#endif // __LANES_STATE_H__ diff --git a/src/threading.h b/src/threading.h index b1706ac..8324bdd 100644 --- a/src/threading.h +++ b/src/threading.h @@ -1,8 +1,4 @@ -/* -* THREADING.H -*/ -#ifndef __threading_h__ -#define __threading_h__ 1 +#pragma once /* * win32-pthread: @@ -261,5 +257,3 @@ void THREAD_SETNAME( char const* _name); void THREAD_MAKE_ASYNCH_CANCELLABLE(); void THREAD_SET_PRIORITY( int prio); void THREAD_SET_AFFINITY( unsigned int aff); - -#endif // __threading_h__ diff --git a/src/tools.c b/src/tools.c index 80e0f71..6f4a06a 100644 --- a/src/tools.c +++ b/src/tools.c @@ -183,7 +183,7 @@ static void* protected_lua_Alloc( void *ud, void *ptr, size_t osize, size_t nsiz static int luaG_provide_protected_allocator( lua_State* L) { Universe* U = universe_get( L); - AllocatorDefinition* const def = lua_newuserdatauv( L, sizeof(AllocatorDefinition), 0); + AllocatorDefinition* const def = (AllocatorDefinition*) lua_newuserdatauv( L, sizeof(AllocatorDefinition), 0); def->allocF = protected_lua_Alloc; def->allocUD = &U->protected_allocator; return 1; diff --git a/src/tools.h b/src/tools.h index a0893e4..c714837 100644 --- a/src/tools.h +++ b/src/tools.h @@ -1,7 +1,5 @@ -#ifndef __LANES_TOOLS_H__ -#define __LANES_TOOLS_H__ +#pragma once -//#include "lauxlib.h" #include "threading.h" #include "deep.h" @@ -53,5 +51,3 @@ static DECLARE_CONST_UNIQUE_KEY( CONFIG_REGKEY, 0x31cd24894eae8624); // 'cancel_ // crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/ static DECLARE_CONST_UNIQUE_KEY( LOOKUP_REGKEY, 0x5051ed67ee7b51a1); // 'cancel_error' sentinel - -#endif // __LANES_TOOLS_H__ diff --git a/src/uniquekey.h b/src/uniquekey.h index 015fbf2..f219ab1 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -1,5 +1,4 @@ -#if !defined __LANES_UNIQUEKEY_H__ -#define __LANES_UNIQUEKEY_H__ 1 +#pragma once #include "compat.h" @@ -21,5 +20,3 @@ typedef struct s_UniqueKey UniqueKey; #define push_unique_key( L, key_) lua_pushlightuserdata( L, key_.value) #define equal_unique_key( L, i, key_) (lua_touserdata( L, i) == key_.value) - -#endif // __LANES_UNIQUEKEY_H__ diff --git a/src/universe.c b/src/universe.c index 9f84baf..0a014f7 100644 --- a/src/universe.c +++ b/src/universe.c @@ -68,7 +68,7 @@ Universe* universe_get( lua_State* L) STACK_GROW( L, 2); STACK_CHECK( L, 0); REGISTRY_GET( L, UNIVERSE_REGKEY); - universe = lua_touserdata( L, -1); // NULL if nil + universe = (Universe*) lua_touserdata( L, -1); // NULL if nil lua_pop( L, 1); STACK_END( L, 0); return universe; diff --git a/src/universe.h b/src/universe.h index 03c78cf..0224e99 100644 --- a/src/universe.h +++ b/src/universe.h @@ -1,10 +1,13 @@ -/* -* UNIVERSE.H -*/ -#ifndef UNIVERSE_H -#define UNIVERSE_H +#pragma once +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #include "lua.h" +#ifdef __cplusplus +} +#endif // __cplusplus + #include "threading.h" #include "macros_and_utils.h" @@ -101,5 +104,3 @@ typedef struct s_Universe Universe; Universe* universe_get( lua_State* L); Universe* universe_create( lua_State* L); void universe_store( lua_State* L, Universe* U); - -#endif // UNIVERSE_H -- cgit v1.2.3-55-g6feb