Skip to content

Commit 80672df

Browse files
author
Benoit Germain
committed
remove uintptr_t again
1 parent 28c7e6b commit 80672df

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGES:
22

3+
CHANGE 162: BGe 29-Apr-24
4+
* remove uintptr_t again. I love optional stuff in standard headers
5+
* expose nil sentinel as lanes.null
6+
37
CHANGE 161: BGe 15-Apr-24
48
* fix keeper state stack accumulating garbage in case of transfer errors
59

src/deep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in
236236
*proxy = prelude;
237237

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

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

279279
// Memorize for later rounds
280280
lua_pushvalue( L, -1); // DPC proxy metatable metatable
281-
lua_pushlightuserdata( L, (void*)(uintptr_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc
281+
lua_pushlightuserdata(L, (void*) prelude->idfunc); // DPC proxy metatable metatable idfunc
282282
set_deep_lookup( L); // DPC proxy metatable
283283

284284
// 2 - cause the target state to require the module that exported the idfunc

src/keeper.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void push_table( lua_State* L, int idx_)
189189
STACK_END( L, 1);
190190
}
191191

192-
int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, uintptr_t magic_)
192+
int keeper_push_linda_storage(Universe* U, lua_State* L, void* ptr_, uint_t magic_)
193193
{
194194
Keeper* const K = which_keeper( U->keepers, magic_);
195195
lua_State* const KL = K ? K->L : NULL;
@@ -731,7 +731,7 @@ void init_keepers( Universe* U, lua_State* L)
731731
}
732732

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

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

761761
MUTEX_LOCK( &K->keeper_cs);

src/keeper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ typedef struct s_Keepers Keepers;
3030
void init_keepers( Universe* U, lua_State* L);
3131
void close_keepers( Universe* U);
3232

33-
Keeper* which_keeper( Keepers* keepers_, uintptr_t magic_);
34-
Keeper* keeper_acquire( Keepers* keepers_, uintptr_t magic_);
33+
Keeper* which_keeper(Keepers* keepers_, uint_t magic_);
34+
Keeper* keeper_acquire(Keepers* keepers_, uint_t magic_);
3535
#define KEEPER_MAGIC_SHIFT 3
3636
void keeper_release( Keeper* K_);
3737
void keeper_toggle_nil_sentinels( lua_State* L, int val_i_, LookupMode const mode_);
38-
int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, uintptr_t magic_);
38+
int keeper_push_linda_storage(Universe* U, lua_State* L, void* ptr_, uint_t magic_);
3939

4040
// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/
4141
static DECLARE_CONST_UNIQUE_KEY( NIL_SENTINEL, 0x7eaafa003a1d11a1);

src/linda.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ struct s_Linda
5252
SIGNAL_T read_happened;
5353
SIGNAL_T write_happened;
5454
Universe* U; // the universe this linda belongs to
55-
uintptr_t group; // a group to control keeper allocation between lindas
55+
uint_t group; // a group to control keeper allocation between lindas
5656
enum e_cancel_request simulate_cancel;
5757
char name[1];
5858
};
59-
#define LINDA_KEEPER_HASHSEED( linda) (linda->group ? linda->group : (uintptr_t)linda)
59+
#define LINDA_KEEPER_HASHSEED(linda) (linda->group ? linda->group : (uint_t)(ptrdiff_t) linda)
6060

6161
static void* linda_id( lua_State*, DeepOp);
6262

@@ -766,7 +766,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
766766
struct s_Linda* s;
767767
size_t name_len = 0;
768768
char const* linda_name = NULL;
769-
unsigned long linda_group = 0;
769+
uint_t linda_group = 0;
770770
// should have a string and/or a number of the stack as parameters (name and group)
771771
switch( lua_gettop( L))
772772
{
@@ -780,13 +780,13 @@ static void* linda_id( lua_State* L, DeepOp op_)
780780
}
781781
else
782782
{
783-
linda_group = (unsigned long) lua_tointeger( L, -1);
783+
linda_group = (uint_t) lua_tointeger(L, -1);
784784
}
785785
break;
786786

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

src/uniquekey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct s_UniqueKey
1111
typedef struct s_UniqueKey UniqueKey;
1212

1313
#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
14-
#define MAKE_UNIQUE_KEY( p_) ((void*)((uintptr_t)(p_) & 0x7fffffffffffull))
14+
#define MAKE_UNIQUE_KEY(p_) ((void*) ((ptrdiff_t) (p_) &0x7fffffffffffull))
1515
#else // LUAJIT_FLAVOR()
16-
#define MAKE_UNIQUE_KEY( p_) ((void*)(uintptr_t)(p_))
16+
#define MAKE_UNIQUE_KEY(p_) ((void*) (ptrdiff_t) (p_))
1717
#endif // LUAJIT_FLAVOR()
1818

1919
#define DECLARE_UNIQUE_KEY( name_) UniqueKey name_

0 commit comments

Comments
 (0)