aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/cxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-29 11:52:32 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-11-29 11:52:32 +0000
commitb01d5d5a5f6f8d272827f0b447971f0786fc30b7 (patch)
treeadb9d71d4b42bd6b36babe6610249846383690ff /src/libutil/cxx
parentb39a9f52ed3f33082f13f51678d053ee80a2e1f4 (diff)
downloadrspamd-b01d5d5a5f6f8d272827f0b447971f0786fc30b7.tar.gz
rspamd-b01d5d5a5f6f8d272827f0b447971f0786fc30b7.zip
[Minor] Various fixes
Diffstat (limited to 'src/libutil/cxx')
-rw-r--r--src/libutil/cxx/rspamd-simdutf.cxx37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/libutil/cxx/rspamd-simdutf.cxx b/src/libutil/cxx/rspamd-simdutf.cxx
index 67b585812..811403884 100644
--- a/src/libutil/cxx/rspamd-simdutf.cxx
+++ b/src/libutil/cxx/rspamd-simdutf.cxx
@@ -23,14 +23,36 @@
extern "C" {
+const simdutf::implementation *impl{nullptr};
+const simdutf::implementation *ref_impl{nullptr};
+
void rspamd_fast_utf8_library_init(unsigned flags)
{
- // This library requires no initialisation
+ impl = simdutf::get_active_implementation();
+ auto all_impls = simdutf::get_available_implementations();
+
+ for (auto &i: all_impls) {
+ if (i->name() == "fallback") {
+ ref_impl = i;
+ break;
+ }
+ }
}
off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len)
{
- auto res = simdutf::validate_utf8_with_errors((const char *) data, len);
+ auto res = impl->validate_utf8_with_errors((const char *) data, len);
+
+ if (res.error == simdutf::error_code::SUCCESS) {
+ return 0;
+ }
+
+ return res.count + 1;// We need to return offset for the first invalid character
+}
+
+off_t rspamd_fast_utf8_validate_ref(const unsigned char *data, size_t len)
+{
+ auto res = ref_impl->validate_utf8_with_errors((const char *) data, len);
if (res.error == simdutf::error_code::SUCCESS) {
return 0;
@@ -38,4 +60,15 @@ off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len)
return res.count + 1;// We need to return offset for the first invalid character
}
+
+const char *rspamd_fast_utf8_library_impl_name(void)
+{
+ static auto impl_name = std::string{};
+
+ if (impl_name.empty()) {
+ impl_name = impl->name() + "(" + impl->description() + ")";
+ }
+
+ return impl_name.c_str();
+}
} \ No newline at end of file