Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
31f7948cd4
!20 [sync] PR-19: cleanup spec
From: @openeuler-sync-bot 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2024-09-06 01:29:29 +00:00
Funda Wang
67fe7f30b1 cleanup spec
(cherry picked from commit 0d598e3cb2c9e8cd1d1e2f7f207101471400d8e4)
2024-09-05 18:07:44 +08:00
openeuler-ci-bot
e8f285962a
!16 [sync] PR-15: Add logic to handle memory allocation failures
From: @openeuler-sync-bot 
Reviewed-by: @hubin95 
Signed-off-by: @hubin95
2024-03-27 11:07:46 +00:00
gengqihu
e3c4a0156b Add logic to handle memory allocation failures
(cherry picked from commit a387b6c0d5169ff2061d73c0f0e44ef3ace69c72)
2024-03-27 18:48:55 +08:00
openeuler-ci-bot
19aea7c472
!10 【轻量级 PR】:Rebuild for next release
From: @dongyuzhen 
Reviewed-by: @xiezhipeng1 
Signed-off-by: @xiezhipeng1
2022-11-16 09:13:18 +00:00
dongyuzhen
06cbea0335
update for mass rebuild and upgrade verification 2022-10-29 03:30:29 +00:00
openeuler-ci-bot
d6c9a9e18d
!7 update to 1.7.3
Merge pull request !7 from wangchen/master
2022-01-18 06:57:57 +00:00
wangchen2020
865e394382 update to 1.7.3 2021-12-30 14:31:26 +08:00
openeuler-ci-bot
436efde7e6 !5 libconfig delete -Sgit from %autosetup, and delete BuildRequires git
From: @chenyanpanHW
Reviewed-by: @xiezhipeng1
Signed-off-by: @xiezhipeng1
2021-08-19 08:22:17 +00:00
chenyanpanHW
cbd2ef860d
delete -Sgit from %autosetup, and delete BuildRequires git 2021-07-30 22:58:13 +08:00
7 changed files with 3820 additions and 18 deletions

View File

