[tarantool-patches] [PATCH v2 07/12] sql: move LIKE UConverter object to collation library

Kirill Shcherbatov kshcherbatov at tarantool.org
Wed Jul 10 14:01:06 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 ae75a1c3c..21ce78c24 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -46,8 +46,6 @@
 #include <unicode/uchar.h>
 #include <unicode/ucol.h>
 
-static UConverter* pUtf8conv;
-
 /*
  * Return the collating function associated with a function.
  */
@@ -659,7 +657,8 @@ randomBlob(sql_context * context, int argc, sql_value ** argv)
 	}
 }
 
-#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
@@ -1732,14 +1731,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