Skip to content

Commit

Permalink
remove uintptr_t again
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Germain committed Apr 29, 2024
1 parent 28c7e6b commit 80672df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CHANGES:

CHANGE 162: BGe 29-Apr-24
* remove uintptr_t again. I love optional stuff in standard headers
* expose nil sentinel as lanes.null

CHANGE 161: BGe 15-Apr-24
* fix keeper state stack accumulating garbage in case of transfer errors

Expand Down
4 changes: 2 additions & 2 deletions src/deep.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in
*proxy = prelude;

// Get/create metatable for 'idfunc' (in this state)
lua_pushlightuserdata( L, (void*)(uintptr_t)(prelude->idfunc)); // DPC proxy idfunc
lua_pushlightuserdata(L, (void*) prelude->idfunc); // DPC proxy idfunc
get_deep_lookup( L); // DPC proxy metatable?

if( lua_isnil( L, -1)) // // No metatable yet.
Expand Down Expand Up @@ -278,7 +278,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in

// Memorize for later rounds
lua_pushvalue( L, -1); // DPC proxy metatable metatable
lua_pushlightuserdata( L, (void*)(uintptr_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc
lua_pushlightuserdata(L, (void*) 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
Expand Down
8 changes: 4 additions & 4 deletions src/keeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static void push_table( lua_State* L, int idx_)
STACK_END( L, 1);
}

int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, uintptr_t magic_)
int keeper_push_linda_storage(Universe* U, lua_State* L, void* ptr_, uint_t magic_)
{
Keeper* const K = which_keeper( U->keepers, magic_);
lua_State* const KL = K ? K->L : NULL;
Expand Down Expand Up @@ -731,7 +731,7 @@ void init_keepers( Universe* U, lua_State* L)
}

// should be called only when inside a keeper_acquire/keeper_release pair (see linda_protected_call)
Keeper* which_keeper(Keepers* keepers_, uintptr_t magic_)
Keeper* which_keeper(Keepers* keepers_, uint_t magic_)
{
int const nbKeepers = keepers_->nb_keepers;
if (nbKeepers)
Expand All @@ -742,7 +742,7 @@ Keeper* which_keeper(Keepers* keepers_, uintptr_t magic_)
return NULL;
}

Keeper* keeper_acquire( Keepers* keepers_, uintptr_t magic_)
Keeper* keeper_acquire(Keepers* keepers_, uint_t magic_)
{
int const nbKeepers = keepers_->nb_keepers;
// can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers)
Expand All @@ -755,7 +755,7 @@ Keeper* keeper_acquire( Keepers* keepers_, uintptr_t magic_)
* Pointers are often aligned by 8 or so - ignore the low order bits
* have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer
*/
unsigned int i = (unsigned int)((magic_ >> KEEPER_MAGIC_SHIFT) % nbKeepers);
uint_t i = (uint_t) ((magic_ >> KEEPER_MAGIC_SHIFT) % nbKeepers);
Keeper* K = &keepers_->keeper_array[i];

MUTEX_LOCK( &K->keeper_cs);
Expand Down
6 changes: 3 additions & 3 deletions src/keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ typedef struct s_Keepers Keepers;
void init_keepers( Universe* U, lua_State* L);
void close_keepers( Universe* U);

Keeper* which_keeper( Keepers* keepers_, uintptr_t magic_);
Keeper* keeper_acquire( Keepers* keepers_, uintptr_t magic_);
Keeper* which_keeper(Keepers* keepers_, uint_t magic_);
Keeper* keeper_acquire(Keepers* keepers_, uint_t magic_);
#define KEEPER_MAGIC_SHIFT 3
void keeper_release( Keeper* K_);
void keeper_toggle_nil_sentinels( lua_State* L, int val_i_, LookupMode const mode_);
int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, uintptr_t magic_);
int keeper_push_linda_storage(Universe* U, lua_State* L, void* ptr_, uint_t magic_);

// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/
static DECLARE_CONST_UNIQUE_KEY( NIL_SENTINEL, 0x7eaafa003a1d11a1);
Expand Down
10 changes: 5 additions & 5 deletions src/linda.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ struct s_Linda
SIGNAL_T read_happened;
SIGNAL_T write_happened;
Universe* U; // the universe this linda belongs to
uintptr_t group; // a group to control keeper allocation between lindas
uint_t group; // a group to control keeper allocation between lindas
enum e_cancel_request simulate_cancel;
char name[1];
};
#define LINDA_KEEPER_HASHSEED( linda) (linda->group ? linda->group : (uintptr_t)linda)
#define LINDA_KEEPER_HASHSEED(linda) (linda->group ? linda->group : (uint_t)(ptrdiff_t) linda)

static void* linda_id( lua_State*, DeepOp);

Expand Down Expand Up @@ -766,7 +766,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
struct s_Linda* s;
size_t name_len = 0;
char const* linda_name = NULL;
unsigned long linda_group = 0;
uint_t linda_group = 0;
// should have a string and/or a number of the stack as parameters (name and group)
switch( lua_gettop( L))
{
Expand All @@ -780,13 +780,13 @@ static void* linda_id( lua_State* L, DeepOp op_)
}
else
{
linda_group = (unsigned long) lua_tointeger( L, -1);
linda_group = (uint_t) lua_tointeger(L, -1);
}
break;

case 2: // 2 parameters, a name and group, in that order
linda_name = lua_tolstring( L, -2, &name_len);
linda_group = (unsigned long) lua_tointeger( L, -1);
linda_group = (uint_t) lua_tointeger(L, -1);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/uniquekey.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ struct s_UniqueKey
typedef struct s_UniqueKey UniqueKey;

#if LUAJIT_FLAVOR() == 64 // building against LuaJIT headers for 64 bits, light userdata is restricted to 47 significant bits, because LuaJIT uses the other bits for internal optimizations
#define MAKE_UNIQUE_KEY( p_) ((void*)((uintptr_t)(p_) & 0x7fffffffffffull))
#define MAKE_UNIQUE_KEY(p_) ((void*) ((ptrdiff_t) (p_) &0x7fffffffffffull))
#else // LUAJIT_FLAVOR()
#define MAKE_UNIQUE_KEY( p_) ((void*)(uintptr_t)(p_))
#define MAKE_UNIQUE_KEY(p_) ((void*) (ptrdiff_t) (p_))
#endif // LUAJIT_FLAVOR()

#define DECLARE_UNIQUE_KEY( name_) UniqueKey name_
Expand Down

0 comments on commit 80672df

Please sign in to comment.