From 9266befd39cf3d64a35141ff97e224afab47d578 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sun, 1 Dec 2019 15:14:28 +0300 Subject: [PATCH 1/2] [R] Rewrote `mk_wcwidth` function --- ChangeLog.md | 1 + lib/fort.c | 14 +++++++++++--- src/wcwidth.c | 14 +++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index dfc14c3..8c4585a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,7 @@ - Fix compilation for compilers other than gcc, clang, msvc. - Add build with tcc to CI. +- Rewrote `mk_wcwidth` function. ## v0.3.1 diff --git a/lib/fort.c b/lib/fort.c index 1fefa4c..846e503 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -7180,8 +7180,8 @@ void vector_clear(f_vector_t *vector) struct interval { - wchar_t first; - wchar_t last; + int32_t first; + int32_t last; }; /* auxiliary function for binary search in interval table */ @@ -7237,7 +7237,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) * in ISO 10646. */ -static int mk_wcwidth(wchar_t ucs) +static int mk_wcwidth(wchar_t wcs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ @@ -7292,6 +7292,14 @@ static int mk_wcwidth(wchar_t ucs) { 0xE0100, 0xE01EF } }; + /* We convert wchar_t to int32_t to avoid compiler warnings + * about implicit integer conversions + * https://github.com/seleznevae/libfort/issues/20 + * + * note: didn't test if we can do it + */ + int32_t ucs = (int32_t)wcs; + /* test for 8-bit control characters */ if (ucs == 0) return 0; diff --git a/src/wcwidth.c b/src/wcwidth.c index f97b879..6bdf790 100644 --- a/src/wcwidth.c +++ b/src/wcwidth.c @@ -65,8 +65,8 @@ struct interval { - wchar_t first; - wchar_t last; + int32_t first; + int32_t last; }; /* auxiliary function for binary search in interval table */ @@ -122,7 +122,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) * in ISO 10646. */ -static int mk_wcwidth(wchar_t ucs) +static int mk_wcwidth(wchar_t wcs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ @@ -177,6 +177,14 @@ static int mk_wcwidth(wchar_t ucs) { 0xE0100, 0xE01EF } }; + /* We convert wchar_t to int32_t to avoid compiler warnings + * about implicit integer conversions + * https://github.com/seleznevae/libfort/issues/20 + * + * note: didn't test if we can do it + */ + int32_t ucs = (int32_t)wcs; + /* test for 8-bit control characters */ if (ucs == 0) return 0; From b9cd4ad8c51fc78c44465bcd04fa31248a56acbe Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sun, 1 Dec 2019 15:19:59 +0300 Subject: [PATCH 2/2] [F] Fix typo --- lib/fort.c | 2 +- src/wcwidth.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fort.c b/lib/fort.c index 846e503..3815b00 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -7185,7 +7185,7 @@ struct interval { }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) +static int bisearch(int32_t ucs, const struct interval *table, int max) { int min = 0; diff --git a/src/wcwidth.c b/src/wcwidth.c index 6bdf790..2e10ed0 100644 --- a/src/wcwidth.c +++ b/src/wcwidth.c @@ -70,7 +70,7 @@ struct interval { }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) +static int bisearch(int32_t ucs, const struct interval *table, int max) { int min = 0;