[glibutil] Make sure that all (and only) required symbols are exported
Even with CFLAGS=-fvisibility=hidden
This commit is contained in:
		
							
								
								
									
										9
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								Makefile
									
									
									
									
									
								
							@@ -80,7 +80,7 @@ SRC = \
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
STRIP ?= strip
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
WARNINGS ?= -Wall
 | 
			
		||||
INCLUDES = -I$(INCLUDE_DIR)
 | 
			
		||||
BASE_FLAGS = -fPIC
 | 
			
		||||
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
 | 
			
		||||
@@ -88,7 +88,8 @@ FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
 | 
			
		||||
  -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_MAX_ALLOWED \
 | 
			
		||||
  -MMD -MP $(shell pkg-config --cflags $(PKGS))
 | 
			
		||||
FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname,$(LIB_SONAME) \
 | 
			
		||||
  $(shell pkg-config --libs $(PKGS))
 | 
			
		||||
  -Wl,--version-script=$(LIB_NAME).ver
 | 
			
		||||
LIBS := $(shell pkg-config --libs $(PKGS))
 | 
			
		||||
DEBUG_FLAGS = -g
 | 
			
		||||
RELEASE_FLAGS =
 | 
			
		||||
COVERAGE_FLAGS = -g
 | 
			
		||||
