Merge branch 'upstream' into feature/bullseye/1.0.52
This commit is contained in:
commit
e012d76174
|
@ -4,6 +4,7 @@ test/libglibutil_test.opt
|
|||
test/coverage/full.gcov
|
||||
test/coverage/libglibutil.gcov
|
||||
test/coverage/results
|
||||
debian/.debhelper
|
||||
debian/files
|
||||
debian/libglibutil-dev.debhelper.log
|
||||
debian/libglibutil-dev.install
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright (C) 2014-2020 Jolla Ltd.
|
||||
Copyright (C) 2014-2021 Jolla Ltd.
|
||||
|
||||
You may use this file under the terms of BSD license as follows:
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -20,7 +20,7 @@ all: debug release pkgconfig
|
|||
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
VERSION_RELEASE = 50
|
||||
VERSION_RELEASE = 52
|
||||
|
||||
# Version for pkg-config
|
||||
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
libglibutil (1.0.52) unstable; urgency=low
|
||||
|
||||
* Added gutil_memdup()
|
||||
|
||||
-- Slava Monich <slava.monich@jolla.com> Sun, 18 Apr 2021 17:40:41 +0300
|
||||
|
||||
libglibutil (1.0.51) unstable; urgency=low
|
||||
|
||||
* Initialize default log settings from the environment
|
||||
* Disable timestamps by default
|
||||
* Added gutil_log_tid option
|
||||
* Added gutil_ptrv_free()
|
||||
|
||||
-- Slava Monich <slava.monich@jolla.com> Thu, 25 Feb 2021 19:36:05 +0200
|
||||
|
||||
libglibutil (1.0.50) unstable; urgency=low
|
||||
|
||||
* Added gutil_ptrv_length()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (C) 2014-2020 Jolla Ltd.
|
||||
Copyright (C) 2014-2021 Jolla Ltd.
|
||||
|
||||
You may use this file under the terms of BSD license as follows:
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2019 Jolla Ltd.
|
||||
* Copyright (C) 2014-2019 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2014-2021 Jolla Ltd.
|
||||
* Copyright (C) 2014-2021 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of BSD license as follows:
|
||||
*
|
||||
|
@ -167,6 +167,7 @@ GLOG_MODULE_DECL(gutil_log_default)
|
|||
extern GLogProc gutil_log_func;
|
||||
extern GLogProc2 gutil_log_func2;
|
||||
extern gboolean gutil_log_timestamp; /* Only affects stdout and stderr */
|
||||
extern gboolean gutil_log_tid; /* Since 1.0.51 */
|
||||
|
||||
/* Log module (optional) */
|
||||
#define GLOG_MODULE_DEFINE_(var,name) \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2016-2020 Jolla Ltd.
|
||||
* Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2016-2021 Jolla Ltd.
|
||||
* Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of BSD license as follows:
|
||||
*
|
||||
|
@ -119,7 +119,16 @@ gutil_bytes_equal_data(
|
|||
|
||||
gsize
|
||||
gutil_ptrv_length(
|
||||
gconstpointer ptrv); /* Since 1.0.50 */
|
||||
const void* ptrv); /* Since 1.0.50 */
|
||||
|
||||
void
|
||||
gutil_ptrv_free(
|
||||
void** ptrv); /* Since 1.0.51 */
|
||||
|
||||
void*
|
||||
gutil_memdup(
|
||||
const void* ptr,
|
||||
gsize size); /* Since 1.0.52 */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Name: libglibutil
|
||||
Version: 1.0.50
|
||||
Version: 1.0.52
|
||||
Release: 0
|
||||
Summary: Library of glib utilities
|
||||
License: BSD
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2017-2020 Jolla Ltd.
|
||||
* Copyright (C) 2017-2020 Slava Monich <slava.monich@jolla.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:
|
||||
*
|
||||
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "gutil_intarray.h"
|
||||
#include "gutil_ints.h"
|
||||
#include "gutil_misc.h"
|
||||
#include "gutil_macros.h"
|
||||
|
||||
struct gutil_ints {
|
||||
|
@ -45,10 +46,10 @@ struct gutil_ints {
|
|||
GUtilInts*
|
||||
gutil_ints_new(
|
||||
const int* data,
|
||||
guint count)
|
||||
guint n)
|
||||
{
|
||||
if (data && count) {
|
||||
return gutil_ints_new_take(g_memdup(data, count*sizeof(int)), count);
|
||||
if (data && n) {
|
||||
return gutil_ints_new_take(gutil_memdup(data, n * sizeof(int)), n);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -155,12 +156,12 @@ gutil_ints_unref_to_data(
|
|||
/* We can allow the caller to free the data */
|
||||
result = (int*)ints->data;
|
||||
} else {
|
||||
result = g_memdup(ints->data, ints->count * sizeof(int));
|
||||
result = gutil_memdup(ints->data, ints->count * sizeof(int));
|
||||
ints->free_func(ints->user_data);
|
||||
}
|
||||
gutil_slice_free(ints);
|
||||
} else {
|
||||
result = g_memdup(ints->data, ints->count * sizeof(int));
|
||||
result = gutil_memdup(ints->data, ints->count * sizeof(int));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2019 Jolla Ltd.
|
||||
* Copyright (C) 2014-2019 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2014-2021 Jolla Ltd.
|
||||
* Copyright (C) 2014-2021 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of BSD license as follows:
|
||||
*
|
||||
|
@ -31,9 +31,17 @@
|
|||
*/
|
||||
|
||||
#include "gutil_log.h"
|
||||
#include "gutil_misc.h"
|
||||
|
||||
#if defined(DEBUG) && defined(_WIN32)
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef unix
|
||||
# include <unistd.h>
|
||||
# include <sys/syscall.h>
|
||||
# define gettid() ((int)syscall(SYS_gettid))
|
||||
#elif defined(_WIN32)
|
||||
# include <windows.h>
|
||||
# define gettid() ((int)GetCurrentThreadId())
|
||||
#endif
|
||||
|
||||
#ifndef GLOG_SYSLOG
|
||||
|
@ -49,7 +57,10 @@
|
|||
#endif /* GLOG_GLIB */
|
||||
|
||||
/* Allows timestamps in stdout log */
|
||||
gboolean gutil_log_timestamp = TRUE;
|
||||
gboolean gutil_log_timestamp = FALSE;
|
||||
|
||||
/* Adds thread id prefix */
|
||||
gboolean gutil_log_tid = FALSE; /* Since 1.0.51 */
|
||||
|
||||
/* Log configuration */
|
||||
static GUTIL_DEFINE_LOG_FN2(gutil_log_default_proc);
|
||||
|
@ -191,8 +202,18 @@ gutil_log_stdio(
|
|||
}
|
||||
#endif
|
||||
if (name) {
|
||||
#ifdef gettid
|
||||
if (gutil_log_tid)
|
||||
fprintf(out, "[%d] %s[%s] %s%s\n", gettid(), t, name, prefix, msg);
|
||||
else
|
||||
#endif
|
||||
fprintf(out, "%s[%s] %s%s\n", t, name, prefix, msg);
|
||||
} else {
|
||||
#ifdef gettid
|
||||
if (gutil_log_tid)
|
||||
fprintf(out, "[%d] %s%s%s\n", gettid(), t, prefix, msg);
|
||||
else
|
||||
#endif
|
||||
fprintf(out, "%s%s%s\n", t, prefix, msg);
|
||||
}
|
||||
if (msg != buf) g_free(msg);
|
||||
|
@ -280,13 +301,27 @@ gutil_log_syslog(
|
|||
}
|
||||
}
|
||||
|
||||
if (name || prefix) {
|
||||
if (name || prefix
|
||||
#ifdef gettid
|
||||
|| gutil_log_tid
|
||||
#endif
|
||||
) {
|
||||
char buf[512];
|
||||
char* msg = gutil_log_format(buf, sizeof(buf), format, va);
|
||||
if (!prefix) prefix = "";
|
||||
if (name) {
|
||||
#ifdef gettid
|
||||
if (gutil_log_tid)
|
||||
syslog(priority, "[%d] [%s] %s%s", gettid(), name, prefix, msg);
|
||||
else
|
||||
#endif
|
||||
syslog(priority, "[%s] %s%s", name, prefix, msg);
|
||||
} else {
|
||||
#ifdef gettid
|
||||
if (gutil_log_tid)
|
||||
syslog(priority, "[%d] %s%s", gettid(), prefix, msg);
|
||||
else
|
||||
#endif
|
||||
syslog(priority, "%s%s", prefix, msg);
|
||||
}
|
||||
if (msg != buf) g_free(msg);
|
||||
|
@ -607,6 +642,33 @@ gutil_log_get_type()
|
|||
GLOG_TYPE_CUSTOM;
|
||||
}
|
||||
|
||||
/* Initialize defaults from the environment */
|
||||
#ifndef _WIN32
|
||||
__attribute__((constructor))
|
||||
static
|
||||
void
|
||||
gutil_log_init()
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
if (gutil_parse_int(getenv("GUTIL_LOG_DEFAULT_LEVEL"), 0, &val) &&
|
||||
val >= GLOG_LEVEL_INHERIT && val <= GLOG_LEVEL_VERBOSE) {
|
||||
gutil_log_default.level = val;
|
||||
GDEBUG("Default log level %d", val);
|
||||
}
|
||||
|
||||
if (gutil_parse_int(getenv("GUTIL_LOG_TIMESTAMP"), 0, &val) && val > 0) {
|
||||
gutil_log_timestamp = (val > 0);
|
||||
GDEBUG("Timestamps %s", (val > 0) ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
if (gutil_parse_int(getenv("GUTIL_LOG_TID"), 0, &val) && val > 0) {
|
||||
gutil_log_tid = (val > 0);
|
||||
GDEBUG("Thread id prefix %s", (val > 0) ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: C
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2016-2020 Jolla Ltd.
|
||||
* Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2016-2021 Jolla Ltd.
|
||||
* Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of BSD license as follows:
|
||||
*
|
||||
|
@ -418,7 +418,7 @@ gutil_bytes_equal_data(
|
|||
/* Calculates the length of NULL-terminated array of pointers */
|
||||
gsize
|
||||
gutil_ptrv_length(
|
||||
gconstpointer ptrv) /* Since 1.0.50 */
|
||||
const void* ptrv) /* Since 1.0.50 */
|
||||
{
|
||||
if (G_LIKELY(ptrv)) {
|
||||
gsize len = 0;
|
||||
|
@ -431,6 +431,35 @@ gutil_ptrv_length(
|
|||
}
|
||||
}
|
||||
|
||||
/* Frees NULL-terminated array of pointers and whatever they're pointing to. */
|
||||
void
|
||||
gutil_ptrv_free(
|
||||
void** ptrv) /* Since 1.0.51 */
|
||||
{
|
||||
if (G_LIKELY(ptrv)) {
|
||||
void** ptr = ptrv;
|
||||
|
||||
while (*ptr) g_free(*ptr++);
|
||||
g_free(ptrv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Similar to g_memdup but takes gsize as the number of bytes to copy */
|
||||
void*
|
||||
gutil_memdup(
|
||||
const void* ptr,
|
||||
gsize size) /* Since 1.0.52 */
|
||||
{
|
||||
if (G_LIKELY(ptr) && G_LIKELY(size)) {
|
||||
void* copy = g_malloc(size);
|
||||
|
||||
memcpy(copy, ptr, size);
|
||||
return copy;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: C
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2016-2020 Jolla Ltd.
|
||||
* Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2016-2021 Jolla Ltd.
|
||||
* Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of BSD license as follows:
|
||||
*
|
||||
|
@ -485,12 +485,12 @@ test_bytes_equal(
|
|||
}
|
||||
|
||||
/*==========================================================================*
|
||||
* ptrv
|
||||
* ptrv_length
|
||||
*==========================================================================*/
|
||||
|
||||
static
|
||||
void
|
||||
test_ptrv(
|
||||
test_ptrv_length(
|
||||
void)
|
||||
{
|
||||
static const gconstpointer ptrv0[] = { NULL };
|
||||
|
@ -501,6 +501,45 @@ test_ptrv(
|
|||
g_assert_cmpuint(gutil_ptrv_length(ptrv1), == ,1);
|
||||
}
|
||||
|
||||
/*==========================================================================*
|
||||
* ptrv_free
|
||||
*==========================================================================*/
|
||||
|
||||
static
|
||||
void
|
||||
test_ptrv_free(
|
||||
void)
|
||||
{
|
||||
void** ptrv0 = g_new0(void*, 1);
|
||||
void** ptrv1 = g_new0(void*, 2);
|
||||
|
||||
ptrv1[0] = g_new0(int, 1);
|
||||
gutil_ptrv_free(NULL);
|
||||
gutil_ptrv_free(ptrv0);
|
||||
gutil_ptrv_free(ptrv1);
|
||||
}
|
||||
|
||||
/*==========================================================================*
|
||||
* memdup
|
||||
*==========================================================================*/
|
||||
|
||||
static
|
||||
void
|
||||
test_memdup(
|
||||
void)
|
||||
{
|
||||
static const guint8 data[] = { 0x01, 0x02, 0x03 };
|
||||
void* copy = gutil_memdup(data, sizeof(data));
|
||||
|
||||
g_assert(copy);
|
||||
g_assert(!memcmp(copy, data, sizeof(data)));
|
||||
g_free(copy);
|
||||
|
||||
g_assert(!gutil_memdup(data, 0));
|
||||
g_assert(!gutil_memdup(NULL, 0));
|
||||
g_assert(!gutil_memdup(NULL, 1));
|
||||
}
|
||||
|
||||
/*==========================================================================*
|
||||
* Common
|
||||
*==========================================================================*/
|
||||
|
@ -530,7 +569,9 @@ int main(int argc, char* argv[])
|
|||
g_test_add_func(TEST_("bytes_concat"), test_bytes_concat);
|
||||
g_test_add_func(TEST_("bytes_xor"), test_bytes_xor);
|
||||
g_test_add_func(TEST_("bytes_equal"), test_bytes_equal);
|
||||
g_test_add_func(TEST_("ptrv"), test_ptrv);
|
||||
g_test_add_func(TEST_("ptrv_lenght"), test_ptrv_length);
|
||||
g_test_add_func(TEST_("ptrv_free"), test_ptrv_free);
|
||||
g_test_add_func(TEST_("memdup"), test_memdup);
|
||||
test_init(&test_opt, argc, argv);
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue