From e797c6907feea11349e43598b49e33954cd4b8ed Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 12 Sep 2023 08:25:57 +0100 Subject: [PATCH 1/2] Prefix macros: LIBCTRU_{ALIGN,PACKED,DEPRECATED} The mitigates compatibility issues with other libraries, such as the one seen in #530. The `BIT` macro is kept because it is commonly used, so renaming it would be too breaking of a change (see https://github.com/devkitPro/libctru/pull/531#issuecomment-1714148532) Fixes #530 --- libctru/Doxyfile | 2 +- libctru/include/3ds/gfx.h | 2 +- libctru/include/3ds/ipc.h | 2 +- libctru/include/3ds/mii.h | 2 +- libctru/include/3ds/services/apt.h | 2 +- libctru/include/3ds/services/fs.h | 2 +- libctru/include/3ds/types.h | 10 +++++----- libctru/source/gdbhio.c | 2 +- libctru/source/services/soc/soc_inet_pton.c | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libctru/Doxyfile b/libctru/Doxyfile index c686766ed..fe24a71c4 100644 --- a/libctru/Doxyfile +++ b/libctru/Doxyfile @@ -2023,7 +2023,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = PACKED +PREDEFINED = LIBCTRU_PACKED # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 9d65b052e..91b8485a6 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -166,7 +166,7 @@ void gfxScreenSwapBuffers(gfxScreen_t scr, bool hasStereo); * @param immediate This parameter no longer has any effect and is thus ignored. * @deprecated This function has been superseded by \ref gfxScreenSwapBuffers, please use that instead. */ -DEPRECATED void gfxConfigScreen(gfxScreen_t scr, bool immediate); +LIBCTRU_DEPRECATED void gfxConfigScreen(gfxScreen_t scr, bool immediate); /** * @brief Updates the configuration of both screens. diff --git a/libctru/include/3ds/ipc.h b/libctru/include/3ds/ipc.h index e3a44b45f..53eb41162 100644 --- a/libctru/include/3ds/ipc.h +++ b/libctru/include/3ds/ipc.h @@ -70,7 +70,7 @@ static inline u32 IPC_Desc_CurProcessId(void) return 0x20; } -static inline DEPRECATED u32 IPC_Desc_CurProcessHandle(void) +static inline LIBCTRU_DEPRECATED u32 IPC_Desc_CurProcessHandle(void) { return IPC_Desc_CurProcessId(); } diff --git a/libctru/include/3ds/mii.h b/libctru/include/3ds/mii.h index 692ceccfc..517b32493 100644 --- a/libctru/include/3ds/mii.h +++ b/libctru/include/3ds/mii.h @@ -156,4 +156,4 @@ typedef struct } mole_details; u16 author_name[10]; ///< Name of Mii's author (Encoded using UTF16) -} PACKED MiiData; +} LIBCTRU_PACKED MiiData; diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index ff4bb574c..540143ea8 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -176,7 +176,7 @@ bool aptShouldJumpToHome(void); bool aptCheckHomePressRejected(void); /// \deprecated Alias for \ref aptCheckHomePressRejected. -static inline DEPRECATED bool aptIsHomePressed(void) +static inline LIBCTRU_DEPRECATED bool aptIsHomePressed(void) { return aptCheckHomePressRejected(); } diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h index 5a3956d39..c9ca0ec7c 100644 --- a/libctru/include/3ds/services/fs.h +++ b/libctru/include/3ds/services/fs.h @@ -202,7 +202,7 @@ typedef struct } FS_IntegrityVerificationSeed; /// Ext save data information. -typedef struct PACKED +typedef struct LIBCTRU_PACKED { FS_MediaType mediaType : 8; ///< Media type. u8 unknown; ///< Unknown. diff --git a/libctru/include/3ds/types.h b/libctru/include/3ds/types.h index eed876a7b..15299c014 100644 --- a/libctru/include/3ds/types.h +++ b/libctru/include/3ds/types.h @@ -47,16 +47,16 @@ typedef void (*voidfn)(void); #define BIT(n) (1U<<(n)) /// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. -#define ALIGN(m) __attribute__((aligned(m))) +#define LIBCTRU_ALIGN(m) __attribute__((aligned(m))) /// Packs a struct (and other types?) so it won't include padding bytes. -#define PACKED __attribute__((packed)) +#define LIBCTRU_PACKED __attribute__((packed)) #ifndef LIBCTRU_NO_DEPRECATION /// Flags a function as deprecated. -#define DEPRECATED __attribute__ ((deprecated)) +#define LIBCTRU_DEPRECATED __attribute__ ((deprecated)) #else /// Flags a function as deprecated. -#define DEPRECATED +#define LIBCTRU_DEPRECATED #endif /// Structure representing CPU registers @@ -71,7 +71,7 @@ typedef struct { /// Structure representing FPU registers typedef struct { union { - struct PACKED { double d[16]; }; ///< d0-d15. + struct LIBCTRU_PACKED { double d[16]; }; ///< d0-d15. float s[32]; ///< s0-s31. }; u32 fpscr; ///< fpscr. diff --git a/libctru/source/gdbhio.c b/libctru/source/gdbhio.c index 7143f859d..f7e3d24a1 100644 --- a/libctru/source/gdbhio.c +++ b/libctru/source/gdbhio.c @@ -205,7 +205,7 @@ static int _gdbExportSeekFlag(int flag) // https://sourceware.org/gdb/onlinedocs/gdb/struct-stat.html#struct-stat typedef u32 gdbhio_time_t; -struct PACKED ALIGN(4) gdbhio_stat { +struct LIBCTRU_PACKED LIBCTRU_ALIGN(4) gdbhio_stat { u32 gst_dev; /* device */ u32 gst_ino; /* inode */ gdbhio_mode_t gst_mode; /* protection */ diff --git a/libctru/source/services/soc/soc_inet_pton.c b/libctru/source/services/soc/soc_inet_pton.c index ebdc9f786..5271f8e53 100644 --- a/libctru/source/services/soc/soc_inet_pton.c +++ b/libctru/source/services/soc/soc_inet_pton.c @@ -6,7 +6,7 @@ static int inet_pton4(const char *restrict src, void *restrict dst) { - u8 ip[4] ALIGN(4); + u8 ip[4] LIBCTRU_ALIGN(4); if(sscanf(src,"%hhu.%hhu.%hhu.%hhu",&ip[0], &ip[1], &ip[2], &ip[3]) != 4) return 0; memcpy(dst,ip,4); From 75f003db5340edab8eb04f49264ddb32d402ce7f Mon Sep 17 00:00:00 2001 From: fincs Date: Wed, 11 Oct 2023 21:55:17 +0200 Subject: [PATCH 2/2] Rename LIBCTRU_ to CTR_ --- libctru/Doxyfile | 2 +- libctru/include/3ds/gfx.h | 2 +- libctru/include/3ds/ipc.h | 2 +- libctru/include/3ds/mii.h | 4 ++-- libctru/include/3ds/services/apt.h | 2 +- libctru/include/3ds/services/fs.h | 2 +- libctru/include/3ds/types.h | 12 ++++++------ libctru/source/gdbhio.c | 2 +- libctru/source/services/soc/soc_inet_pton.c | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libctru/Doxyfile b/libctru/Doxyfile index fe24a71c4..d6a43a186 100644 --- a/libctru/Doxyfile +++ b/libctru/Doxyfile @@ -2023,7 +2023,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = LIBCTRU_PACKED +PREDEFINED = CTR_PACKED # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 91b8485a6..b1502c3f3 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -166,7 +166,7 @@ void gfxScreenSwapBuffers(gfxScreen_t scr, bool hasStereo); * @param immediate This parameter no longer has any effect and is thus ignored. * @deprecated This function has been superseded by \ref gfxScreenSwapBuffers, please use that instead. */ -LIBCTRU_DEPRECATED void gfxConfigScreen(gfxScreen_t scr, bool immediate); +CTR_DEPRECATED void gfxConfigScreen(gfxScreen_t scr, bool immediate); /** * @brief Updates the configuration of both screens. diff --git a/libctru/include/3ds/ipc.h b/libctru/include/3ds/ipc.h index 53eb41162..4c4ff82e5 100644 --- a/libctru/include/3ds/ipc.h +++ b/libctru/include/3ds/ipc.h @@ -70,7 +70,7 @@ static inline u32 IPC_Desc_CurProcessId(void) return 0x20; } -static inline LIBCTRU_DEPRECATED u32 IPC_Desc_CurProcessHandle(void) +static inline CTR_DEPRECATED u32 IPC_Desc_CurProcessHandle(void) { return IPC_Desc_CurProcessId(); } diff --git a/libctru/include/3ds/mii.h b/libctru/include/3ds/mii.h index 517b32493..fc395d956 100644 --- a/libctru/include/3ds/mii.h +++ b/libctru/include/3ds/mii.h @@ -147,7 +147,7 @@ typedef struct } glasses_details; /// Mole details - struct + struct { bool enable : 1; u16 scale : 5; @@ -156,4 +156,4 @@ typedef struct } mole_details; u16 author_name[10]; ///< Name of Mii's author (Encoded using UTF16) -} LIBCTRU_PACKED MiiData; +} CTR_PACKED MiiData; diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index 540143ea8..4e9de7e97 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -176,7 +176,7 @@ bool aptShouldJumpToHome(void); bool aptCheckHomePressRejected(void); /// \deprecated Alias for \ref aptCheckHomePressRejected. -static inline LIBCTRU_DEPRECATED bool aptIsHomePressed(void) +static inline CTR_DEPRECATED bool aptIsHomePressed(void) { return aptCheckHomePressRejected(); } diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h index c9ca0ec7c..8a6f6596f 100644 --- a/libctru/include/3ds/services/fs.h +++ b/libctru/include/3ds/services/fs.h @@ -202,7 +202,7 @@ typedef struct } FS_IntegrityVerificationSeed; /// Ext save data information. -typedef struct LIBCTRU_PACKED +typedef struct CTR_PACKED { FS_MediaType mediaType : 8; ///< Media type. u8 unknown; ///< Unknown. diff --git a/libctru/include/3ds/types.h b/libctru/include/3ds/types.h index 15299c014..02f4d96ca 100644 --- a/libctru/include/3ds/types.h +++ b/libctru/include/3ds/types.h @@ -47,16 +47,16 @@ typedef void (*voidfn)(void); #define BIT(n) (1U<<(n)) /// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. -#define LIBCTRU_ALIGN(m) __attribute__((aligned(m))) +#define CTR_ALIGN(m) __attribute__((aligned(m))) /// Packs a struct (and other types?) so it won't include padding bytes. -#define LIBCTRU_PACKED __attribute__((packed)) +#define CTR_PACKED __attribute__((packed)) -#ifndef LIBCTRU_NO_DEPRECATION +#ifndef CTR_NO_DEPRECATION /// Flags a function as deprecated. -#define LIBCTRU_DEPRECATED __attribute__ ((deprecated)) +#define CTR_DEPRECATED __attribute__ ((deprecated)) #else /// Flags a function as deprecated. -#define LIBCTRU_DEPRECATED +#define CTR_DEPRECATED #endif /// Structure representing CPU registers @@ -71,7 +71,7 @@ typedef struct { /// Structure representing FPU registers typedef struct { union { - struct LIBCTRU_PACKED { double d[16]; }; ///< d0-d15. + struct CTR_PACKED { double d[16]; }; ///< d0-d15. float s[32]; ///< s0-s31. }; u32 fpscr; ///< fpscr. diff --git a/libctru/source/gdbhio.c b/libctru/source/gdbhio.c index f7e3d24a1..96caea0f4 100644 --- a/libctru/source/gdbhio.c +++ b/libctru/source/gdbhio.c @@ -205,7 +205,7 @@ static int _gdbExportSeekFlag(int flag) // https://sourceware.org/gdb/onlinedocs/gdb/struct-stat.html#struct-stat typedef u32 gdbhio_time_t; -struct LIBCTRU_PACKED LIBCTRU_ALIGN(4) gdbhio_stat { +struct CTR_PACKED CTR_ALIGN(4) gdbhio_stat { u32 gst_dev; /* device */ u32 gst_ino; /* inode */ gdbhio_mode_t gst_mode; /* protection */ diff --git a/libctru/source/services/soc/soc_inet_pton.c b/libctru/source/services/soc/soc_inet_pton.c index 5271f8e53..99a8e2433 100644 --- a/libctru/source/services/soc/soc_inet_pton.c +++ b/libctru/source/services/soc/soc_inet_pton.c @@ -6,7 +6,7 @@ static int inet_pton4(const char *restrict src, void *restrict dst) { - u8 ip[4] LIBCTRU_ALIGN(4); + u8 ip[4] CTR_ALIGN(4); if(sscanf(src,"%hhu.%hhu.%hhu.%hhu",&ip[0], &ip[1], &ip[2], &ip[3]) != 4) return 0; memcpy(dst,ip,4);