-
Notifications
You must be signed in to change notification settings - Fork 58
Fix building under MSVC #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SergioFLS
wants to merge
5
commits into
ButterscotchRunner:main
Choose a base branch
from
SergioFLS:msvc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6828119
Make GLFW backend buildable under MSVC
SergioFLS 0b38ad9
Fix -Wdiscarded-qualifiers warning in GCC
SergioFLS dce211a
Change calloc string allocations to use malloc instead
SergioFLS 7b4fb83
Add TYPEOF(x) macro to reduce LoC in utils.h, add TCC check
SergioFLS 3e5bbec
oops (forgot unsigned in TYPEOF)
SergioFLS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| build/ | ||
| build_ps2/ | ||
| build_ps3/ | ||
| build_*/ | ||
| .gitignore | ||
| .cache | ||
| CMakeUserPresets.json | ||
| .devcontainer/ | ||
| vcpkg_installed/ | ||
| .vs/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "version": 2, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "vcpkg", | ||
| "generator": "Ninja", | ||
| "binaryDir": "${sourceDir}/build", | ||
| "cacheVariables": { | ||
| "PLATFORM": "glfw", | ||
| "ENABLE_ASAN": false, | ||
| "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" | ||
| } | ||
| } | ||
| ], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <stdio.h> | ||
| #ifndef _MSC_VER | ||
| #include <sys/time.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the change it from #else
#include <time.h>
#endifto #else
#include <time.h>
#ifndef CLOCK_MONOTONIC
#include <sys/time.h>
#endif
#endif |
||
| #endif | ||
|
|
||
| #include "utils.h" | ||
| #include "stb_ds.h" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,30 @@ | |
| #include "common.h" | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #include <math.h> | ||
|
|
||
| #include "real_type.h" | ||
|
|
||
| #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) \ | ||
| || defined(__GNUC__) || defined(__clang__) || defined(__TINYC__) | ||
| // The "typeof((typeof(x))0" is used to remove the "const" from the typeof | ||
| #define TYPEOF(x) typeof((typeof(x))0) | ||
| #else | ||
| #define TYPEOF(x) unsigned long long | ||
| #endif | ||
|
|
||
| #define forEach(type, item, array, count) \ | ||
|
SergioFLS marked this conversation as resolved.
|
||
| for (typeof(count) item##_i_ = 0; item##_i_ < (count); item##_i_++) \ | ||
| for (type* item = &(array)[item##_i_]; item; item = NULL) | ||
| for (TYPEOF(count) item##_i_ = 0; item##_i_ < (long long)(count); item##_i_++) \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why cast count to long long here? |
||
| for (type* item = &(array)[item##_i_]; item; item = 0) | ||
|
|
||
| #define forEachIndexed(type, item, index, array, count) \ | ||
| for (typeof(count) index = 0; index < (count); index++) \ | ||
| for (type* item = &(array)[index]; item; item = NULL) | ||
|
|
||
| // The "typeof((typeof(n))0" is used to remove the "const" from the typeof | ||
| for (TYPEOF(count) index = 0; index < (long long)(count); index++) \ | ||
| for (type* item = &(array)[index]; item; item = 0) | ||
|
|
||
| #define repeat(n, it) for (typeof((typeof(n))0) it = 0; it < (n); it++) | ||
| #define repeat(n, it) for (TYPEOF(n) it = 0; it < (long long)(n); it++) | ||
|
|
||
| #define require(condition) \ | ||
| do { \ | ||
|
|
@@ -45,52 +52,49 @@ abort(); \ | |
| } \ | ||
| } while (0) | ||
|
|
||
| #define requireNotNull(ptr) ({ \ | ||
| typeof(ptr) _val = (ptr); \ | ||
| if (_val == NULL) { \ | ||
| fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", __FILE__, __LINE__, #ptr); \ | ||
| abort(); \ | ||
| } \ | ||
| _val; \ | ||
| }) | ||
| static inline void* requireNotNullFunction(void* ptr, char* file, int line, char* name) { | ||
| if (ptr == nullptr) { | ||
| fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", file, line, name); | ||
| abort(); | ||
| } | ||
| return ptr; | ||
| } | ||
| #define requireNotNull(ptr) requireNotNullFunction((void*)ptr, __FILE__, __LINE__, #ptr) | ||
|
|
||
| #define requireNotNullMessage(ptr, msg) ({ \ | ||
| typeof(ptr) _val = (ptr); \ | ||
| if (_val == NULL) { \ | ||
| fprintf(stderr, "%s:%d: requireNotNull failed: %s\n", __FILE__, __LINE__, (msg)); \ | ||
| abort(); \ | ||
| } \ | ||
| _val; \ | ||
| }) | ||
| #define requireNotNullMessage(ptr, msg) requireNotNullFunction((void*)ptr, __FILE__, __LINE__, msg) | ||
|
|
||
| // Safe allocation macros - check for nullptr and abort with file/line info | ||
| #define safeMalloc(size) ({ \ | ||
| void* _ptr = malloc(size); \ | ||
| if (_ptr == nullptr) { \ | ||
| fprintf(stderr, "FATAL: malloc(%zu) failed at %s:%d\n", (size_t)(size), __FILE__, __LINE__); \ | ||
| abort(); \ | ||
| } \ | ||
| _ptr; \ | ||
| }) | ||
|
|
||
| #define safeCalloc(count, size) ({ \ | ||
| void* _ptr = calloc(count, size); \ | ||
| if (_ptr == nullptr) { \ | ||
| fprintf(stderr, "FATAL: calloc(%zu, %zu) failed at %s:%d\n", (size_t)(count), (size_t)(size), __FILE__, __LINE__); \ | ||
| abort(); \ | ||
| } \ | ||
| _ptr; \ | ||
| }) | ||
|
|
||
| #define safeRealloc(ptr, size) ({ \ | ||
| void* _ptr = realloc(ptr, size); \ | ||
| if (_ptr == nullptr) { \ | ||
| fprintf(stderr, "FATAL: realloc(%zu) failed at %s:%d\n", (size_t)(size), __FILE__, __LINE__); \ | ||
| abort(); \ | ||
| } \ | ||
| _ptr; \ | ||
| }) | ||
| static inline void* safeMallocFunction(size_t size, char* file, int line) { | ||
| void* _ptr = malloc(size); | ||
| if (_ptr == nullptr) { | ||
| fprintf(stderr, "FATAL: malloc(%zu) failed at %s:%d\n", size, file, line); | ||
| abort(); | ||
| } | ||
| return _ptr; | ||
| } | ||
| #define safeMalloc(size) safeMallocFunction(size, __FILE__, __LINE__) | ||
|
|
||
| static inline void* safeCallocFunction(size_t count, size_t size, char* file, int line) { | ||
| void* _ptr = calloc(count, size); | ||
| if (_ptr == nullptr) { | ||
| fprintf(stderr, "FATAL: calloc(%zu, %zu) failed at %s:%d\n", count, size, file, line); | ||
| abort(); | ||
| } | ||
| return _ptr; | ||
| } | ||
| #define safeCalloc(count, size) safeCallocFunction(count, size, __FILE__, __LINE__) | ||
|
|
||
| static inline void* safeReallocFunction(void* ptr, size_t size, char* file, int line) { | ||
| void* _ptr = realloc(ptr, size); | ||
| if (_ptr == nullptr) { | ||
| fprintf(stderr, "FATAL: realloc(%zu) failed at %s:%d\n", size, file, line); | ||
| abort(); | ||
| } | ||
| return _ptr; | ||
| } | ||
| #define safeRealloc(ptr, size) safeReallocFunction(ptr, size, __FILE__, __LINE__) | ||
|
|
||
| #if defined(PLATFORM_PS2) | ||
| #define safeMemalign(alignment, size) ({ \ | ||
| void* _ptr = memalign(alignment, size); \ | ||
| if (_ptr == nullptr) { \ | ||
|
|
@@ -99,15 +103,17 @@ _val; \ | |
| } \ | ||
| _ptr; \ | ||
| }) | ||
|
|
||
| #define safeStrdup(str) ({ \ | ||
| char* _ptr = strdup(str); \ | ||
| if (_ptr == nullptr) { \ | ||
| fprintf(stderr, "FATAL: strdup() failed at %s:%d\n", __FILE__, __LINE__); \ | ||
| abort(); \ | ||
| } \ | ||
| _ptr; \ | ||
| }) | ||
| #endif | ||
|
|
||
| static inline char* safeStrdupFunction(const char* str, char* file, int line) { | ||
| char* _ptr = strdup(str); | ||
| if (_ptr == nullptr) { | ||
| fprintf(stderr, "FATAL: strdup() failed at %s:%d\n", file, line); | ||
| abort(); | ||
| } | ||
| return _ptr; | ||
| } | ||
| #define safeStrdup(str) safeStrdupFunction(str, __FILE__, __LINE__) | ||
|
|
||
| // Truncates to 6 decimal places, matching the HTML5 runner's ClampFloat | ||
| static inline GMLReal clampFloat(GMLReal f) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you free buf here right before it gets used the very next line, you need to free it later