Skip to content

Commit

Permalink
Fix build error on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
qgymib committed Dec 27, 2024
1 parent 1f5e794 commit 9a91ac9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 58 deletions.
63 changes: 37 additions & 26 deletions ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ EV_LOCAL int ev__fs_remove(const char* path, int recursive);
// #line 13 "ev.c"
////////////////////////////////////////////////////////////////////////////////
// FILE: ev/misc_internal.h
// SIZE: 724
// SHA-256: a81194a7b3f7a4ce2b6251095a548c0b082a28e8e1de7916d822f7c5335bfb9d
// SIZE: 767
// SHA-256: d868e98713600d57cf502123aaffa79eb35ea0d27edc2b49be60d238602e0e49
////////////////////////////////////////////////////////////////////////////////
// #line 1 "ev/misc_internal.h"
#ifndef __EV_MISC_INTERNAL_H__
Expand Down Expand Up @@ -798,6 +798,8 @@ EV_LOCAL int ev__translate_posix_sys_error(int syserr);
*/
EV_LOCAL int ev__random(void* buf, size_t len);

EV_LOCAL void ev__backend_shutdown(void);

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -2250,14 +2252,14 @@ extern "C" {
// #line 32 "ev.c"
////////////////////////////////////////////////////////////////////////////////
// FILE: ev/win/misc_win.h
// SIZE: 1393
// SHA-256: 9c0371bad1f19fbae9e3aa87f56381a57a80dcf783abe9555f7276703c27345e
// SIZE: 1419
// SHA-256: ade18c2c9e8c05f2cee92967830bb3b89b57052cd1924d1353ab1de62f6bfe7f
////////////////////////////////////////////////////////////////////////////////
// #line 1 "ev/win/misc_win.h"
#ifndef __EV_MISC_WIN_INTERNAL_H__
#define __EV_MISC_WIN_INTERNAL_H__

#define EV_FATAL_SYSCALL(errcode, syscall) \
#define EV_FATAL_SYSCALL(errcode, syscall) \
ev__fatal_syscall(__FILE__, __LINE__, errcode, syscall)

#ifdef __cplusplus
Expand All @@ -2268,17 +2270,19 @@ extern "C" {
* @brief Maps a character string to a UTF-16 (wide character) string.
* @param[out] dst Pointer to store wide string. Use #ev_free() to release it.
* @param[in] src Source string.
* @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error.
* @return The number of characters (not bytes) of \p dst, or
* #ev_errno_t if error.
*/
EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR** dst, const char* src);
EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR **dst, const char *src);

/**
* @brief Maps a UTF-16 (wide character) string to a character string.
* @param[out] dst Pointer to store wide string. Use #ev_free() to release it.
* @param[in] src Source string.
* @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error.
* @return The number of characters (not bytes) of \p dst, or
* #ev_errno_t if error.
*/
EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src);
EV_LOCAL ssize_t ev__wide_to_utf8(char **dst, const WCHAR *src);

/**
* @brief Show fatal information about syscall and abort().
Expand All @@ -2288,10 +2292,8 @@ EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src);
* @param[in] errcode Error code from GetLastError().
* @param[in] syscall The name of syscall.
*/
EV_LOCAL void ev__fatal_syscall(const char* file, int line,
DWORD errcode, const char* syscall);

EV_LOCAL void ev__backend_shutdown(void);
EV_LOCAL void ev__fatal_syscall(const char *file, int line, DWORD errcode,
const char *syscall);

#ifdef __cplusplus
}
Expand Down Expand Up @@ -3870,40 +3872,49 @@ EV_LOCAL void ev__backend_shutdown(void)
// #line 41 "ev.c"
////////////////////////////////////////////////////////////////////////////////
// FILE: ev/win/mutex_win.c
// SIZE: 596
// SHA-256: 632743a2ae28e1891ab133d38739a792140699923aac149471a5c9d5af3f9a3c
// SIZE: 746
// SHA-256: bc8cb146ca579cc8031f31da769da05062f2cdfec1c32a1af706c5b22710e99a
////////////////////////////////////////////////////////////////////////////////
// #line 1 "ev/win/mutex_win.c"

struct ev_mutex
{
ev_os_mutex_t r; /**< Real mutex */
ev_os_mutex_t r; /**< Real mutex */
};

void ev_mutex_init(ev_mutex_t* handle, int recursive)
void ev_mutex_init(ev_mutex_t **handle, int recursive)
{
(void)recursive;
InitializeCriticalSection(&handle->u.r);
ev_mutex_t *new_mutex = ev_malloc(sizeof(ev_mutex_t));
if (new_mutex == NULL)
{
abort();
}

InitializeCriticalSection(&new_mutex->r);

*handle = new_mutex;
}

