Skip to content

Commit

Permalink
Merge branch 'ddnet' into chillerbot
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Sep 28, 2024
2 parents ab2543d + 2a64dac commit d2eab60
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
sudo apt-get update -y
# mount: /var/lib/grub/esp: special device /dev/disk/by-id/scsi-... does not exist.
# sudo apt-get upgrade -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libvulkan-dev glslang-tools spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libpng-dev valgrind gcovr -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libvulkan-dev glslang-tools spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libpng-dev valgrind gcovr libglew-dev -y
- name: Prepare Linux (non-fancy)
if: ${{ contains(matrix.os, 'ubuntu') && !matrix.fancy }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-sanitizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Prepare linux
run: |
sudo apt-get update -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libvulkan-dev glslang-tools spirv-tools -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libvulkan-dev glslang-tools spirv-tools libglew-dev -y
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Build with ASan and UBSan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install clang-tidy
run: |
sudo apt-get update -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev clang-tidy libvulkan-dev glslang-tools spirv-tools -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev clang-tidy libvulkan-dev glslang-tools spirv-tools libglew-dev -y
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
if: matrix.language == 'cpp'
run: |
sudo apt-get update -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libmariadb-dev libwebsockets-dev libvulkan-dev glslang-tools spirv-tools -y
sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libmariadb-dev libwebsockets-dev libvulkan-dev glslang-tools spirv-tools libglew-dev -y
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Prepare
run: |
sudo apt-get update -y
sudo apt-get install clang-format imagemagick ddnet-tools shellcheck pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev python3-clang libvulkan-dev glslang-tools spirv-tools -y
sudo apt-get install clang-format imagemagick ddnet-tools shellcheck pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev python3-clang libvulkan-dev glslang-tools spirv-tools libglew-dev -y
rustup default stable
pip3 install pylint
wget -O ~/.local/bin/shfmt https://github.com/mvdan/sh/releases/download/v3.8.0/shfmt_v3.8.0_linux_amd64
Expand Down
136 changes: 68 additions & 68 deletions src/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,58 +84,6 @@
#include <sys/filio.h>
#endif

IOHANDLE io_stdin()
{
return stdin;
}

IOHANDLE io_stdout()
{
return stdout;
}

IOHANDLE io_stderr()
{
return stderr;
}

IOHANDLE io_current_exe()
{
// From https://stackoverflow.com/a/1024937.
#if defined(CONF_FAMILY_WINDOWS)
wchar_t wide_path[IO_MAX_PATH_LENGTH];
if(GetModuleFileNameW(NULL, wide_path, std::size(wide_path)) == 0 || GetLastError() != ERROR_SUCCESS)
{
return 0;
}
const std::optional<std::string> path = windows_wide_to_utf8(wide_path);
return path.has_value() ? io_open(path.value().c_str(), IOFLAG_READ) : 0;
#elif defined(CONF_PLATFORM_MACOS)
char path[IO_MAX_PATH_LENGTH];
uint32_t path_size = sizeof(path);
if(_NSGetExecutablePath(path, &path_size))
{
return 0;
}
return io_open(path, IOFLAG_READ);
#else
static const char *NAMES[] = {
"/proc/self/exe", // Linux, Android
"/proc/curproc/exe", // NetBSD
"/proc/curproc/file", // DragonFly
};
for(auto &name : NAMES)
{
IOHANDLE result = io_open(name, IOFLAG_READ);
if(result)
{
return result;
}
}
return 0;
#endif
}

static NETSTATS network_stats = {0};

#define VLEN 128
Expand Down Expand Up @@ -412,11 +360,6 @@ long int io_length(IOHANDLE io)
return length;
}

int io_error(IOHANDLE io)
{
return ferror((FILE *)io);
}

unsigned io_write(IOHANDLE io, const void *buffer, unsigned size)
{
return fwrite(buffer, 1, size, (FILE *)io);
Expand Down Expand Up @@ -454,6 +397,63 @@ int io_sync(IOHANDLE io)
#endif
}

int io_error(IOHANDLE io)
{
return ferror((FILE *)io);
}

IOHANDLE io_stdin()
{
return stdin;
}

IOHANDLE io_stdout()
{
return stdout;
}

IOHANDLE io_stderr()
{
return stderr;
}

IOHANDLE io_current_exe()
{
// From https://stackoverflow.com/a/1024937.
#if defined(CONF_FAMILY_WINDOWS)
wchar_t wide_path[IO_MAX_PATH_LENGTH];
if(GetModuleFileNameW(NULL, wide_path, std::size(wide_path)) == 0 || GetLastError() != ERROR_SUCCESS)
{
return 0;
}
const std::optional<std::string> path = windows_wide_to_utf8(wide_path);
return path.has_value() ? io_open(path.value().c_str(), IOFLAG_READ) : 0;
#elif defined(CONF_PLATFORM_MACOS)
char path[IO_MAX_PATH_LENGTH];
uint32_t path_size = sizeof(path);
if(_NSGetExecutablePath(path, &path_size))
{
return 0;
}
return io_open(path, IOFLAG_READ);
#else
static const char *NAMES[] = {
"/proc/self/exe", // Linux, Android
"/proc/curproc/exe", // NetBSD
"/proc/curproc/file", // DragonFly
};
for(auto &name : NAMES)
{
IOHANDLE result = io_open(name, IOFLAG_READ);
if(result)
{
return result;
}
}
return 0;
#endif
}

#define ASYNC_BUFSIZE (8 * 1024)
#define ASYNC_LOCAL_BUFSIZE (64 * 1024)

Expand Down Expand Up @@ -728,17 +728,6 @@ int aio_error(ASYNCIO *aio)
return aio->error;
}

void aio_free(ASYNCIO *aio)
{
aio->lock.lock();
if(aio->thread)
{
thread_detach(aio->thread);
aio->thread = 0;
}
aio_handle_free_and_unlock(aio);
}

void aio_close(ASYNCIO *aio)
{
{
Expand All @@ -764,6 +753,17 @@ void aio_wait(ASYNCIO *aio)
thread_wait(thread);
}

void aio_free(ASYNCIO *aio)
{
aio->lock.lock();
if(aio->thread)
{
thread_detach(aio->thread);
aio->thread = 0;
}
aio_handle_free_and_unlock(aio);
}

struct THREAD_RUN
{
void (*threadfunc)(void *);
Expand Down
Loading

0 comments on commit d2eab60

Please sign in to comment.