-
Notifications
You must be signed in to change notification settings - Fork 3
config_gnome3: support glib 2.78+ g_free_sized #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,27 @@ typedef struct g_proxy_config_gnome3_s { | |
| // Glib module handle | ||
| void *glib_module; | ||
| // Glib memory functions | ||
| #if G_GNUC_CHECK_VERSION(4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) | ||
| void (*g_free_sized)(gpointer mem, size_t size); | ||
| #endif | ||
| void (*g_free)(gpointer mem); | ||
| void (*g_strfreev)(gchar **str_array); | ||
| } g_proxy_config_gnome3_s; | ||
|
|
||
| g_proxy_config_gnome3_s g_proxy_config_gnome3; | ||
|
|
||
| #ifdef g_free | ||
| # undef g_free | ||
| # if G_GNUC_CHECK_VERSION(4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) | ||
| # define g_free(mem) \ | ||
| (__builtin_object_size((mem), 0) != ((size_t)-1)) \ | ||
| ? (g_proxy_config_gnome3.g_free_sized)(mem, __builtin_object_size((mem), 0)) \ | ||
| : (g_proxy_config_gnome3.g_free)(mem) | ||
| # else | ||
| # define g_free(mem) (g_proxy_config_gnome3.g_free)(mem) | ||
| # endif | ||
| #endif | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
Comment on lines
+37
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== config_gnome3.c relevant lines ==\n'
nl -ba config_gnome3.c | sed -n '1,220p'
printf '\n== search for gfree / g_free references ==\n'
rg -n '\bgfree\b|\bg_free\b|G_HAVE_FREE_SIZED|GLIB_VERSION_MAX_ALLOWED' config_gnome3.cRepository: snxd/proxyres Length of output: 229 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== surrounding context for call sites ==\n'
nl -ba config_gnome3.c | sed -n '48,170p'Repository: snxd/proxyres Length of output: 233 🏁 Script executed: #!/bin/bash
set -euo pipefail
# If the file exists elsewhere, locate it and inspect exact sections.
file="$(git ls-files '*config_gnome3.c' | head -n 1)"
printf 'file=%s\n' "$file"
nl -ba "$file" | sed -n '1,220p'Repository: snxd/proxyres Length of output: 212 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== config_gnome3.c relevant lines ==\n'
sed -n '1,220p' config_gnome3.c
printf '\n== search for gfree / g_free references ==\n'
grep -nE '\bgfree\b|\bg_free\b|G_HAVE_FREE_SIZED|GLIB_VERSION_MAX_ALLOWED' config_gnome3.cRepository: snxd/proxyres Length of output: 9392 Fix the 🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what do you propose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
`#ifdef` g_free
# undef g_free
`#endif`
`#if` G_GNUC_CHECK_VERSION(4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED)
# define g_free(mem) \
(__builtin_object_size((mem), 0) != ((size_t)-1)) \
? (g_proxy_config_gnome3.g_free_sized)(mem, __builtin_object_size((mem), 0)) \
: (g_proxy_config_gnome3.g_free)(mem)
`#else`
# define g_free(mem) (g_proxy_config_gnome3.g_free)(mem)
`#endif`Two changes from the current code:
Let me know if you'd like me to open a PR-scoped follow-up or if you want to apply this directly. |
||
| static bool proxy_config_gnome3_is_mode(const char *mode) { | ||
| bool equal = false; | ||
|
|
||
|
|
@@ -41,7 +56,7 @@ static bool proxy_config_gnome3_is_mode(const char *mode) { | |
| char *system_mode = g_proxy_config_gnome3.g_settings_get_string(settings, "mode"); | ||
| if (system_mode) { | ||
| equal = strcmp(system_mode, mode) == 0; | ||
| g_proxy_config_gnome3.g_free(system_mode); | ||
| g_free(system_mode); | ||
| } | ||
| g_proxy_config_gnome3.g_object_unref(settings); | ||
| return equal; | ||
|
|
@@ -63,7 +78,7 @@ char *proxy_config_gnome3_get_auto_config_url(void) { | |
| if (url) { | ||
| if (*url) | ||
| auto_config_url = strdup(url); | ||
| g_proxy_config_gnome3.g_free(url); | ||
| g_free(url); | ||
| } | ||
| g_proxy_config_gnome3.g_object_unref(settings); | ||
| return auto_config_url; | ||
|
|
@@ -108,7 +123,7 @@ char *proxy_config_gnome3_get_proxy(const char *scheme) { | |
| snprintf(proxy, max_proxy, "%s:%" PRIu32 "", host, port); | ||
| } | ||
|
|
||
| g_proxy_config_gnome3.g_free(host); | ||
| g_free(host); | ||
| } | ||
| g_proxy_config_gnome3.g_object_unref(settings); | ||
| return proxy; | ||
|
|
@@ -162,9 +177,15 @@ bool proxy_config_gnome3_global_init(void) { | |
| goto gnome3_init_error; | ||
|
|
||
| // Glib functions | ||
| g_proxy_config_gnome3.g_free = (void (*)(gpointer))dlsym(g_proxy_config_gnome3.glib_module, "g_free"); | ||
| (g_proxy_config_gnome3.g_free) = (void (*)(gpointer))dlsym(g_proxy_config_gnome3.glib_module, "g_free"); | ||
| if (!g_proxy_config_gnome3.g_free) | ||
| goto gnome3_init_error; | ||
| #if G_GNUC_CHECK_VERSION(4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) | ||
| g_proxy_config_gnome3.g_free_sized = | ||
| (void (*)(gpointer, size_t))dlsym(g_proxy_config_gnome3.glib_module, "g_free_sized"); | ||
| if (!g_proxy_config_gnome3.g_free_sized) | ||
| goto gnome3_init_error; | ||
| #endif | ||
|
coderabbitai[bot] marked this conversation as resolved.
nmoinvaz marked this conversation as resolved.
|
||
| g_proxy_config_gnome3.g_strfreev = (void (*)(gchar **))dlsym(g_proxy_config_gnome3.glib_module, "g_strfreev"); | ||
| if (!g_proxy_config_gnome3.g_strfreev) | ||
| goto gnome3_init_error; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.