summary refs log tree commit diff stats
path: root/lib/std
Commit message (Collapse)AuthorAgeFilesLines
* fixes #24174; allow copyDir and copyDirWithPermissions skipping special ↵ringabout2024-09-272-7/+16
| | | | | files (#24190) fixes #24174
* fixes symbolName for range enums (#24052)ringabout2024-09-031-1/+7
|
* fixes JS semicolon omissions (#23896)ringabout2024-07-261-3/+3
|
* fixes #23838: Compilation by MinGW for cpu=i386 with time_t bug (#23876)Ward2024-07-221-1/+1
| | | | Change Time type in std/time_t to `distinct clong` instead of `distinct int32`
* Fix out-of-bounds slicing in std/varints (#23868)Buldram2024-07-221-6/+6
| | | | | | Corrects a slicing mistake in the `std/varints` implementation which caused it to fail when writing large numbers into buffers smaller than 10..13-bytes, now 9-byte buffers are sufficient as the documentation states.
* 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 #23663; Add hash() for Path (#23664)ringabout2024-05-311-1/+8
| | | fixes #23663
* 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>
* 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-201-3/+3
| | | followup #23560
* provides a `$` function for `Path` (#23617)ringabout2024-05-171-0/+3
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes deprecation messages and adds missing commas (#23609)ringabout2024-05-141-3/+3
|
* 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>
* 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>
* 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.
* 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.
* fixes #23304; uses `snprintf` instead of `sprintf` (#23322)ringabout2024-02-201-3/+3
| | | fixes #23304
* fixes refc with non-var destructor; cancel warnings (#23156)ringabout2024-02-132-2/+4
| | | fixes https://forum.nim-lang.org/t/10807
* follow up #22380; fixes incorrect usages of `newWideCString` (#23278)ringabout2024-02-053-3/+4
| | | follow up #22380
* Update cmdline.nim, fix broken (dragged) doc-reference for getAppFile… ↵litlighilit2024-01-281-4/+4
| | | | | | | | (#23262) In doc, there are 4 references for `getAppFilename` `getAppFilename` is still in `os`, but the references refer it as if it's in the current module `cmdline`
* Deprecate asm stmt for js target (#23149)ASVIEST2024-01-022-10/+10
| | | | | | | | | | | | | | | | | | | | | | | why ? - We already have an emit that does the same thing - The name asm itself is a bit confusing, you might think it's an alias for asm.js or something else. - The asm keyword is used differently on different compiler targets (it makes it inexpressive). - Does anyone (other than some compiler libraries) use asm instead of emit ? If yes, it's a bit strange to use asm somewhere and emit somewhere. By making the asm keyword for js target deprecated, there would be even less use of the asm keyword for js target, reducing the amount of confusion. - New users might accidentally use a non-universal approach via the asm keyword instead of emit, and then when they learn about asm, try to figure out what the differences are. see https://forum.nim-lang.org/t/10821 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* allow non var deinit for locks and conds: alternative way (#23099)ringabout2023-12-191-14/+14
| | | alternative to https://github.com/nim-lang/Nim/pull/23092
* fixes #23060; `editDistance` wrongly compare the length of rune strings (#23062)ringabout2023-12-131-1/+1
| | | fixes #23060
* Silence several Hint[Performance] warnings (#23003)c-blake2023-11-291-1/+1
| | | | With `--mm:arc` one gets the "implicit copy; if possible, rearrange your program's control flow" `Performance` warnings without these `move`s.
* reserve `sysFatal` for `Defect` (#22158)Jacek Sieka2023-11-061-9/+6
| | | | | | | | Per manual, `panics:on` affects _only_ `Defect`:s - thus `sysFatal` should not redirect any other exceptions. Also, when `sysFatal` is used in `nimPanics` mode, it should use regular exception handling pipeline to ensure exception hooks are called consistently for all raised defects.
* complete std prefixes for stdlib (#22887)ringabout2023-10-3035-52/+52
| | | | follow up https://github.com/nim-lang/Nim/pull/22851 follow up https://github.com/nim-lang/Nim/pull/22873
* explicitly import using `std/` in `tempfiles.nim` (#22851)Vindaar2023-10-201-1/+1
| | | | | At least on modern Nim `tempfiles` is not usable if the user has https://github.com/oprypin/nim-random installed, because the compiler picks the nimble path over the stdlib path (apparently).
* fixes #22844; uses arrays to store holeyenums for iterations; much more ↵ringabout2023-10-201-1/+1
| | | | | efficient than sets and reasonable for holeyenums (#22845) fixes #22844
* NIR: Nim intermediate representation (#22777)Andreas Rumpf2023-10-111-15/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Theoretical Benefits / Plans: - Typed assembler-like language. - Allows for a CPS transformation. - Can replace the existing C backend by a new C backend. - Can replace the VM. - Can do more effective "not nil" checking and static array bounds checking. - Can be used instead of the DFA. - Easily translatable to LLVM. - Reasonably easy to produce native code from. - Tiny memory consumption. No pointers, no cry. **In very early stages of development.** Todo: - [x] Map Nim types to IR types. - [ ] Map Nim AST to IR instructions: - [x] Map bitsets to bitops. - [ ] Implement string cases. - [ ] Implement range and index checks. - [x] Implement `default(T)` builtin. - [x] Implement multi string concat. - [ ] Write some analysis passes. - [ ] Write a backend. - [x] Integrate into the compilation pipeline.
* document `atomicInc` and `atomicDec` (#22789)ringabout2023-10-041-0/+2
|
* copyFile with POSIX_FADV_SEQUENTIAL (#22776)Juan Carlos2023-10-011-0/+8
| | | | | | | | | | | - Continuation of https://github.com/nim-lang/Nim/pull/22769 - See https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fadvise.html - The code was already there in `std/posix` since years ago. 3 line diff. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* copyFile with bufferSize instead of hardcoded value (#22769)Juan Carlos2023-09-301-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - `copyFile` allows to specify `bufferSize` instead of hardcoded wrong value. Tiny diff. # Performance - 1200% Performance improvement. # Check it yourself Execute: ```bash for i in $(seq 0 10); do bs=$((1024*2**$i)) printf "%7s Kb\t" $bs timeout --foreground -sINT 2 dd bs=$bs if=/dev/zero of=/dev/null 2>&1 | sed -n 's/.* \([0-9.,]* [GM]B\/s\)/\1/p' done ``` (This script can be ported to PowerShell for Windows I guess, it works in Windows MinGW Bash anyways). # Stats - Hardcoded `8192` or `8000` Kb bufferSize gives `5` GB/s. - Setting `262144` Kb bufferSize gives `65` GB/s (script suggestion). --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make parseEnum skip type aliases for enum type sym (#22727)metagn2023-09-191-1/+2
| | | fixes #22726
* Update osfiles.nim, make `moveFile` consider permission on *nix (#22719)litlighilit2023-09-181-1/+1
| | | see https://github.com/nim-lang/Nim/issues/22674
* fixes incorrect cint overflow in system (#22718)ringabout2023-09-181-1/+1
| | | fixes #22700
* allow tuples and procs in 'toTask' + minor things (#22530)Andreas Rumpf2023-08-221-1/+1
|
* Add staticFileExists and staticDirExists (#22278)Tomohiro2023-08-181-0/+13
|
* fixes syncio document (#22498)Nan Xiao2023-08-171-2/+2
|
* Markdown code blocks migration part 8 (#22478)Andrey Makarov2023-08-155-52/+57
|
* fixes CI (#22471)ringabout2023-08-142-3/+3
| | | | | Revert "fixes bareExcept warnings; catch specific exceptions (#21119)" This reverts commit 9207d77848d6f5db3635ae64f3cd4972cdbe3296.
* fixes syncio document (#22467)Nan Xiao2023-08-141-2/+2
|
* fixes bareExcept warnings; catch specific exceptions (#21119)ringabout2023-08-132-3/+3
| | | | | * fixes bareExcept warnings; catch specific exceptions * Update lib/pure/coro.nim
* replace `doAssert false` with `raiseAssert` in lib, which works better with ↵ringabout2023-08-118-14/+14
| | | | strictdefs (#22458)
* clean up `gc:arc` or `gc:orc` in docs and in error messages (#22408)ringabout2023-08-081-2/+2
| | | | | * clean up gc:arc/orc in docs * in error messages
* use strictdefs for compiler (#22365)ringabout2023-08-061-0/+1
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* Prevent early destruction of gFuns, fixes AddressSanitizer: ↵norrath-hero-cn2023-08-051-1/+1
| | | | | heap-use-after-free (#22386) Prevent destruction of gFuns before callClosures
* Revert adding generic `V: Ordinal` parameter to `succ`, `pred`, `inc`, `dec` ↵konsumlamm2023-08-063-11/+11
| | | | | | | (#22328) * Use `int` in `digitsutils`, `dragonbox`, `schubfach` * Fix error message
* Fix searchExtPos so that it returns -1 when the path is not a file ext (#22245)Tomohiro2023-08-041-4/+17
| | | | | | | * Fix searchExtPos so that it returns -1 when the path is not a file ext * fix comparision expression * Remove splitDrive from searchExtPos
* Remove declared and not used variable in packedsets.bitincl (#22334)Eric N. Vander Weele2023-07-271-1/+0
| | | | When compiling code that uses PackedSet with warnings enabled, `var ret` in `bitincl` emits a "XDeclaredButNotUsed" warning.