summary refs log tree commit diff stats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* Allocator: Track number of foreign cells a small chunk has access to (#23856)SirOlaf2024-07-201-29/+46
| | | | | | | | | Ref: https://github.com/nim-lang/Nim/issues/23788 There was a small leak in the above issue even after fixing the segfault. The sizes of `free` and `acc` were changed to 32bit because adding the `foreignCells` field will drastically increase the memory usage for programs that hold onto memory for a long time if they stay as 64bit.
* Add '.' (period, dot, ..) to `FormatLiterals` so that `ss.fff` can work. ↵c-blake2024-07-191-1/+1
| | | | | | | | | | | | | (#23861) Honestly, to me the entire design of a (highly!) restricted set of `FormatLiterals` characters seems antithetical to the very idea of a format string template. Fixing that is a much larger change, though. So, this PR just adds `'.'` so that the standard (both input & output!) notation for decimal numbers in Nim can be used for the seconds part of a time format in `lib/pure/times.format(.., f)`. It should only make legal what was illegal and should be harmless since `'.'` is not used in any special way otherwise.
* doc: times.nim: DD -> dd (#23857)lit2024-07-181-2/+2
| | | `YYYY-MM-dd` was mistaken as `YYYY-MM-DD`.
* fixes #23844; Nim devel nightly i386 build failing (#23849)ringabout2024-07-171-1/+1
| | | | | | | | | | | | fixes #23844 follow up https://github.com/nim-lang/Nim/pull/23834 ```nim type Timespec* {.importc: "struct timespec", header: "<time.h>", final, pure.} = object ## struct timespec tv_sec*: Time ## Seconds. tv_nsec*: clong ## Nanoseconds. ```
* Add warnings about exec usage. (#23820)Antonis Geralis2024-07-171-2/+9
| | | | | | | | | | | Related to https://github.com/nim-lang/Nim/issues/23819 and also found in discord https://discord.com/channels/371759389889003530/371759389889003532/1260845467147829372 Since nothing can be done, besides deprecating the function, a warning is a better option. --------- Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* Silence `hint:performance` message when using very basic http client (#23832)c-blake2024-07-151-1/+2
| | | | | | | | | | | | code such as: ```Nim import std/httpclient # nim c --hint:performance:on echo newHttpClient(proxy=nil, headers=newHttpHeaders({"Accept": "*/*"})).getContent("x") ``` (Fix was suggested by @ringabout in a private channel.) Seems useful since `httpclient` is so basic/probably pervasive with many hundreds of `import`s across the NimbleVerse.
* Use monotonic timestamp to calculate timeouts refs #23826 (#23834)Mark Leyva2024-07-151-10/+16
| | | | | | Related to #23826. This address issues raised [here](https://github.com/nim-lang/Nim/pull/23826#issuecomment-2226877361) by using a monotonic timestamp to calculate timeouts and increasing the max sleep time to 50ms.
* bump NimVersion to 2.1.9 (#23831)Miran2024-07-121-1/+1
| | | This is a 2.2 RC1.
* fixes #23825; Busy wait on waitid, sleeping at regular intervals (#23826)Mark Leyva2024-07-121-101/+42
| | | | | | | | | Addresses #23825 by using the approaching described in https://github.com/nim-lang/Nim/pull/23743#issuecomment-2199523110. This takes the approach from Python's `subprocess` library which calls `waitid` in loop, while sleeping at regular intervals. CC @alex65536
* deprecate `owner` from `std/macros` (#23828)ringabout2024-07-121-1/+1
|
* conditional compilation of gcd(SomeInteger,SomeInteger) in std/math (#23773)quimt2024-07-091-34/+37
| | | | | | | | | | | The most specific version of `gcd(int,int)` in `std/math` uses bitwise comparisons from C compilers, which can't be borrowed on the js platform in the web browser. Conditional compilation here should fix the issue for this and downstream libraries such as `std/rationals` when compiling to browser js as the backend. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Adjust the correct chunk's free space in allocator (#23795)SirOlaf2024-07-081-2/+2
| | | Fixes #23788
* Replacement PR for https://github.com/nim-lang/Nim/pull/23779 that (#23793)c-blake2024-07-071-26/+42
| | | | | | | makes new hash the default, with an opt-out (& js-no-big-int) define. Also update changelog (& fix one typo). Only really expect the chronos hash-order sensitive test to fail until they merge that PR and tag a new release.
* Update documentation for parseEnum in strutils.nim (#23804)Leon Lysak2024-07-061-2/+2
| | | | | | | added small note regarding style insensitivity for parsing enums. the casing of the first letter is still taken into account for this function. was confused a little at first because when I read "style insensitive manner" I thought it meant casing as well and ran into a couple of `ValueError`'s because of it.
* Fixed issues when using `std/parseopt` in miscripts with cmdline = "" (#23785)Gianmarco2024-07-021-3/+15
| | | | | | | Using initOptParser with an empty cmdline (so that it gets the cmdline from the command line) in nimscripts does not yield the expected results. Fixes #23774.
* Fix doc: '\c' '\L' in lexbase.nim (#23781)lit2024-07-011-4/+4
| | | - In lexbase.nim, `\c` `\L` were rendered as `c` `L`.
* refine: strmisc.expandTabs better code structure (#23783)lit2024-07-011-9/+6
| | | | | | | | | After this pr, for a string with just 20 length and 6 `'\t'`, the time reduces by about 1.5%[^t]. Also, the code is clearer than the previous at some places. [^t]: Generally speaking, this rate increases with length. I may test for longer string later.
* fixes #5091; Ensure we don't wait on an exited process on Linux (#23743)Mark Leyva2024-07-011-0/+2
| | | | | Fixes #5091. Ensure we don't wait on an exited process on Linux
* fixes #23725; Size computations work better when they are correct (#23758)Andreas Rumpf2024-06-261-6/+10
| | | [backport]
* Check for nil in cstringArrayToSeq (#23747)Yuriy Glukhov2024-06-241-0/+2
| | | | | | | | This fixes crashes in some specific network configurations (as `cstringArrayToSeq` is used extensively in `nativesockets`). --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #23742; setLen(0) no longer allocates memory for uninitialized ↵ringabout2024-06-211-2/+8
| | | | | | | | | | strs/seqs for refc (#23745) fixes #23742 Before my PR, `setLen(0)` doesn't free buffer if `s != nil`, but it allocated unnecessary memory for `strs`. This PR rectifies this behavior. `setLen(0)` no longer allocates memory for uninitialized strs/seqs
* Add Farm Hash conditioned upon `nimPreviewHashFarm` as 64-bit `Hash` (#23735)c-blake2024-06-191-20/+184
| | | | | | | | | | | | | | | | | | | | | | | | | Unlike present Nim this actually fills `Hash` for `string` & related. For the curious, note that `hashData` remains the aboriginal Nim string hasher & `import hashes {.all.}` allows simultaneous test/time of {orig, murmur, farm} on your favorite CPU & back end compiler. Update tests also conditioned upon `nimPreviewHashFarm` so they should pass either with or without that `define` on. In `--jsbigint=on` mode, only the lower 32-bits of `Hash` match nimvm & run-time values because `type Hash = int` and on JS int=int32, not int64 as for 64-bit Nim platforms. Due to the matching, `const` Table should match run-time `Table` on all platforms. To operate in `--jsbigint=off` mode is feasible but needs much "double precision mul/xor/ror/shr-arithmetic"-style work. That is distracting & also of questionable value since JS added BigInt in 2018, ringabout added Nim support for it in 2021 & `nimPreviewHashFarm` is unlikely to swap from an opt-in to an opt-out default before 2025..2026 which will have given a backward looking time window of 7..8 years for deployment platforms - reasonably generous. Add a changelog entry for 2.2.
* fixes #23732, os.sleep(-1) now returns immediately (#23734)lit2024-06-181-0/+3
| | | fixes #23732
* Fix NIM_STATIC_ASSERT_AUX being redefined on different lines (#23729)fakuivan2024-06-181-4/+8
| | | | | | | | | fixes #17247 This generates a new NIM_STATIC_ASSERT_AUX variable for each line that NIM_STATIC_ASSERT is called from. While this can solve all existing issues in the current code base, this method is not effective for multiple asserts on a single line.
* Fix non-exported `memfiles.setFileSize` to be able to shrink files on posix ↵c-blake2024-06-141-36/+30
| | | | | | | | | | | | | | via `memfiles.resize` (#23717) Fix non-exported `setFileSize` to take optional `oldSize` to (on posix) shrink differently than it grows (`ftruncate` not `posix_fallocate`) since it makes sense to assume the higher address space has already been allocated there and include the old file size in the `proc resize` call. Also, do not even try `setFileSize` in the first place unless the `open` itself works by moving the call into the `if newFileSize != -1` branch. Just cosmetics, also improve some old 2011 comments, note a logic diff for callers using both `mappedSize` & `newFileSize` from windows branch in case someone wants to fix that & simplify code formatting a little.
* fixes #22927; no test case extractable [backport] (#23707)Andreas Rumpf2024-06-121-11/+23
|
* fixes #23513, parseutils.nim: parseInt's doc example. (#23561)lit2024-06-121-8/+12
| | | | | | | | | | fixes #23513 Also, the old `runnableExample` is just a copy of `proc parseInt(openArray[char], var int, int)` variant (in Line 1000). --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* fixes #22510 (#23100)Andreas Rumpf2024-06-061-27/+24
|
* make `std/options` compatible with strictdefs (#23675)ringabout2024-06-051-6/+6
|
* fix noreturn/implicit discard check logic (#23681)metagn2024-06-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677 The false positive in #23677 was caused by behavior in `implicitlyDiscardable` where only the last node of `if`/`case`/`try` etc expressions were considered, as in the final node of the final branch (in this case `else`). To fix this we use the same iteration in `implicitlyDiscardable` that we use in `endsInNoReturn`, with the difference that for an `if`/`case`/`try` statement to be implicitly discardable, all of its branches must be implicitly discardable. `noreturn` calls are also considered implicitly discardable for this reason, otherwise stuff like `if true: discardableCall() else: error()` doesn't compile. However `endsInNoReturn` also had bugs, one where `finally` was considered in noreturn checking when it shouldn't, another where only `nkIfStmt` was checked and not `nkIfExpr`, and the node given for the error message was bad. So `endsInNoReturn` now skips over `skipForDiscardable` which no longer contains `nkIfStmt`/`nkCaseStmt`/`nkTryStmt`, stores the first encountered returning node in a var parameter for the error message, and handles `finally` and `nkIfExpr`. Fixing #23677 already broke a line in `syncio` so some package code might be affected.
* fixes #22798; Duplicate libraries linker warning (i.e., '-lm') on macOS (#23292)ringabout2024-06-022-2/+2
| | | | | | | | | | | | | | | fixes #22798 Per https://stackoverflow.com/questions/33675638/gcc-link-the-math-library-by-default-in-c-on-mac-os-x and https://stackoverflow.com/questions/30694042/c-std-library-dont-appear-to-be-linked-in-object-file > There's no separate math library on OSX. While a lot of systems ship functions in the standard C math.h header in a separate math library, OSX does not do that, it's part of the libSystem library, which is always linked in. required by https://github.com/nim-lang/Nim/pull/23290
* fixes #23663; Add hash() for Path (#23664)ringabout2024-05-311-1/+8
| | | fixes #23663
* Treat CJK Ideographs as letters in `isAlpha()` (#23651)Alexander Kernozhitsky2024-05-291-1957/+1948
| | | | | | | | | | | | | | | | | Because of the bug in `tools/parse_unicodedata.nim`, CJK Ideographs were not considered letters in `isAlpha()`, even though they have category Lo. This is because they are specified as range in `UnicodeData.txt`, not as separate characters: ``` 4E00;<CJK Ideograph, First>;Lo;0;L;;;;;N;;;;; 9FEF;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;; ``` The parser was not prepared to parse such ranges and thus omitted almost all CJK Ideographs from consideration. To fix this, we need to consider ranges from `UnicodeData.txt` in `tools/parse_unicodedata.nim`.
* revert #23436; remove workaround (#23653)ringabout2024-05-281-2/+0
| | | revert #23436
* fixes #23635; tasks.toTask Doesn't Expect a Dot Expression (#23641)ringabout2024-05-271-4/+20
| | | | | | | fixes #23635 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22852; fixes #23435; fixes #23645; SIGSEGV when slicing string or ↵ringabout2024-05-271-4/+1
| | | | | | | | | | | | | | | | | | seq[T] with index out of range (#23279) follow up https://github.com/nim-lang/Nim/pull/23013 fixes #22852 fixes #23435 fixes #23645 reports rangeDefect correctly ```nim /workspaces/Nim/test9.nim(1) test9 /workspaces/Nim/lib/system/indices.nim(116) [] /workspaces/Nim/lib/system/fatal.nim(53) sysFatal Error: unhandled exception: value out of range: -2 notin 0 .. 9223372036854775807 [RangeDefect] ```
* Handle arbitrarily long symlink target in `expandSymlinks()` (#23650)Alexander Kernozhitsky2024-05-271-8/+10
| | | | | | | | | | | | | | | For now, `expandSymlinks()` can handle only symlinks with lengths up to 1024. We can improve this logic and retry inside a loop with increasing lengths until we succeed. The same approach is used in [Go](https://github.com/golang/go/blob/377646589d5fb0224014683e0d1f1db35e60c3ac/src/os/file_unix.go#L446), [Rust](https://github.com/rust-lang/rust/blob/785eb65377e5d7f8d8e8b82ede044212bbd2d76e/library/std/src/sys/pal/unix/fs.rs#L1700) and [Nim's `getCurrentDir()`](https://github.com/nim-lang/Nim/blob/devel/lib/std/private/ospaths2.nim#L877), so maybe it's a good idea to use the same logic in `expandSymlinks()` also.
* doc(format): ospaths2,strutils: followup #23560 (#23629)lit2024-05-202-9/+9
| | | followup #23560
* doc(format): system.nim: doc of hostCPU for `loongarch64` (#23621)lit2024-05-171-1/+1
| | | | | In doc, `loongarch64` used to be written as `'"loongarch64"'` since it's [supported](https://github.com/nim-lang/Nim/pull/19223)
* provides a `$` function for `Path` (#23617)ringabout2024-05-171-0/+3
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Support NetBSD/aarch64 (#23616)PHO2024-05-161-2/+3
| | | | | I could trivially port Nim to NetBSD/aarch64 because it already supported NetBSD and aarch64. I only needed to generate `c_code` for this combination.
* fixes deprecation messages and adds missing commas (#23609)ringabout2024-05-141-3/+3
|
* adds Nim-related mimetypes back (#23589)ringabout2024-05-101-0/+4
| | | ref https://github.com/nim-lang/Nim/pull/23226
* Improve strutils.rsplit doc, proc and iterator have oppose result order. ↵lit2024-05-101-6/+6
| | | | | | | | | | | | | | (#23570) [`rsplit iterator`](https://nim-lang.org/docs/strutils.html#rsplit.i,string,char,int) yields substring in reversed order, while [`proc rsplit`](https://nim-lang.org/docs/strutils.html#rsplit%2Cstring%2Cchar%2Cint)'s order is not reversed, but its doc only declare ``` The same as the rsplit iterator, but is a func that returns a sequence of substrings. ```
* Add Complex version of almostEqual function (#23549)Angel Ezquerra2024-05-081-3/+18
| | | | | | | | This adds a version of `almostEqual` (which was already available for floats) thata works with `Complex[SomeFloat]`. Proof that this is needed is that the first thing that the complex.nim runnable examples block did before this commit was define (an incomplete) `almostEqual` function that worked with complex values.
* fixes 12381, HttpClient socket handle leak (#23575)Marius Andra2024-05-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Bug Fixes https://github.com/nim-lang/Nim/issues/12381 - HttpClient socket handle leak To replicate the bug, run the following code in a loop: ```nim import httpclient while true: echo "New loop" var client = newHttpClient(timeout = 1000) try: let response = client.request("http://10.44.0.4/bla", httpMethod = HttpPost, body = "boo") echo "HTTP " & $response.status except CatchableError as e: echo "Error sending logs: " & $e.msg finally: echo "Finally" client.close() ``` Note the IP address as the hostname. I'm directly connecting to a plausible local IP, but one that does not resolve, as I have everything under 10.4.x.x. The output looks like this to me: ``` New loop Error sending logs: Operation timed out Finally New loop Error sending logs: Operation timed out Finally New loop ... ``` In Nim 2.0.4, running the code above leaks the socket: <img width="944" alt="Screenshot 2024-05-05 at 22 00 13" src="https://github.com/nim-lang/Nim/assets/53387/ddac67db-d7df-45e6-b7a5-3d42f79775ea"> ## Fix With the added line of code, each old socket is cleanly removed: <img width="938" alt="Screenshot 2024-05-05 at 21 54 18" src="https://github.com/nim-lang/Nim/assets/53387/5b0b4b2d-d4f0-4e74-a9cf-74aec0c50d2e"> I believe the line below, `closeUnusedFds(ord(domain))` was supposed to clean up the failed connection attempts, but it failed to do so for the last one, assuming it succeeded. Yet it didn't. This fix makes sure failed connections are closed immediately. ## Tests I don't have a test with this PR. When testing locally, the `connect(lastFd, ..)` call on line 2032 blocks for ~75 seconds, ignoring the http timeout. I fear any test I could add would either 1) take way too long, 2) one day run in an environment where my randomly chosen IP is real, yielding in weird flakes. The only bug i can imagine is if running `lastFd.close()` twice is a bad idea. I tested by actually running it twice, and... no crash/op? So seems safe? I'm hoping the CI run will be green, and this will be enough. However I'm happy to take feedback on how I should test this, and do the necessary changes. ~Edit: looks like a test does fail, so moving to a draft while I figure this out.~ Attempt 2 fixed it.
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-081-31/+0
| | | | | `reset`, `wasMoved` and `move` doesn't support primitive types, which generate `null` for these types. It is now produce `x = default(...)` in the backend. Ideally it should be done by ast2ir in the future
* fixes #23442, fix for FileId under Windows (#23444)lit2024-05-081-4/+4
| | | | | | | | | | | See according issue: Details: <https://github.com/nim-lang/Nim/issues/23442#issuecomment-2021763669> --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #23556; typeinfo.extendSeq generates random values in ORC (#23557)ringabout2024-05-032-2/+11
| | | | | fixes #23556 It should somehow handle default fields in the future
* Update unicode.nim: cmpRunesIgnoreCase: fix doc format (#23560)lit2024-05-021-6/+6
| | | | | | Its doc used to render wrongly where `>` is considered as quote block: ![image](https://github.com/nim-lang/Nim/assets/97860435/4aeda257-3231-42a5-9dd9-0052950a160e)