changeset 296:2a0a88799737

A number of fixes and enhancmenets to "normal" bytearrays
author Michael Pavone <pavone@retrodev.com>
date Thu, 24 Jul 2014 23:52:37 -0700
parents 9a30510f6e52
children abe3141caefe
files modules/bytearray.tp
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/modules/bytearray.tp	Thu Jul 24 23:51:54 2014 -0700
+++ b/modules/bytearray.tp	Thu Jul 24 23:52:37 2014 -0700
@@ -7,14 +7,14 @@
 			llProperty: bytes withType: uint32_t
 			llProperty: buffer withType: (void ptr)
 			llMessage: _init_buf withVars: {
-				sz <_ obj_int32 ptr
+				sz <- obj_int32 ptr
 			} andCode: :sz {
 				bytes <- sz num
 				buffer <- GC_MALLOC_ATOMIC: bytes
 				self
 			}
 
-			llMessage: _buf_ptr withVArs: {
+			llMessage: _buf_ptr withVars: {
 				ptrret <- cpointer ptr
 			} andCode: {
 				ptrret <- make_object: (addr_of: cpointer_meta) NULL 0
@@ -46,7 +46,16 @@
 				ret
 			}
 
-			llMessage: stringFrom:to withVars:{
+			llMessage: shrinkTo withVars: {
+				newsize <- obj_int32 ptr
+			} andCode: :newsize {
+				if: (newsize num) < bytes {
+					bytes <- newsize num
+				}
+				self
+			}
+
+			llMessage: stringFrom:to withVars: {
 				from <- obj_int32 ptr
 				to <- obj_int32 ptr
 				str <- string ptr
@@ -56,20 +65,20 @@
 				str bytes!: (to num) - (from num)
 				str len!: (str bytes)
 				str data!: (GC_MALLOC_ATOMIC: (str bytes) + 1)
-				memcpy: (str data) buffer (str bytes)
+				memcpy: (str data) (buffer castTo: (uint8_t ptr)) + (from num) (str bytes)
 				(str data) set: (str bytes) 0
 				str
 			}
 
 			string <- {
-				stringFrom: 0 to:
+				stringFrom: 0 to: length
 			}
 
-			findChar:else <- :char found :else {
+			findChar:from:else <- :char :start found :else {
 				notfound <- true
 				n <- length
-				i <- 0
-				while: { notFound && i < n } do: {
+				i <- start
+				while: { notfound && i < n } do: {
 					if: (get: i) = char {
 						notfound <- false
 					} else: {