Skip to content

Commit 054b608

Browse files
committed
Refactor noexcept_call usage for improved clarity and consistency
- Updated calls to `noexcept_call` across various headers to ensure consistent usage of the scope resolution operator (::) for system functions. - Enhanced readability by standardizing function call patterns in memory allocation, OpenSSL, and POSIX headers. - Improved error handling and maintainability by ensuring all system function calls are wrapped with `noexcept_call` for safer error management.
1 parent e9f5daf commit 054b608

File tree

32 files changed

+164
-164
lines changed

32 files changed

+164
-164
lines changed

include/fast_io_core_impl/allocation/c_malloc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace details
1616
inline ::std::size_t c_malloc_usable_size_impl(void *p) noexcept
1717
{
1818
#if defined(_WIN32) && !defined(__WINE__) && !defined(__CYGWIN__)
19-
return ::fast_io::noexcept_call(_msize, p);
19+
return ::fast_io::noexcept_call(::_msize, p);
2020
#else
2121
return ::malloc_usable_size(p);
2222
#endif
@@ -139,7 +139,7 @@ class c_malloc_allocator
139139
}
140140
else
141141
{
142-
p = ::fast_io::noexcept_call(_aligned_malloc, n, alignment);
142+
p = ::fast_io::noexcept_call(::_aligned_malloc, n, alignment);
143143
}
144144
if (p == nullptr)
145145
{
@@ -169,7 +169,7 @@ class c_malloc_allocator
169169
}
170170
else
171171
{
172-
p = ::fast_io::noexcept_call(_aligned_realloc, p, n, alignment);
172+
p = ::fast_io::noexcept_call(::_aligned_realloc, p, n, alignment);
173173
}
174174
if (p == nullptr)
175175
{
@@ -194,7 +194,7 @@ class c_malloc_allocator
194194
}
195195
else
196196
{
197-
::fast_io::noexcept_call(_aligned_free, p);
197+
::fast_io::noexcept_call(::_aligned_free, p);
198198
}
199199
}
200200
#endif

