Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fast_io_driver/qt_impl/qiodevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ inline Iter read(basic_general_qdevice_io_observer<ch_type, T> qiob, Iter begin,

template <::std::integral ch_type, typename T>
requires(sizeof(ch_type) == 1)
inline ::std::pair<ch_type, bool> try_get(basic_general_qdevice_io_observer<ch_type, T> qiob)
inline ::fast_io::try_get_result<ch_type> try_get(basic_general_qdevice_io_observer<ch_type, T> qiob)
{
char ch;
bool ef{qiob.qdevice->getChar(&ch)};
Expand Down
196 changes: 154 additions & 42 deletions include/fast_io_legacy_impl/c/done.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,78 @@ inline ::std::size_t c_fwrite_unlocked_impl(void const *__restrict begin, ::std:
throw_posix_error(rent._errno);
}
#else
::std::size_t written_count{
#if defined(__CYGWIN__)
my_cygwin_fwrite_unlocked(begin, type_size, count, fp)
#elif (defined(__USE_MISC) || defined(__BSD_VISIBLE)) && (!defined(__BIONIC__) || (defined(__USE_BSD)))
#if !defined(fwrite_unlocked) && defined(__has_builtin)

#pragma push_macro("FAST_IO_FWRITE_UNLOCKED")
#pragma push_macro("FAST_IO_FWRITE")
#pragma push_macro("FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED")
#pragma push_macro("FAST_IO_FWRITE_UNLOCKED_IMPL")

#undef FAST_IO_FWRITE_UNLOCKED
#undef FAST_IO_FWRITE
#undef FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED
#undef FAST_IO_FWRITE_UNLOCKED_IMPL

#ifdef __has_builtin
#if __has_builtin(__builtin_fwrite_unlocked)
__builtin_fwrite_unlocked(begin, type_size, count, fp)
#else
fwrite_unlocked(begin, type_size, count, fp)
#define FAST_IO_FWRITE_UNLOCKED(...) __builtin_fwrite_unlocked(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FWRITE_UNLOCKED
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FWRITE_UNLOCKED(...) ::fwrite_unlocked(__VA_ARGS__)
#elif defined(fwrite_unlocked)
#define FAST_IO_FWRITE_UNLOCKED(...) fwrite_unlocked(__VA_ARGS__)
#else
fwrite_unlocked(begin, type_size, count, fp)
#define FAST_IO_FWRITE_UNLOCKED(...) ::fast_io::noexcept_call(::fwrite_unlocked, __VA_ARGS__)
#endif
#endif
#elif !defined(fwrite) && defined(__has_builtin)

#ifdef __has_builtin
#if __has_builtin(__builtin_fwrite)
__builtin_fwrite(begin, type_size, count, fp)
#define FAST_IO_FWRITE(...) __builtin_fwrite(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FWRITE
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FWRITE(...) ::fwrite(__VA_ARGS__)
#elif defined(fwrite)
#define FAST_IO_FWRITE(...) fwrite(__VA_ARGS__)
#else
fwrite(begin, type_size, count, fp)
#define FAST_IO_FWRITE(...) ::fast_io::noexcept_call(::fwrite, __VA_ARGS__)
#endif
#endif

#if defined(__BIONIC__)
#if defined(__BIONIC_AVAILABILITY_GUARD)
#if __BIONIC_AVAILABILITY_GUARD(28)
#define FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED 1
#endif
#endif
#elif defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED 1
#elif defined(__USE_MISC) || defined(__BSD_VISIBLE)
#define FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED 1
#endif

#if defined(__CYGWIN__)
#define FAST_IO_FWRITE_UNLOCKED_IMPL(...) my_cygwin_fwrite_unlocked(__VA_ARGS__)
#elif defined(FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED)
#define FAST_IO_FWRITE_UNLOCKED_IMPL(...) FAST_IO_FWRITE_UNLOCKED(__VA_ARGS__)
#else
fwrite(begin, type_size, count, fp)
#define FAST_IO_FWRITE_UNLOCKED_IMPL(...) FAST_IO_FWRITE(__VA_ARGS__)
#endif
};

::std::size_t const written_count{FAST_IO_FWRITE_UNLOCKED_IMPL(begin, type_size, count, fp)};

#pragma pop_macro("FAST_IO_FWRITE_UNLOCKED_IMPL")
#pragma pop_macro("FAST_IO_PLATFORM_SUPPORTS_FWRITE_UNLOCKED")
#pragma pop_macro("FAST_IO_FWRITE")
#pragma pop_macro("FAST_IO_FWRITE_UNLOCKED")
if (!written_count) [[unlikely]]
{
throw_posix_error();
}

#endif
return written_count;
}
Expand Down Expand Up @@ -110,29 +155,77 @@ inline ::std::size_t c_fread_unlocked_impl(void *__restrict begin, ::std::size_t
}
}
#else
::std::size_t read_count{
#if defined(__CYGWIN__)
my_cygwin_fread_unlocked(begin, type_size, count, fp)
#elif (defined(__USE_MISC) || defined(__BSD_VISIBLE)) && (!defined(__BIONIC__) || (defined(__USE_BSD)))
#if !defined(fread_unlocked) && defined(__has_builtin)

#pragma push_macro("FAST_IO_FREAD_UNLOCKED")
#pragma push_macro("FAST_IO_FREAD")
#pragma push_macro("FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED")
#pragma push_macro("FAST_IO_FREAD_UNLOCKED_IMPL")

#undef FAST_IO_FREAD_UNLOCKED
#undef FAST_IO_FREAD
#undef FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED
#undef FAST_IO_FREAD_UNLOCKED_IMPL

// Define FAST_IO_FREAD_UNLOCKED
#ifdef __has_builtin
#if __has_builtin(__builtin_fread_unlocked)
__builtin_fread_unlocked(begin, type_size, count, fp)
#else
fread_unlocked(begin, type_size, count, fp)
#define FAST_IO_FREAD_UNLOCKED(...) __builtin_fread_unlocked(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FREAD_UNLOCKED
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FREAD_UNLOCKED(...) ::fread_unlocked(__VA_ARGS__)
#elif defined(fread_unlocked)
#define FAST_IO_FREAD_UNLOCKED(...) fread_unlocked(__VA_ARGS__)
#else
fread_unlocked(begin, type_size, count, fp)
#define FAST_IO_FREAD_UNLOCKED(...) ::fast_io::noexcept_call(::fread_unlocked, __VA_ARGS__)
#endif
#elif !defined(fread) && defined(__has_builtin)
#endif

// Define FAST_IO_FREAD
#ifdef __has_builtin
#if __has_builtin(__builtin_fread)
__builtin_fread(begin, type_size, count, fp)
#define FAST_IO_FREAD(...) __builtin_fread(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FREAD
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FREAD(...) ::fread(__VA_ARGS__)
#elif defined(fread)
#define FAST_IO_FREAD(...) fread(__VA_ARGS__)
#else
fread(begin, type_size, count, fp)
#define FAST_IO_FREAD(...) ::fast_io::noexcept_call(::fread, __VA_ARGS__)
#endif
#endif

// Detect whether platform supports fread_unlocked
#if defined(__BIONIC__)
#if defined(__BIONIC_AVAILABILITY_GUARD)
#if __BIONIC_AVAILABILITY_GUARD(28)
#define FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED 1
#endif
#endif
#elif defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED 1
#elif defined(__USE_MISC) || defined(__BSD_VISIBLE)
#define FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED 1
#endif

// Define the unified dispatch macro
#if defined(__CYGWIN__)
#define FAST_IO_FREAD_UNLOCKED_IMPL(...) my_cygwin_fread_unlocked(__VA_ARGS__)
#elif defined(FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED)
#define FAST_IO_FREAD_UNLOCKED_IMPL(...) FAST_IO_FREAD_UNLOCKED(__VA_ARGS__)
#else
fread(begin, type_size, count, fp)
#define FAST_IO_FREAD_UNLOCKED_IMPL(...) FAST_IO_FREAD(__VA_ARGS__)
#endif
};