@ -13,9 +13,9 @@ index c27b21c..ab03a75 100644
size_t capacity;
} strbuf_t;
-void strbuf_append_string(strbuf_t *buf, const char *s);
+__attribute__ ((visibility("hidden"))) void strbuf_append_string(strbuf_t *buf, const char *s);
-void libconfig_strbuf_append_string(strbuf_t *buf, const char *s);
+__attribute__ ((visibility("hidden"))) void libconfig_strbuf_append_string(strbuf_t *buf, const char *s);
void strbuf_append_char(strbuf_t *buf, char c);
void libconfig_strbuf_append_char(strbuf_t *buf, char c);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
From 92b5bba28f4497790e4111839ff0c45ed72a0b8a Mon Sep 17 00:00:00 2001
From: Mark Lindner <mark.a.lindner@gmail.com>
Date: Tue, 22 Nov 2022 14:40:08 -0700
Subject: [PATCH] Added unit test for config_read()
---
tests/tests.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tests/tests.c b/tests/tests.c
index 2b6d5e8..1637414 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -638,6 +638,32 @@ TT_TEST(SettingLookups)
/* ------------------------------------------------------------------------- */
+TT_TEST(ReadStream)
+{
+ config_t cfg;
+ int ok;
+ FILE *stream;
+
+ config_init(&cfg);
+ config_set_include_dir(&cfg, "./testdata");
+
+ stream = fopen("testdata/nesting.cfg", "rt");
+ TT_ASSERT_PTR_NOTNULL(stream);
+
+ ok = config_read(&cfg, stream);
+
+ fclose(stream);
+
+ if(!ok)
+ {
+ printf("error: %s:%d\n", config_error_text(&cfg),
+ config_error_line(&cfg));
+ }
+ TT_ASSERT_TRUE(ok);
+}
+
+/* ------------------------------------------------------------------------- */
+
int main(int argc, char **argv)
{
int failures;
@@ -657,6 +683,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST(LibConfigTests, EscapedStrings);
TT_SUITE_TEST(LibConfigTests, OverrideSetting);
TT_SUITE_TEST(LibConfigTests, SettingLookups);
+ TT_SUITE_TEST(LibConfigTests, ReadStream);
TT_SUITE_RUN(LibConfigTests);
failures = TT_SUITE_NUM_FAILURES(LibConfigTests);
TT_SUITE_END(LibConfigTests);
--
2.27.0

View File

@ -0,0 +1,281 @@
From 5ff6aecbdb7f85a8e7a2ea7fd63c03b4bdd42076 Mon Sep 17 00:00:00 2001
From: Mark Lindner <mark.a.lindner@gmail.com>
Date: Tue, 22 Nov 2022 14:10:16 -0700
Subject: [PATCH] Fixed various bugs in setting lookups by name/path.
---
lib/libconfig.c | 79 ++++++++++++++------------------
tests/testdata/nesting.cfg | 6 +++
tests/tests.c | 94 ++++++++++++++++++++++++++++++++++++++
3 files changed, 135 insertions(+), 44 deletions(-)
create mode 100644 tests/testdata/nesting.cfg
diff --git a/lib/libconfig.c b/lib/libconfig.c
index 1a935be..e25ed26 100644
--- a/lib/libconfig.c
+++ b/lib/libconfig.c
@@ -125,32 +125,6 @@ static void __config_locale_restore(void)
/* ------------------------------------------------------------------------- */
-static int __config_name_compare(const char *a, const char *b)
-{
- const char *p, *q;
-
- for(p = a, q = b; ; p++, q++)
- {
- int pd = ((! *p) || strchr(PATH_TOKENS, *p));
- int qd = ((! *q) || strchr(PATH_TOKENS, *q));
-
- if(pd && qd)
- break;
- else if(pd)
- return(-1);
- else if(qd)
- return(1);
- else if(*p < *q)
- return(-1);
- else if(*p > *q)
- return(1);
- }
-
- return(0);
-}
-
-/* ------------------------------------------------------------------------- */
-
static void __config_indent(FILE *stream, int depth, unsigned short w)
{
if(w)
@@ -385,8 +359,12 @@ static void __config_list_add(config_list_t *list, config_setting_t *setting)
/* ------------------------------------------------------------------------- */
+/* This function takes the length of the name to be searched for, so that one
+ * component of a longer path can be passed in.
+ */
static config_setting_t *__config_list_search(config_list_t *list,
const char *name,
+ size_t namelen,
unsigned int *idx)
{
config_setting_t **found = NULL;
@@ -400,7 +378,8 @@ static config_setting_t *__config_list_search(config_list_t *list,
if(! (*found)->name)
continue;
- if(! __config_name_compare(name, (*found)->name))
+ if((strlen((*found)->name) == namelen)
+ && !strncmp(name, (*found)->name, namelen))
{
if(idx)
*idx = i;
@@ -1226,27 +1205,37 @@ config_setting_t *config_setting_lookup(config_setting_t *setting,
const char *p = path;
config_setting_t *found = setting;
- for(;;)
+ while(*p && found)
{
- while(*p && strchr(PATH_TOKENS, *p))
- p++;
-
- if(! *p)
- break;
+ if(strchr(PATH_TOKENS, *p))
+ ++p;
if(*p == '[')
- found = config_setting_get_elem(found, atoi(++p));
- else
- found = config_setting_get_member(found, p);
+ {
+ char *q;
+ long index = strtol(++p, &q, 10);
+ if(*q != ']')
+ return NULL;
- if(! found)
- break;
+ p = ++q;
+ found = config_setting_get_elem(found, index);
+ }
+ else if(found->type == CONFIG_TYPE_GROUP)
+ {
+ const char *q = p;
- while(! strchr(PATH_TOKENS, *p))
- p++;
+ while(*q && !strchr(PATH_TOKENS, *q))
+ ++q;
+
+ found = __config_list_search(found->value.list, p, (size_t)(q - p),
+ NULL);
+ p = q;
+ }
+ else
+ break;
}
- return(*p || (found == setting) ? NULL : found);
+ return((*p || (found == setting)) ? NULL : found);
}
/* ------------------------------------------------------------------------- */
@@ -1565,7 +1554,7 @@ config_setting_t *config_setting_get_member(const config_setting_t *setting,
if(setting->type != CONFIG_TYPE_GROUP)
return(NULL);
- return(__config_list_search(setting->value.list, name, NULL));
+ return(__config_list_search(setting->value.list, name, strlen(name), NULL));
}
/* ------------------------------------------------------------------------- */
@@ -1676,9 +1665,11 @@ int config_setting_remove(config_setting_t *parent, const char *name)
break;
}
- }while(*++settingName);
+ }
+ while(*++settingName);
- if(!(setting = __config_list_search(setting->parent->value.list, settingName, &idx)))
+ if(!(setting = __config_list_search(setting->parent->value.list, settingName,
+ strlen(settingName), &idx)))
return(CONFIG_FALSE);
__config_list_remove(setting->parent->value.list, idx);
diff --git a/tests/testdata/nesting.cfg b/tests/testdata/nesting.cfg
new file mode 100644
index 0000000..3e37234
--- /dev/null
+++ b/tests/testdata/nesting.cfg
@@ -0,0 +1,6 @@
+
+foo = (
+ { string: "orange", number: 3, flag: false, array: [7, 13] },
+ { string: "blue", number: 11, flag: true, array: [1, 2, 3, 4] },
+ { string: "red", number: 7, flag: false, array: [77, 88] }
+)
diff --git a/tests/tests.c b/tests/tests.c
index 7d37655..2b6d5e8 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -482,6 +482,15 @@ TT_TEST(EscapedStrings)
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\"def\"", str);
+ ok = config_lookup_string(&cfg, "escape_seqs.dquote.[0]", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "escape_seqs.dquote.extrajunk", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "escape_seqs.dquote.", &str);
+ TT_ASSERT_TRUE(ok);
+
config_destroy(&cfg);
}
@@ -545,6 +554,90 @@ TT_TEST(OverrideSetting)
/* ------------------------------------------------------------------------- */
+TT_TEST(SettingLookups)
+{
+ config_t cfg;
+ int ok;
+ int ival;
+ const char *str;
+ config_setting_t *setting, *parent;
+
+ config_init(&cfg);
+ config_set_options(&cfg, CONFIG_OPTION_ALLOW_OVERRIDES);
+ config_set_include_dir(&cfg, "./testdata");
+
+ ok = config_read_file(&cfg, "testdata/nesting.cfg");
+ if(!ok)
+ {
+ printf("error: %s:%d\n", config_error_text(&cfg),
+ config_error_line(&cfg));
+ }
+ TT_ASSERT_TRUE(ok);
+
+ ok = config_lookup_string(&cfg, "foo.[0].string", &str);
+ TT_ASSERT_TRUE(ok);
+ TT_ASSERT_STR_EQ("orange", str);
+
+ ok = config_lookup_int(&cfg, "foo.[1].array.[3]", &ival);
+ TT_ASSERT_TRUE(ok);
+ TT_ASSERT_INT_EQ(4, ival);
+
+ ok = config_lookup_bool(&cfg, "foo.[1].flag", &ival);
+ TT_ASSERT_TRUE(ok);
+ TT_ASSERT_INT_EQ(CONFIG_TRUE, ival);
+
+ ok = config_lookup_int(&cfg, "foo.[2].number", &ival);
+ TT_ASSERT_TRUE(ok);
+ TT_ASSERT_INT_EQ(7, ival);
+
+ ok = config_lookup_string(&cfg, "foo.[0].string.blah", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "foo.[0].string.[0]", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "foo.[0].[1]", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "foo.[0].array.[0].blah", &str);
+ TT_ASSERT_FALSE(ok);
+
+ ok = config_lookup_string(&cfg, "[0]", &str);
+ TT_ASSERT_FALSE(ok);
+
+ setting = config_lookup(&cfg, "foo.[0].array.[0]");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ setting = config_lookup(&cfg, "foo.[0].array.[0");
+ TT_ASSERT_PTR_NULL(setting);
+
+ setting = config_lookup(&cfg, "/foo.[0].array.[0]");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ setting = config_lookup(&cfg, "/foo/[0]/array/[0]");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ parent = config_lookup(&cfg, ".foo");
+ TT_ASSERT_PTR_NOTNULL(parent);
+
+ setting = config_setting_lookup(parent, ".[0]");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ setting = config_setting_lookup(parent, ".[0].array");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ setting = config_setting_lookup(parent, ".[0].array.[1]");
+ TT_ASSERT_PTR_NOTNULL(setting);
+
+ setting = config_setting_lookup(parent, "[0].array.[1000]");
+ TT_ASSERT_PTR_NULL(setting);
+
+ setting = config_setting_lookup(parent, "[0].array.[0].blah");
+ TT_ASSERT_PTR_NULL(setting);
+}
+
+/* ------------------------------------------------------------------------- */
+
int main(int argc, char **argv)
{
int failures;
@@ -563,6 +656,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST(LibConfigTests, RemoveSetting);
TT_SUITE_TEST(LibConfigTests, EscapedStrings);
TT_SUITE_TEST(LibConfigTests, OverrideSetting);
+ TT_SUITE_TEST(LibConfigTests, SettingLookups);
TT_SUITE_RUN(LibConfigTests);
failures = TT_SUITE_NUM_FAILURES(LibConfigTests);
TT_SUITE_END(LibConfigTests);
--
2.27.0

BIN
libconfig-1.7.3.tar.gz Normal file

Binary file not shown.

View File

@ -1,17 +1,23 @@
Name: libconfig
Version: 1.7.2
Release: 9
Version: 1.7.3
Release: 4
Summary: C/C++ Configuration File Library
License: LGPLv2+
License: LGPL-2.1-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2
URL: http://www.hyperrealm.com/libconfig/libconfig.html
# This tarball comes from libconfig-1.7.2/docs/dist/libconfig-1.7.2.tar.gz
# in archive(https://github.com/hyperrealm/libconfig/archive/v1.7.2.tar.gz)
Source0: https://github.com/hyperrealm/libconfig/archive/v%{version}.tar.gz
Source0: https://github.com/hyperrealm/libconfig/releases/download/v%{version}/%{name}-%{version}.tar.gz
Source1: libconfig.pdf
Patch6000: backport-Add-logic-to-handle-memory-allocation-failures.patch
Patch6001: backport-Fixed-various-bugs-in-setting-lookups-by-name-path.patch
Patch6002: backport-Added-unit-test-for-config_read.patch
Patch9000: add-to-strbuf_append_string.patch
BuildRequires: git gcc gcc-c++ bison flex
BuildRequires: gcc gcc-c++ bison flex
BuildRequires: cmake-rpm-macros
BuildRequires: texinfo-tex tex(ecbx1095.tfm) tex(ecrm1095.tfm) tex(cm-super-t1.enc)
%description
@ -21,14 +27,14 @@ Libconfig is a simple library for processing structured configuration files.
Summary: Files for %{name} development
Requires: %{name} = %{version}-%{release}
Provides: libconfig-static
Obsoletes: libconfig-static
Provides: libconfig-static = %{version}-%{release}
Obsoletes: libconfig-static < %{version}-%{release}
%description devel
Files for %{name} development
%prep
%autosetup -n %{name}-%{version} -p1 -Sgit
%autosetup -n %{name}-%{version} -p1
cp %{SOURCE1} .
%build
@ -37,22 +43,18 @@ cp %{SOURCE1} .
%install
%make_install
%delete_la
rm -rf %{buildroot}%{_infodir}/dir
%check
make check
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%make_build check
%files
%defattr(-,root,root)
%doc AUTHORS ChangeLog README
%license COPYING.LIB
%{_libdir}/%{name}*.so.*
%files devel
%defattr(-,root,root)
%doc libconfig.pdf
%{_includedir}/%{name}*
%{_libdir}/cmake/%{name}*
@ -60,9 +62,32 @@ make check
%{_libdir}/pkgconfig/%{name}*.pc
%{_infodir}/libconfig.info*
%{_libdir}/*.a
%{_libdir}/*.la
%changelog
* Tue Sep 03 2024 Funda Wang <fundawang@yeah.net> - 1.7.3-4
- cleanup spec
* Wed Mar 27 2024 gengqihu <gengqihu2@h-partners.com> - 1.7.3-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Add logic to handle memory allocation failures
* Sat Oct 29 2022 dongyuzhen <dongyuzhen@h-partners.com> - 1.7.3-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Rebuild for next release
* Thu Dec 30 2021 wangchen<wangchen137@huawei.com> - 1.7.3-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update to 1.7.3
* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 1.7.2-10
- DESC: delete -Sgit from %autosetup, and delete BuildRequires git
* Tue Sep 8 2020 linwei<linwei54@huawei.com> - 1.7.2-9
- Type:enhancement
- ID:NA

Binary file not shown.