Ruby 3.3.0p0 (2023-12-25 revision 5124f9ac7513eb590c37717337c430cb93caa151)
Macros
defines.h File Reference

Macro definitions used throughout the prism library. More...

#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define PRISM_EXPORTED_FUNCTION
 By default, we compile with -fvisibility=hidden.
 
#define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index)   __attribute__((format(printf, string_index, argument_index)))
 Certain compilers support specifying that a function accepts variadic parameters that look like printf format strings to provide a better developer experience when someone is using the function.
 
#define PRISM_ATTRIBUTE_UNUSED   __attribute__((unused))
 GCC will warn if you specify a function or parameter that is unused at runtime.
 
#define inline   __inline
 Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
 
#define PM_CONCATENATE(left, right)   left ## right
 Old Visual Studio versions before 2015 do not implement sprintf, but instead implement _snprintf.
 
#define PM_STATIC_ASSERT(line, condition, message)   typedef char PM_CONCATENATE(static_assert_, line)[(condition) ? 1 : -1]
 We want to be able to use static assertions, but they weren't standardized until C11.
 

Detailed Description

Macro definitions used throughout the prism library.

This file should be included first by any *.h or *.c in prism for consistency and to ensure that the macros are defined before they are used.

Definition in file defines.h.

Macro Definition Documentation

◆ inline

#define inline   __inline

Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.

Definition at line 66 of file defines.h.

◆ PM_CONCATENATE

#define PM_CONCATENATE ( left,
right )   left ## right

Old Visual Studio versions before 2015 do not implement sprintf, but instead implement _snprintf.

We standard that here. A simple utility macro to concatenate two tokens together, necessary when one of the tokens is itself a macro.

Definition at line 81 of file defines.h.

◆ PM_STATIC_ASSERT

#define PM_STATIC_ASSERT ( line,
condition,
message )   typedef char PM_CONCATENATE(static_assert_, line)[(condition) ? 1 : -1]

We want to be able to use static assertions, but they weren't standardized until C11.

As such, we polyfill it here by making a hacky typedef that will fail to compile due to a negative array size if the condition is false.

Definition at line 91 of file defines.h.

◆ PRISM_ATTRIBUTE_FORMAT

#define PRISM_ATTRIBUTE_FORMAT ( string_index,
argument_index )   __attribute__((format(printf, string_index, argument_index)))

Certain compilers support specifying that a function accepts variadic parameters that look like printf format strings to provide a better developer experience when someone is using the function.

This macro does that in a compiler-agnostic way.

Definition at line 43 of file defines.h.

◆ PRISM_ATTRIBUTE_UNUSED

#define PRISM_ATTRIBUTE_UNUSED   __attribute__((unused))

GCC will warn if you specify a function or parameter that is unused at runtime.

This macro allows you to mark a function or parameter as unused in a compiler-agnostic way.

Definition at line 56 of file defines.h.

◆ PRISM_EXPORTED_FUNCTION

#define PRISM_EXPORTED_FUNCTION

By default, we compile with -fvisibility=hidden.

When this is enabled, we need to mark certain functions as being publically-visible. This macro does that in a compiler-agnostic way.

Definition at line 32 of file defines.h.