Skip to content

Commit ebc737a

Browse files
committed
ctype.h considered harmful and other cleanups
Hmmm ... ``` $ cat ctype_considered_harmful.c #include <stdio.h> #include <ctype.h> int main( int argc, char ** argv ) { int bad_standards_make_babies_cry = isspace( '\n' ); printf( "isspace( '\\n' ) = %i\n", bad_standards_make_babies_cry ); return 0; } $ gcc ctype_considered_harmful.c $ ./a.out isspace( '\n' ) = 8192 ``` ... see code for more discussions. Also, by popular demand, renamed fd_map_para to fd_map_chain_para.
1 parent 157a2e9 commit ebc737a

21 files changed

+191
-110
lines changed

src/ballet/toml/fd_toml.c

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fd_toml_parse_escaped( fd_toml_parser_t * parser ) {
315315
return 1;
316316
case 'u':
317317
if( FD_UNLIKELY( fd_toml_avail( parser ) < 4UL ) ) return 0;
318-
for( ulong j=0; j<4; j++ ) valid &= ( !!isxdigit( parser->c.data[j] ) );
318+
for( ulong j=0; j<4; j++ ) valid &= fd_isxdigit( parser->c.data[j] );
319319
if( FD_UNLIKELY( !valid ) ) return 0;
320320
rune = ( fd_toml_xdigit( parser->c.data[0] )<<12 );
321321
rune |= ( fd_toml_xdigit( parser->c.data[1] )<< 8 );
@@ -326,7 +326,7 @@ fd_toml_parse_escaped( fd_toml_parser_t * parser ) {
326326
return 1;
327327
case 'U':
328328
if( FD_UNLIKELY( fd_toml_avail( parser ) < 8UL ) ) return 0;
329-
for( ulong j=0; j<8; j++ ) valid &= ( !!isxdigit( parser->c.data[j] ) );
329+
for( ulong j=0; j<8; j++ ) valid &= fd_isxdigit( parser->c.data[j] );
330330
if( FD_UNLIKELY( !valid ) ) return 0;
331331
rune = ( fd_toml_xdigit( parser->c.data[0] )<<28 );
332332
rune |= ( fd_toml_xdigit( parser->c.data[1] )<<24 );
@@ -971,8 +971,8 @@ fd_toml_parse_zero_prefixable_int( fd_toml_parser_t * parser,
971971
if( FD_UNLIKELY( allow_underscore && parser->c.data[0] == '_' ) ) {
972972
allow_underscore = 0;
973973
fd_toml_advance_inline( parser, 1UL );
974-
if( FD_UNLIKELY( !fd_toml_avail( parser ) ) ) return 0;
975-
if( FD_UNLIKELY( !isdigit( parser->c.data[0] ) ) ) return 0;
974+
if( FD_UNLIKELY( !fd_toml_avail( parser ) ) ) return 0;
975+
if( FD_UNLIKELY( !fd_isdigit( parser->c.data[0] ) ) ) return 0;
976976
} else {
977977
int digit = (uchar)parser->c.data[0];
978978
if( FD_UNLIKELY(
@@ -983,7 +983,7 @@ fd_toml_parse_zero_prefixable_int( fd_toml_parser_t * parser,
983983
}
984984
fd_toml_advance_inline( parser, 1UL );
985985
if( !fd_toml_avail( parser ) ) break;
986-
if( !isdigit( parser->c.data[0] ) && parser->c.data[0] != '_' ) break;
986+
if( !fd_isdigit( parser->c.data[0] ) && parser->c.data[0] != '_' ) break;
987987
allow_underscore = 1;
988988
}
989989
}
@@ -1041,10 +1041,10 @@ fd_toml_parse_dec_int( fd_toml_parser_t * parser ) {
10411041

10421042
static int
10431043
fd_toml_parse_hex_int( fd_toml_parser_t * parser ) {
1044-
if( FD_UNLIKELY( fd_toml_avail( parser ) < 3 ) ) return 0;
1045-
if( FD_UNLIKELY( parser->c.data[0] != '0' ) ) return 0;
1046-
if( FD_UNLIKELY( parser->c.data[1] != 'x' ) ) return 0;
1047-
if( FD_UNLIKELY( !isxdigit( parser->c.data[2] ) ) ) return 0; /* at least one digit */
1044+
if( FD_UNLIKELY( fd_toml_avail( parser ) < 3 ) ) return 0;
1045+
if( FD_UNLIKELY( parser->c.data[0] != '0' ) ) return 0;
1046+
if( FD_UNLIKELY( parser->c.data[1] != 'x' ) ) return 0;
1047+
if( FD_UNLIKELY( !fd_isxdigit( parser->c.data[2] ) ) ) return 0; /* at least one digit */
10481048
fd_toml_advance_inline( parser, 2UL );
10491049

10501050
ulong res = 0UL;
@@ -1054,10 +1054,10 @@ fd_toml_parse_hex_int( fd_toml_parser_t * parser ) {
10541054
if( FD_UNLIKELY( allow_underscore && digit == '_' ) ) {
10551055
allow_underscore = 0;
10561056
fd_toml_advance_inline( parser, 1UL );
1057-
if( FD_UNLIKELY( !fd_toml_avail( parser ) ) ) return 0;
1058-
if( FD_UNLIKELY( !isxdigit( parser->c.data[0] ) ) ) return 0;
1057+
if( FD_UNLIKELY( !fd_toml_avail( parser ) ) ) return 0;
1058+
if( FD_UNLIKELY( !fd_isxdigit( parser->c.data[0] ) ) ) return 0;
10591059
} else {
1060-
if( !isxdigit( digit ) ) break;
1060+
if( !fd_isxdigit( digit ) ) break;
10611061
if( FD_UNLIKELY( res>>60 ) ) {
10621062
parser->error = FD_TOML_ERR_RANGE;
10631063
return 0;
@@ -1319,16 +1319,16 @@ fd_toml_parse_full_date( fd_toml_parser_t * parser,
13191319
struct tm * time ) {
13201320
if( FD_UNLIKELY( fd_toml_avail( parser ) < 10 ) ) return 0;
13211321

1322-
if( ( !isdigit( parser->c.data[0] ) ) |
1323-
( !isdigit( parser->c.data[1] ) ) |
1324-
( !isdigit( parser->c.data[2] ) ) |
1325-
( !isdigit( parser->c.data[3] ) ) |
1326-
( parser->c.data[4] != '-' ) |
1327-
( !isdigit( parser->c.data[5] ) ) |
1328-
( !isdigit( parser->c.data[6] ) ) |
1329-
( parser->c.data[7] != '-' ) |
1330-
( !isdigit( parser->c.data[8] ) ) |
1331-
( !isdigit( parser->c.data[9] ) ) ) {
1322+
if( ( !fd_isdigit( parser->c.data[0] ) ) |
1323+
( !fd_isdigit( parser->c.data[1] ) ) |
1324+
( !fd_isdigit( parser->c.data[2] ) ) |
1325+
( !fd_isdigit( parser->c.data[3] ) ) |
1326+
( parser->c.data[4] != '-' ) |
1327+
( !fd_isdigit( parser->c.data[5] ) ) |
1328+
( !fd_isdigit( parser->c.data[6] ) ) |
1329+
( parser->c.data[7] != '-' ) |
1330+
( !fd_isdigit( parser->c.data[8] ) ) |
1331+
( !fd_isdigit( parser->c.data[9] ) ) ) {
13321332
return 0;
13331333
}
13341334

@@ -1362,9 +1362,9 @@ fd_toml_parse_time_delim( fd_toml_parser_t * parser ) {
13621362
static int
13631363
fd_toml_parse_time_secfrac( fd_toml_parser_t * parser,
13641364
ulong * pnanos ) {
1365-
if( fd_toml_avail( parser ) < 2 ) return 0;
1366-
if( parser->c.data[0] != '.' ) return 0;
1367-
if( FD_UNLIKELY( !isdigit( parser->c.data[1] ) ) ) return 0;
1365+
if( fd_toml_avail( parser ) < 2 ) return 0;
1366+
if( parser->c.data[0] != '.' ) return 0;
1367+
if( FD_UNLIKELY( !fd_isdigit( parser->c.data[1] ) ) ) return 0;
13681368
fd_toml_advance_inline( parser, 1UL );
13691369

13701370
ulong secfrac = 0UL;
@@ -1374,7 +1374,7 @@ fd_toml_parse_time_secfrac( fd_toml_parser_t * parser,
13741374
secfrac = secfrac * 10UL + (ulong)( digit - '0' );
13751375
fd_toml_advance_inline( parser, 1UL );
13761376
len++;
1377-
} while( fd_toml_avail( parser ) && isdigit( parser->c.data[0] ) );
1377+
} while( fd_toml_avail( parser ) && fd_isdigit( parser->c.data[0] ) );
13781378
if( FD_UNLIKELY( len > 9 ) ) {
13791379
FD_LOG_WARNING(( "TOML parse error: invalid time fraction format" ));
13801380
return 0;
@@ -1395,14 +1395,14 @@ fd_toml_parse_partial_time( fd_toml_parser_t * parser,
13951395
ulong * pnanos ) {
13961396

13971397
if( FD_UNLIKELY( fd_toml_avail( parser ) < 8 ) ) return 0;
1398-
if( ( !isdigit( parser->c.data[0] ) ) |
1399-
( !isdigit( parser->c.data[1] ) ) |
1400-
( parser->c.data[2] != ':' ) |
1401-
( !isdigit( parser->c.data[3] ) ) |
1402-
( !isdigit( parser->c.data[4] ) ) |
1403-
( parser->c.data[5] != ':' ) |
1404-
( !isdigit( parser->c.data[6] ) ) |
1405-
( !isdigit( parser->c.data[7] ) ) ) {
1398+
if( ( !fd_isdigit( parser->c.data[0] ) ) |
1399+
( !fd_isdigit( parser->c.data[1] ) ) |
1400+
( parser->c.data[2] != ':' ) |
1401+
( !fd_isdigit( parser->c.data[3] ) ) |
1402+
( !fd_isdigit( parser->c.data[4] ) ) |
1403+
( parser->c.data[5] != ':' ) |
1404+
( !fd_isdigit( parser->c.data[6] ) ) |
1405+
( !fd_isdigit( parser->c.data[7] ) ) ) {
14061406
return 0;
14071407
}
14081408

@@ -1446,11 +1446,11 @@ fd_toml_parse_time_numoffset( fd_toml_parser_t * parser,
14461446
fd_toml_advance_inline( parser, 1UL );
14471447

14481448
if( FD_UNLIKELY( fd_toml_avail( parser ) < 5 ) ) return 0;
1449-
if( ( !isdigit( parser->c.data[0] ) ) |
1450-
( !isdigit( parser->c.data[1] ) ) |
1451-
( parser->c.data[2] != ':' ) |
1452-
( !isdigit( parser->c.data[3] ) ) |
1453-
( !isdigit( parser->c.data[4] ) ) ) {
1449+
if( ( !fd_isdigit( parser->c.data[0] ) ) |
1450+
( !fd_isdigit( parser->c.data[1] ) ) |
1451+
( parser->c.data[2] != ':' ) |
1452+
( !fd_isdigit( parser->c.data[3] ) ) |
1453+
( !fd_isdigit( parser->c.data[4] ) ) ) {
14541454
FD_LOG_WARNING(( "TOML parse error: invalid time offset format" ));
14551455
return 0;
14561456
}
@@ -1769,7 +1769,6 @@ fd_toml_parse( void const * toml,
17691769
.scratch_end = scratch + scratch_sz
17701770
}};
17711771

1772-
17731772
int ok = fd_toml_parse_toml( parser );
17741773
opt_err->line = parser->c.lineno;
17751774

src/flamenco/runtime/fd_blockstore.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ static const fd_shred_key_t fd_shred_key_null = { 0 };
118118
#define FD_SHRED_KEY_EQ(k0,k1) (!(((k0).slot) ^ ((k1).slot))) & !(((k0).idx) ^ (((k1).idx)))
119119
#define FD_SHRED_KEY_HASH(key) ((uint)(((key).slot)<<15UL) | (((key).idx))) /* current max shred idx is 32KB = 2 << 15*/
120120

121-
122-
123121
/* fd_buf_shred is a thin wrapper around fd_shred_t that facilitates
124122
buffering data shreds before all the shreds for a slot have been
125123
received. After all shreds are received, these buffered shreds are
@@ -166,7 +164,7 @@ typedef struct fd_buf_shred fd_buf_shred_t;
166164
#define MAP_KEY_EQ(k0,k1) (FD_SHRED_KEY_EQ(*k0,*k1))
167165
#define MAP_KEY_EQ_IS_SLOW 1
168166
#define MAP_KEY_HASH(key,seed) (FD_SHRED_KEY_HASH(*key)^seed)
169-
#include "../../util/tmpl/fd_map_para.c"
167+
#include "../../util/tmpl/fd_map_chain_para.c"
170168

171169
#define DEQUE_NAME fd_slot_deque
172170
#define DEQUE_T ulong

src/flamenco/vm/test_vm_instr.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ parse_advance( test_parser_t * p,
100100

101101
static void
102102
parse_assign_sep( test_parser_t * p ) {
103-
while( p->cur != p->end && isspace( p->cur[0] ) ) {
103+
while( p->cur != p->end && fd_isspace( p->cur[0] ) ) {
104104
parse_advance( p, 1UL );
105105
}
106106
if( p->cur == p->end || p->cur[0] != '=' ) {
107107
FD_LOG_ERR(( "Expected '=' at %s(%lu)", p->path, p->line ));
108108
}
109109
parse_advance( p, 1UL );
110-
while( p->cur != p->end && isspace( p->cur[0] ) ) {
110+
while( p->cur != p->end && fd_isspace( p->cur[0] ) ) {
111111
parse_advance( p, 1UL );
112112
}
113113
}
@@ -127,7 +127,7 @@ parse_hex_buf( test_parser_t * p,
127127
while( peek + 1 < p->end ) {
128128
int c0 = peek[0];
129129
int c1 = peek[1];
130-
if( !isxdigit( c0 ) || !isxdigit( c1 ) ) break;
130+
if( !fd_isxdigit( c0 ) || !fd_isxdigit( c1 ) ) break;
131131
peek += 2;
132132
sz += 1;
133133
}
@@ -141,9 +141,9 @@ parse_hex_buf( test_parser_t * p,
141141
while( p->cur + 1 < p->end ) {
142142
int c0 = p->cur[0];
143143
int c1 = p->cur[1];
144-
if( !isxdigit( c0 ) || !isxdigit( c1 ) ) break;
145-
int hi = isdigit( c0 ) ? c0 - '0' : tolower( c0 ) - 'a' + 10;
146-
int lo = isdigit( c1 ) ? c1 - '0' : tolower( c1 ) - 'a' + 10;
144+
if( !fd_isxdigit( c0 ) || !fd_isxdigit( c1 ) ) break;
145+
int hi = fd_isdigit( c0 ) ? c0 - '0' : tolower( c0 ) - 'a' + 10;
146+
int lo = fd_isdigit( c1 ) ? c1 - '0' : tolower( c1 ) - 'a' + 10;
147147
*(cur++) = (uchar)( ( hi << 4 ) | lo );
148148
parse_advance( p, 2UL );
149149
}
@@ -160,8 +160,8 @@ parse_hex_int( test_parser_t * p ) {
160160
int empty = 1;
161161
while( p->cur != p->end ) {
162162
int c = p->cur[0];
163-
if( !isxdigit( c ) ) break;
164-
int digit = isdigit( c ) ? c - '0' : tolower( c ) - 'a' + 10;
163+
if( !fd_isxdigit( c ) ) break;
164+
int digit = fd_isdigit( c ) ? c - '0' : tolower( c ) - 'a' + 10;
165165
val <<= 4;
166166
val |= (ulong)digit;
167167
empty = 0;
@@ -187,7 +187,7 @@ static test_fixture_t *
187187
parse_token( test_parser_t * p,
188188
test_fixture_t * out ) {
189189

190-
while( p->cur != p->end && isspace( p->cur[0] ) ) {
190+
while( p->cur != p->end && fd_isspace( p->cur[0] ) ) {
191191
parse_advance( p, 1UL );
192192
}
193193

@@ -250,7 +250,7 @@ parse_token( test_parser_t * p,
250250
char const * word = p->cur;
251251
while( p->cur != p->end ) {
252252
int c = p->cur[0];
253-
if( isalnum( c ) || c == '_' ) {
253+
if( fd_isalnum( c ) || c == '_' ) {
254254
parse_advance( p, 1UL );
255255
} else {
256256
break;
@@ -321,7 +321,7 @@ parse_token( test_parser_t * p,
321321
p->effects.status = STATUS_VERIFY_FAIL;
322322
p->effects.force_exec = 0;
323323

324-
} else if( word_len >= 2 && word[0] == 'r' && isdigit( word[1] ) ) {
324+
} else if( word_len >= 2 && word[0] == 'r' && fd_isdigit( word[1] ) ) {
325325

326326
ulong reg = fd_cstr_to_uchar( word+1 );
327327
assert( reg < REG_CNT );

src/funk/fd_funk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fd_funk_delete( void * shfunk ) {
204204
/* Free all the records */
205205
fd_alloc_t * alloc = fd_funk_alloc( funk, wksp);
206206

207-
/* Thread-safe iteration as described in the documentation of fd_map_para.c */
207+
/* Thread-safe iteration as described in the documentation of fd_map_chain_para.c */
208208
fd_funk_rec_map_t rec_map = fd_funk_rec_map( funk, wksp );
209209
ulong lock_cnt = fd_funk_rec_map_chain_cnt( &rec_map );
210210
ulong * lock_seq = (ulong *)fd_alloc_malloc( alloc, alignof(ulong), sizeof(ulong) * lock_cnt );

src/funk/fd_funk.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ struct __attribute__((aligned(FD_FUNK_ALIGN))) fd_funk_private {
172172

173173
/* The funk transaction map stores the details about transactions
174174
in preparation and their relationships to each other. This is a
175-
fd_map_para/fd_pool_para and more details are given in fd_funk_txn.h
175+
fd_map_chain_para/fd_pool_para and more details are given in
176+
fd_funk_txn.h
176177
177178
txn_max is the maximum number of transactions that can be in
178179
preparation. Due to the use of compressed map indices to reduce
@@ -223,7 +224,8 @@ struct __attribute__((aligned(FD_FUNK_ALIGN))) fd_funk_private {
223224
/* The funk record map stores the details about all the records in
224225
the funk, including all those in the last published transaction and
225226
all those getting updated in an in-preparation translation. This
226-
is a fd_map_para/fd_pool_para and more details are given in fd_funk_rec.h
227+
is a fd_map_chain_para/fd_pool_para and more details are given in
228+
fd_funk_rec.h
227229
228230
rec_max is the maximum number of records that can exist in this
229231
funk.

src/funk/fd_funk_rec.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define MAP_MAGIC (0xf173da2ce77ecdb0UL) /* Firedancer rec db version 0 */
2121
#define MAP_MEMOIZE 1
2222
#define MAP_IMPL_STYLE 2
23-
#include "../util/tmpl/fd_map_para.c"
23+
#include "../util/tmpl/fd_map_chain_para.c"
2424

2525
fd_funk_rec_t const *
2626
fd_funk_rec_query_try( fd_funk_t * funk,
@@ -303,8 +303,6 @@ fd_funk_rec_clone( fd_funk_t * funk,
303303
}
304304
}
305305

306-
307-
308306
int
309307
fd_funk_rec_is_full( fd_funk_t * funk ) {
310308
fd_wksp_t * wksp = fd_funk_wksp( funk );

src/funk/fd_funk_rec.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct __attribute__((aligned(FD_FUNK_REC_ALIGN))) fd_funk_rec {
6969
has tag wksp_tag) and the owner of the region will be the record. The allocator is
7070
fd_funk_alloc(). IMPORTANT! HAS NO GUARANTEED ALIGNMENT! */
7171

72-
7372
/* Padding to FD_FUNK_REC_ALIGN here */
7473
};
7574

@@ -103,7 +102,7 @@ FD_STATIC_ASSERT( sizeof(fd_funk_rec_t) == 2U*FD_FUNK_REC_ALIGN, record size is
103102
#define MAP_MAGIC (0xf173da2ce77ecdb0UL) /* Firedancer rec db version 0 */
104103
#define MAP_MEMOIZE 1
105104
#define MAP_IMPL_STYLE 1
106-
#include "../util/tmpl/fd_map_para.c"
105+
#include "../util/tmpl/fd_map_chain_para.c"
107106
#undef MAP_MEMOIZE
108107
#undef MAP_HASH
109108

@@ -313,7 +312,6 @@ fd_funk_rec_hard_remove( fd_funk_t * funk,
313312
fd_funk_txn_t * txn,
314313
fd_funk_rec_key_t const * key );
315314

316-
317315
/* When a record is erased there is metadata stored in the five most
318316
significant bytes of record flags. These are helpers to make setting
319317
and getting these values simple. The caller is responsible for doing

src/funk/fd_funk_txn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define MAP_HASH map_hash
2020
#define MAP_MAGIC (0xf173da2ce7172db0UL) /* Firedancer txn db version 0 */
2121
#define MAP_IMPL_STYLE 2
22-
#include "../util/tmpl/fd_map_para.c"
22+
#include "../util/tmpl/fd_map_chain_para.c"
2323

2424
/* TODO: remove this lock */
2525
#include "../flamenco/fd_rwlock.h"

src/funk/fd_funk_txn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef struct fd_funk_txn_private fd_funk_txn_t;
7171
#define MAP_HASH map_hash
7272
#define MAP_MAGIC (0xf173da2ce7172db0UL) /* Firedancer txn db version 0 */
7373
#define MAP_IMPL_STYLE 1
74-
#include "../util/tmpl/fd_map_para.c"
74+
#include "../util/tmpl/fd_map_chain_para.c"
7575
#undef MAP_HASH
7676

7777
FD_PROTOTYPES_BEGIN

0 commit comments

Comments
 (0)