void ev_mutex_exit(ev_mutex_t* handle)
void ev_mutex_exit(ev_mutex_t *handle)
{
DeleteCriticalSection(&handle->u.r);
DeleteCriticalSection(&handle->r);
ev_free(handle);
}

void ev_mutex_enter(ev_mutex_t* handle)
void ev_mutex_enter(ev_mutex_t *handle)
{
EnterCriticalSection(&handle->u.r);
EnterCriticalSection(&handle->r);
}

void ev_mutex_leave(ev_mutex_t* handle)
void ev_mutex_leave(ev_mutex_t *handle)
{
LeaveCriticalSection(&handle->u.r);
LeaveCriticalSection(&handle->r);
}

int ev_mutex_try_enter(ev_mutex_t* handle)
int ev_mutex_try_enter(ev_mutex_t *handle)
{
if (TryEnterCriticalSection(&handle->u.r))
if (TryEnterCriticalSection(&handle->r))
{
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ev/misc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ EV_LOCAL int ev__translate_posix_sys_error(int syserr);
*/
EV_LOCAL int ev__random(void* buf, size_t len);

EV_LOCAL void ev__backend_shutdown(void);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 0 additions & 12 deletions src/ev/unix/misc_unix.h

This file was deleted.

18 changes: 9 additions & 9 deletions src/ev/win/misc_win.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __EV_MISC_WIN_INTERNAL_H__
#define __EV_MISC_WIN_INTERNAL_H__

#define EV_FATAL_SYSCALL(errcode, syscall) \
#define EV_FATAL_SYSCALL(errcode, syscall) \
ev__fatal_syscall(__FILE__, __LINE__, errcode, syscall)

#ifdef __cplusplus
Expand All @@ -12,17 +12,19 @@ extern "C" {
* @brief Maps a character string to a UTF-16 (wide character) string.
* @param[out] dst Pointer to store wide string. Use #ev_free() to release it.
* @param[in] src Source string.
* @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error.
* @return The number of characters (not bytes) of \p dst, or
* #ev_errno_t if error.
*/
EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR** dst, const char* src);
EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR **dst, const char *src);

/**
* @brief Maps a UTF-16 (wide character) string to a character string.
* @param[out] dst Pointer to store wide string. Use #ev_free() to release it.
* @param[in] src Source string.
* @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error.
* @return The number of characters (not bytes) of \p dst, or
* #ev_errno_t if error.
*/
EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src);
EV_LOCAL ssize_t ev__wide_to_utf8(char **dst, const WCHAR *src);

/**
* @brief Show fatal information about syscall and abort().
Expand All @@ -32,10 +34,8 @@ EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src);
* @param[in] errcode Error code from GetLastError().
* @param[in] syscall The name of syscall.
*/
EV_LOCAL void ev__fatal_syscall(const char* file, int line,
DWORD errcode, const char* syscall);

EV_LOCAL void ev__backend_shutdown(void);
EV_LOCAL void ev__fatal_syscall(const char *file, int line, DWORD errcode,
const char *syscall);

#ifdef __cplusplus
}
Expand Down
31 changes: 20 additions & 11 deletions src/ev/win/mutex_win.c
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@

struct ev_mutex
{
ev_os_mutex_t r; /**< Real mutex */
ev_os_mutex_t r; /**< Real mutex */
};

void ev_mutex_init(ev_mutex_t* handle, int recursive)
void ev_mutex_init(ev_mutex_t **handle, int recursive)
{
(void)recursive;
InitializeCriticalSection(&handle->u.r);
ev_mutex_t *new_mutex = ev_malloc(sizeof(ev_mutex_t));
if (new_mutex == NULL)
{
abort();
}

InitializeCriticalSection(&new_mutex->r);

*handle = new_mutex;
}

void ev_mutex_exit(ev_mutex_t* handle)
void ev_mutex_exit(ev_mutex_t *handle)
{
DeleteCriticalSection(&handle->u.r);
DeleteCriticalSection(&handle->r);
ev_free(handle);
}

void ev_mutex_enter(ev_mutex_t* handle)
void ev_mutex_enter(ev_mutex_t *handle)
{
EnterCriticalSection(&handle->u.r);
EnterCriticalSection(&handle->r);
}

void ev_mutex_leave(ev_mutex_t* handle)
void ev_mutex_leave(ev_mutex_t *handle)
{
LeaveCriticalSection(&handle->u.r);
LeaveCriticalSection(&handle->r);
}

int ev_mutex_try_enter(ev_mutex_t* handle)
int ev_mutex_try_enter(ev_mutex_t *handle)
{
if (TryEnterCriticalSection(&handle->u.r))
if (TryEnterCriticalSection(&handle->r))
{
return 0;
}
Expand Down

0 comments on commit 9a91ac9

Please sign in to comment.