include/fast_io_core_impl/allocation/wincrt_malloc_dbg.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class wincrt_malloc_dbg_allocator
1717
{
1818
n = 1;
1919
}
20-
void *p = ::fast_io::noexcept_call(_malloc_dbg, n, 1, __FILE__, __LINE__);
20+
void *p = ::fast_io::noexcept_call(::_malloc_dbg, n, 1, __FILE__, __LINE__);
2121
if (p == nullptr)
2222
{
2323
::fast_io::fast_terminate();
@@ -33,7 +33,7 @@ class wincrt_malloc_dbg_allocator
3333
{
3434
n = 1;
3535
}
36-
p = ::fast_io::noexcept_call(_realloc_dbg, p, n, 1, __FILE__, __LINE__);
36+
p = ::fast_io::noexcept_call(::_realloc_dbg, p, n, 1, __FILE__, __LINE__);
3737
if (p == nullptr)
3838
{
3939
::fast_io::fast_terminate();
@@ -49,7 +49,7 @@ class wincrt_malloc_dbg_allocator
4949
{
5050
n = 1;
5151
}
52-
void *p = ::fast_io::noexcept_call(_calloc_dbg, 1, n, 1, __FILE__, __LINE__);
52+
void *p = ::fast_io::noexcept_call(::_calloc_dbg, 1, n, 1, __FILE__, __LINE__);
5353
if (p == nullptr)
5454
{
5555
::fast_io::fast_terminate();
@@ -62,24 +62,24 @@ class wincrt_malloc_dbg_allocator
6262
{
6363
return;
6464
}
65-
::fast_io::noexcept_call(_free_dbg, p, 1);
65+
::fast_io::noexcept_call(::_free_dbg, p, 1);
6666
}
6767

6868
#if 0
6969
static inline allocation_least_result allocate_at_least(::std::size_t n) noexcept
7070
{
7171
auto p{::fast_io::wincrt_malloc_dbg_allocator::allocate(n)};
72-
return {p, ::fast_io::noexcept_call(_msize_dbg, p, 1)};
72+
return {p, ::fast_io::noexcept_call(::_msize_dbg, p, 1)};
7373
}
7474
static inline allocation_least_result allocate_zero_at_least(::std::size_t n) noexcept
7575
{
7676
auto p{::fast_io::wincrt_malloc_dbg_allocator::allocate_zero(n)};
77-
return {p, ::fast_io::noexcept_call(_msize_dbg, p, 1)};
77+
return {p, ::fast_io::noexcept_call(::_msize_dbg, p, 1)};
7878
}
7979
static inline allocation_least_result reallocate_at_least(void *oldp, ::std::size_t n) noexcept
8080
{
8181
auto p{::fast_io::wincrt_malloc_dbg_allocator::reallocate(oldp, n)};
82-
return {p, ::fast_io::noexcept_call(_msize_dbg, p, 1)};
82+
return {p, ::fast_io::noexcept_call(::_msize_dbg, p, 1)};
8383
}
8484
#endif
8585
};

include/fast_io_core_impl/freestanding/noexcept_call.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline
5353
#if __cpp_if_consteval >= 202106L || __cpp_lib_is_constant_evaluated >= 201811
5454
constexpr
5555
#endif
56-
decltype(auto) noexcept_call(F *f, Args &&...args) noexcept
56+
decltype(auto) noexcept_call(::F *f, Args &&...args) noexcept
5757
{
5858
if (__builtin_is_constant_evaluated())
5959
{

include/fast_io_crypto/platforms/ossl_evp.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ossl_evp_guard
1111
public:
1212
EVP_MD_CTX *pmdctx{};
1313
inline ossl_evp_guard()
14-
: pmdctx{noexcept_call(EVP_MD_CTX_new)}
14+
: pmdctx{noexcept_call(::EVP_MD_CTX_new)}
1515
{
1616
if (this->pmdctx == nullptr)
1717
{
@@ -30,20 +30,20 @@ class ossl_evp_guard
3030
{
3131
if (this->pmdctx)
3232
{
33-
noexcept_call(EVP_MD_CTX_free, this->pmdctx);
33+
noexcept_call(::EVP_MD_CTX_free, this->pmdctx);
3434
}
3535
}
3636
};
3737

3838
inline EVP_MD_CTX *create_ossl_evp_hash_impl(char const *name)
3939
{
40-
auto md{noexcept_call(EVP_get_digestbyname, name)};
40+
auto md{noexcept_call(::EVP_get_digestbyname, name)};
4141
if (md == nullptr)
4242
{
4343
throw_posix_error(EINVAL);
4444
}
4545
ossl_evp_guard guard;
46-
if (!noexcept_call(EVP_DigestInit_ex, guard.pmdctx, md, nullptr))
46+
if (!noexcept_call(::EVP_DigestInit_ex, guard.pmdctx, md, nullptr))
4747
{
4848
throw_posix_error(EINVAL);
4949
}
@@ -86,19 +86,19 @@ class ossl_evp_hash_file
8686
{
8787
if (this->pmdctx)
8888
{
89-
noexcept_call(EVP_MD_CTX_free, this->pmdctx);
89+
noexcept_call(::EVP_MD_CTX_free, this->pmdctx);
9090
}
9191
}
9292
inline void update(::std::byte const *first, ::std::byte const *last)
9393
{
94-
if (!noexcept_call(EVP_DigestUpdate, this->pmdctx, first, static_cast<::std::size_t>(last - first)))
94+
if (!noexcept_call(::EVP_DigestUpdate, this->pmdctx, first, static_cast<::std::size_t>(last - first)))
9595
{
9696
throw_posix_error(EINVAL);
9797
}
9898
}
9999
inline void reset()
100100
{
101-
noexcept_call(EVP_MD_CTX_reset, this->pmdctx);
101+
noexcept_call(::EVP_MD_CTX_reset, this->pmdctx);
102102
}
103103
inline constexpr native_handle_type native_handle() const noexcept
104104
{
@@ -107,7 +107,7 @@ class ossl_evp_hash_file
107107
inline void do_final()
108108
{
109109
int unsigned u{};
110-
if (!noexcept_call(EVP_DigestFinal_ex, this->pmdctx, reinterpret_cast<char unsigned *>(digest_buffer),
110+
if (!noexcept_call(::EVP_DigestFinal_ex, this->pmdctx, reinterpret_cast<char unsigned *>(digest_buffer),
111111
__builtin_addressof(u)))
112112
{
113113
throw_posix_error(EINVAL);

include/fast_io_driver/avformat/avio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ struct avformat_context_guard
381381
{
382382
return;
383383
}
384-
::fast_io::noexcept_call(avformat_free_context, pFormatCtx);
384+
::fast_io::noexcept_call(::avformat_free_context, pFormatCtx);
385385
this->pFormatCtx = nullptr;
386386
}
387387

@@ -415,7 +415,7 @@ struct avformat_input_guard
415415
{
416416
return;
417417
}
418-
::fast_io::noexcept_call(avformat_close_input, ppFormatCtx);
418+
::fast_io::noexcept_call(::avformat_close_input, ppFormatCtx);
419419
this->ppFormatCtx = nullptr;
420420
}
421421

include/fast_io_driver/capstone.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ class cs_file : public cs_io_observer
6868
{
6969
if (this->csh) [[likely]]
7070
{
71-
::fast_io::noexcept_call(cs_close, __builtin_addressof(this->csh));
71+
::fast_io::noexcept_call(::cs_close, __builtin_addressof(this->csh));
7272
}
7373
this->csh = c.csh;
7474
c.csh = 0;
7575
return *this;
7676
}
7777
cs_file(cs_arch arch, cs_mode mode)
7878
{
79-
auto ret{::fast_io::noexcept_call(cs_open, arch, mode, __builtin_addressof(this->csh))};
79+
auto ret{::fast_io::noexcept_call(::cs_open, arch, mode, __builtin_addressof(this->csh))};
8080
if (ret != CS_ERR_OK)
8181
{
8282
throw_cs_error(ret);
@@ -86,7 +86,7 @@ class cs_file : public cs_io_observer
8686
{
8787
if (this->csh) [[likely]]
8888
{
89-
::fast_io::noexcept_call(cs_close, __builtin_addressof(this->csh));
89+
::fast_io::noexcept_call(::cs_close, __builtin_addressof(this->csh));
9090
}
9191
}
9292
};
@@ -114,7 +114,7 @@ class cs_insn_range
114114
explicit cs_insn_range(cs_io_observer csiob, char const *buffer, ::std::size_t code_size,
115115
::std::uint_least64_t address, ::std::size_t c) noexcept
116116
{
117-
count = noexcept_call(cs_disasm, csiob.csh, reinterpret_cast<::std::uint_least8_t const *>(buffer), code_size,
117+
count = noexcept_call(::cs_disasm, csiob.csh, reinterpret_cast<::std::uint_least8_t const *>(buffer), code_size,
118118
address, c, __builtin_addressof(ins));
119119
}
120120
cs_insn_range(cs_insn_range const &) = delete;
@@ -129,7 +129,7 @@ class cs_insn_range
129129
{
130130
if (this->ins) [[likely]]
131131
{
132-
::fast_io::noexcept_call(cs_free, this->ins, this->count);
132+
::fast_io::noexcept_call(::cs_free, this->ins, this->count);
133133
}
134134
this->ins = other.ins;
135135
this->count = other.count;
@@ -141,7 +141,7 @@ class cs_insn_range
141141
{
142142
if (this->ins) [[likely]]
143143
{
144-
::fast_io::noexcept_call(cs_free, this->ins, this->count);
144+
::fast_io::noexcept_call(::cs_free, this->ins, this->count);
145145
}
146146
}
147147
constexpr pointer data() const noexcept

include/fast_io_driver/openssl_driver/bio.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct bio_new_fp_flags
2929
inline FILE *bio_to_fp(BIO *bio) noexcept
3030
{
3131
FILE *fp{};
32-
::fast_io::noexcept_call(BIO_ctrl, bio, BIO_C_GET_FILE_PTR, 0, reinterpret_cast<char *>(__builtin_addressof(fp)));
32+
::fast_io::noexcept_call(::BIO_ctrl, bio, BIO_C_GET_FILE_PTR, 0, reinterpret_cast<char *>(__builtin_addressof(fp)));
3333
return fp;
3434
}
3535

@@ -69,7 +69,7 @@ inline decltype(auto) get_cookie_data_from_void_ptr_data(void *data) noexcept
6969
template <typename stm>
7070
inline decltype(auto) get_cookie_data_from_bio_data(BIO *bio) noexcept
7171
{
72-
return get_cookie_data_from_void_ptr_data<stm>(noexcept_call(BIO_get_data, bio));
72+
return get_cookie_data_from_void_ptr_data<stm>(noexcept_call(::BIO_get_data, bio));
7373
}
7474

7575
} // namespace details
@@ -147,7 +147,7 @@ struct bio_io_cookie_functions_t
147147
if constexpr (!::std::is_reference_v<stm> && !::std::is_trivially_copyable_v<value_type>)
148148
{
149149
functions.destroy = [](BIO *bbio) noexcept -> int {
150-
delete reinterpret_cast<value_type *>(noexcept_call(BIO_get_data, bbio));
150+
delete reinterpret_cast<value_type *>(noexcept_call(::BIO_get_data, bbio));
151151
return 1;
152152
};
153153
}
@@ -173,7 +173,7 @@ namespace details
173173

174174
inline BIO *bio_new_stream_type(bio_method_st const *methods)
175175
{
176-
auto bio{::fast_io::noexcept_call(BIO_new, methods)};
176+
auto bio{::fast_io::noexcept_call(::BIO_new, methods)};
177177
if (bio == nullptr)
178178
{
179179
throw_openssl_error();
@@ -191,7 +191,7 @@ inline BIO *construct_bio_by_t(void *ptr)
191191
= bio_method_st const *;
192192
auto bp{bio_new_stream_type(reinterpret_cast<bio_method_st_const_may_alias_ptr>(
193193
__builtin_addressof(bio_io_cookie_functions<stm>.functions)))};
194-
::fast_io::noexcept_call(BIO_set_data, bp, ptr);
194+
::fast_io::noexcept_call(::BIO_set_data, bp, ptr);
195195
return bp;
196196
}
197197

@@ -257,7 +257,7 @@ inline BIO *construct_bio_by_args(Args &&...args)
257257

258258
inline BIO *open_bio_with_fp_phase2(FILE *fp, int om)
259259
{
260-
auto bio{::fast_io::noexcept_call(BIO_new_fp, fp, om)};
260+
auto bio{::fast_io::noexcept_call(::BIO_new_fp, fp, om)};
261261
if (bio == nullptr) [[unlikely]]
262262
{
263263
throw_openssl_error();
@@ -383,7 +383,7 @@ class basic_bio_file : public basic_bio_io_observer<ch_type>
383383
{
384384
if (this->bio) [[likely]]
385385
{
386-
noexcept_call(BIO_free, this->bio);
386+
noexcept_call(::BIO_free, this->bio);
387387
}
388388
this->bio = newhandle;
389389
}
@@ -398,7 +398,7 @@ class basic_bio_file : public basic_bio_io_observer<ch_type>
398398
{
399399
if (this->bio) [[likely]]
400400
{
401-
noexcept_call(BIO_free, this->bio);
401+
noexcept_call(::BIO_free, this->bio);
402402
}
403403
this->bio = bf.bio;
404404
bf.bio = nullptr;
@@ -408,7 +408,7 @@ class basic_bio_file : public basic_bio_io_observer<ch_type>
408408
{
409409
if (this->bio) [[likely]]
410410
{
411-
int ret{noexcept_call(BIO_free, this->bio)};
411+
int ret{noexcept_call(::BIO_free, this->bio)};
412412
this->bio = nullptr;
413413
if (!ret) [[unlikely]]
414414
{
@@ -420,7 +420,7 @@ class basic_bio_file : public basic_bio_io_observer<ch_type>
420420
{
421421
if (this->bio) [[likely]]
422422
{
423-
noexcept_call(BIO_free, this->bio);
423+
noexcept_call(::BIO_free, this->bio);
424424
}
425425
}
426426
};
@@ -441,7 +441,7 @@ namespace details
441441
inline ::std::byte *bio_read_impl(BIO *bio, ::std::byte *first, ::std::byte *last)
442442
{
443443
::std::size_t read_bytes{};
444-
if (::fast_io::noexcept_call(BIO_read_ex, bio, first, static_cast<::std::size_t>(last - first),
444+
if (::fast_io::noexcept_call(::BIO_read_ex, bio, first, static_cast<::std::size_t>(last - first),
445445
__builtin_addressof(read_bytes)) == -1)
446446
{
447447
throw_openssl_error();
@@ -452,7 +452,7 @@ inline ::std::byte *bio_read_impl(BIO *bio, ::std::byte *first, ::std::byte *las
452452
inline ::std::byte const *bio_write_impl(BIO *bio, ::std::byte const *first, ::std::byte const *last)
453453
{
454454
::std::size_t written_bytes{};
455-
if (::fast_io::noexcept_call(BIO_write_ex, bio, first, static_cast<::std::size_t>(last - first),
455+
if (::fast_io::noexcept_call(::BIO_write_ex, bio, first, static_cast<::std::size_t>(last - first),
456456
__builtin_addressof(written_bytes)) == -1)
457457
{
458458
throw_openssl_error();
@@ -588,12 +588,12 @@ inline void print_define_openssl_error(output out)
588588
{
589589
if constexpr (::std::same_as<output, bio_io_observer>)
590590
{
591-
::fast_io::noexcept_call(ERR_print_errors, out.bio);
591+
::fast_io::noexcept_call(::ERR_print_errors, out.bio);
592592
}
593593
else
594594
{
595595
bio_file bf(io_cookie_type<output>, out);
596-
::fast_io::noexcept_call(ERR_print_errors, bf.bio);
596+
::fast_io::noexcept_call(::ERR_print_errors, bf.bio);
597597
}
598598
}
599599

include/fast_io_driver/openssl_driver/evp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ inline void print_define(io_reserve_type_t<typename output::char_type, private_k
253253
{
254254
if constexpr (::std::derived_from<::std::remove_cvref_t<output>, bio_io_observer>)
255255
{
256-
if (!noexcept_call(PEM_write_bio_PrivateKey, out.bio, key.x.key, key.enc, key.kstr, key.klen, key.cb, key.u))
256+
if (!noexcept_call(::PEM_write_bio_PrivateKey, out.bio, key.x.key, key.enc, key.kstr, key.klen, key.cb, key.u))
257257
{
258258
throw_openssl_error();
259259
}
@@ -273,7 +273,7 @@ inline void print_define(io_reserve_type_t<typename output::char_type, public_ke
273273
{
274274
if constexpr (::std::derived_from<::std::remove_cvref_t<output>, bio_io_observer>)
275275
{
276-
if (!noexcept_call(PEM_write_bio_PUBKEY, out.bio, key.x.key))
276+
if (!noexcept_call(::PEM_write_bio_PUBKEY, out.bio, key.x.key))
277277
{
278278
throw_openssl_error();
279279
}

0 commit comments

Comments
 (0)