Skip to content

Commit 17da45e

Browse files
committed
adapt to changes in libyang 4.7
The regex handling has been changed, and the order of some built-in modules is now different. Change-Id: I2b790ad516254af20bb425accbeeea485b7d13d0
1 parent 44bcc35 commit 17da45e

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

.zuul.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
- f38-gcc-cover:
55
required-projects:
66
- name: github/CESNET/libyang
7-
override-checkout: cesnet/2026-01-16--before-pcre2
7+
override-checkout: devel
88
- name: github/doctest/doctest
99
override-checkout: v2.3.6
1010
- f38-clang-asan-ubsan:
1111
required-projects: &projects
1212
- name: github/CESNET/libyang
13-
override-checkout: cesnet/2026-01-16--before-pcre2
13+
override-checkout: devel
1414
- name: github/doctest/doctest
1515
override-checkout: v2.4.11
1616
- f38-clang-tsan:

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${D
2222
option(BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON)
2323

2424
find_package(PkgConfig REQUIRED)
25-
# FIXME: there's no version for this one...
26-
pkg_check_modules(LIBYANG REQUIRED libyang>=4.6.1 IMPORTED_TARGET)
25+
pkg_check_modules(LIBYANG REQUIRED libyang>=4.7.0 IMPORTED_TARGET)
2726

2827
# FIXME from gcc 14.1 on we should be able to use the calendar/time from libstdc++ and thus remove the date dependency
2928
find_package(date)
3029

31-
# libyang::Regex::~Regex() bypasses libyang and calls out to libpcre directly
32-
pkg_check_modules(LIBPCRE2 REQUIRED libpcre2-8 IMPORTED_TARGET)
33-
3430
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
3531

3632
include(CheckIncludeFileCXX)
@@ -61,7 +57,7 @@ add_library(yang-cpp
6157
src/utils/newPath.cpp
6258
)
6359

64-
target_link_libraries(yang-cpp PRIVATE PkgConfig::LIBYANG PkgConfig::LIBPCRE2)
60+
target_link_libraries(yang-cpp PRIVATE PkgConfig::LIBYANG)
6561
# We do not offer any long-term API/ABI guarantees. To make stuff easier for downstream consumers,
6662
# we will be bumping both API and ABI versions very deliberately.
6763
# There will be no attempts at semver tracking, for example.

src/Regex.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,28 @@
66
* SPDX-License-Identifier: BSD-3-Clause
77
*/
88

9-
// The following header MUST be included before anything else which "might" use PCRE2
10-
// because that library uses the preprocessor to prepare the "correct" versions of symbols.
11-
#include <libyang/tree_data.h>
12-
139
#include <libyang-cpp/Regex.hpp>
14-
#include <pcre2.h>
10+
#include <libyang/tree_data.h>
1511
#include "utils/exception.hpp"
1612

17-
#define THE_PCRE2_CODE_P reinterpret_cast<pcre2_code*>(this->code)
18-
#define THE_PCRE2_CODE_P_P reinterpret_cast<pcre2_code**>(&this->code)
19-
2013
namespace libyang {
2114

2215
Regex::Regex(const std::string& pattern)
2316
: code(nullptr)
2417
{
25-
auto res = ly_pattern_compile(nullptr, pattern.c_str(), THE_PCRE2_CODE_P_P);
18+
auto res = ly_pattern_compile(nullptr, pattern.c_str(), &code);
2619
throwIfError(res, ly_last_logmsg());
2720
}
2821

2922
Regex::~Regex()
3023
{
31-
pcre2_code_free(THE_PCRE2_CODE_P);
24+
ly_pattern_free(code);
25+
code = nullptr;
3226
}
3327

3428
bool Regex::matches(const std::string& input)
3529
{
36-
auto res = ly_pattern_match(nullptr, nullptr /* we have a precompiled pattern */, input.c_str(), input.size(), THE_PCRE2_CODE_P_P);
30+
auto res = ly_pattern_match(nullptr, nullptr /* we have a precompiled pattern */, input.c_str(), input.size(), &code);
3731
if (res == LY_SUCCESS) {
3832
return true;
3933
} else if (res == LY_ENOT) {

tests/context.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,16 @@ TEST_CASE("context")
372372
ctx->parseModule(valid_yang_model, libyang::SchemaFormat::YANG);
373373
auto modules = ctx->modules();
374374
REQUIRE(modules.size() == 9);
375-
REQUIRE(modules.at(0).name() == "ietf-yang-metadata");
376-
REQUIRE(modules.at(0).ns() == "urn:ietf:params:xml:ns:yang:ietf-yang-metadata");
377-
REQUIRE(modules.at(1).name() == "yang");
378-
REQUIRE(modules.at(1).ns() == "urn:ietf:params:xml:ns:yang:1");
379-
REQUIRE(modules.at(2).name() == "default");
380-
REQUIRE(modules.at(2).ns() == "urn:ietf:params:xml:ns:netconf:default:1.0");
381-
REQUIRE(modules.at(3).name() == "ietf-inet-types");
382-
REQUIRE(modules.at(3).ns() == "urn:ietf:params:xml:ns:yang:ietf-inet-types");
383-
REQUIRE(modules.at(4).name() == "ietf-yang-types");
384-
REQUIRE(modules.at(4).ns() == "urn:ietf:params:xml:ns:yang:ietf-yang-types");
375+
REQUIRE(modules.at(0).name() == "ietf-inet-types");
376+
REQUIRE(modules.at(0).ns() == "urn:ietf:params:xml:ns:yang:ietf-inet-types");
377+
REQUIRE(modules.at(1).name() == "ietf-yang-types");
378+
REQUIRE(modules.at(1).ns() == "urn:ietf:params:xml:ns:yang:ietf-yang-types");
379+
REQUIRE(modules.at(2).name() == "ietf-yang-metadata");
380+
REQUIRE(modules.at(2).ns() == "urn:ietf:params:xml:ns:yang:ietf-yang-metadata");
381+
REQUIRE(modules.at(3).name() == "yang");
382+
REQUIRE(modules.at(3).ns() == "urn:ietf:params:xml:ns:yang:1");
383+
REQUIRE(modules.at(4).name() == "default");
384+
REQUIRE(modules.at(4).ns() == "urn:ietf:params:xml:ns:netconf:default:1.0");
385385
REQUIRE(modules.at(5).name() == "ietf-yang-schema-mount");
386386
REQUIRE(modules.at(5).ns() == "urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount");
387387
REQUIRE(modules.at(6).name() == "ietf-yang-structure-ext");

0 commit comments

Comments
 (0)