build: fix CXX_BUILD=1 compilation

Compiling the C sources as C++ (CXX_BUILD=1) failed in 12 places where
the code relied on implicit conversions that C permits but C++ rejects.
All are mechanical and behaviour-preserving:

void* -> typed pointer (explicit cast):
  - input/common/linux_common.c  (illuminance sensor data)
  - tasks/task_screenshot.c       (copy.buffer -> uint32_t*)
  - libretro-db/rmsgpack_dom.c    (alloca result -> dom_value**)

const char* -> char* (strrchr/strchr return values):
  - libretro-common/file/file_path.c  (cast strrchr result; matches the
    char* return contract of the C function)
  - configuration.c                   (extra_path points at a mutable
    stack buffer that is written through -> make it char*)
  - menu/menu_displaylist.c           (hash_type likewise -> char*)

integer -> enum (explicit cast at use site):
  - runloop.c           (unsigned pending_cmd -> enum event_command)
  - runtime_file.c      (settings uints -> last_played style/separator)
  - tasks/task_database.c (int iterate result -> enum scan_verdict)
  - menu/menu_driver.c  (unsigned confirm_msg -> enum msg_hash_enums)

std::atomic copy:
  - cheevos/cheevos.c: the static rcheevos_locals aggregate brace-init
    of the two retro_atomic_int_t members used a bare '0', which under
    CXX_BUILD (std::atomic<int>) selects the deleted copy constructor.
    Use {0} so C++ list-initializes via the converting constructor;
    for the C atomic/int/volatile backends {0} is an equivalent scalar
    initializer.

With these, the tree compiles cleanly under CXX_BUILD=1 (every object
builds and the link stage is reached). This addresses the compilation
failures from #6009; note that CXX_BUILD has no CI coverage, so it will
regress again as new C-idiomatic code lands unless a build job is added.
This commit is contained in:
libretroadmin authored and libretroadmin committed 2026-06-25 09:47:38 +02:00
1 parent 1dd859a4ab
commit 059ca263df
11 files changed
+17 -15

No files matched your search

