[PATCH v1 11/12] sql: move LIKE UConverter object to collation library
Kirill Shcherbatov
kshcherbatov at tarantool.org
Mon Jul 8 14:26:17 MSK 2019
Moved UConverter object to collation library. This is required
to get rid of sqlRegisterBuiltinFunctions function in further
patches.
Needed for #4113, #2200, #2233
---
src/box/sql/func.c | 13 ++-----------
src/lib/coll/coll.c | 7 ++++++-
src/lib/coll/coll.h | 2 ++
3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index e137f6999..6000b7971 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -48,8 +48,6 @@
#include <unicode/uchar.h>
#include <unicode/ucol.h>
-static UConverter* pUtf8conv;
-
/*
* Return the collating function associated with a function.
*/
@@ -787,7 +785,8 @@ sql_builtin_random_blob(struct func *func, struct port *args, struct port *ret)
return sqlVdbeMemSetStr(val, p, n, 0, SQL_DYNAMIC) != 0 ? -1 : 0;
}
-#define Utf8Read(s, e) ucnv_getNextUChar(pUtf8conv, &(s), (e), &status)
+#define Utf8Read(s, e) \
+ ucnv_getNextUChar(icu_utf8_conv, &(s), (e), &status)
#define SQL_END_OF_STRING 0xffff
#define SQL_INVALID_UTF8_SYMBOL 0xfffd
@@ -2054,14 +2053,6 @@ sql_is_like_func(struct sql *db, struct Expr *expr, int *is_like_ci)
void
sqlRegisterBuiltinFunctions(void)
{
- /*
- * Initialize default case map for UPPER/LOWER functions
- * This structure is not freed at db exit, but that is ok.
- */
- UErrorCode status = U_ZERO_ERROR;
-
- pUtf8conv = ucnv_open("utf8", &status);
- assert(pUtf8conv);
/*
* The following array holds FuncDef structures for all of the functions
* defined in this file.
diff --git a/src/lib/coll/coll.c b/src/lib/coll/coll.c
index 98e4d0e64..fa27bf34e 100644
--- a/src/lib/coll/coll.c
+++ b/src/lib/coll/coll.c
@@ -34,10 +34,12 @@
#include "diag.h"
#include "assoc.h"
#include <unicode/ucol.h>
+#include <unicode/ucnv.h>
#include <unicode/ucasemap.h>
#include "tt_static.h"
struct UCaseMap *icu_ucase_default_map = NULL;
+struct UConverter *icu_utf8_conv = NULL;
#define mh_name _coll
struct mh_coll_key_t {
@@ -420,7 +422,9 @@ coll_init()
UErrorCode err = U_ZERO_ERROR;
coll_cache = mh_coll_new();
icu_ucase_default_map = ucasemap_open("", 0, &err);
- if (coll_cache == NULL || icu_ucase_default_map == NULL)
+ icu_utf8_conv = ucnv_open("utf8", &err);
+ if (coll_cache == NULL || icu_ucase_default_map == NULL ||
+ icu_utf8_conv == NULL)
panic("Can not create system collations cache");
}
@@ -428,5 +432,6 @@ void
coll_free()
{
ucasemap_close(icu_ucase_default_map);
+ ucnv_close(icu_utf8_conv);
mh_coll_delete(coll_cache);
}
diff --git a/src/lib/coll/coll.h b/src/lib/coll/coll.h
index 1f5b29a2e..dc343539e 100644
--- a/src/lib/coll/coll.h
+++ b/src/lib/coll/coll.h
@@ -55,6 +55,8 @@ struct UCollator;
/** Default universal casemap for case transformations. */
extern struct UCaseMap *icu_ucase_default_map;
+/** Default universal utf8 converter. */
+extern struct UConverter *icu_utf8_conv;
/**
* Collation. It has no unique features like name, id or owner.
--
2.21.0
More information about the Tarantool-patches
mailing list