summary refs log tree commit diff stats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* 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)
* fixes #23524; global variables cannot be analysed when injecting `move` (#23529)ringabout2024-04-241-3/+5
| | | | | | | | | | | | fixes #23524 ```nim proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool = ... result = n.kind == nkSym and n.sym.owner == owner and {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and (n.sym.kind != skParam or isSinkParam(n.sym)) ``` In `isAnalysableFieldAccess`, globals, cursors are already rejected
* Fix std/base64.decode out of bounds read (#23526)bptato2024-04-221-1/+1
| | | | inputLen may end up as 0 in the loop if the input string only includes trailing characters. e.g. without the patch, decode(" ") would panic.
* workaround #23435; real fix pending #23279 (#23436)ringabout2024-04-181-0/+2
| | | | | | | workaround #23435 related to https://github.com/nim-lang/Nim/issues/22852 see also #23279
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* allow Nix builds by not calling git in isGitRepo for Nimble (#23515)Jakub2024-04-181-10/+3
| | | | | | | | | | | | | | | Because `isGitRepo()` call requires `/bin/sh` it will always fail when building Nim in a Nix build sandbox, and the check doesn't even make sense if Nix already provides Nimble source code. Since for Nimble `allowBundled` is set to `true` this effectlvely does not change behavior for normal builds, but does avoid ugly hacks when building in Nix which lacks `/bin/sh` and fails to call `git`. Reference: * https://github.com/status-im/nimbus-eth2/pull/6180#discussion_r1570237858 Signed-off-by: Jakub Sokołowski <jakub@status.im>
* strictdefs for `repr` so that it can used for debugging purposes in t… ↵ringabout2024-04-151-2/+2
| | | | | (#23501) …he compiler
* fixes #23487; JS chckNilDisp is wrong (#23490)ringabout2024-04-131-1/+1
| | | | | fixes #23487 uses JSRef
* fix JSON deep copy description (#23495)Pouriya Jamshidi2024-04-121-1/+1
| | | | | | Hi, This is a tiny change, fixing the error in the documentation of JSON's deep copy proc.
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-112-1/+13
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* Better documentation for typedthreads module (#23483)Antoine Delègue2024-04-111-27/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a second example inside the `typedthreads` file. Also, add a more detailed introduction. When Nim is one's first programming language, a short explanation of what a thread is might not hurt. For reference, the thread documentation of other languages looks like this: - https://en.cppreference.com/w/cpp/thread/thread - https://doc.rust-lang.org/std/thread/ The documentation of a module is the first place one will look when using a standard library feature, so I think it is important to have a few usable examples for the main modules. This is the example added ```nim import locks var l: Lock proc threadFunc(obj: ptr seq[int]) {.thread.} = withLock l: for i in 0..<100: obj[].add(obj[].len * obj[].len) proc threadHandler() = var thr: array[0..4, Thread[ptr seq[int]]] var s = newSeq[int]() for i in 0..high(thr): createThread(thr[i], threadFunc, s.addr) joinThreads(thr) echo s initLock(l) threadHandler() deinitLock(l) ``` Sharing memory between threads is very very common, so I think having an example showcasing this is crucial. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-1/+1
|
* Update encodings.nim, fix `open` with bad arg raising no `EncodingError` ↵lit2024-04-061-1/+1
| | | | | | (#23481) On POSIX, `std/encodings` uses iconv, and `iconv_open` returns `(iconv_t) -1` on failure, not `NULL`
* remove `internalNew` from system (#23475)ringabout2024-04-041-3/+0
|
* fixes #16771; lower `swap` for JS backend (#23473)ringabout2024-04-031-3/+1
| | | | | | | | | | | | fixes #16771 follow up https://github.com/nim-lang/Nim/pull/16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime https://github.com/nim-lang/Nim/issues/16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
* Update syncio.nim, fixes "open by FileHandle" doesn't work on Windows (#23456)lit2024-04-031-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Reprodution if on Windows: ```Nim when defined(windows): var file: File let succ = file.open(<aFileHandle>) ``` then `succ` will be false. If tested, it can be found to fail with errno `22` and message: `Invalid argument` ## Problem After some investigations and tests, I found it's due to the `mode` argument for `fdopen`. Currently `NoInheritFlag`(`'N'` in Windows) is added to `mode` arg passed to `_fdopen`, but if referring to [Windows `_fdopen` doc](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fdopen-wfdopen?view=msvc-170), you'll find there is no `'N'` describled. That's `'N'` is not accepted by `_fdopen`. Therefore, the demo above will fail. ## In Addition To begin with, technologically speaking, when opening with a `fileHandle`(or called `fd`), there is no concept of fd-inheritable as `fd` is opened already. In POSIX, `NoInheritFlag` is defined as `e`. It's pointed out in [POSIX `open` man-doc](https://www.man7.org/linux/man-pages/man3/fopen.3.html) that `e` in mode is ignored for fdopen(), which means `e` for `fdopen()` is not wanted, just allowed. Therefore, better to also not pass `e` to `fdopen` --- In all, that's this PR.
* dynlib keeps exported functions alive in emscripten (#23469)ringabout2024-04-021-5/+12
| | | | | | | | | | | | | | | | | | | ref https://forum.nim-lang.org/t/11338 ref https://github.com/beef331/wasm3/blob/master/src/wasm3/exporter.nim ref https://github.com/emscripten-core/emscripten/issues/6233 ref https://github.com/emscripten-core/emscripten/blob/3.1.56/system/include/emscripten/em_macros.h#L10 `EMSCRIPTEN_KEEPALIVE` is a macro that is used to prevent unused functions from being deadcode eliminated in emscripten, which is a simple wrapper around `__attribute__((used))`. This PR follows suits and expects dynlib is supposed to keep these functions alive. In the future, `exportwasm` might be introduced. After this PR, a function with `{.dynlib, exportc.}` can be reused from other wasm programs reliably.
* Fix compile time errors when using tables on 8/16-bits systems. (#23450)Gianmarco2024-03-281-1/+4
| | | Refer to the discussion in #23439.
* Change unicode lookup tables to have int32 elements to support platforms ↵Gianmarco2024-03-252-9/+9
| | | | | | | | | | | | | | | where sizeof(int) < 4 (#23433) Fixes an issue that comes up when using strutils.`%` or any other strutils/strformat feature that uses the unicode lookup tables behind the scenes, on systems where ints are than 32-bit wide. Tested with: ```bash ./koch test cat lib ``` Refer to the discussion in #23125.
* fix atomicarc increment (#23427)Jaremy Creechley2024-03-251-1/+1
| | | | | | | | | | | | The fix to the atomicArc looks to use `-1` as the check value from the `SharedPtr` solution. However, it should be `-rcIncrement` since the refcount is bit shifted in ARC/ORC. I discovered this playing around doing atomic updates of refcounts in a user library. Related to https://github.com/nim-lang/Nim/issues/22711 @ringabout I believe you ported the sharedptr fix?
* Adds support for custom ASTs in the Nim parser (#23417)Andreas Rumpf2024-03-181-1/+1
|
* chore: fix some typos (#23412)soonsouth2024-03-161-2/+2
| | | Signed-off-by: soonsouth <cuibuwei@163.com>
* fix BigInt conversion, xOffset/yOffset to int from int64 (#23404)Chancy K2024-03-151-1/+1
| | | | | Problem described here: https://github.com/karaxnim/karax/issues/284 Co-authored-by: Chancy Kennedy <chancy@conciergecloset.com>
* Fix #23381, Use `sink` and `lent` to avoid Future[object] making a copy (#23389)握猫猫2024-03-141-10/+16
| | | | | | | | | fix #23381 As for the read function, the original plan was to use lent for annotation, but after my experiments, it still produced copies, so I had to move it out. Now the `read` function cannot be called repeatedly
* fixes #22166; adds sideeffects for `close` and `setFilePos` (#23380)ringabout2024-03-091-2/+2
| | | fixes #22166
* fix `isAbsolute` broken when `nodejs` on Windows (#23365)litlighilit2024-03-041-3/+3
| | | | | | | | | | | When target is nodejs, `isAbsolute` used to only check in the POSIX flavor, i.e. for js backend on Windows, ```nim isAbsolute(r"C:\Windows") == false ``` This fixes it.
* ref #23333; fixes AF_INET6 value on Linux (#23334)ringabout2024-03-031-1/+1
| | | ref #23333
* Update browsers.nim, deprecate unimplemented `openDefaultBrowser()` (#23332)litlighilit2024-03-031-14/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | For this [proc](https://github.com/nim-lang/Nim/blob/773c066634d831a968bb464eab35b25a00026525/lib/pure/browsers.nim#L83) `proc openDefaultBrowser*() {.since: (1, 1).}`: though it's documented to open default browser with `about:blank` page, it behaves differently: - On Windows, it failed and open no window - On Linux(Debian with Kde), it opens not default browser but `Konqueror` I have paid much effort to implement this variant, but even the implementation on Windows is considerably complex. In short, it's not only hard but unworthy to fix this. Just as Araq [said](https://github.com/nim-lang/Nim/issues/22250#issuecomment-1631360617), we shall remove the `proc openDefaultBrowser*() {.since: (1, 1).}` variant --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* strformat: detect format string errors at compile-time (#23356)Jacek Sieka2024-03-031-39/+97
| | | | | | | | | | | | This also prevents unwanted `raises: [ValueError]` effects from bubbling up from correct format strings which makes `fmt` broadly unusable with `raises`. The old runtime-based `formatValue` overloads are kept for backwards-compatibility, should anyone be using runtime format strings. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* ORC: added -d:nimOrcStats switch and related API (#23272)Andreas Rumpf2024-02-214-18/+62
|
* Remove count field from Deque (#23318)Tomohiro2024-02-201-51/+46
| | | | This PR removes `count` field from `Deque` and get `count` from `tail - head`.
* fixes #23304; uses `snprintf` instead of `sprintf` (#23322)ringabout2024-02-204-9/+12
| | | fixes #23304
* fixes refc with non-var destructor; cancel warnings (#23156)ringabout2024-02-132-2/+4
| | | fixes https://forum.nim-lang.org/t/10807
* Remove mask field from Deque (#23299)Tomohiro2024-02-111-5/+6
| | | | | | | | | It seems Deque doesn't need `mask` field because `data.len - 1` equals to `mask`. Deque without `mask` field passes test `tests/stdlib/tdeques.nim`. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Add items and contains to heapqueue (#23296)Antonis Geralis2024-02-091-0/+15
| | | | The implementation of these functions are trivial yet they were missing from the module.
* fixes #23275; Add `==` for Deque (#23276)Tomohiro2024-02-081-1/+28
|
* follow up #22380; fixes incorrect usages of `newWideCString` (#23278)ringabout2024-02-054-5/+6
| | | follow up #22380
* Docs-improve: os.getCurrentCompilerExe replace with clearer short-desc (#23270)litlighilit2024-02-021-1/+1
| | | | | | | | | | | | | | | | | The doc for `getCurrentCompilerExe` was originally added at [this commit](https://github.com/nim-lang/Nim/commit/c4e3c4ca2d0a1f44ed1e3dd9db564b66031f0843), saying "`getAppFilename` at CT", and modified as "This is `getAppFilename()`_ at compile time..." since [this](https://github.com/nim-lang/Nim/commit/0c2c2dca2a8a3bcdb9729021d1f4734b8db9efbd#diff-8ed10106605d9e0e3f28a927432acd8312e96791c96dbb126a52a7010cf4b44a) Which means "at compile time, get result innerly from Nim compiler via `getAppFilename`", not "get from nim programs". Thus, the doc was confusing, only mentioning `compile time` and `getAppFilename` --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>