::std::size_t const read_count{FAST_IO_FREAD_UNLOCKED_IMPL(begin, type_size, count, fp)};

#pragma pop_macro("FAST_IO_FREAD_UNLOCKED_IMPL")
#pragma pop_macro("FAST_IO_PLATFORM_SUPPORTS_FREAD_UNLOCKED")
#pragma pop_macro("FAST_IO_FREAD")
#pragma pop_macro("FAST_IO_FREAD_UNLOCKED")
if (read_count == 0) [[unlikely]]
{
if (
Expand Down Expand Up @@ -179,18 +272,27 @@ inline ::std::size_t c_fwrite_impl(void const *__restrict begin, ::std::size_t t
throw_posix_error(rent._errno);
}
#else
#pragma push_macro("FAST_IO_FWRITE")
#undef FAST_IO_FWRITE

::std::size_t written_count{
#if !defined(fwrite) && defined(__has_builtin)
#ifdef __has_builtin
#if __has_builtin(__builtin_fwrite)
__builtin_fwrite(begin, type_size, count, fp)
#else
fwrite(begin, type_size, count, fp)
#define FAST_IO_FWRITE(...) __builtin_fwrite(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FWRITE
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FWRITE(...) ::fwrite(__VA_ARGS__)
#elif defined(fwrite)
#define FAST_IO_FWRITE(...) fwrite(__VA_ARGS__)
#else
fwrite(begin, type_size, count, fp)
#define FAST_IO_FWRITE(...) ::fast_io::noexcept_call(::fwrite, __VA_ARGS__)
#endif
};
#endif

::std::size_t const written_count{FAST_IO_FWRITE(begin, type_size, count, fp)};

#pragma pop_macro("FAST_IO_FWRITE")
if (!written_count) [[unlikely]]
{
throw_posix_error();
Expand All @@ -217,17 +319,27 @@ inline ::std::size_t c_fread_impl(void *__restrict begin, ::std::size_t type_siz
}
}
#else
::std::size_t read_count{
#if !defined(fread) && defined(__has_builtin)
#pragma push_macro("FAST_IO_FREAD")
#undef FAST_IO_FREAD

#ifdef __has_builtin
#if __has_builtin(__builtin_fread)
__builtin_fread(begin, type_size, count, fp)
#else
fread(begin, type_size, count, fp)
#define FAST_IO_FREAD(...) __builtin_fread(__VA_ARGS__)
#endif
#endif
#ifndef FAST_IO_FREAD
#if defined(__GLIBC__) || defined(__LLVM_LIBC_TYPES_FILE_H__)
#define FAST_IO_FREAD(...) ::fread(__VA_ARGS__)
#elif defined(fread)
#define FAST_IO_FREAD(...) fread(__VA_ARGS__)
#else
fread(begin, type_size, count, fp)
#define FAST_IO_FREAD(...) ::fast_io::noexcept_call(::fread, __VA_ARGS__)
#endif
};
#endif

::std::size_t const read_count{FAST_IO_FREAD(begin, type_size, count, fp)};

#pragma pop_macro("FAST_IO_FREAD")
if (read_count == 0) [[unlikely]]
{
if (
Expand Down
Loading