summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-15 06:16:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-15 06:16:23 -0700
commitac14e0f1adeb637cf7c393b42f50bf0cab6dc756 (patch)
treefa9a7eb953d5d20b2bea6ef7cd28232889104657
parent657c6fedce9c743e46badcc4457a1fbaa8901d7e (diff)
downloadtxr-ac14e0f1adeb637cf7c393b42f50bf0cab6dc756.tar.gz
txr-ac14e0f1adeb637cf7c393b42f50bf0cab6dc756.tar.bz2
txr-ac14e0f1adeb637cf7c393b42f50bf0cab6dc756.zip
ffi and utf8: C++ fixes.
* ffi.c (ffi_varray_alloc, ffi_char_array_put): Use cnum type consistently to avoid signed/unsigned comparison warning from g++. (ffi_closure_dispatch_safe): Put block of code into a braced statement so that the macro-generated switch case branch isn't crossing the initialization of a variable. Also, convert cast added where we are passing a void * to a mem_* parameter. * utf8.c (utf8_dup_from): Fix coerce macros being used to strip qualifiers, not only convert type.
-rw-r--r--ffi.c54
-rw-r--r--utf8.c4
2 files changed, 30 insertions, 28 deletions
diff --git a/ffi.c b/ffi.c
index 1fef6402..71f095df 100644
--- a/ffi.c
+++ b/ffi.c
@@ -247,10 +247,10 @@ static mem_t *ffi_fixed_alloc(struct txr_ffi_type *tft, val obj, val self)
static mem_t *ffi_varray_alloc(struct txr_ffi_type *tft, val obj, val self)
{
- ucnum len = c_unum(length(obj));
+ cnum len = c_num(length(obj));
val eltype = tft->mtypes;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
- size_t size = etft->size * len;
+ cnum size = etft->size * len;
if (size < len || size < tft->size)
uw_throwf(error_s, lit("~a: array size overflow"), self, nao);
return chk_malloc(size);
@@ -1031,7 +1031,7 @@ static void ffi_char_array_put(struct txr_ffi_type *tft, val str, mem_t *dst,
{
int nt = tft->null_term;
const wchar_t *wstr = c_str(str);
- size_t needed = utf8_to_buf(0, wstr, nt);
+ cnum needed = utf8_to_buf(0, wstr, nt);
if (needed <= nelem) {
utf8_to_buf(dst, wstr, nt);
@@ -2041,34 +2041,36 @@ static void ffi_closure_dispatch_safe(ffi_cif *cif, void *cret,
uw_simple_catch_begin;
- args_decl(args, tfcl->nparam);
- args_decl(args_cp, tfcl->nparam);
- rtft = ffi_type_struct(rtype);
-
- for (i = 0; i < nargs; i++) {
- val type = pop(&types);
- struct txr_ffi_type *mtft = ffi_type_struct(type);
- val arg = mtft->get(mtft, convert(mem_t *, cargs[i]), self);
- args_add(args, arg);
- if (mtft->out != 0)
- out_pass_needed = 1;
- }
-
- args_copy(args_cp, args);
-
- retval = generic_funcall(tfcl->fun, args);
+ {
+ args_decl(args, tfcl->nparam);
+ args_decl(args_cp, tfcl->nparam);
+ rtft = ffi_type_struct(rtype);
- if (out_pass_needed) {
- for (types = tfcd->argtypes, i = 0; i < nargs; i++) {
+ for (i = 0; i < nargs; i++) {
val type = pop(&types);
- val arg = args_at(args_cp, i);
struct txr_ffi_type *mtft = ffi_type_struct(type);
+ val arg = mtft->get(mtft, convert(mem_t *, cargs[i]), self);
+ args_add(args, arg);
if (mtft->out != 0)
- mtft->out(mtft, 0, arg, convert(mem_t *, cargs[i]), self);
+ out_pass_needed = 1;
}
- }
- rtft->put(rtft, retval, convert(mem_t *, cret), self);
+ args_copy(args_cp, args);
+
+ retval = generic_funcall(tfcl->fun, args);
+
+ if (out_pass_needed) {
+ for (types = tfcd->argtypes, i = 0; i < nargs; i++) {
+ val type = pop(&types);
+ val arg = args_at(args_cp, i);
+ struct txr_ffi_type *mtft = ffi_type_struct(type);
+ if (mtft->out != 0)
+ mtft->out(mtft, 0, arg, convert(mem_t *, cargs[i]), self);
+ }
+ }
+
+ rtft->put(rtft, retval, convert(mem_t *, cret), self);
+ }
uw_unwind {
s_exit_point = uw_curr_exit_point;
@@ -2076,7 +2078,7 @@ static void ffi_closure_dispatch_safe(ffi_cif *cif, void *cret,
if (!tfcl->abort_retval)
memset(cret, 0, rtft->size);
else
- rtft->put(rtft, tfcl->abort_retval, cret, self);
+ rtft->put(rtft, tfcl->abort_retval, convert(mem_t *, cret), self);
}
uw_curr_exit_point = 0; /* stops unwinding */
}
diff --git a/utf8.c b/utf8.c
index 37d4bf73..ecd3c01b 100644
--- a/utf8.c
+++ b/utf8.c
@@ -202,9 +202,9 @@ size_t utf8_to(char *dst, const wchar_t *wsrc)
wchar_t *utf8_dup_from(const char *str)
{
size_t len = strlen(str);
- size_t nchar = utf8_from_buf(0, coerce(unsigned char *, str), len);
+ size_t nchar = utf8_from_buf(0, coerce(const unsigned char *, str), len);
wchar_t *wstr = chk_wmalloc(nchar);
- utf8_from_buf(wstr, coerce(unsigned char *, str), len);
+ utf8_from_buf(wstr, coerce(const unsigned char *, str), len);
return wstr;
}