@@ -195,10 +196,10 @@ $(COVERAGE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
 | 
			
		||||
	$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
 | 
			
		||||
 | 
			
		||||
$(DEBUG_LIB): $(DEBUG_OBJS)
 | 
			
		||||
	$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@
 | 
			
		||||
	$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@ $(LIBS)
 | 
			
		||||
 | 
			
		||||
$(RELEASE_LIB): $(RELEASE_OBJS)
 | 
			
		||||
	$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@
 | 
			
		||||
	$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@ $(LIBS)
 | 
			
		||||
ifeq ($(KEEP_SYMBOLS),0)
 | 
			
		||||
	$(STRIP) $@
 | 
			
		||||
endif
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										232
									
								
								libglibutil.ver
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								libglibutil.ver
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,232 @@
 | 
			
		||||
{
 | 
			
		||||
global:
 | 
			
		||||
    GLOG_TYPE_CUSTOM;
 | 
			
		||||
    GLOG_TYPE_GLIB;
 | 
			
		||||
    GLOG_TYPE_STDERR;
 | 
			
		||||
    GLOG_TYPE_STDOUT;
 | 
			
		||||
    GLOG_TYPE_SYSLOG;
 | 
			
		||||
    gutil_bin2hex;
 | 
			
		||||
    gutil_bytes_concat;
 | 
			
		||||
    gutil_bytes_equal;
 | 
			
		||||
    gutil_bytes_equal_data;
 | 
			
		||||
    gutil_bytes_has_prefix;
 | 
			
		||||
    gutil_bytes_has_suffix;
 | 
			
		||||
    gutil_bytes_xor;
 | 
			
		||||
    gutil_data2hex;
 | 
			
		||||
    gutil_data_copy;
 | 
			
		||||
    gutil_data_copy_as_variant;
 | 
			
		||||
    gutil_data_equal;
 | 
			
		||||
    gutil_data_from_bytes;
 | 
			
		||||
    gutil_data_from_string;
 | 
			
		||||
    gutil_data_has_prefix;
 | 
			
		||||
    gutil_data_has_suffix;
 | 
			
		||||
    gutil_data_new;
 | 
			
		||||
    gutil_disconnect_handlers;
 | 
			
		||||
    gutil_hex2bin;
 | 
			
		||||
    gutil_hex2bytes;
 | 
			
		||||
    gutil_hexdump;
 | 
			
		||||
    gutil_idle_pool_add;
 | 
			
		||||
    gutil_idle_pool_add_bytes;
 | 
			
		||||
    gutil_idle_pool_add_bytes_ref;
 | 
			
		||||
    gutil_idle_pool_add_object;
 | 
			
		||||
    gutil_idle_pool_add_object_ref;
 | 
			
		||||
    gutil_idle_pool_add_ptr_array;
 | 
			
		||||
    gutil_idle_pool_add_ptr_array_ref;
 | 
			
		||||
    gutil_idle_pool_add_strv;
 | 
			
		||||
    gutil_idle_pool_add_variant;
 | 
			
		||||
    gutil_idle_pool_add_variant_ref;
 | 
			
		||||
    gutil_idle_pool_destroy;
 | 
			
		||||
    gutil_idle_pool_drain;
 | 
			
		||||
    gutil_idle_pool_get;
 | 
			
		||||
    gutil_idle_pool_new;
 | 
			
		||||
    gutil_idle_pool_ref;
 | 
			
		||||
    gutil_idle_pool_unref;
 | 
			
		||||
    gutil_idle_queue_add;
 | 
			
		||||
    gutil_idle_queue_add_full;
 | 
			
		||||
    gutil_idle_queue_add_tag;
 | 
			
		||||
    gutil_idle_queue_add_tag_full;
 | 
			
		||||
    gutil_idle_queue_cancel_all;
 | 
			
		||||
    gutil_idle_queue_cancel_tag;
 | 
			
		||||
    gutil_idle_queue_contains_tag;
 | 
			
		||||
    gutil_idle_queue_free;
 | 
			
		||||
    gutil_idle_queue_new;
 | 
			
		||||
    gutil_idle_queue_ref;
 | 
			
		||||
    gutil_idle_queue_unref;
 | 
			
		||||
    gutil_inotify_watch_add_handler;
 | 
			
		||||
    gutil_inotify_watch_callback_free;
 | 
			
		||||
    gutil_inotify_watch_callback_new;
 | 
			
		||||
    gutil_inotify_watch_destroy;
 | 
			
		||||
    gutil_inotify_watch_new;
 | 
			
		||||
    gutil_inotify_watch_ref;
 | 
			
		||||
    gutil_inotify_watch_remove_handler;
 | 
			
		||||
    gutil_inotify_watch_unref;
 | 
			
		||||
    gutil_int_array_append;
 | 
			
		||||
    gutil_int_array_append_vals;
 | 
			
		||||
    gutil_int_array_contains;
 | 
			
		||||
    gutil_int_array_find;
 | 
			
		||||
    gutil_int_array_free;
 | 
			
		||||
    gutil_int_array_free_to_ints;
 | 
			
		||||
    gutil_int_array_insert;
 | 
			
		||||
    gutil_int_array_insert_vals;
 | 
			
		||||
    gutil_int_array_new;
 | 
			
		||||
    gutil_int_array_new_from_vals;
 | 
			
		||||
    gutil_int_array_new_from_value;
 | 
			
		||||
    gutil_int_array_prepend;
 | 
			
		||||
    gutil_int_array_prepend_vals;
 | 
			
		||||
    gutil_int_array_ref;
 | 
			
		||||
    gutil_int_array_remove;
 | 
			
		||||
    gutil_int_array_remove_all;
 | 
			
		||||
    gutil_int_array_remove_all_fast;
 | 
			
		||||
    gutil_int_array_remove_fast;
 | 
			
		||||
    gutil_int_array_remove_index;
 | 
			
		||||
    gutil_int_array_remove_index_fast;
 | 
			
		||||
    gutil_int_array_remove_range;
 | 
			
		||||
    gutil_int_array_set_count;
 | 
			
		||||
    gutil_int_array_sized_new;
 | 
			
		||||
    gutil_int_array_sort_ascending;
 | 
			
		||||
    gutil_int_array_sort_descending;
 | 
			
		||||
    gutil_int_array_unref;
 | 
			
		||||
    gutil_int_history_add;
 | 
			
		||||
    gutil_int_history_clear;
 | 
			
		||||
    gutil_int_history_interval;
 | 
			
		||||
    gutil_int_history_median;
 | 
			
		||||
    gutil_int_history_new;
 | 
			
		||||
    gutil_int_history_new_full;
 | 
			
		||||
    gutil_int_history_ref;
 | 
			
		||||
    gutil_int_history_size;
 | 
			
		||||
    gutil_int_history_unref;
 | 
			
		||||
    gutil_ints_compare;
 | 
			
		||||
    gutil_ints_contains;
 | 
			
		||||
    gutil_ints_equal;
 | 
			
		||||
    gutil_ints_find;
 | 
			
		||||
    gutil_ints_get_count;
 | 
			
		||||
    gutil_ints_get_data;
 | 
			
		||||
    gutil_ints_hash;
 | 
			
		||||
    gutil_ints_new;
 | 
			
		||||
    gutil_ints_new_from_ints;
 | 
			
		||||
    gutil_ints_new_static;
 | 
			
		||||
    gutil_ints_new_take;
 | 
			
		||||
    gutil_ints_new_with_free_func;
 | 
			
		||||
    gutil_ints_ref;
 | 
			
		||||
    gutil_ints_unref;
 | 
			
		||||
    gutil_ints_unref_to_data;
 | 
			
		||||
    gutil_log;
 | 
			
		||||
    gutil_log_assert;
 | 
			
		||||
    gutil_log_default;
 | 
			
		||||
    gutil_log_description;
 | 
			
		||||
    gutil_log_dump;
 | 
			
		||||
    gutil_log_dump_bytes;
 | 
			
		||||
    gutil_log_enabled;
 | 
			
		||||
    gutil_log_func;
 | 
			
		||||
    gutil_log_func2;
 | 
			
		||||
    gutil_log_get_type;
 | 
			
		||||
    gutil_log_glib;
 | 
			
		||||
    gutil_log_glib2;
 | 
			
		||||
    gutil_log_parse_option;
 | 
			
		||||
    gutil_log_set_timestamp_format;
 | 
			
		||||
    gutil_log_set_type;
 | 
			
		||||
    gutil_log_stderr;
 | 
			
		||||
    gutil_log_stderr2;
 | 
			
		||||
    gutil_log_stdio;
 | 
			
		||||
    gutil_log_stdout;
 | 
			
		||||
    gutil_log_stdout2;
 | 
			
		||||
    gutil_log_syslog;
 | 
			
		||||
    gutil_log_syslog2;
 | 
			
		||||
    gutil_log_tid;
 | 
			
		||||
    gutil_log_timestamp;
 | 
			
		||||
    gutil_logv;
 | 
			
		||||
    gutil_memdup;
 | 
			
		||||
    gutil_object_ref;
 | 
			
		||||
    gutil_object_unref;
 | 
			
		||||
    gutil_objv_add;
 | 
			
		||||
    gutil_objv_append;
 | 
			
		||||
    gutil_objv_at;
 | 
			
		||||
    gutil_objv_contains;
 | 
			
		||||
    gutil_objv_copy;
 | 
			
		||||
    gutil_objv_equal;
 | 
			
		||||
    gutil_objv_find;
 | 
			
		||||
    gutil_objv_find_last;
 | 
			
		||||
    gutil_objv_first;
 | 
			
		||||
    gutil_objv_free;
 | 
			
		||||
    gutil_objv_insert;
 | 
			
		||||
    gutil_objv_last;
 | 
			
		||||
    gutil_objv_new;
 | 
			
		||||
    gutil_objv_remove;
 | 
			
		||||
    gutil_objv_remove_at;
 | 
			
		||||
    gutil_parse_int;
 | 
			
		||||
    gutil_parse_int64;
 | 
			
		||||
    gutil_parse_uint;
 | 
			
		||||
    gutil_parse_uint64;
 | 
			
		||||
    gutil_ptrv_free;
 | 
			
		||||
    gutil_ptrv_is_empty;
 | 
			
		||||
    gutil_ptrv_length;
 | 
			
		||||
    gutil_range_has_prefix;
 | 
			
		||||
    gutil_range_init_with_bytes;
 | 
			
		||||
    gutil_range_skip_prefix;
 | 
			
		||||
    gutil_ring_can_put;
 | 
			
		||||
    gutil_ring_clear;
 | 
			
		||||
    gutil_ring_compact;
 | 
			
		||||
    gutil_ring_data_at;
 | 
			
		||||
    gutil_ring_drop;
 | 
			
		||||
    gutil_ring_drop_last;
 | 
			
		||||
    gutil_ring_flatten;
 | 
			
		||||
    gutil_ring_get;
 | 
			
		||||
    gutil_ring_get_last;
 | 
			
		||||
    gutil_ring_max_size;
 | 
			
		||||
    gutil_ring_new;
 | 
			
		||||
    gutil_ring_new_full;
 | 
			
		||||
    gutil_ring_put;
 | 
			
		||||
    gutil_ring_put_front;
 | 
			
		||||
    gutil_ring_ref;
 | 
			
		||||
    gutil_ring_reserve;
 | 
			
		||||
    gutil_ring_set_free_func;
 | 
			
		||||
    gutil_ring_set_max_size;
 | 
			
		||||
    gutil_ring_size;
 | 
			
		||||
    gutil_ring_sized_new;
 | 
			
		||||
    gutil_ring_unref;
 | 
			
		||||
    gutil_signed_mbn_decode;
 | 
			
		||||
    gutil_signed_mbn_decode2;
 | 
			
		||||
    gutil_signed_mbn_encode;
 | 
			
		||||
    gutil_signed_mbn_encode2;
 | 
			
		||||
    gutil_signed_mbn_size;
 | 
			
		||||
    gutil_strlen0;
 | 
			
		||||
    gutil_strv_add;
 | 
			
		||||
    gutil_strv_addv;
 | 
			
		||||
    gutil_strv_at;
 | 
			
		||||
    gutil_strv_bsearch;
 | 
			
		||||
    gutil_strv_contains;
 | 
			
		||||
    gutil_strv_equal;
 | 
			
		||||
    gutil_strv_find;
 | 
			
		||||
    gutil_strv_find_last;
 | 
			
		||||
    gutil_strv_last;
 | 
			
		||||
    gutil_strv_length;
 | 
			
		||||
    gutil_strv_remove;
 | 
			
		||||
    gutil_strv_remove_at;
 | 
			
		||||
    gutil_strv_remove_dups;
 | 
			
		||||
    gutil_strv_sort;
 | 
			
		||||
    gutil_strv_strip;
 | 
			
		||||
    gutil_time_notify_add_handler;
 | 
			
		||||
    gutil_time_notify_new;
 | 
			
		||||
    gutil_time_notify_ref;
 | 
			
		||||
    gutil_time_notify_remove_handler;
 | 
			
		||||
    gutil_time_notify_unref;
 | 
			
		||||
    gutil_tlv_decode;
 | 
			
		||||
    gutil_tlv_encode;
 | 
			
		||||
    gutil_tlvs_decode;
 | 
			
		||||
    gutil_tlv_size;
 | 
			
		||||
    gutil_unsigned_mbn_decode;
 | 
			
		||||
    gutil_unsigned_mbn_decode2;
 | 
			
		||||
    gutil_unsigned_mbn_encode;
 | 
			
		||||
    gutil_unsigned_mbn_encode2;
 | 
			
		||||
    gutil_unsigned_mbn_size;
 | 
			
		||||
    gutil_version_major;
 | 
			
		||||
    gutil_version_micro;
 | 
			
		||||
    gutil_version_minor;
 | 
			
		||||
    gutil_weakref_get;
 | 
			
		||||
    gutil_weakref_new;
 | 
			
		||||
    gutil_weakref_ref;
 | 
			
		||||
    gutil_weakref_set;
 | 
			
		||||
    gutil_weakref_unref;
 | 
			
		||||
local:
 | 
			
		||||
    *;
 | 
			
		||||
};
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -31,6 +31,10 @@
 | 
			
		||||
 | 
			
		||||
#include "gutil_datapack.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Compact 7 bits per byte representation of a signed integer with
 | 
			
		||||
 * redundant sign bits removed. Most significant bit is the continuation
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2017-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2017 Jolla Ltd.
 | 
			
		||||
 * Contact: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -13,9 +13,9 @@
 | 
			
		||||
 *   2. Redistributions in binary form must reproduce the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      documentation and/or other materials provided with the distribution.
 | 
			
		||||
 *   3. Neither the name of Jolla Ltd nor the names of its contributors may
 | 
			
		||||
 *      be used to endorse or promote products derived from this software
 | 
			
		||||
 *      without specific prior written permission.
 | 
			
		||||
 *   3. Neither the names of the copyright holders nor the names of its
 | 
			
		||||
 *      contributors may be used to endorse or promote products derived
 | 
			
		||||
 *      from this software without specific prior written permission.
 | 
			
		||||
 *
 | 
			
		||||
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | 
			
		||||
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
			
		||||
@@ -33,6 +33,10 @@
 | 
			
		||||
#include "gutil_history.h"
 | 
			
		||||
#include "gutil_log.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define GUTIL_HISTORY_DEFAULT_TIME_FUNC g_get_monotonic_time
 | 
			
		||||
 | 
			
		||||
typedef struct gutil_int_history_entry {
 | 
			
		||||
@@ -65,13 +69,14 @@ gutil_int_history_new_full(
 | 
			
		||||
    GUtilHistoryTimeFunc fn)
 | 
			
		||||
{
 | 
			
		||||
    if (max_size > 0 && max_interval > 0) {
 | 
			
		||||
        /* 
 | 
			
		||||
        /*
 | 
			
		||||
         * We don't allow to dynamically change the maximum history size
 | 
			
		||||
         * so we can allocate the whole thing from a single memory block.
 | 
			
		||||
         */
 | 
			
		||||
        GUtilIntHistory* h = g_malloc0(sizeof(GUtilIntHistory) +
 | 
			
		||||
            (max_size-1)*sizeof(GUtilIntHistoryEntry));
 | 
			
		||||
        h->ref_count = 1;
 | 
			
		||||
            (max_size - 1) * sizeof(GUtilIntHistoryEntry));
 | 
			
		||||
 | 
			
		||||
        g_atomic_int_set(&h->ref_count, 1);
 | 
			
		||||
        h->max_size = max_size;
 | 
			
		||||
        h->max_interval = max_interval;
 | 
			
		||||
        h->first = h->last = -1;
 | 
			
		||||
@@ -111,6 +116,7 @@ gutil_int_history_flush(
 | 
			
		||||
    const gint64 now)
 | 
			
		||||
{
 | 
			
		||||
    const gint64 cutoff = now - h->max_interval;
 | 
			
		||||
 | 
			
		||||
    if (h->entry[h->last].time >= cutoff) {
 | 
			
		||||
        /* At least the last entry is valid */
 | 
			
		||||
        while (h->entry[h->first].time < cutoff) {
 | 
			
		||||
@@ -147,6 +153,7 @@ gutil_int_history_interval(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(h) && h->last >= 0) {
 | 
			
		||||
	const gint64 now = h->time();
 | 
			
		||||
 | 
			
		||||
        if (gutil_int_history_flush(h, now)) {
 | 
			
		||||
            return now - h->entry[h->first].time;
 | 
			
		||||
        }
 | 
			
		||||
@@ -179,9 +186,11 @@ gutil_int_history_median_at(
 | 
			
		||||
        gint64 t = h->entry[pos].time;
 | 
			
		||||
        gint64 dt = 0;
 | 
			
		||||
        gint64 area = 0;
 | 
			
		||||
 | 
			
		||||
        while (pos != h->last) {
 | 
			
		||||
            gint64 t1;
 | 
			
		||||
            int v1;
 | 
			
		||||
 | 
			
		||||
            pos = (pos + 1) % h->max_size;
 | 
			
		||||
            t1 = h->entry[pos].time;
 | 
			
		||||
            v1 = h->entry[pos].value;
 | 
			
		||||
@@ -202,10 +211,12 @@ gutil_int_history_add(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(h)) {
 | 
			
		||||
	gint64 now = h->time();
 | 
			
		||||
 | 
			
		||||
        if (h->last < 0 || !gutil_int_history_flush(h, now)) {
 | 
			
		||||
            h->last = h->first = 0;
 | 
			
		||||
        } else {
 | 
			
		||||
            const gint64 last_time = h->entry[h->last].time;
 | 
			
		||||
 | 
			
		||||
            if (now > last_time) {
 | 
			
		||||
                /* Need a new entry */
 | 
			
		||||
                h->last = (h->last + 1) % h->max_size;
 | 
			
		||||
@@ -231,6 +242,7 @@ gutil_int_history_median(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(h) && h->last >= 0) {
 | 
			
		||||
	const gint64 now = h->time();
 | 
			
		||||
 | 
			
		||||
        if (gutil_int_history_flush(h, now)) {
 | 
			
		||||
            return gutil_int_history_median_at(h, now);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,10 @@
 | 
			
		||||
 | 
			
		||||
#include <glib-object.h>
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct gutil_idle_pool_item GUtilIdlePoolItem;
 | 
			
		||||
 | 
			
		||||
struct gutil_idle_pool_item {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2017-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2017-2020 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2017-2020 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -34,6 +34,10 @@
 | 
			
		||||
#include "gutil_macros.h"
 | 
			
		||||
#include "gutil_log.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct gutil_idle_queue_item GUtilIdleQueueItem;
 | 
			
		||||
 | 
			
		||||
struct gutil_idle_queue_item {
 | 
			
		||||
@@ -121,7 +125,8 @@ GUtilIdleQueue*
 | 
			
		||||
gutil_idle_queue_new()
 | 
			
		||||
{
 | 
			
		||||
    GUtilIdleQueue* q = g_slice_new0(GUtilIdleQueue);
 | 
			
		||||
    q->ref_count = 1;
 | 
			
		||||
 | 
			
		||||
    g_atomic_int_set(&q->ref_count, 1);
 | 
			
		||||
    return q;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,10 @@
 | 
			
		||||
#define NO_SANITIZE_CFI
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct gutil_inotify {
 | 
			
		||||
    int ref_count;
 | 
			
		||||
    int fd;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2017-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2017 Jolla Ltd.
 | 
			
		||||
 * Contact: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -13,9 +13,9 @@
 | 
			
		||||
 *   2. Redistributions in binary form must reproduce the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      documentation and/or other materials provided with the distribution.
 | 
			
		||||
 *   3. Neither the name of Jolla Ltd nor the names of its contributors may
 | 
			
		||||
 *      be used to endorse or promote products derived from this software
 | 
			
		||||
 *      without specific prior written permission.
 | 
			
		||||
 *   3. Neither the names of the copyright holders nor the names of its
 | 
			
		||||
 *      contributors may be used to endorse or promote products derived
 | 
			
		||||
 *      from this software without specific prior written permission.
 | 
			
		||||
 *
 | 
			
		||||
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | 
			
		||||
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
			
		||||
@@ -33,6 +33,10 @@
 | 
			
		||||
#include "gutil_intarray.h"
 | 
			
		||||
#include "gutil_ints.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GUtilIntArray) == sizeof(GArray));
 | 
			
		||||
#define ELEMENT_SIZE (sizeof(int))
 | 
			
		||||
 | 
			
		||||
@@ -56,6 +60,7 @@ gutil_int_array_new_from_vals(
 | 
			
		||||
    guint count)
 | 
			
		||||
{
 | 
			
		||||
    GUtilIntArray* array = gutil_int_array_sized_new(count);
 | 
			
		||||
 | 
			
		||||
    gutil_int_array_append_vals(array, vals, count);
 | 
			
		||||
    return array;
 | 
			
		||||
}
 | 
			
		||||
@@ -91,6 +96,7 @@ gutil_int_array_free_to_ints(
 | 
			
		||||
        if (array->count) {
 | 
			
		||||
            guint count = array->count;
 | 
			
		||||
            int* values = gutil_int_array_free(array, FALSE);
 | 
			
		||||
 | 
			
		||||
            return gutil_ints_new_take(values, count);
 | 
			
		||||
        } else {
 | 
			
		||||
            gutil_int_array_free(array, TRUE);
 | 
			
		||||
@@ -198,6 +204,7 @@ gutil_int_array_find(
 | 
			
		||||
{
 | 
			
		||||
    if (array) {
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        for (i = 0; i < array->count; i++) {
 | 
			
		||||
            if (array->data[i] == value) {
 | 
			
		||||
                return i;
 | 
			
		||||
@@ -220,7 +227,8 @@ gutil_int_array_remove(
 | 
			
		||||
    GUtilIntArray* array,
 | 
			
		||||
    int value)
 | 
			
		||||
{
 | 
			
		||||
    int pos = gutil_int_array_find(array, value);
 | 
			
		||||
    const int pos = gutil_int_array_find(array, value);
 | 
			
		||||
 | 
			
		||||
    if (pos >= 0) {
 | 
			
		||||
        g_array_remove_index((GArray*)array, pos);
 | 
			
		||||
        return TRUE;
 | 
			
		||||
@@ -233,7 +241,8 @@ gutil_int_array_remove_fast(
 | 
			
		||||
    GUtilIntArray* array,
 | 
			
		||||
    int value)
 | 
			
		||||
{
 | 
			
		||||
    int pos = gutil_int_array_find(array, value);
 | 
			
		||||
    const int pos = gutil_int_array_find(array, value);
 | 
			
		||||
 | 
			
		||||
    if (pos >= 0) {
 | 
			
		||||
        g_array_remove_index_fast((GArray*)array, pos);
 | 
			
		||||
        return TRUE;
 | 
			
		||||
@@ -247,6 +256,7 @@ gutil_int_array_remove_all(
 | 
			
		||||
    int value)
 | 
			
		||||
{
 | 
			
		||||
    guint n;
 | 
			
		||||
 | 
			
		||||
    for (n = 0; gutil_int_array_remove(array, value); n++);
 | 
			
		||||
    return n;
 | 
			
		||||
}
 | 
			
		||||
@@ -257,6 +267,7 @@ gutil_int_array_remove_all_fast(
 | 
			
		||||
    int value)
 | 
			
		||||
{
 | 
			
		||||
    guint n;
 | 
			
		||||
 | 
			
		||||
    for (n = 0; gutil_int_array_remove_fast(array, value); n++);
 | 
			
		||||
    return n;
 | 
			
		||||
}
 | 
			
		||||
@@ -291,6 +302,7 @@ gutil_int_array_remove_range(
 | 
			
		||||
{
 | 
			
		||||
    if (array && pos < array->count && count) {
 | 
			
		||||
        guint end = pos + count;
 | 
			
		||||
 | 
			
		||||
        if (end > array->count) {
 | 
			
		||||
            end = array->count;
 | 
			
		||||
        }
 | 
			
		||||
@@ -307,6 +319,7 @@ gutil_int_array_sort_ascending_proc(
 | 
			
		||||
{
 | 
			
		||||
    const int* v1 = a;
 | 
			
		||||
    const int* v2 = b;
 | 
			
		||||
 | 
			
		||||
    return *v1 - *v2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -327,6 +340,7 @@ gutil_int_array_sort_descending_proc(
 | 
			
		||||
{
 | 
			
		||||
    const int* v1 = a;
 | 
			
		||||
    const int* v2 = b;
 | 
			
		||||
 | 
			
		||||
    return *v2 - *v1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2017-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2017-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2017-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -35,6 +35,10 @@
 | 
			
		||||
#include "gutil_misc.h"
 | 
			
		||||
#include "gutil_macros.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
struct gutil_ints {
 | 
			
		||||
    const int* data;
 | 
			
		||||
    guint count;
 | 
			
		||||
@@ -80,11 +84,12 @@ gutil_ints_new_with_free_func(
 | 
			
		||||
{
 | 
			
		||||
    if (data && count) {
 | 
			
		||||
        GUtilInts* ints = g_slice_new(GUtilInts);
 | 
			
		||||
 | 
			
		||||
        ints->data = data;
 | 
			
		||||
        ints->count = count;
 | 
			
		||||
        ints->free_func = free_func;
 | 
			
		||||
        ints->user_data = user_data;
 | 
			
		||||
        ints->ref_count = 1;
 | 
			
		||||
        g_atomic_int_set(&ints->ref_count, 1);
 | 
			
		||||
        return ints;
 | 
			
		||||
    } else {
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -107,6 +112,7 @@ gutil_ints_new_from_ints(
 | 
			
		||||
{
 | 
			
		||||
    if (ints && offset < ints->count) {
 | 
			
		||||
        guint end = offset + count;
 | 
			
		||||
 | 
			
		||||
        if (end > ints->count) {
 | 
			
		||||
            end = ints->count;
 | 
			
		||||
        }
 | 
			
		||||
@@ -148,6 +154,7 @@ gutil_ints_unref_to_data(
 | 
			
		||||
{
 | 
			
		||||
    if (ints) {
 | 
			
		||||
        int* result;
 | 
			
		||||
 | 
			
		||||
        if (count) {
 | 
			
		||||
            *count = ints->count;
 | 
			
		||||
        }
 | 
			
		||||
@@ -204,6 +211,7 @@ gutil_ints_find(
 | 
			
		||||
{
 | 
			
		||||
    if (ints) {
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        for (i=0; i<ints->count; i++) {
 | 
			
		||||
            if (ints->data[i] == value) {
 | 
			
		||||
                return i;
 | 
			
		||||
@@ -225,6 +233,7 @@ gutil_ints_contains(
 | 
			
		||||
     */
 | 
			
		||||
    if (ints) {
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        for (i=0; i<ints->count; i++) {
 | 
			
		||||
            if (ints->data[i] == value) {
 | 
			
		||||
                return TRUE;
 | 
			
		||||
@@ -241,6 +250,7 @@ gutil_ints_hash(
 | 
			
		||||
    if (data) {
 | 
			
		||||
        const GUtilInts* ints = data;
 | 
			
		||||
        guint i, h = 1234;
 | 
			
		||||
 | 
			
		||||
        for (i=0; i<ints->count; i++) {
 | 
			
		||||
            h ^= ints->data[i] * (i+1);
 | 
			
		||||
        }
 | 
			
		||||
@@ -257,6 +267,7 @@ gutil_ints_equal(
 | 
			
		||||
{
 | 
			
		||||
    const GUtilInts* i1 = a;
 | 
			
		||||
    const GUtilInts* i2 = b;
 | 
			
		||||
 | 
			
		||||
    if (i1 == i2) {
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    } else if (i1 && i2) {
 | 
			
		||||
@@ -280,11 +291,13 @@ gutil_ints_compare(
 | 
			
		||||
{
 | 
			
		||||
    const GUtilInts* i1 = a;
 | 
			
		||||
    const GUtilInts* i2 = b;
 | 
			
		||||
 | 
			
		||||
    if (i1 == i2) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    } else if (i1 && i2) {
 | 
			
		||||
        const int ret = memcmp(i1->data, i2->data,
 | 
			
		||||
            MIN(i1->count, i2->count) * sizeof(int));
 | 
			
		||||
 | 
			
		||||
        if (ret || i1->count == i2->count) {
 | 
			
		||||
            return ret;
 | 
			
		||||
        } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * Copyright (C) 2014-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2014-2022 Jolla Ltd.
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -35,6 +35,10 @@
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef unix
 | 
			
		||||
#  include <unistd.h>
 | 
			
		||||
#  include <sys/syscall.h>
 | 
			
		||||
@@ -445,6 +449,7 @@ gutil_log(
 | 
			
		||||
    ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list va;
 | 
			
		||||
 | 
			
		||||
    va_start(va, format);
 | 
			
		||||
    gutil_logv(module, level, format, va);
 | 
			
		||||
    va_end(va);
 | 
			
		||||
@@ -540,6 +545,7 @@ gutil_log_dump_bytes(
 | 
			
		||||
    if (G_LIKELY(bytes) && gutil_log_enabled(module, level)) {
 | 
			
		||||
        gsize size = 0;
 | 
			
		||||
        const guint8* data = g_bytes_get_data(bytes, &size);
 | 
			
		||||
 | 
			
		||||
        gutil_log_dump2(module, level, prefix, data, size);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -582,9 +588,11 @@ gutil_log_parse_level(
 | 
			
		||||
    if (str && str[0]) {
 | 
			
		||||
        guint i;
 | 
			
		||||
        const size_t len = strlen(str);
 | 
			
		||||
 | 
			
		||||
        if (len == 1) {
 | 
			
		||||
            const char* valid_numbers = "012345";
 | 
			
		||||
            const char* number = strchr(valid_numbers, str[0]);
 | 
			
		||||
 | 
			
		||||
            if (number) {
 | 
			
		||||
                return number - valid_numbers;
 | 
			
		||||
            }
 | 
			
		||||
@@ -617,9 +625,11 @@ gutil_log_parse_option(
 | 
			
		||||
    const char* sep = strchr(opt, ':');
 | 
			
		||||
    if (sep) {
 | 
			
		||||
        const int modlevel = gutil_log_parse_level(sep+1, error);
 | 
			
		||||
 | 
			
		||||
        if (modlevel >= 0) {
 | 
			
		||||
            int i;
 | 
			
		||||
            const size_t namelen = sep - opt;
 | 
			
		||||
 | 
			
		||||
            for (i=0; i<count; i++) {
 | 
			
		||||
                if (!g_ascii_strncasecmp(modules[i]->name, opt, namelen) &&
 | 
			
		||||
                    strlen(modules[i]->name) == namelen) {
 | 
			
		||||
@@ -653,6 +663,7 @@ gutil_log_description(
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    GString* desc = g_string_sized_new(128);
 | 
			
		||||
 | 
			
		||||
    g_string_append(desc, "Log Levels:\n");
 | 
			
		||||
    for (i=0; i<=GLOG_LEVEL_VERBOSE; i++) {
 | 
			
		||||
        g_string_append_printf(desc, "   %d, ", i);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2016-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2016-2022 Jolla Ltd.
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -38,6 +38,10 @@
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gutil_disconnect_handlers(
 | 
			
		||||
    gpointer instance,
 | 
			
		||||
@@ -190,6 +194,7 @@ gutil_hexdump(
 | 
			
		||||
        }
 | 
			
		||||
        if (i < len) {
 | 
			
		||||
            const guchar b = bytes[i];
 | 
			
		||||
 | 
			
		||||
            *ptr++ = hex[(b >> 4) & 0xf];
 | 
			
		||||
            *ptr++ = hex[b & 0xf];
 | 
			
		||||
        } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -32,6 +32,10 @@
 | 
			
		||||
#include "gutil_objv.h"
 | 
			
		||||
#include "gutil_misc.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
GObject**
 | 
			
		||||
gutil_objv_new(
 | 
			
		||||
    GObject* obj1,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2016-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2016-2020 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -34,6 +34,10 @@
 | 
			
		||||
#include "gutil_macros.h"
 | 
			
		||||
#include "gutil_log.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
struct gutil_ring {
 | 
			
		||||
    gint ref_count;
 | 
			
		||||
    gint alloc;
 | 
			
		||||
@@ -65,7 +69,8 @@ gutil_ring_new_full(
 | 
			
		||||
    GDestroyNotify free_func)
 | 
			
		||||
{
 | 
			
		||||
    GUtilRing* r = g_slice_new0(GUtilRing);
 | 
			
		||||
    r->ref_count = 1;
 | 
			
		||||
 | 
			
		||||
    g_atomic_int_set(&r->ref_count, 1);
 | 
			
		||||
    r->start = r->end = -1;
 | 
			
		||||
    r->maxsiz = (max_size < 0) ? GUTIL_RING_UNLIMITED_SIZE : max_size;
 | 
			
		||||
    r->free_func = free_func;
 | 
			
		||||
@@ -97,6 +102,7 @@ gutil_ring_unref(
 | 
			
		||||
            if (r->free_func) {
 | 
			
		||||
                const gint n = gutil_ring_size(r);
 | 
			
		||||
                gint i;
 | 
			
		||||
 | 
			
		||||
                for (i=0; i<n; i++) {
 | 
			
		||||
                    r->free_func(r->data[(r->start + i) % r->alloc]);
 | 
			
		||||
                }
 | 
			
		||||
@@ -114,7 +120,7 @@ gutil_ring_set_free_func(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(r)) {
 | 
			
		||||
        r->free_func = free_func;
 | 
			
		||||
    }    
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gint
 | 
			
		||||
@@ -133,6 +139,7 @@ gutil_ring_set_max_size(
 | 
			
		||||
    if (max_size < 0) max_size = GUTIL_RING_UNLIMITED_SIZE;
 | 
			
		||||
    if (G_LIKELY(r) && r->maxsiz != max_size) {
 | 
			
		||||
        const gint size = gutil_ring_size(r);
 | 
			
		||||
 | 
			
		||||
        if (max_size >= 0 && size > max_size) {
 | 
			
		||||
            gutil_ring_drop(r, size - max_size);
 | 
			
		||||
        }
 | 
			
		||||
@@ -166,6 +173,7 @@ gutil_ring_clear(
 | 
			
		||||
        gint n = gutil_ring_size(r);
 | 
			
		||||
        if (n > 0) {
 | 
			
		||||
            GDestroyNotify free_func = r->free_func;
 | 
			
		||||
 | 
			
		||||
            if (free_func) {
 | 
			
		||||
                do {
 | 
			
		||||
                    free_func(gutil_ring_get(r));
 | 
			
		||||
@@ -184,9 +192,11 @@ gutil_ring_compact(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(r)) {
 | 
			
		||||
        int n = gutil_ring_size(r);
 | 
			
		||||
 | 
			
		||||
        if (r->alloc > n) {
 | 
			
		||||
            if (n > 0) {
 | 
			
		||||
                gpointer* buf = g_new(gpointer,n);
 | 
			
		||||
 | 
			
		||||
                if (r->start < r->end) {
 | 
			
		||||
                    memcpy(buf, r->data + r->start, sizeof(gpointer) * n);
 | 
			
		||||
                } else {
 | 
			
		||||
@@ -223,6 +233,7 @@ gutil_ring_reserve(
 | 
			
		||||
            return FALSE;
 | 
			
		||||
        } else {
 | 
			
		||||
            gpointer* buf;
 | 
			
		||||
 | 
			
		||||
            /* At least double the allocation size */
 | 
			
		||||
            minsize = MAX(minsize, r->alloc*2);
 | 
			
		||||
            if (r->maxsiz > 0 && minsize > r->maxsiz) {
 | 
			
		||||
@@ -232,11 +243,13 @@ gutil_ring_reserve(
 | 
			
		||||
            buf = g_new(gpointer, minsize);
 | 
			
		||||
            if (r->start < r->end) {
 | 
			
		||||
                const int n = r->end - r->start;
 | 
			
		||||
 | 
			
		||||
                memcpy(buf, r->data + r->start, sizeof(gpointer) * n);
 | 
			
		||||
                r->start = 0;
 | 
			
		||||
                r->end = n;
 | 
			
		||||
            } else if (r->start >= 0) {
 | 
			
		||||
                const int tail = r->alloc - r->start;
 | 
			
		||||
 | 
			
		||||
                memcpy(buf, r->data + r->start, sizeof(gpointer) * tail);
 | 
			
		||||
                memcpy(buf + tail, r->data, sizeof(gpointer) * r->end);
 | 
			
		||||
                r->start = 0;
 | 
			
		||||
@@ -304,6 +317,7 @@ gutil_ring_get(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(r) && r->start >= 0) {
 | 
			
		||||
        gpointer data = r->data[r->start++];
 | 
			
		||||
 | 
			
		||||
        if (r->start == r->end) {
 | 
			
		||||
            r->start = r->end = -1;
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -323,6 +337,7 @@ gutil_ring_get_last(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(r) && r->start >= 0) {
 | 
			
		||||
        gpointer data;
 | 
			
		||||
 | 
			
		||||
        r->end = (r->end + r->alloc - 1) % r->alloc;
 | 
			
		||||
        data = r->data[r->end];
 | 
			
		||||
        if (r->start == r->end) {
 | 
			
		||||
@@ -339,6 +354,7 @@ gutil_ring_drop(
 | 
			
		||||
    gint n)
 | 
			
		||||
{
 | 
			
		||||
    int size, dropped = 0;
 | 
			
		||||
 | 
			
		||||
    if (n > 0 && (size = gutil_ring_size(r)) > 0) {
 | 
			
		||||
        if (n >= size) {
 | 
			
		||||
            dropped = size;
 | 
			
		||||
@@ -366,6 +382,7 @@ gutil_ring_drop_last(
 | 
			
		||||
    gint n)
 | 
			
		||||
{
 | 
			
		||||
    int size, dropped = 0;
 | 
			
		||||
 | 
			
		||||
    if (n > 0 && (size = gutil_ring_size(r)) > 0) {
 | 
			
		||||
        if (n >= size) {
 | 
			
		||||
            dropped = size;
 | 
			
		||||
@@ -405,11 +422,13 @@ gutil_ring_flatten(
 | 
			
		||||
    gint* size)
 | 
			
		||||
{
 | 
			
		||||
    gpointer* data = NULL;
 | 
			
		||||
    gint n = gutil_ring_size(r);
 | 
			
		||||
    const gint n = gutil_ring_size(r);
 | 
			
		||||
 | 
			
		||||
    if (G_LIKELY(r) && n > 0) {
 | 
			
		||||
        if (r->start > 0 && r->start >= r->end) {
 | 
			
		||||
            gpointer* buf = g_new(gpointer, n); 
 | 
			
		||||
            gpointer* buf = g_new(gpointer, n);
 | 
			
		||||
            const gint n1 = r->alloc - r->start;
 | 
			
		||||
 | 
			
		||||
            memcpy(buf, r->data + r->start, sizeof(gpointer) * n1);
 | 
			
		||||
            memcpy(buf + n1, r->data, sizeof(gpointer) * r->end);
 | 
			
		||||
            g_free(r->data);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2014-2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 * Copyright (C) 2014-2022 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2014-2022 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -35,6 +35,10 @@
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * NULL-tolerant version of g_strv_length
 | 
			
		||||
 */
 | 
			
		||||
@@ -55,6 +59,7 @@ gutil_strv_at(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(sv)) {
 | 
			
		||||
        guint k = 0;
 | 
			
		||||
 | 
			
		||||
        while (sv[k] && k < i) k++;
 | 
			
		||||
        if (k == i) {
 | 
			
		||||
            /* We also end up here if i == len but that's OK */
 | 
			
		||||
@@ -73,6 +78,7 @@ gutil_strv_last(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(sv) && G_LIKELY(sv[0])) {
 | 
			
		||||
        guint k = 0;
 | 
			
		||||
 | 
			
		||||
        while (sv[k + 1]) k++;
 | 
			
		||||
        return sv[k];
 | 
			
		||||
    }
 | 
			
		||||
@@ -341,7 +347,8 @@ gutil_strv_sort(
 | 
			
		||||
    GStrV* sv,
 | 
			
		||||
    gboolean ascending)
 | 
			
		||||
{
 | 
			
		||||
    guint len = gutil_strv_length(sv);
 | 
			
		||||
    const guint len = gutil_strv_length(sv);
 | 
			
		||||
 | 
			
		||||
    if (len > 0) {
 | 
			
		||||
        qsort(sv, len, sizeof(char*), ascending ?
 | 
			
		||||
              gutil_strv_sort_ascending :
 | 
			
		||||
@@ -364,10 +371,12 @@ gutil_strv_bsearch(
 | 
			
		||||
    gboolean ascending) /* Since 1.0.40 */
 | 
			
		||||
{
 | 
			
		||||
    if (s) {
 | 
			
		||||
        guint len = gutil_strv_length(sv);
 | 
			
		||||
        const guint len = gutil_strv_length(sv);
 | 
			
		||||
 | 
			
		||||
        if (len > 0) {
 | 
			
		||||
            GStrV* found = bsearch(&s, sv, len, sizeof(char*), ascending ?
 | 
			
		||||
                gutil_strv_sort_ascending : gutil_strv_sort_descending);
 | 
			
		||||
 | 
			
		||||
            if (found) {
 | 
			
		||||
                return found - sv;
 | 
			
		||||
            }
 | 
			
		||||
@@ -385,6 +394,7 @@ gutil_strv_strip(
 | 
			
		||||
{
 | 
			
		||||
    if (sv) {
 | 
			
		||||
        GStrV* ptr;
 | 
			
		||||
 | 
			
		||||
        for (ptr = sv; *ptr; ptr++) {
 | 
			
		||||
            *ptr = g_strstrip(*ptr);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -46,6 +46,10 @@
 | 
			
		||||
#define NO_SANITIZE_CFI
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef TFD_TIMER_CANCEL_ON_SET
 | 
			
		||||
#  define TFD_TIMER_CANCEL_ON_SET (1 << 1)
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -31,6 +31,10 @@
 | 
			
		||||
 | 
			
		||||
#include "gutil_version.h"
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
const guint gutil_version_major = GUTIL_VERSION_MAJOR;
 | 
			
		||||
const guint gutil_version_minor = GUTIL_VERSION_MINOR;
 | 
			
		||||
const guint gutil_version_micro = GUTIL_VERSION_MICRO;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2023 Slava Monich <slava@monich.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 * You may use this file under the terms of the BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
@@ -35,6 +35,10 @@
 | 
			
		||||
 | 
			
		||||
#include <glib-object.h>
 | 
			
		||||
 | 
			
		||||
#if __GNUC__ >= 4
 | 
			
		||||
#pragma GCC visibility push(default)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Ref-countable weak reference can be used to avoid calling g_weak_ref_set()
 | 
			
		||||
 * too often because it grabs global weak_locations_lock for exclusive access.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user