diff options
author | Araq <rumpf_a@web.de> | 2019-09-20 20:22:37 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-09-21 06:43:37 +0200 |
commit | 5abe8804698f403ab9cd10f0d8f8ba92bc15b68c (patch) | |
tree | 03502f61bb63a22bb70216f06e6f22c97aa936f0 /lib | |
parent | 9776f926a22aa28075fdbaf2f5ef28c7fba15c02 (diff) | |
download | Nim-5abe8804698f403ab9cd10f0d8f8ba92bc15b68c.tar.gz |
last stdlib cleanups
Diffstat (limited to 'lib')
29 files changed, 110 insertions, 42 deletions
diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 259319ca2..25df59b63 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -7,6 +7,8 @@ # distribution, for details about the copyright. # +## Unstable API. + type AllocatorFlag* {.pure.} = enum ## flags describing the properties of the allocator ThreadLocal ## the allocator is thread local only. diff --git a/lib/core/hotcodereloading.nim b/lib/core/hotcodereloading.nim index 118e7f25c..7458b3996 100644 --- a/lib/core/hotcodereloading.nim +++ b/lib/core/hotcodereloading.nim @@ -1,3 +1,14 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2019 Nim contributors +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Unstable API. + when defined(hotcodereloading): import macros diff --git a/lib/pure/asyncftpclient.nim b/lib/pure/asyncftpclient.nim index 4c38e0b8c..489c4a842 100644 --- a/lib/pure/asyncftpclient.nim +++ b/lib/pure/asyncftpclient.nim @@ -321,7 +321,7 @@ proc getFile(ftp: AsyncFtpClient, file: File, total: BiggestInt, assertReply(await(ftp.expectReply()), "226") proc defaultOnProgressChanged*(total, progress: BiggestInt, - speed: float): Future[void] {.nimcall,gcsafe,procvar.} = + speed: float): Future[void] {.nimcall, gcsafe, procvar.} = ## Default FTP ``onProgressChanged`` handler. Does nothing. result = newFuture[void]() #echo(total, " ", progress, " ", speed) diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index 00660e56e..5b2d50dda 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -1,3 +1,12 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Dominik Picheta +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + import os, tables, strutils, times, heapqueue, options, deques, cstrutils # TODO: This shouldn't need to be included, but should ideally be exported. diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim index 4045609a4..876a3a40b 100644 --- a/lib/pure/asynchttpserver.nim +++ b/lib/pure/asynchttpserver.nim @@ -296,7 +296,7 @@ proc processClient(server: AsyncHttpServer, client: AsyncSocket, address: string if not retry: break proc serve*(server: AsyncHttpServer, port: Port, - callback: proc (request: Request): Future[void] {.closure,gcsafe.}, + callback: proc (request: Request): Future[void] {.closure, gcsafe.}, address = "") {.async.} = ## Starts the process of listening for incoming HTTP connections on the ## specified address and port. diff --git a/lib/pure/asyncstreams.nim b/lib/pure/asyncstreams.nim index 923bfe96e..573663f55 100644 --- a/lib/pure/asyncstreams.nim +++ b/lib/pure/asyncstreams.nim @@ -1,3 +1,14 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Dominik Picheta +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Unstable API. + import asyncfutures import deques diff --git a/lib/pure/base64.nim b/lib/pure/base64.nim index ee5388a24..a8c490d4d 100644 --- a/lib/pure/base64.nim +++ b/lib/pure/base64.nim @@ -9,6 +9,8 @@ ## This module implements a base64 encoder and decoder. ## +## Unstable API. +## ## Base64 is an encoding and decoding technique used to convert binary ## data to an ASCII string format. ## Each Base64 digit represents exactly 6 bits of data. Three 8-bit @@ -110,7 +112,7 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped = #assert(r == result.len) discard -proc encode*[T:SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string = +proc encode*[T: SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string = ## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a ## ``newline`` is added. ## diff --git a/lib/pure/browsers.nim b/lib/pure/browsers.nim index 6912b893c..cdac60d6e 100644 --- a/lib/pure/browsers.nim +++ b/lib/pure/browsers.nim @@ -9,6 +9,8 @@ ## This module implements a simple proc for opening URLs with the user's ## default browser. +## +## Unstable API. import strutils @@ -22,8 +24,10 @@ proc openDefaultBrowser*(url: string) = ## ## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open`` ## command is used. Under Unix, it is checked if ``xdg-open`` exists and - ## used if it does. Otherwise the environment variable ``BROWSER`` is + ## used if it does. Otherwise the environment variable ``BROWSER`` is ## used to determine the default browser to use. + ## + ## This proc doesn't raise an exception on error, beware. when defined(windows): var o = newWideCString("open") var u = newWideCString(url) diff --git a/lib/pure/collections/rtarrays.nim b/lib/pure/collections/rtarrays.nim index fbaf30fd3..3c3ffda7c 100644 --- a/lib/pure/collections/rtarrays.nim +++ b/lib/pure/collections/rtarrays.nim @@ -10,6 +10,8 @@ ## Module that implements a fixed length array whose size ## is determined at runtime. Note: This is not ready for other people to use! +## +## Unstable API. const ArrayPartSize = 10 diff --git a/lib/pure/collections/sharedlist.nim b/lib/pure/collections/sharedlist.nim index f5da6b14a..f9182acce 100644 --- a/lib/pure/collections/sharedlist.nim +++ b/lib/pure/collections/sharedlist.nim @@ -8,6 +8,8 @@ # ## Shared list support. +## +## Unstable API. {.push stackTrace: off.} diff --git a/lib/pure/collections/sharedtables.nim b/lib/pure/collections/sharedtables.nim index 185be88fa..1a6148752 100644 --- a/lib/pure/collections/sharedtables.nim +++ b/lib/pure/collections/sharedtables.nim @@ -11,6 +11,8 @@ ## you'll be in trouble. Uses a single lock to protect the table, lockfree ## implementations welcome but if lock contention is so high that you need a ## lockfree hash table, you're doing it wrong. +## +## Unstable API. import hashes, math, locks diff --git a/lib/pure/concurrency/atomics.nim b/lib/pure/concurrency/atomics.nim index b9d45681e..32c37236f 100644 --- a/lib/pure/concurrency/atomics.nim +++ b/lib/pure/concurrency/atomics.nim @@ -8,6 +8,8 @@ # ## Types and operations for atomic operations and lockless algorithms. +## +## Unstable API. import macros @@ -18,7 +20,7 @@ when defined(cpp) or defined(nimdoc): type MemoryOrder* {.importcpp: "std::memory_order".} = enum - ## Specifies how non-atomic operations can be reordered around atomic + ## Specifies how non-atomic operations can be reordered around atomic ## operations. moRelaxed @@ -131,7 +133,7 @@ else: # Since MSVC does not implement C11, we fall back to MS intrinsics # where available. - type + type Trivial = SomeNumber | bool | ptr | pointer # A type that is known to be atomic and whose size is known at # compile time to be 8 bytes or less @@ -144,7 +146,7 @@ else: elif sizeof(T) == 8: int64 when defined(vcc): - + # TODO: Trivial types should be volatile and use VC's special volatile # semantics for store and loads. @@ -231,7 +233,7 @@ else: cast[T](interlockedOr(addr(location.value), cast[nonAtomicType(T)](value))) proc fetchXor*[T: SomeInteger](location: var Atomic[T]; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = cast[T](interlockedXor(addr(location.value), cast[nonAtomicType(T)](value))) - + else: {.push, header: "<stdatomic.h>".} @@ -275,22 +277,22 @@ else: proc atomic_exchange_explicit[T, A](location: ptr A; desired: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} proc atomic_compare_exchange_strong_explicit[T, A](location: ptr A; expected: ptr T; desired: T; success, failure: MemoryOrder): bool {.importc.} proc atomic_compare_exchange_weak_explicit[T, A](location: ptr A; expected: ptr T; desired: T; success, failure: MemoryOrder): bool {.importc.} - + # Numerical operations proc atomic_fetch_add_explicit[T, A](location: ptr A; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} proc atomic_fetch_sub_explicit[T, A](location: ptr A; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} proc atomic_fetch_and_explicit[T, A](location: ptr A; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} proc atomic_fetch_or_explicit[T, A](location: ptr A; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} proc atomic_fetch_xor_explicit[T, A](location: ptr A; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.importc.} - + # Flag operations # var ATOMIC_FLAG_INIT {.importc, nodecl.}: AtomicFlag # proc init*(location: var AtomicFlag) {.inline.} = location = ATOMIC_FLAG_INIT proc testAndSet*(location: var AtomicFlag; order: MemoryOrder = moSequentiallyConsistent): bool {.importc: "atomic_flag_test_and_set_explicit".} proc clear*(location: var AtomicFlag; order: MemoryOrder = moSequentiallyConsistent) {.importc: "atomic_flag_clear_explicit".} - + proc fence*(order: MemoryOrder) {.importc: "atomic_thread_fence".} - proc signalFence*(order: MemoryOrder) {.importc: "atomic_signal_fence".} + proc signalFence*(order: MemoryOrder) {.importc: "atomic_signal_fence".} {.pop.} @@ -309,7 +311,7 @@ else: atomic_compare_exchange_weak_explicit(addr(location.value), cast[ptr nonAtomicType(T)](addr(expected)), cast[nonAtomicType(T)](desired), success, failure) proc compareExchangeWeak*[T: Trivial](location: var Atomic[T]; expected: var T; desired: T; order: MemoryOrder = moSequentiallyConsistent): bool {.inline.} = compareExchangeWeak(location, expected, desired, order, order) - + # Numerical operations proc fetchAdd*[T: SomeInteger](location: var Atomic[T]; value: T; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = cast[T](atomic_fetch_add_explicit(addr(location.value), cast[nonAtomicType(T)](value), order)) @@ -327,11 +329,11 @@ else: body location.guard.clear(moRelease) - proc load*[T: not Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = + proc load*[T: not Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = withLock(location, order): result = location.nonAtomicValue - proc store*[T: not Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} = + proc store*[T: not Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} = withLock(location, order): location.nonAtomicValue = desired @@ -375,4 +377,3 @@ proc `+=`*[T: SomeInteger](location: var Atomic[T]; value: T) {.inline.} = proc `-=`*[T: SomeInteger](location: var Atomic[T]; value: T) {.inline.} = ## Atomically decrements the atomic integer by some `value`. discard location.fetchSub(value) - \ No newline at end of file diff --git a/lib/pure/concurrency/cpuload.nim b/lib/pure/concurrency/cpuload.nim index 78a95681d..3ee7336f0 100644 --- a/lib/pure/concurrency/cpuload.nim +++ b/lib/pure/concurrency/cpuload.nim @@ -9,6 +9,8 @@ ## This module implements a helper for a thread pool to determine whether ## creating a thread is a good idea. +## +## Unstable API. when defined(windows): import winlean, os, strutils, math diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index 3ade6b4f2..b0fc33f07 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -14,6 +14,8 @@ ## * `channels module <channels.html>`_ ## * `locks module <locks.html>`_ ## * `asyncdispatch module <asyncdispatch.html>`_ +## +## Unstable API. when not compileOption("threads"): {.error: "Threadpool requires --threads:on option.".} diff --git a/lib/pure/coro.nim b/lib/pure/coro.nim index 4b446f44c..2a58554e3 100644 --- a/lib/pure/coro.nim +++ b/lib/pure/coro.nim @@ -6,6 +6,7 @@ # See the file "copying.txt", included in this # distribution, for details about the copyright. # + ## Nim coroutines implementation, supports several context switching methods: ## -------- ------------ ## ucontext available on unix and alike (default) @@ -17,6 +18,8 @@ ## -d:nimCoroutinesUcontext Use ucontext backend. ## -d:nimCoroutinesSetjmp Use setjmp backend. ## -d:nimCoroutinesSetjmpBundled Use bundled setjmp implementation. +## +## Unstable API. when not nimCoroutines and not defined(nimdoc): when defined(noNimCoroutines): diff --git a/lib/pure/endians.nim b/lib/pure/endians.nim index 54ec308f1..3ec0fe38c 100644 --- a/lib/pure/endians.nim +++ b/lib/pure/endians.nim @@ -9,6 +9,8 @@ ## This module contains helpers that deal with different byte orders ## (`endian`:idx:). +## +## Unstable API. when defined(gcc) or defined(llvm_gcc) or defined(clang): const useBuiltinSwap = true diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index e51ad86f4..d013c6342 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -7,8 +7,8 @@ # distribution, for details about the copyright. # -## This module parses an HTML document and creates its XML tree representation. -## It is supposed to handle the *wild* HTML the real world uses. +## **NOTE**: The behaviour might change in future versions as it is not +## clear what "*wild* HTML the real world uses" really implies. ## ## It can be used to parse a wild HTML document and output it as valid XHTML ## document (well, if you are lucky): diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index 94d1340b5..9397deb34 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -9,6 +9,8 @@ ## Contains functionality shared between the ``httpclient`` and ## ``asynchttpserver`` modules. +## +## Unstable API. import tables, strutils, parseutils diff --git a/lib/pure/lenientops.nim b/lib/pure/lenientops.nim index cc7784c19..c70e12e5f 100644 --- a/lib/pure/lenientops.nim +++ b/lib/pure/lenientops.nim @@ -57,4 +57,4 @@ proc `<=`*[I: SomeInteger, F: SomeFloat](f: F, i: I): bool {.noSideEffect, inlin # Note that we must not defined `>=` and `>`, because system.nim already has a # template with signature (x, y: untyped): untyped, which would lead to -# ambigous calls. +# ambiguous calls. diff --git a/lib/pure/parsesql.nim b/lib/pure/parsesql.nim index 8cc0ffedf..0b4249d2a 100644 --- a/lib/pure/parsesql.nim +++ b/lib/pure/parsesql.nim @@ -9,6 +9,8 @@ ## The ``parsesql`` module implements a high performance SQL file ## parser. It parses PostgreSQL syntax and the SQL ANSI standard. +## +## Unstable API. import strutils, lexbase diff --git a/lib/pure/pathnorm.nim b/lib/pure/pathnorm.nim index a067fbbed..00b3ebc0a 100644 --- a/lib/pure/pathnorm.nim +++ b/lib/pure/pathnorm.nim @@ -8,8 +8,9 @@ # ## OS-Path normalization. Used by ``os.nim`` but also -## generally useful for dealing with paths. Note that this module -## does not provide a stable API. +## generally useful for dealing with paths. +## +## Unstable API. # Yes, this uses import here, not include so that # we don't end up exporting these symbols from pathnorm and os: diff --git a/lib/pure/punycode.nim b/lib/pure/punycode.nim index ab6501ed1..9a0c744c4 100644 --- a/lib/pure/punycode.nim +++ b/lib/pure/punycode.nim @@ -7,6 +7,9 @@ # distribution, for details about the copyright. # +## Implements a representation of Unicode with the limited +## ASCII character subset. + import strutils import unicode @@ -23,7 +26,7 @@ const Delimiter = '-' type - PunyError* = object of Exception + PunyError* = object of ValueError proc decodeDigit(x: char): int {.raises: [PunyError].} = if '0' <= x and x <= '9': diff --git a/lib/pure/rationals.nim b/lib/pure/rationals.nim index 3946cf85b..76891a830 100644 --- a/lib/pure/rationals.nim +++ b/lib/pure/rationals.nim @@ -18,7 +18,7 @@ type Rational*[T] = object ## a rational number, consisting of a numerator and denominator num*, den*: T -proc initRational*[T:SomeInteger](num, den: T): Rational[T] = +proc initRational*[T: SomeInteger](num, den: T): Rational[T] = ## Create a new rational number. assert(den != 0, "a denominator of zero value is invalid") result.num = num @@ -34,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string = ## Turn a rational number into a string. result = $x.num & "/" & $x.den -proc toRational*[T:SomeInteger](x: T): Rational[T] = +proc toRational*[T: SomeInteger](x: T): Rational[T] = ## Convert some integer `x` to a rational number. result.num = x result.den = 1 @@ -82,7 +82,7 @@ proc toInt*[T](x: Rational[T]): int = ## `x` does not contain an integer value. x.num div x.den -proc reduce*[T:SomeInteger](x: var Rational[T]) = +proc reduce*[T: SomeInteger](x: var Rational[T]) = ## Reduce rational `x`. let common = gcd(x.num, x.den) if x.den > 0: @@ -288,20 +288,20 @@ when isMainModule: m1 = -1 // 1 tt = 10 // 2 - assert( a == a ) + assert( a == a ) assert( (a-a) == z ) assert( (a+b) == o ) assert( (a/b) == o ) assert( (a*b) == 1 // 4 ) assert( (3/a) == 6 // 1 ) assert( (a/3) == 1 // 6 ) - assert( a*b == 1 // 4 ) - assert( tt*z == z ) - assert( 10*a == tt ) - assert( a*10 == tt ) + assert( a*b == 1 // 4 ) + assert( tt*z == z ) + assert( 10*a == tt ) + assert( a*10 == tt ) assert( tt/10 == a ) - assert( a-m1 == 3 // 2 ) - assert( a+m1 == -1 // 2 ) + assert( a-m1 == 3 // 2 ) + assert( a+m1 == -1 // 2 ) assert( m1+tt == 16 // 4 ) assert( m1-tt == 6 // -1 ) diff --git a/lib/pure/reservedmem.nim b/lib/pure/reservedmem.nim index 41fcf68ea..cb1d4e06a 100644 --- a/lib/pure/reservedmem.nim +++ b/lib/pure/reservedmem.nim @@ -15,6 +15,8 @@ ## is guaranteed to remain in the same memory location. The buffer ## will be able to grow up to the size of the initially reserved ## portion of the address space. +## +## Unstable API. from ospaths import raiseOSError, osLastError diff --git a/lib/pure/segfaults.nim b/lib/pure/segfaults.nim index 6b10e4822..27572b6ff 100644 --- a/lib/pure/segfaults.nim +++ b/lib/pure/segfaults.nim @@ -13,6 +13,8 @@ ## ## Tested on these OSes: Linux, Windows, OSX +{.used.} + # do allocate memory upfront: var se: ref NilAccessError new(se) diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index 0f257b90b..24aed52b0 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -9,6 +9,8 @@ ## This module defines compile-time reflection procs for ## working with types. +## +## Unstable API. export system.`$` # for backward compatibility diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index 469e75c16..46d63db8b 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -9,6 +9,11 @@ ## :Author: Zahary Karadjov ## +## **Note**: Instead of ``unittest.nim``, please consider to use +## the ``testament`` tool which offers process isolation for your tests. +## Also ``when isMainModule: doAssert conditionHere`` is usually a +## much simpler solution for testing purposes. +## ## This module implements boilerplate to make unit testing easy. ## ## The test status and name is printed after any output or traceback. @@ -306,7 +311,7 @@ method testEnded*(formatter: JUnitOutputFormatter, testResult: TestResult) = let time = epochTime() - formatter.testStartTime let timeStr = time.formatFloat(ffDecimal, precision = 8) formatter.stream.writeLine("\t\t<testcase name=\"$#\" time=\"$#\">" % [xmlEscape(testResult.testName), timeStr]) - case testResult.status: + case testResult.status of OK: discard of SKIPPED: diff --git a/lib/std/varints.nim b/lib/std/varints.nim index 483d5c96c..4d0ff3c2c 100644 --- a/lib/std/varints.nim +++ b/lib/std/varints.nim @@ -7,8 +7,10 @@ # distribution, for details about the copyright. # -## Note this API is still experimental! A variable length integer +## A variable length integer ## encoding implementation inspired by SQLite. +## +## Unstable API. const maxVarIntLen* = 9 ## the maximal number of bytes a varint can take diff --git a/lib/system/inclrtl.nim b/lib/system/inclrtl.nim index 3caeefcbc..4193f2bdd 100644 --- a/lib/system/inclrtl.nim +++ b/lib/system/inclrtl.nim @@ -44,15 +44,7 @@ else: {.pragma: inl, inline.} {.pragma: compilerRtl, compilerproc.} -when not defined(nimsuperops): - {.pragma: operator.} - when defined(nimlocks): {.pragma: benign, gcsafe, locks: 0.} else: {.pragma: benign, gcsafe.} - -when defined(nimTableGet): - {.pragma: deprecatedGet, deprecated.} -else: - {.pragma: deprecatedGet.} |