shithub: mc

Download patch

ref: f5a7e459867d990f4d9aa2d99706bd58676e5eca
parent: 91e0b9594c2852d446d238a1678231be4d1c13b5
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Aug 28 16:05:59 EDT 2020

copy bytes to a dest buffer.

--- a/lib/std/test/ipparse.myr
+++ b/lib/std/test/ipparse.myr
@@ -60,12 +60,13 @@
 }
 
 const eq = {ip, expected
+	var dst : byte[16]
 	var parsed
 	var p, e
 
 	parsed = std.ipparse(ip)
-	p = ipbytes(parsed)
-	e = ipbytes(expected)
+	p = ipbytes(dst[:], parsed)
+	e = ipbytes(dst[:], expected)
 	if !std.eq(p, e)
 		std.fput(1, "misparsed ip {}\n", ip)
 		std.put("parsed: ")
@@ -81,14 +82,19 @@
 	;;
 }
 
-const ipbytes = {ipopt
+const ipbytes = {dst, ipopt
 	match ipopt
+	| `std.None:
+		-> [][:]
 	| `std.Some ip:
 		match ip
-		| `std.Ipv4 b:	-> b[:]
-		| `std.Ipv6 b:	-> b[:]
+		| `std.Ipv4 b:
+			std.slcp(dst[:4], b[:])
+			-> dst[:4]
+		| `std.Ipv6 b:
+			std.slcp(dst[:16], b[:])
+			-> dst[:4]
 		;;
-	| `std.None:	-> [][:]
 	;;
 	-> [][:]
 }