Skip to content

Commit

Permalink
debug windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
eileencodes committed Feb 6, 2024
1 parent a736bef commit fc37245
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/prism/util/pm_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// The following headers are necessary to read files using demand paging.
#ifdef _WIN32
#include <windows.h>
#include <ruby.h>
#include <ruby/win32.h>
#else
#include <fcntl.h>
#include <sys/mman.h>
Expand Down
6 changes: 5 additions & 1 deletion src/util/pm_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if (file == INVALID_HANDLE_VALUE) {
return errno;
return rb_w32_map_errno(GetLastError());
}

// Get the file size.
DWORD file_size = GetFileSize(file, NULL);
if (file_size == INVALID_FILE_SIZE) {
fprintf(stderr, "invalid file size\n");
CloseHandle(file);
return errno;
}
Expand All @@ -79,6 +80,7 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
// the source to a constant empty string and return.
if (file_size == 0) {
CloseHandle(file);
fprintf(stderr, "close handle\n");
const uint8_t source[] = "";
*string = (pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
return 0;
Expand All @@ -88,6 +90,7 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (mapping == NULL) {
CloseHandle(file);
fprintf(stderr, "close handle, mapping is null\n");
return errno;
}

Expand All @@ -97,6 +100,7 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
CloseHandle(file);

if (source == NULL) {
fprintf(stderr, "source was null\n");
return errno;
}

Expand Down

0 comments on commit fc37245

Please sign in to comment.