summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--changelog.md8
-rw-r--r--include/u8c/u32free.h (renamed from include/u8c/freeu32.h)6
-rw-r--r--include/u8c/u8free.h (renamed from include/u8c/freeu8.h)6
-rw-r--r--include/u8c/ver.h2
-rw-r--r--src/u8c/end.c4
-rw-r--r--src/u8c/geterr.c7
-rw-r--r--src/u8c/init.c2
-rw-r--r--src/u8c/seterr.c4
-rw-r--r--src/u8c/vprint.c8
-rw-r--r--test.c12
11 files changed, 37 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index d5371fb..21590af 100644
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,6 @@ HDRS = \
include/u8c/end.h \
include/u8c/fmt.h \
include/u8c/fmttyp.h \
- include/u8c/freeu32.h \
- include/u8c/freeu8.h \
include/u8c/geterr.h \
include/u8c/init.h \
include/u8c/isalnum.h \
@@ -60,9 +58,11 @@ HDRS = \
include/u8c/txt.h \
include/u8c/u32cmp.h \
include/u8c/u32cp.h \
+ include/u8c/u32free.h \
include/u8c/u32sz.h \
include/u8c/u8dec.h \
include/u8c/u8enc.h \
+ include/u8c/u8free.h \
include/u8c/ver.h \
include/u8c/vfmt.h \
include/u8c/vprint.h
diff --git a/changelog.md b/changelog.md
index 77907fd..09135ac 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,9 @@
+# 14
+
+* Free error message when `u8c_geterr` is called (after copying, of course).
+* Update `u8c_freeu8`.
+* Rename `u8c_freeu32` to and `u8c_u32free` and `u8c_freeu8` to `u8c_u8free`.
+
# 13
* Fix `u8c_txt` in C++.
@@ -12,7 +18,7 @@
* Update Makefile.
* Use constant variables more.
* Create macro for creating human-readable UTF-32 strings; `u8c_txt`.
-* Add macros for deallocating UTF-32 and UTF-8 strings (use these instead of `free` og `std::free`); `u8c_freeu32` and `u8c_freeu8`.
+* Add macros for deallocating UTF-32 and UTF-8 strings (use these instead of `free` or `std::free`); `u8c_u32free` and `u8c_u8free`.
* Optimisations.
# 10
diff --git a/include/u8c/freeu32.h b/include/u8c/u32free.h
index 99ac8c2..8a12c97 100644
--- a/include/u8c/freeu32.h
+++ b/include/u8c/u32free.h
@@ -14,13 +14,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
/* Format */
-# if !defined(u8c_freeu32)
+# if !defined(u8c_u32free)
# if defined(__cplusplus)
# include <cstdlib>
-# define u8c_freeu32(u32) (std::free(const_cast<uint_least32_t *>(u32)))
+# define u8c_u32free(u32) (std::free(const_cast<uint_least32_t *>(u32)))
# else
# include <stdint.h>
# include <stdlib.h>
-# define u8c_freeu32(u32) (free((uint_least32_t *)u32))
+# define u8c_u32free(u32) (free((uint_least32_t *)u32))
# endif
# endif
diff --git a/include/u8c/freeu8.h b/include/u8c/u8free.h
index 7ae7abd..a1940da 100644
--- a/include/u8c/freeu8.h
+++ b/include/u8c/u8free.h
@@ -14,13 +14,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
/* Format */
-# if !defined(u8c_freeu8)
+# if !defined(u8c_u8free)
# if defined(__cplusplus)
# include <cstdlib>
-# define u8c_freeu8(u8) (std::free(u8))
+# define u8c_u8free(u8) (std::free(const_cast<std::uint_least8_t *>(u8)))
# else
# include <stdint.h>
# include <stdlib.h>
-# define u8c_freeu8(u8) (free((uint_least8_t *)u8))
+# define u8c_u8free(u8) (free((uint_least8_t *)u8))
# endif
# endif
diff --git a/include/u8c/ver.h b/include/u8c/ver.h
index edf91ed..c53bd70 100644
--- a/include/u8c/ver.h
+++ b/include/u8c/ver.h
@@ -16,5 +16,5 @@
/* Version */
# if !defined(u8c_ver)
# include <stdint.h>
-# define u8c_ver (UINT64_C(0xF))
+# define u8c_ver (UINT64_C(0x10))
# endif
diff --git a/src/u8c/end.c b/src/u8c/end.c
index 8cd243d..af9661c 100644
--- a/src/u8c/end.c
+++ b/src/u8c/end.c
@@ -19,7 +19,7 @@
# include <stdint.h>
# include <stdlib.h>
# include <u8c/end.h>
-# include <u8c/freeu32.h>
+# include <u8c/u32free.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
@@ -30,7 +30,7 @@ uint_least8_t u8c_end(void) {
# if defined(u8c_bethrdsafe)
mtx_destroy(&u8c_errlock);
# endif
- u8c_freeu32(u8c_err);
+ u8c_u32free(u8c_err);
u8c_stat = UINT8_C(0x1);
return UINT8_C(0x0);
}
diff --git a/src/u8c/geterr.c b/src/u8c/geterr.c
index d18f696..9f09327 100644
--- a/src/u8c/geterr.c
+++ b/src/u8c/geterr.c
@@ -18,12 +18,19 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/geterr.h>
+# include <u8c/seterr.h>
# include <u8c/u32cp.h>
+# include <u8c/u8free.h>
uint_least8_t u8c_geterr(size_t * const _sz,uint_least32_t const * * const _out) {
+ if(u8c_err == NULL) {
+ u8c_seterr((uint_least32_t[]){UINT32_C(0x0)});
+ }
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_errlock);
# endif
u8c_u32cp(_sz,_out,u8c_err);
+ u8c_u8free(u8c_err);
+ u8c_err = NULL;
# if defined(u8c_bethrdsafe)
mtx_unlock(&u8c_errlock);
# endif
diff --git a/src/u8c/init.c b/src/u8c/init.c
index e73272e..e13f15a 100644
--- a/src/u8c/init.c
+++ b/src/u8c/init.c
@@ -29,8 +29,6 @@ uint_least8_t u8c_init(void) {
return UINT8_C(0x2);
}
# endif
- /* Set default error message: */
- u8c_u32cp(NULL,&u8c_err,(uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x69),UINT32_C(0x74),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x44),UINT32_C(0x65),UINT32_C(0x66),UINT32_C(0x61),UINT32_C(0x75),UINT32_C(0x6C),UINT32_C(0x74),UINT32_C(0x20),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0x72),UINT32_C(0x6F),UINT32_C(0x72),UINT32_C(0x20),UINT32_C(0x6D),UINT32_C(0x65),UINT32_C(0x73),UINT32_C(0x73),UINT32_C(0x61),UINT32_C(0x67),UINT32_C(0x65),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_init: Default error message. */
/* Set status: */
u8c_stat = UINT8_C(0x0);
return UINT8_C(0x0);
diff --git a/src/u8c/seterr.c b/src/u8c/seterr.c
index 5796683..c500ff4 100644
--- a/src/u8c/seterr.c
+++ b/src/u8c/seterr.c
@@ -19,9 +19,9 @@
# include <stdint.h>
# include <stdlib.h>
# include <u8c/dbgprint.h>
-# include <u8c/freeu32.h>
# include <u8c/seterr.h>
# include <u8c/u32cp.h>
+# include <u8c/u32free.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
@@ -31,7 +31,7 @@ uint_least8_t u8c_seterr(uint_least32_t const * const _msg) {
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_errlock);
# endif
- u8c_freeu32(u8c_err);
+ u8c_u32free(u8c_err);
u8c_u32cp(NULL,&u8c_err,_msg);
# if defined(u8c_bethrdsafe)
mtx_unlock(&u8c_errlock);
diff --git a/src/u8c/vprint.c b/src/u8c/vprint.c
index 2e418ca..503ca88 100644
--- a/src/u8c/vprint.c
+++ b/src/u8c/vprint.c
@@ -18,10 +18,10 @@
# include <stdint.h>
# include <stdio.h>
# include <stdlib.h>
-# include <u8c/freeu32.h>
-# include <u8c/freeu8.h>
# include <u8c/seterr.h>
+# include <u8c/u32free.h>
# include <u8c/u8enc.h>
+# include <u8c/u8free.h>
# include <u8c/SIZE_C.h>
# include <u8c/vfmt.h>
# include <u8c/vprint.h>
@@ -37,7 +37,7 @@ uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t const * const _msg,va_list _a
u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x76),UINT32_C(0x70),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x66),UINT32_C(0x77),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x55),UINT32_C(0x6E),UINT32_C(0x61),UINT32_C(0x62),UINT32_C(0x6C),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x77),UINT32_C(0x72),UINT32_C(0x69),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x73),UINT32_C(0x74),UINT32_C(0x64),UINT32_C(0x6F),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_vprint: fwrite: Unable to write to stdout. */
return UINT8_C(0x1);
}
- u8c_freeu32(str0);
- u8c_freeu8(str1);
+ u8c_u32free(str0);
+ u8c_u8free(str1);
return UINT8_C(0x0);
}
diff --git a/test.c b/test.c
index f1ea154..ecd8c44 100644
--- a/test.c
+++ b/test.c
@@ -9,8 +9,6 @@
# include <u8c/end.h>
# include <u8c/fmt.h>
# include <u8c/fmttyp.h>
-# include <u8c/freeu32.h>
-# include <u8c/freeu8.h>
# include <u8c/geterr.h>
# include <u8c/init.h>
# include <u8c/isalnum.h>
@@ -26,9 +24,11 @@
# include <u8c/thrdsafe.h>
# include <u8c/u32cmp.h>
# include <u8c/u32cp.h>
+# include <u8c/u32free.h>
# include <u8c/u32sz.h>
# include <u8c/u8dec.h>
# include <u8c/u8enc.h>
+# include <u8c/u8free.h>
# include <u8c/ver.h>
# include <u8c/vfmt.h>
# include <u8c/vprint.h>
@@ -60,7 +60,7 @@ int main(void) {
uint_least32_t const * err = NULL;
errcount1 += u8c_geterr(NULL,&err);
errcount1 += u8c_println(stdout,err);
- u8c_freeu32(err);
+ u8c_u32free(err);
}
testmsgdone(&errcount0,&errcount1);
testmsg("UTF-8 encoding/decoding");
@@ -70,11 +70,11 @@ int main(void) {
errcount1 += u8c_u8enc(NULL,&msg1,msg0);
printf("Encoded: %s\n",msg1);
errcount1 += u8c_u8dec(NULL,&msg0,msg1);
- u8c_freeu8(msg1);
+ u8c_u8free(msg1);
errcount1 += u8c_u8enc(NULL,&msg1,msg0);
printf("Encoded -> Decoded -> Encoded: %s\n",msg1);
- u8c_freeu32(msg0);
- u8c_freeu8(msg1);
+ u8c_u32free(msg0);
+ u8c_u8free(msg1);
}
testmsgdone(&errcount0,&errcount1);
testmsg("Printing (u8c_print)");