SgObject Sg_ByteVectorCopy(SgByteVector *src, int start, int end) { SgByteVector *dst; int len = SG_BVECTOR_SIZE(src); SG_CHECK_START_END(start, end, len); dst = make_bytevector(end - start); memcpy(SG_BVECTOR_ELEMENTS(dst), SG_BVECTOR_ELEMENTS(src) + start, (end-start) * sizeof(uint8_t)); return SG_OBJ(dst); }
SgObject Sg_MakeByteVector(int size, int fill) { SgByteVector *b; size_t i; if (!(SG_IS_BYTE(fill) || SG_IS_OCTET(fill))) { /* out of range */ Sg_Error(UC("fill must be between -128 and 255, but got %d"), fill); } b = make_bytevector(size); for (i = 0; i < size; i++) { b->elements[i] = fill; } return SG_OBJ(b); }
/* Build a vector from a list. XXX move this to obj_bytevec.c. */ static obj_t *build_bytevec(obj_t *list) { PUSH_ROOT(list); obj_t *p = list; size_t i, size = 0; while (!is_null(p)) { size++; p = pair_cdr(p); } AUTO_ROOT(bvec, make_bytevector(size, 0)); for (i = 0, p = list; i < size; i++) { bytevector_set(bvec, i, fixnum_value(pair_car(p))); p = pair_cdr(p); } POP_FUNCTION_ROOTS(); return bvec; }