From 5ca3e835a7e8e97a168b0fee3e16a576c82e5e3f Mon Sep 17 00:00:00 2001 From: deepend Date: Sun, 25 Jan 2026 23:00:20 -0700 Subject: [PATCH 1/4] Replaced GLib allocation helpers in history management with standard free/strdup to reduce unnecessary GLib coupling. Updated the network helper API to use uint32_t and standard allocation/duplication routines, dropping the GLib include from the implementation and adding to the header. --- Makefile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..038b2ec8 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +PREFIX ?= /usr/local +BUILD_DIR ?= build +MESON ?= meson +NINJA ?= ninja +MESON_SETUP_ARGS ?= +MESON_COMPILE_ARGS ?= +MESON_INSTALL_ARGS ?= + +.PHONY: all configure build reconfigure install clean distclean + +all: build + +configure: + $(MESON) setup $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) + +build: configure + $(MESON) compile -C $(BUILD_DIR) $(MESON_COMPILE_ARGS) + +reconfigure: + $(MESON) setup --reconfigure $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) + +install: build + $(MESON) install -C $(BUILD_DIR) $(MESON_INSTALL_ARGS) + +clean: + $(MESON) compile -C $(BUILD_DIR) --clean + +distclean: + rm -rf $(BUILD_DIR) \ No newline at end of file From d4134c94b386449ec9e4c0aae11f54821bd6099c Mon Sep 17 00:00:00 2001 From: deepend Date: Sun, 25 Jan 2026 23:32:33 -0700 Subject: [PATCH 2/4] Swapped glib integer types in the sysinfo interface for standard stdint types to remove glib coupling in the header. Replaced glib string/util usage in the win32 sysinfo backend with local helpers, a small string builder, and Windows UTF-8 conversion, removing the glib dependency there. --- Makefile | 30 +++- src/common/sysinfo/sysinfo.h | 4 +- src/common/sysinfo/win32/backend.c | 261 +++++++++++++++++++++++++---- 3 files changed, 256 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 038b2ec8..fc23a5f4 100644 --- a/Makefile +++ b/Makefile @@ -6,24 +6,38 @@ MESON_SETUP_ARGS ?= MESON_COMPILE_ARGS ?= MESON_INSTALL_ARGS ?= -.PHONY: all configure build reconfigure install clean distclean +CONFIG_STAMP := $(BUILD_DIR)/build.ninja + +.PHONY: all configure build reconfigure install uninstall clean distclean all: build -configure: - $(MESON) setup $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) +# Only run initial meson setup if we don't have a configured build dir yet. +$(CONFIG_STAMP): + @mkdir -p $(BUILD_DIR) + @env NINJA=$(NINJA) $(MESON) setup $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) + +configure: $(CONFIG_STAMP) build: configure - $(MESON) compile -C $(BUILD_DIR) $(MESON_COMPILE_ARGS) + @env NINJA=$(NINJA) $(MESON) compile -C $(BUILD_DIR) $(MESON_COMPILE_ARGS) reconfigure: - $(MESON) setup --reconfigure $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) + @mkdir -p $(BUILD_DIR) + @env NINJA=$(NINJA) $(MESON) setup --reconfigure $(BUILD_DIR) --prefix=$(PREFIX) $(MESON_SETUP_ARGS) install: build - $(MESON) install -C $(BUILD_DIR) $(MESON_INSTALL_ARGS) + @env NINJA=$(NINJA) $(MESON) install -C $(BUILD_DIR) $(MESON_INSTALL_ARGS) + +uninstall: configure + @$(NINJA) -C $(BUILD_DIR) uninstall clean: - $(MESON) compile -C $(BUILD_DIR) --clean + @if [ -f "$(CONFIG_STAMP)" ]; then \ + env NINJA=$(NINJA) $(MESON) compile -C $(BUILD_DIR) --clean; \ + else \ + echo "Nothing to clean (no $(CONFIG_STAMP))."; \ + fi distclean: - rm -rf $(BUILD_DIR) \ No newline at end of file + rm -rf $(BUILD_DIR) diff --git a/src/common/sysinfo/sysinfo.h b/src/common/sysinfo/sysinfo.h index 18b9503c..c238e90a 100644 --- a/src/common/sysinfo/sysinfo.h +++ b/src/common/sysinfo/sysinfo.h @@ -1,13 +1,13 @@ #ifndef ZOITECHAT_SYSINFO_H #define ZOITECHAT_SYSINFO_H -#include +#include int sysinfo_get_cpu_arch (void); int sysinfo_get_build_arch (void); char *sysinfo_get_cpu (void); char *sysinfo_get_os (void); -void sysinfo_get_hdd_info (guint64 *hdd_capacity_out, guint64 *hdd_free_space_out); +void sysinfo_get_hdd_info (uint64_t *hdd_capacity_out, uint64_t *hdd_free_space_out); char *sysinfo_get_gpu (void); #endif diff --git a/src/common/sysinfo/win32/backend.c b/src/common/sysinfo/win32/backend.c index ec21bad7..0a80b1f8 100644 --- a/src/common/sysinfo/win32/backend.c +++ b/src/common/sysinfo/win32/backend.c @@ -20,7 +20,14 @@ * THE SOFTWARE. */ +#include +#include +#include +#include +#include #include +#include +#include #include #include #include @@ -47,12 +54,26 @@ static char *read_os_name (IWbemClassObject *object); static char *read_cpu_info (IWbemClassObject *object); static char *read_vga_name (IWbemClassObject *object); -static guint64 hdd_capacity; -static guint64 hdd_free_space; +static uint64_t hdd_capacity; +static uint64_t hdd_free_space; static char *read_hdd_info (IWbemClassObject *object); static char *bstr_to_utf8 (BSTR bstr); -static guint64 variant_to_uint64 (VARIANT *variant); +static uint64_t variant_to_uint64 (VARIANT *variant); +static char *zoitechat_strdup (const char *value); +static char *zoitechat_strdup_printf (const char *format, ...); +static char *zoitechat_strchomp (char *value); + +typedef struct +{ + char *data; + size_t len; + size_t cap; +} StringBuilder; + +static bool string_builder_init (StringBuilder *builder); +static void string_builder_free (StringBuilder *builder); +static bool string_builder_append (StringBuilder *builder, const char *text); char * sysinfo_get_cpu (void) @@ -60,7 +81,7 @@ sysinfo_get_cpu (void) if (cpu_info == NULL) cpu_info = query_wmi (QUERY_WMI_CPU); - return g_strdup (cpu_info); + return zoitechat_strdup (cpu_info); } char * @@ -69,7 +90,12 @@ sysinfo_get_os (void) if (os_name == NULL) os_name = query_wmi (QUERY_WMI_OS); - return g_strdup_printf ("%s (x%d)", os_name, sysinfo_get_cpu_arch ()); + if (os_name == NULL) + { + return NULL; + } + + return zoitechat_strdup_printf ("%s (x%d)", os_name, sysinfo_get_cpu_arch ()); } int @@ -124,11 +150,11 @@ sysinfo_get_gpu (void) if (vga_name == NULL) vga_name = query_wmi (QUERY_WMI_VGA); - return g_strdup (vga_name); + return zoitechat_strdup (vga_name); } void -sysinfo_get_hdd_info (guint64 *hdd_capacity_out, guint64 *hdd_free_space_out) +sysinfo_get_hdd_info (uint64_t *hdd_capacity_out, uint64_t *hdd_free_space_out) { char *hdd_info; @@ -149,7 +175,8 @@ sysinfo_get_hdd_info (guint64 *hdd_capacity_out, guint64 *hdd_free_space_out) /* https://msdn.microsoft.com/en-us/library/aa390423 */ static char *query_wmi (QueryWmiType type) { - GString *result = NULL; + StringBuilder result; + bool result_initialized = false; HRESULT hr; IWbemLocator *locator = NULL; @@ -160,7 +187,7 @@ static char *query_wmi (QueryWmiType type) IUnknown *namespaceUnknown = NULL; IEnumWbemClassObject *enumerator = NULL; int i; - gboolean atleast_one_appended = FALSE; + bool atleast_one_appended = false; hr = CoCreateInstance (&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (LPVOID *) &locator); if (FAILED (hr)) @@ -214,7 +241,11 @@ static char *query_wmi (QueryWmiType type) goto release_query; } - result = g_string_new (""); + if (!string_builder_init (&result)) + { + goto release_query; + } + result_initialized = true; for (i = 0;; i++) { @@ -256,14 +287,22 @@ static char *query_wmi (QueryWmiType type) { if (atleast_one_appended) { - g_string_append (result, ", "); + if (!string_builder_append (&result, ", ")) + { + free (line); + goto release_query; + } } - g_string_append (result, line); + if (!string_builder_append (&result, line)) + { + free (line); + goto release_query; + } - g_free (line); + free (line); - atleast_one_appended = TRUE; + atleast_one_appended = true; } } @@ -286,12 +325,12 @@ release_locator: SysFreeString (namespaceName); exit: - if (result == NULL) + if (!result_initialized || result.data == NULL) { return NULL; } - return g_string_free (result, FALSE); + return result.data; } static char *read_os_name (IWbemClassObject *object) @@ -315,7 +354,7 @@ static char *read_os_name (IWbemClassObject *object) return NULL; } - g_strchomp (caption_utf8); + zoitechat_strchomp (caption_utf8); return caption_utf8; } @@ -326,7 +365,7 @@ static char *read_cpu_info (IWbemClassObject *object) VARIANT name_variant; char *name_utf8; VARIANT max_clock_speed_variant; - guint cpu_freq_mhz; + uint32_t cpu_freq_mhz; char *result; hr = object->lpVtbl->Get (object, L"Name", 0, &name_variant, NULL, NULL); @@ -347,7 +386,7 @@ static char *read_cpu_info (IWbemClassObject *object) hr = object->lpVtbl->Get (object, L"MaxClockSpeed", 0, &max_clock_speed_variant, NULL, NULL); if (FAILED (hr)) { - g_free (name_utf8); + free (name_utf8); return NULL; } @@ -356,18 +395,18 @@ static char *read_cpu_info (IWbemClassObject *object) VariantClear (&max_clock_speed_variant); - g_strchomp (name_utf8); + zoitechat_strchomp (name_utf8); if (cpu_freq_mhz > 1000) { - result = g_strdup_printf ("%s (%.2fGHz)", name_utf8, cpu_freq_mhz / 1000.f); + result = zoitechat_strdup_printf ("%s (%.2fGHz)", name_utf8, cpu_freq_mhz / 1000.f); } else { - result = g_strdup_printf ("%s (%" G_GUINT32_FORMAT "MHz)", name_utf8, cpu_freq_mhz); + result = zoitechat_strdup_printf ("%s (%" PRIu32 "MHz)", name_utf8, cpu_freq_mhz); } - g_free (name_utf8); + free (name_utf8); return result; } @@ -393,7 +432,7 @@ static char *read_vga_name (IWbemClassObject *object) return NULL; } - return g_strchomp (name_utf8); + return zoitechat_strchomp (name_utf8); } static char *read_hdd_info (IWbemClassObject *object) @@ -401,11 +440,11 @@ static char *read_hdd_info (IWbemClassObject *object) HRESULT hr; VARIANT name_variant; BSTR name_bstr; - gsize name_len; + size_t name_len; VARIANT capacity_variant; - guint64 capacity; + uint64_t capacity; VARIANT free_space_variant; - guint64 free_space; + uint64_t free_space; hr = object->lpVtbl->Get (object, L"Name", 0, &name_variant, NULL, NULL); if (FAILED (hr)) @@ -464,10 +503,38 @@ static char *read_hdd_info (IWbemClassObject *object) static char *bstr_to_utf8 (BSTR bstr) { - return g_utf16_to_utf8 (bstr, SysStringLen (bstr), NULL, NULL, NULL); + int utf8_len; + char *utf8; + + if (bstr == NULL) + { + return NULL; + } + + utf8_len = WideCharToMultiByte (CP_UTF8, 0, bstr, SysStringLen (bstr), NULL, 0, NULL, NULL); + if (utf8_len <= 0) + { + return NULL; + } + + utf8 = malloc ((size_t) utf8_len + 1); + if (utf8 == NULL) + { + return NULL; + } + + if (WideCharToMultiByte (CP_UTF8, 0, bstr, SysStringLen (bstr), utf8, utf8_len, NULL, NULL) <= 0) + { + free (utf8); + return NULL; + } + + utf8[utf8_len] = '\0'; + + return utf8; } -static guint64 variant_to_uint64 (VARIANT *variant) +static uint64_t variant_to_uint64 (VARIANT *variant) { switch (V_VT (variant)) { @@ -481,3 +548,139 @@ static guint64 variant_to_uint64 (VARIANT *variant) return 0; } } + +static char *zoitechat_strdup (const char *value) +{ + size_t len; + char *copy; + + if (value == NULL) + { + return NULL; + } + + len = strlen (value); + copy = malloc (len + 1); + if (copy == NULL) + { + return NULL; + } + + memcpy (copy, value, len + 1); + + return copy; +} + +static char *zoitechat_strdup_printf (const char *format, ...) +{ + va_list args; + va_list args_copy; + int length; + char *buffer; + + va_start (args, format); + va_copy (args_copy, args); + length = vsnprintf (NULL, 0, format, args_copy); + va_end (args_copy); + + if (length < 0) + { + va_end (args); + return NULL; + } + + buffer = malloc ((size_t) length + 1); + if (buffer == NULL) + { + va_end (args); + return NULL; + } + + vsnprintf (buffer, (size_t) length + 1, format, args); + va_end (args); + + return buffer; +} + +static char *zoitechat_strchomp (char *value) +{ + size_t len; + + if (value == NULL) + { + return NULL; + } + + len = strlen (value); + while (len > 0 && isspace ((unsigned char) value[len - 1]) != 0) + { + value[len - 1] = '\0'; + len--; + } + + return value; +} + +static bool string_builder_init (StringBuilder *builder) +{ + builder->cap = 64; + builder->len = 0; + builder->data = malloc (builder->cap); + if (builder->data == NULL) + { + return false; + } + + builder->data[0] = '\0'; + return true; +} + +static void string_builder_free (StringBuilder *builder) +{ + if (builder->data != NULL) + { + free (builder->data); + builder->data = NULL; + } + builder->len = 0; + builder->cap = 0; +} + +static bool string_builder_append (StringBuilder *builder, const char *text) +{ + size_t add_len; + size_t needed; + size_t new_cap; + char *new_data; + + if (text == NULL) + { + return true; + } + + add_len = strlen (text); + needed = builder->len + add_len + 1; + if (needed > builder->cap) + { + new_cap = builder->cap; + while (new_cap < needed) + { + new_cap *= 2; + } + + new_data = realloc (builder->data, new_cap); + if (new_data == NULL) + { + string_builder_free (builder); + return false; + } + + builder->data = new_data; + builder->cap = new_cap; + } + + memcpy (builder->data + builder->len, text, add_len); + builder->len += add_len; + builder->data[builder->len] = '\0'; + return true; +} From c8ee118f00d8a12a64f9792b9d43c8da1720638e Mon Sep 17 00:00:00 2001 From: deepend Date: Sun, 25 Jan 2026 23:37:09 -0700 Subject: [PATCH 3/4] Replaced GLib allocation helpers in history management with standard free/strdup to reduce unnecessary GLib coupling. Updated the network helper API to use uint32_t and standard allocation/duplication routines, dropping the GLib include from the implementation and adding to the header. --- src/common/history.c | 7 +++---- src/common/network.c | 14 +++++++------- src/common/network.h | 4 +++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/common/history.c b/src/common/history.c index 23a8463e..c6529f30 100644 --- a/src/common/history.c +++ b/src/common/history.c @@ -18,14 +18,13 @@ #include #include -#include #include "history.h" void history_add (struct history *his, char *text) { - g_free (his->lines[his->realpos]); - his->lines[his->realpos] = g_strdup (text); + free (his->lines[his->realpos]); + his->lines[his->realpos] = strdup (text); his->realpos++; if (his->realpos == HISTORY_SIZE) his->realpos = 0; @@ -40,7 +39,7 @@ history_free (struct history *his) { if (his->lines[i]) { - g_free (his->lines[i]); + free (his->lines[i]); his->lines[i] = 0; } } diff --git a/src/common/network.c b/src/common/network.c index fcdaf547..52e7ece5 100644 --- a/src/common/network.c +++ b/src/common/network.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #ifndef WIN32 #include @@ -54,7 +54,7 @@ net_set_socket_options (int sok) } char * -net_ip (guint32 addr) +net_ip (uint32_t addr) { struct in_addr ia; @@ -67,13 +67,13 @@ net_store_destroy (netstore * ns) { if (ns->ip6_hostent) freeaddrinfo (ns->ip6_hostent); - g_free (ns); + free (ns); } netstore * net_store_new (void) { - return g_new0 (netstore, 1); + return calloc (1, sizeof (netstore)); } /* =================== IPV6 ================== */ @@ -121,11 +121,11 @@ net_resolve (netstore * ns, char *hostname, int port, char **real_host) ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST); if (ns->ip6_hostent->ai_canonname) - *real_host = g_strdup (ns->ip6_hostent->ai_canonname); + *real_host = strdup (ns->ip6_hostent->ai_canonname); else - *real_host = g_strdup (hostname); + *real_host = strdup (hostname); - return g_strdup (ipstring); + return strdup (ipstring); } /* the only thing making this interface unclean, this shitty sok4, sok6 business */ diff --git a/src/common/network.h b/src/common/network.h index 7ecfd39a..537f2a84 100644 --- a/src/common/network.h +++ b/src/common/network.h @@ -20,6 +20,8 @@ #ifndef ZOITECHAT_NETWORK_H #define ZOITECHAT_NETWORK_H +#include + typedef struct netstore_ { #ifdef NETWORK_PRIVATE @@ -36,7 +38,7 @@ void net_store_destroy (netstore *ns); int net_connect (netstore *ns, int sok4, int sok6, int *sok_return); char *net_resolve (netstore *ns, char *hostname, int port, char **real_host); void net_bind (netstore *tobindto, int sok4, int sok6); -char *net_ip (guint32 addr); +char *net_ip (uint32_t addr); void net_sockets (int *sok4, int *sok6); #endif From 041288cdad14c37dea1128f86a044b7c605a03f8 Mon Sep 17 00:00:00 2001 From: deepend Date: Sun, 25 Jan 2026 23:52:52 -0700 Subject: [PATCH 4/4] Removed the GLib dependency from the Windows 8 spellcheck provider by swapping in Windows/stdlib UTF-8/UTF-16 conversions and standard allocation/free routines. --- src/libenchant_win8/win8_provider.cpp | 98 ++++++++++++++++++++------- 1 file changed, 72 insertions(+), 26 deletions(-) diff --git a/src/libenchant_win8/win8_provider.cpp b/src/libenchant_win8/win8_provider.cpp index 71e8b417..584f64a6 100644 --- a/src/libenchant_win8/win8_provider.cpp +++ b/src/libenchant_win8/win8_provider.cpp @@ -23,7 +23,9 @@ #include "config.h" #include -#include +#include + +#include #include "typedef.h" // for ssize_t #include @@ -33,9 +35,24 @@ ENCHANT_PLUGIN_DECLARE ("win8") /* --------- Utils ----------*/ static char * -utf16_to_utf8 (const wchar_t * const str, gboolean from_bcp47) +utf16_to_utf8 (const wchar_t * const str, bool from_bcp47) { - char *utf8 = g_utf16_to_utf8 ((gunichar2*)str, -1, nullptr, nullptr, nullptr); + if (!str) + return nullptr; + + int needed = WideCharToMultiByte (CP_UTF8, 0, str, -1, nullptr, 0, nullptr, nullptr); + if (needed <= 0) + return nullptr; + + char *utf8 = static_cast(std::malloc (static_cast(needed))); + if (!utf8) + return nullptr; + + if (WideCharToMultiByte (CP_UTF8, 0, str, -1, utf8, needed, nullptr, nullptr) != needed) + { + std::free (utf8); + return nullptr; + } if (utf8 && from_bcp47) { char *p = utf8; @@ -51,9 +68,27 @@ utf16_to_utf8 (const wchar_t * const str, gboolean from_bcp47) } static wchar_t * -utf8_to_utf16 (const char * const str, size_t len, gboolean to_bcp47) +utf8_to_utf16 (const char * const str, int len, bool to_bcp47) { - wchar_t *utf16 = (wchar_t*)g_utf8_to_utf16 (str, len, nullptr, nullptr, nullptr); + if (!str) + return nullptr; + + int needed = MultiByteToWideChar (CP_UTF8, 0, str, len, nullptr, 0); + if (needed <= 0) + return nullptr; + + int alloc_len = (len == -1) ? needed : needed + 1; + wchar_t *utf16 = static_cast(std::malloc (sizeof (wchar_t) * static_cast(alloc_len))); + if (!utf16) + return nullptr; + + if (MultiByteToWideChar (CP_UTF8, 0, str, len, utf16, needed) != needed) + { + std::free (utf16); + return nullptr; + } + if (len != -1) + utf16[needed] = L'\0'; if (utf16 && to_bcp47) { wchar_t *p = utf16; @@ -69,12 +104,19 @@ utf8_to_utf16 (const char * const str, size_t len, gboolean to_bcp47) } static char ** -enumstring_to_chararray (IEnumString *strings, size_t *out_len, gboolean from_bcp47) +enumstring_to_chararray (IEnumString *strings, size_t *out_len, bool from_bcp47) { - char **chars = g_new (char*, 256); /* Hopefully large enough */ + char **chars = static_cast(std::calloc (256, sizeof (char*))); /* Hopefully large enough */ LPOLESTR wstr = nullptr; size_t i = 0; + if (!chars) + { + *out_len = 0; + strings->Release (); + return nullptr; + } + while (SUCCEEDED (strings->Next (1, &wstr, nullptr)) && i < 256 && wstr) { char *str = utf16_to_utf8 (wstr, from_bcp47); @@ -98,33 +140,33 @@ static void win8_dict_add_to_personal (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, len, FALSE); + wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); checker->Add (wword); - g_free (wword); + std::free (wword); } static void win8_dict_add_to_session (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, len, FALSE); + wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); checker->Ignore (wword); - g_free (wword); + std::free (wword); } static int win8_dict_check (EnchantDict *dict, const char *const word, size_t len) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, len, FALSE); + wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); IEnumSpellingError *errors; ISpellingError *error = nullptr; HRESULT hr; hr = checker->Check (wword, &errors); - g_free (wword); + std::free (wword); if (FAILED (hr)) return -1; /* Error */ @@ -146,12 +188,12 @@ static char ** win8_dict_suggest (EnchantDict *dict, const char *const word, size_t len, size_t *out_n_suggs) { auto checker = static_cast(dict->user_data); - wchar_t *wword = utf8_to_utf16 (word, len, FALSE); + wchar_t *wword = utf8_to_utf16 (word, static_cast(len), false); IEnumString *suggestions; HRESULT hr; hr = checker->Suggest (wword, &suggestions); - g_free (wword); + std::free (wword); if (FAILED (hr)) { @@ -159,7 +201,7 @@ win8_dict_suggest (EnchantDict *dict, const char *const word, size_t len, size_t return nullptr; } - return enumstring_to_chararray (suggestions, out_n_suggs, FALSE); + return enumstring_to_chararray (suggestions, out_n_suggs, false); } /* ---------- Provider ------------ */ @@ -170,16 +212,16 @@ win8_provider_request_dict (EnchantProvider *provider, const char *const tag) auto factory = static_cast(provider->user_data); ISpellChecker *checker; EnchantDict *dict; - wchar_t *wtag = utf8_to_utf16 (tag, -1, TRUE); + wchar_t *wtag = utf8_to_utf16 (tag, -1, true); HRESULT hr; hr = factory->CreateSpellChecker (wtag, &checker); - g_free (wtag); + std::free (wtag); if (FAILED (hr)) return nullptr; - dict = g_new0 (EnchantDict, 1); + dict = static_cast(std::calloc (1, sizeof (EnchantDict))); dict->suggest = win8_dict_suggest; dict->check = win8_dict_check; dict->add_to_personal = win8_dict_add_to_personal; @@ -199,7 +241,7 @@ win8_provider_dispose_dict (EnchantProvider *provider, EnchantDict *dict) auto checker = static_cast(dict->user_data); checker->Release (); - g_free (dict); + std::free (dict); } } @@ -207,12 +249,12 @@ static int win8_provider_dictionary_exists (EnchantProvider *provider, const char *const tag) { auto factory = static_cast(provider->user_data); - wchar_t *wtag = utf8_to_utf16 (tag, -1, TRUE); + wchar_t *wtag = utf8_to_utf16 (tag, -1, true); BOOL is_supported = FALSE; factory->IsSupported (wtag, &is_supported); - g_free (wtag); + std::free (wtag); return is_supported; } @@ -229,13 +271,17 @@ win8_provider_list_dicts (EnchantProvider *provider, size_t *out_n_dicts) return nullptr; } - return enumstring_to_chararray (dicts, out_n_dicts, TRUE); + return enumstring_to_chararray (dicts, out_n_dicts, true); } static void win8_provider_free_string_list (EnchantProvider *provider, char **str_list) { - g_strfreev (str_list); + if (!str_list) + return; + for (size_t i = 0; str_list[i]; ++i) + std::free (str_list[i]); + std::free (str_list); } static void @@ -246,7 +292,7 @@ win8_provider_dispose (EnchantProvider *provider) auto factory = static_cast(provider->user_data); factory->Release(); - g_free (provider); + std::free (provider); } } @@ -275,7 +321,7 @@ init_enchant_provider (void) CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&factory)))) return nullptr; - provider = g_new0 (EnchantProvider, 1); + provider = static_cast(std::calloc (1, sizeof (EnchantProvider))); provider->dispose = win8_provider_dispose; provider->request_dict = win8_provider_request_dict; provider->dispose_dict = win8_provider_dispose_dict;