ref: d658e39bc35277b5405c1f64e6f373bf62de4ad6
parent: 12e6e4059651285cbc6df5c58e9ed43c81919b36
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jan 29 20:34:38 EST 2025
iostream: a bit of style
--- a/src/iostream.c
+++ b/src/iostream.c
@@ -152,9 +152,10 @@
{
argcount(nargs, 2);
ios_t *s = toiostream(args[0]);
- if(!iscprim(args[1]) || ((cprim_t*)ptr(args[1]))->type != FL(runetype))
+ cprim_t *cp = ptr(args[1]);
+ if(!iscprim(args[1]) || cp_class(cp) != FL(runetype))
type_error("rune", args[1]);
- Rune r = *(Rune*)cp_data(ptr(args[1]));
+ Rune r = *(Rune*)cp_data(cp);
return fixnum(ios_pututf8(s, r));
}
@@ -279,7 +280,9 @@
if(nargs < 2 || nargs > 4)
argcount(nargs, 2);
ios_t *s = toiostream(args[0]);
- if(iscprim(args[1]) && ((cprim_t*)ptr(args[1]))->type == FL(runetype)){
+ value_t v = args[1];
+ cprim_t *cp = ptr(v);
+ if(iscprim(args[1]) && cp_class(cp) == FL(runetype)){
if(nargs > 2)
lerrorf(FL_ArgError, "offset argument not supported for characters");
Rune r = *(Rune*)cp_data(ptr(args[1]));
@@ -287,10 +290,10 @@
}
uint8_t *data;
size_t sz, offs = 0;
- to_sized_ptr(args[1], &data, &sz);
+ to_sized_ptr(v, &data, &sz);
size_t nb = sz;
if(nargs > 2){
- get_start_count_args(&args[1], nargs-1, sz, &offs, &nb);
+ get_start_count_args(args+1, nargs-1, sz, &offs, &nb);
data += offs;
}
return size_wrap(ios_write(s, data, nb));