Skip to content

Commit 8f52840

Browse files
author
龙虾机器人
committed
fix(vfs): use public VFS API instead of internal _impl functions
- Replace retro_vfs_*_impl with public API - Revert unrelated XMB changes
1 parent ddf70e8 commit 8f52840

6 files changed

Lines changed: 1294 additions & 69 deletions

File tree

fix_c89.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
import re
3+
4+
with open('menu/menu_vfs_browser.c.fixed', 'r') as f:
5+
content = f.read()
6+
7+
# Fix vfs_browser_read_dir function
8+
old_func = '''static void vfs_browser_read_dir(void)
9+
{
10+
libretro_vfs_implementation_dir *vfs_dir;
11+
size_t i;
12+
13+
/* Clean up old entries */'''
14+
15+
new_func = '''static void vfs_browser_read_dir(void)
16+
{
17+
libretro_vfs_implementation_dir *vfs_dir;
18+
size_t i;
19+
const char *name;
20+
bool is_dir;
21+
uint64_t size;
22+
char full_path[PATH_MAX_LENGTH];
23+
size_t new_capacity;
24+
char **new_names;
25+
bool *new_is_dir;
26+
uint64_t *new_sizes;
27+
28+
/* Clean up old entries */'''
29+
30+
content = content.replace(old_func, new_func)
31+
32+
# Fix variable declarations in while loop
33+
old_while = ''' /* Read entries */
34+
while (retro_vfs_readdir_impl(vfs_dir))
35+
{
36+
const char *name = retro_vfs_dirent_get_name_impl(vfs_dir);
37+
bool is_dir = retro_vfs_dirent_is_dir_impl(vfs_dir);
38+
uint64_t size = 0;
39+
char full_path[PATH_MAX_LENGTH];'''
40+
41+
new_while = ''' /* Read entries */
42+
while (retro_vfs_readdir_impl(vfs_dir))
43+
{
44+
name = retro_vfs_dirent_get_name_impl(vfs_dir);
45+
is_dir = retro_vfs_dirent_is_dir_impl(vfs_dir);
46+
size = 0;'''
47+
48+
content = content.replace(old_while, new_while)
49+
50+
# Fix if block variables
51+
old_if = ''' /* Expand capacity if needed */
52+
if (g_vfs_browser.entry_count >= g_vfs_browser.entry_capacity)
53+
{
54+
size_t new_capacity = g_vfs_browser.entry_capacity * 2;
55+
char **new_names = (char**)realloc(g_vfs_browser.entry_names,
56+
new_capacity * sizeof(char*));
57+
bool *new_is_dir = (bool*)realloc(g_vfs_browser.entry_is_dir,
58+
new_capacity * sizeof(bool));
59+
uint64_t *new_sizes = (uint64_t*)realloc(g_vfs_browser.entry_sizes,
60+
new_capacity * sizeof(uint64_t));'''
61+
62+
new_if = ''' /* Expand capacity if needed */
63+
if (g_vfs_browser.entry_count >= g_vfs_browser.entry_capacity)
64+
{
65+
new_capacity = g_vfs_browser.entry_capacity * 2;
66+
new_names = (char**)realloc(g_vfs_browser.entry_names,
67+
new_capacity * sizeof(char*));
68+
new_is_dir = (bool*)realloc(g_vfs_browser.entry_is_dir,
69+
new_capacity * sizeof(bool));
70+
new_sizes = (uint64_t*)realloc(g_vfs_browser.entry_sizes,
71+
new_capacity * sizeof(uint64_t));'''
72+
73+
content = content.replace(old_if, new_if)
74+
75+
with open('menu/menu_vfs_browser.c', 'w') as f:
76+
f.write(content)
77+
78+
print("C89 fix applied successfully!")