+6 -4
View File
@@ -90,12 +90,14 @@ static rcheevos_locals_t rcheevos_locals =
NULL, /* client */
{{0}},/* memory */
#ifdef HAVE_THREADS
/* queued_command (atomic). CMD_EVENT_NONE == 0; static
* zero-initialization satisfies all retro_atomic.h backends. */
0,
/* queued_command (atomic). CMD_EVENT_NONE == 0. Brace-init so that
* under CXX_BUILD (std::atomic<int>) this list-initializes via the
* converting constructor rather than the deleted copy constructor;
* for the C backends {0} is an equivalent scalar initializer. */
{0},
/* load_generation (atomic). Starts at 0; bumped by
* rcheevos_unload and rcheevos_load. */
0,
{0},
#endif
"", /* user_agent_prefix */
"", /* user_agent_core */
+1 -1
View File
@@ -4019,7 +4019,7 @@ static bool config_load_file(global_t *global,
if (!path_is_empty(RARCH_PATH_CONFIG_OVERRIDE) && !without_overrides)
{
char tmp_append_path[PATH_MAX_LENGTH];
const char *extra_path = NULL;
char *extra_path = NULL;
#ifdef HAVE_OVERLAY
char old_overlay_path[PATH_MAX_LENGTH], new_overlay_path[PATH_MAX_LENGTH];
config_get_path(conf, "input_overlay", old_overlay_path, sizeof(old_overlay_path));
+1 -1
View File
@@ -159,7 +159,7 @@ bool linux_terminal_disable_input(void)
static void linux_poll_illuminance_sensor(void *data)
{
linux_illuminance_sensor_t *sensor = data;
linux_illuminance_sensor_t *sensor = (linux_illuminance_sensor_t*)data;
if (!data)
return;
+1 -1
View File
@@ -380,7 +380,7 @@ char *find_last_slash(const char *str)
return s1;
return (s2 > s1) ? s2 : s1;
#else
return strrchr(str, '/');
return (char*)strrchr(str, '/');
#endif
}
+1 -1
View File
@@ -482,7 +482,7 @@ int rmsgpack_dom_read(intfstream_t *fd, struct rmsgpack_dom_value *out)
s.i = 0;
s.growable = false;
s.capacity = MAX_DEPTH;
s.stack = alloca(MAX_DEPTH*sizeof(struct rmsgpack_dom_value *));
s.stack = (struct rmsgpack_dom_value **)alloca(MAX_DEPTH*sizeof(struct rmsgpack_dom_value *));
return rmsgpack_dom_read_with(fd, out, &s);
}
+1 -1
View File
@@ -2886,7 +2886,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu,
if (crc_len < sizeof(entry_crc32_buf))
{
const char *elem0 = entry_crc32_buf;
const char *hash_type = NULL;
char *hash_type = NULL;
char *delim = strchr(entry_crc32_buf, '|');
if (delim)
+1 -1
View File
@@ -7236,7 +7236,7 @@ static int generic_menu_iterate(
break;
case ITERATE_TYPE_CONFIRM:
strlcpy(menu->menu_state_msg,
msg_hash_to_str(menu_st->dialog_st.confirm_msg),
msg_hash_to_str((enum msg_hash_enums)menu_st->dialog_st.confirm_msg),
sizeof(menu->menu_state_msg));
#ifdef HAVE_ACCESSIBILITY
+1 -1
View File
@@ -6561,7 +6561,7 @@ static enum runloop_state_enum runloop_check_state(
if (menu_st->dialog_st.pending_cmd != CMD_EVENT_NONE)
{
/* Event also wants to resume */
if (!command_event(menu_st->dialog_st.pending_cmd, NULL))
if (!command_event((enum event_command)menu_st->dialog_st.pending_cmd, NULL))
command_event(CMD_EVENT_RESUME, NULL);
menu_dialog_confirm_clear(menu_st);
+2 -2
View File
@@ -1325,9 +1325,9 @@ void runtime_update_playlist(
unsigned runtime_type = settings->uints.playlist_sublabel_runtime_type;
bool log_per_core = (runtime_type == PLAYLIST_RUNTIME_PER_CORE);
enum playlist_sublabel_last_played_style_type
timedate_style = settings->uints.playlist_sublabel_last_played_style;
timedate_style = (enum playlist_sublabel_last_played_style_type)settings->uints.playlist_sublabel_last_played_style;
enum playlist_sublabel_last_played_date_separator_type
date_separator = settings->uints.menu_timedate_date_separator;
date_separator = (enum playlist_sublabel_last_played_date_separator_type)settings->uints.menu_timedate_date_separator;
/* Sanity check */
if (!playlist)
+1 -1
View File
@@ -2214,7 +2214,7 @@ static void task_manual_content_scan_handler(retro_task_t *task)
if (dbinfo->type == DATABASE_TYPE_ITERATE)
dbinfo->type = DATABASE_TYPE_ITERATE_ARCHIVE;
current_verdict = task_database_iterate(manual_scan, content_path, dbstate, dbinfo,
current_verdict = (enum scan_verdict)task_database_iterate(manual_scan, content_path, dbstate, dbinfo,
path_contains_compressed_file);
#ifdef DEBUG
RARCH_DBG("[Scanner] Scan verdict is %d for %s\n", current_verdict, content_path);
+1 -1
View File
@@ -747,7 +747,7 @@ static bool take_screenshot_raw(
if ((buf = (uint32_t*)calloc(1, size)))
{
screenshot_rotate(buf, copy.buffer, size,
screenshot_rotate(buf, (uint32_t*)copy.buffer, size,
&width, &height, &pitch,
sys_info->rotation);
memcpy(copy.buffer, buf, size);