Skip to content

Commit

Permalink
Add some function attributes supported by MSVC.
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet committed Feb 14, 2024
1 parent 534a61c commit 4939234
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
3 changes: 2 additions & 1 deletion inc/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void Com_AbortFunc(void (*func)(void *), void *arg);
void Com_SetLastError(const char *msg);
const char *Com_GetLastError(void);

void Com_Quit(const char *reason, error_type_t type) q_noreturn;
q_noreturn
void Com_Quit(const char *reason, error_type_t type);

void Com_SetColor(color_index_t color);

Expand Down
15 changes: 10 additions & 5 deletions inc/common/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ void Z_Free(void *ptr);
void Z_Freep(void *ptr);
void *Z_Realloc(void *ptr, size_t size);
void *Z_ReallocArray(void *ptr, size_t nmemb, size_t size);
void *Z_Malloc(size_t size) q_malloc;
void *Z_Mallocz(size_t size) q_malloc;
void *Z_TagMalloc(size_t size, memtag_t tag) q_malloc;
void *Z_TagMallocz(size_t size, memtag_t tag) q_malloc;
char *Z_TagCopyString(const char *in, memtag_t tag) q_malloc;
q_malloc
void *Z_Malloc(size_t size);
q_malloc
void *Z_Mallocz(size_t size);
q_malloc
void *Z_TagMalloc(size_t size, memtag_t tag);
q_malloc
void *Z_TagMallocz(size_t size, memtag_t tag);
q_malloc
char *Z_TagCopyString(const char *in, memtag_t tag);
void Z_FreeTags(memtag_t tag);
void Z_LeakTest(memtag_t tag);
void Z_Stats_f(void);
Expand Down
2 changes: 1 addition & 1 deletion inc/shared/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct {
// they connect, and changes are sent to all connected clients.
void (*configstring)(int num, const char *string);

void (* q_noreturn q_printf(1, 2) error)(const char *fmt, ...);
void (* q_noreturn_ptr q_printf(1, 2) error)(const char *fmt, ...);

// the *index functions create configstrings and some internal server state
int (*modelindex)(const char *name);
Expand Down
18 changes: 12 additions & 6 deletions inc/shared/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define q_printf(f, a) __attribute__((format(printf, f, a)))
#endif
#define q_noreturn __attribute__((noreturn))
#define q_noreturn_ptr q_noreturn
#define q_noinline __attribute__((noinline))
#define q_malloc __attribute__((malloc))
#if __GNUC__ >= 4
Expand Down Expand Up @@ -126,21 +127,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#else /* __GNUC__ */

#define q_printf(f, a)
#ifdef _MSC_VER
#define q_noreturn __declspec(noreturn)
#define q_noinline __declspec(noinline)
#define q_malloc __declspec(restrict)
#define q_alignof(t) __alignof(t)
#else
#define q_noreturn
#define q_noinline
#define q_malloc
#define q_alignof(t) 1
#endif

#define q_printf(f, a)
#define q_noreturn_ptr
#define q_sentinel
#define q_cold

#define q_likely(x) (x)
#define q_unlikely(x) (x)
#define q_offsetof(t, m) ((size_t)&((t *)0)->m)
#ifdef _MSC_VER
#define q_alignof(t) __alignof(t)
#else
#define q_alignof(t) 1
#endif

#define q_gameabi

Expand Down
9 changes: 5 additions & 4 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ typedef enum {
PRINT_NOTICE // print in cyan color
} print_type_t;

void Com_LPrintf(print_type_t type, const char *fmt, ...)
q_printf(2, 3);
void Com_Error(error_type_t code, const char *fmt, ...)
q_cold q_noreturn q_printf(2, 3);
q_printf(2, 3)
void Com_LPrintf(print_type_t type, const char *fmt, ...);

q_cold q_noreturn q_printf(2, 3)
void Com_Error(error_type_t code, const char *fmt, ...);

#define Com_Printf(...) Com_LPrintf(PRINT_ALL, __VA_ARGS__)
#define Com_WPrintf(...) Com_LPrintf(PRINT_WARNING, __VA_ARGS__)
Expand Down
7 changes: 5 additions & 2 deletions inc/system/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ void Sys_Printf(const char *fmt, ...) q_printf(1, 2);
#define Sys_Printf(...) (void)0
#endif

void Sys_Error(const char *error, ...) q_noreturn q_printf(1, 2);
void Sys_Quit(void) q_noreturn;
q_noreturn q_printf(1, 2)
void Sys_Error(const char *error, ...);

q_noreturn
void Sys_Quit(void);

void Sys_ListFiles_r(listfiles_t *list, const char *path, int depth);

Expand Down
3 changes: 2 additions & 1 deletion src/server/mvd/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ extern jmp_buf mvd_jmpbuf;
extern cvar_t *mvd_shownet;
#endif

void MVD_Destroyf(mvd_t *mvd, const char *fmt, ...) q_noreturn q_printf(2, 3);
q_noreturn q_printf(2, 3)
void MVD_Destroyf(mvd_t *mvd, const char *fmt, ...);
void MVD_Shutdown(void);

mvd_t *MVD_SetChannel(int arg);
Expand Down

0 comments on commit 4939234

Please sign in to comment.