menu/drivers/xmb.c

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7171,13 +7171,6 @@ static void xmb_render(void *data,
71717171

71727172
thumbnail_icon = &node->thumbnail_icon;
71737173

7174-
/* LOW-MEMORY FIX: Skip loading if already at max concurrent loads */
7175-
if (!gfx_thumbnail_can_start_load())
7176-
{
7177-
node->icon_hide = true;
7178-
continue;
7179-
}
7180-
71817174
if (cur_per_frame >= max_per_frame)
71827175
{
71837176
node->icon_hide = true;
@@ -7310,58 +7303,12 @@ static void xmb_render(void *data,
73107303
xmb->thumbnails_right_status_prev = xmb->thumbnails.right.status;
73117304
}
73127305

7313-
/* LOW-MEMORY FIX: Detect rapid scrolling and defer thumbnail loading
7314-
* This prevents texture exhaustion on devices like Raspberry Pi and Switch */
7315-
{
7316-
static retro_time_t last_scroll_time = 0;
7317-
static unsigned scroll_count = 0;
7318-
retro_time_t current_time = cpu_features_get_time_usec();
7319-
7320-
/* Count scrolls within 100ms window */
7321-
if (current_time - last_scroll_time < 100000)
7322-
scroll_count++;
7323-
else
7324-
scroll_count = 1;
7325-
7326-
last_scroll_time = current_time;
7327-
7328-
/* If scrolling rapidly (>5 scrolls in 100ms), skip thumbnail updates
7329-
* except for the currently selected item */
7330-
if (scroll_count > 5)
7331-
{
7332-
/* Only load thumbnail for selected item */
7333-
size_t selection = menu_st->selection_ptr;
7334-
if (selection < selection_buf->size)
7335-
{
7336-
xmb_node_t *node = (xmb_node_t*)selection_buf->list[selection].userdata;
7337-
if (node)
7338-
{
7339-
/* Reset all other visible thumbnails to free memory */
7340-
for (i = menu_st->entries.begin; i < menu_st->entries.end; i++)
7341-
{
7342-
if (i != selection)
7343-
{
7344-
xmb_node_t *other_node = (xmb_node_t*)selection_buf->list[i].userdata;
7345-
if (other_node && other_node != node)
7346-
gfx_thumbnail_reset(&other_node->thumbnail_icon.icon);
7347-
}
7348-
}
7349-
}
7350-
}
7351-
7352-
/* Skip full thumbnail update - will retry when scrolling stops */
7353-
xmb->thumbnails.pending_icons = XMB_PENDING_THUMBNAIL_ICONS;
7354-
goto end;
7355-
}
7356-
}
7357-
73587306
i = menu_st->entries.begin;
73597307

73607308
if (i >= end)
73617309
menu_st->entries.begin = 0;
73627310

73637311
GFX_ANIMATION_CLEAR_ACTIVE(p_anim);
7364-
end:;
73657312
}
73667313

73677314
static void xmb_draw_bg(
@@ -9232,14 +9179,6 @@ static void *xmb_init(void **userdata, bool video_is_threaded)
92329179
gfx_thumbnail_set_stream_delay(-1.0f);
92339180
gfx_thumbnail_set_fade_duration(-1.0f);
92349181
gfx_thumbnail_set_fade_missing(false);
9235-
9236-
/* LOW-MEMORY FIX: Set conservative concurrent load limit
9237-
* Lower values for low-memory platforms (RPi, Switch, etc.) */
9238-
#if defined(HAVE_OPENGLES) || defined(__SWITCH__) || defined(ANDROID)
9239-
gfx_thumbnail_set_max_concurrent_loads(2);
9240-
#else
9241-
gfx_thumbnail_set_max_concurrent_loads(4);
9242-
#endif
92439182

92449183
xmb->use_ps3_layout =
92459184
xmb_use_ps3_layout(settings->uints.menu_xmb_layout, width, height);

menu/menu_vfs_browser.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ static void vfs_browser_read_dir(void)
108108
g_vfs_browser.dir = vfs_dir;
109109

110110
/* Read entries */
111-
while (retro_vfs_readdir_impl(vfs_dir))
111+
while (retro_vfs_readdir(vfs_dir))
112112
{
113-
name = retro_vfs_dirent_get_name_impl(vfs_dir);
114-
is_dir = retro_vfs_dirent_is_dir_impl(vfs_dir);
113+
name = retro_vfs_dirent_get_name(vfs_dir);
114+
is_dir = retro_vfs_dirent_is_dir(vfs_dir);
115115
size = 0;
116116

117117
if (!name)
@@ -153,14 +153,14 @@ static void vfs_browser_read_dir(void)
153153
{
154154
fill_pathname_join(full_path, g_vfs_browser.current_path, name,
155155
sizeof(full_path));
156-
size = retro_vfs_stat_impl(full_path, NULL);
156+
size = retro_vfs_stat(full_path, NULL);
157157
}
158158

159159
g_vfs_browser.entry_sizes[g_vfs_browser.entry_count] = size;
160160
g_vfs_browser.entry_count++;
161161
}
162162

163-
retro_vfs_closedir_impl(vfs_dir);
163+
retro_vfs_closedir(vfs_dir);
164164
g_vfs_browser.dir = NULL;
165165

166166
RARCH_LOG("[VFS Browser] Read %zu entries from %s\n",
@@ -316,7 +316,7 @@ bool menu_vfs_browser_operation(unsigned operation, const char *name, const char
316316

317317
case 2: /* Delete */
318318
RARCH_LOG("[VFS Browser] Delete: %s\n", full_path);
319-
if (retro_vfs_remove_impl(full_path) == 0)
319+
if (retro_vfs_remove(full_path) == 0)
320320
{
321321
vfs_browser_read_dir(); /* Refresh */
322322
return true;
@@ -329,7 +329,7 @@ bool menu_vfs_browser_operation(unsigned operation, const char *name, const char
329329
fill_pathname_join(new_path, g_vfs_browser.current_path, new_name,
330330
sizeof(new_path));
331331
RARCH_LOG("[VFS Browser] Rename: %s -> %s\n", full_path, new_path);
332-
if (retro_vfs_rename_impl(full_path, new_path) == 0)
332+
if (retro_vfs_rename(full_path, new_path) == 0)
333333
{
334334
vfs_browser_read_dir(); /* Refresh */
335335
return true;
@@ -338,7 +338,7 @@ bool menu_vfs_browser_operation(unsigned operation, const char *name, const char
338338

339339
case 4: /* Create directory */
340340
RARCH_LOG("[VFS Browser] Create directory: %s\n", full_path);
341-
if (retro_vfs_mkdir_impl(full_path))
341+
if (retro_vfs_mkdir(full_path))
342342
{
343343
vfs_browser_read_dir(); /* Refresh */
344344
return true;

0 commit comments

Comments
 (0)