summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/nativesockets.nim4
-rw-r--r--lib/pure/os.nim2
-rw-r--r--lib/system.nim15
-rw-r--r--lib/system/repr.nim6
4 files changed, 6 insertions, 21 deletions
diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim
index 7568408a6..a33836458 100644
--- a/lib/pure/nativesockets.nim
+++ b/lib/pure/nativesockets.nim
@@ -500,7 +500,7 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
     if inet_ntop(name.sin6_family.cint,
                  addr name, buf.cstring, sizeof(buf).int32).isNil:
       raiseOSError(osLastError())
-    result = ($buf, Port(nativesockets.ntohs(name.sin6_port)))
+    result = ($buf.cstring, Port(nativesockets.ntohs(name.sin6_port)))
   else:
     raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")
 
@@ -536,7 +536,7 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
     if inet_ntop(name.sin6_family.cint,
                  addr name, buf.cstring, sizeof(buf).int32).isNil:
       raiseOSError(osLastError())
-    result = ($buf, Port(nativesockets.ntohs(name.sin6_port)))
+    result = ($buf.cstring, Port(nativesockets.ntohs(name.sin6_port)))
   else:
     raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")
 
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 5211bc00c..a227e9f32 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1010,7 +1010,7 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
         while true:
           var x = readdir(d)
           if x == nil: break
-          var y = newString(x.d_name)
+          var y = $x.d_name.cstring
           if y != "." and y != "..":
             var s: Stat
             if not relative:
diff --git a/lib/system.nim b/lib/system.nim
index b5008129d..014538098 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1872,21 +1872,6 @@ proc `$` *[Enum: enum](x: Enum): string {.magic: "EnumToStr", noSideEffect.}
   ## a ``$`` operator for a concrete enumeration is provided, this is
   ## used instead. (In other words: *Overwriting* is possible.)
 
-proc newString*[N](data: array[N, char]): string {.noSideEffect.} =
-  ## Construct a string from an array of characters. The `data` is
-  ## expected to be a null terminated string as it is often used in C.
-  when nimvm:
-    # cannot cast on the vm
-    # not recommended to use this procedure on the vm at all, but at least it doesn't fail.
-    result = ""
-    for c in data:
-      if c == '\0':
-        return
-      else:
-        result.add c
-  else:
-    result = $(cast[cstring](data[0].unsafeAddr))
-
 # undocumented:
 proc getRefcount*[T](x: ref T): int {.importc: "getRefcount", noSideEffect.}
 proc getRefcount*(x: string): int {.importc: "getRefcount", noSideEffect.}
diff --git a/lib/system/repr.nim b/lib/system/repr.nim
index 2775b1b3e..172b4c08c 100644
--- a/lib/system/repr.nim
+++ b/lib/system/repr.nim
@@ -16,9 +16,9 @@ proc reprInt(x: int64): string {.compilerproc.} = return $x
 proc reprFloat(x: float): string {.compilerproc.} = return $x
 
 proc reprPointer(x: pointer): string {.compilerproc.} =
-  result = newString(60)
-  let newLen = c_sprintf(result[0].addr, "%p", x)
-  result.setLen newLen
+  var buf: array[60, char]
+  discard c_sprintf(result[0].addr, "%p", x)
+  result = $buf.cstring
 
 proc `$`(x: uint64): string =
   if x == 0: