Commit Graph

223 Commits

Author SHA1 Message Date
Jaremy Creechley
6976d18519 Implement zephyr urandom and monotime (#19142)
* implement urandom for Zephyr

* add monotime on zephyr

Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
2021-11-14 12:49:30 +01:00
Anuken
270a5a372d Fix undeclared 'SYS_getrandom' on emscripten (#19144) 2021-11-13 19:09:15 -05:00
Andreas Rumpf
9d51197aa4 fixes #19078 [backport] (#19090) 2021-11-02 16:30:59 +01:00
Tail Wag Games
cfdac6666f Freeing critical sections via atexit in system/alloc and system/io (#19062)
* adding new system module sysexitprocs and including system exit procedures when registering exit handlers defined in userland

* fixing failing tests and adding initialization guard to handle cases where the module's global init logic isn't invoked first as is the case with some gc implementaions

* js backend shouldn't try to invoke actual system exit procs

* fixing formatting in sysexitprocs.nim

* 256 was too much - my max number of plugins in my engine is 64 and I require two hooks per runtime it looks like with tls emulation turned off, so for my purposes 128 should be sufficient

* so atExit should be enough here, can get rid of all the extra cruft I had added on top since I didn't realize atExit already provided a stack

* done being cute - since newruntime prevents correct cpp codegen for object variants apparently and breaks tests if I try to use std/exitprocs, ddSysExitProc is just going into both modules. Since system doesn't include system/io, polluting system with it doesn't make sense either... at least it is only importc'd when it is required in either module and we don't have to have any weird when defined(nimOwnedEnabled) with a comment explaining why
2021-10-29 13:42:44 +02:00
Timothy Alexander
dde556665a Fix #19052; [backport:1.6.0] (#19053)
* Fix #19052; [backport:1.6.0]

Adds a compile flag to avoid a getrandom syscall, fixing #19052.

This is neccesary when the getrandom syscall is missing, as noted in #19052, particularly in kernel versions < 3.17 when getrandom was introduced. Specifically relevant is this is missing from kernel 3.10, which is the supported kernel throughout RHEL 7 and CentOS 7, which is widely used at many organizations. Without this, versions of nim that include sysrand (i.e. versions >= 1.6.0) will not compile without modification, however with this change a compile flag may be used to fall back using /dev/urandom as done with any unknown Posix OS (preferred here as a fallback since it already supplies a cryptographically secure PRNG and existing code deals with entropy pool init, etc).

The change is placed behind a compile flag, as discussed in github ticket #19052 (summed up here):
* First, I can't seem to catch that a importc such as SYS_getrandom is declared without using it (the declared proc returns true, but compiler throws an undeclared identifier flag when referencing it).
* Second, it seemed preferable to be behaviorally explicit vs implicit when considering this is intended to be a cryptographically secure PRNG.
* Third, if I intend to compile on a kernel >= 3.17 while running the binary on at least one system < 3.17, I'll want to be able to target this without relying on a compile time determination if the getrandom syscall is available.

* Documenting compile flag for -d:nimNoGetRandom and adding changelog entry
Related to #19052 and comments in PR #19053. Also created a new changelog file since none currently exists.

Co-authored-by: Timothy Alexander <talexander@midwestlabs.com>
2021-10-26 20:32:52 +02:00
Tail Wag Games
582468da1c deinitializing locks at program exit (#19043)
* deinitializing locks at program exit

* deinitLock shouldn't be called for js backend I guess...

* I suppose this is the best way to detect the
ewruntime option

* I guess I need these guards here too...

* fixing merge conflict
2021-10-25 10:13:30 +02:00
flywind
c4c9876785 fix a potential bug (#18900) 2021-10-14 09:23:01 +02:00
flywind
5c4692fad4 rename nimLegacyJsonutilsHoleyEnum [backport] (#18938)
* enable nimPreviewJsonutilsHoleyEnum [backport]

* docuement nimPreviewJsonutilsHoleyEnum
2021-10-01 20:26:29 +02:00
flywind
7577ea9e4c [std/tempfiles] docs improvement (#18936)
* unify comments

* more
2021-10-01 20:14:10 +02:00
flywind
2aeac26f08 correct licence header (#18935)
* rename licence

* spaces
2021-10-01 13:57:06 +02:00
flywind
6bb32da4ae [std/tasks] more gcsafe stuffs [backport] (#18926) 2021-09-30 07:46:30 +02:00
flywind
b3ad68edea remove channels (#18801)
* remove channels

* test
2021-09-04 15:57:02 +02:00
Tomohiro
7c8ea490a2 Fix initrand to avoid random number sequences overlapping (#18744)
* Fix initrand to avoid random number sequences overlapping

* Minor fix

* Fix compile error on js backend

* Disable new test for js backend

* Minor fix

* tempfiles module uses random.initRand()

* Remove unused module import from lib/std/tempfiles.nim

* Initialize baseState in initRand()

* Run tests/stdlib/trandom.nim from tests/test_nimscript.nims

* baseState is initialized only with sysrand.urandom and quit if failed

* Add comments
2021-09-02 14:12:14 +02:00
Andreas Rumpf
e0ef859130 strict effects (#18777)
* fixes #17369
* megatest is green for --cpu:arm64
* docgen output includes more tags/raises
* implemented 'effectsOf' 
* algorithm.nim: uses new effectsOf annotation
* closes #18376
* closes #17475
* closes #13905
* allow effectsOf: [a, b]
* added a test case
* parameters that are not ours cannot be declared as .effectsOf
* documentation
* manual: added the 'sort' example
* bootstrap with the new better options
2021-09-02 12:10:14 +02:00
Juan Carlos
e65dc36ddd Implement RFC-391 (#18585) 2021-08-22 12:32:55 -07:00
flywind
cc08d5c2c6 fix #17898(randomPathName called twice in a row can return the same string on windows) (#18729)
* close #17898

* no need to consider js
2021-08-22 07:40:20 +02:00
Timothee Cour
394f4ac7bb improvements to addInt and $ for integer types (#18592)
* improvements to $(SomeInteger) and addInt
* remove mIntToStr, mInt64ToStr
* improvements
* fix tests/pragmas/tinjectstmt.nim; the diff is harmless, cgen code is identical with -d:danger or debug mode
* rm tests/system/tstrmantle.nim
* revert compiler/jsgen.nim for -d:nimVersion140
2021-08-19 11:33:52 +02:00
flywind
f559319a68 fix a sqlite bug (#18669) 2021-08-12 09:21:01 -07:00
Timothee Cour
8ce782d463 Add optional recursive arg to distinctBase (v2) (#18659)
* Add optional recursive arg to distinctBase
* Add docs and examples

Co-authored-by: ALANVF <alan.invents@gmail.com>
2021-08-09 08:51:39 +02:00
Timothee Cour
988c02b7cb renamed: lib/std/private/vmutils.nim -> lib/std/private/bitops_utils.nim to avoid confusion with unrelated std/vmutils (#18660) 2021-08-08 19:24:45 -07:00
Andreas Rumpf
562dde624f fixes #18371 (#18617) 2021-07-30 12:05:14 +02:00
Timothee Cour
6b3c77e7f4 Remove tracking of environment from osenv.nim v2 (#18575)
* Remove unnecessary environment tracking

* try to fix windows

* fix delEnv

* make putEnv work on windows even with empty values; improve tests: add tests, add js, vm testing

* [skip ci] fix changelog

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>
2021-07-29 23:05:26 +02:00
Vindaar
7d3c3e00ef Allow nnkAccQuoted in genEnumCaseStmt (#18606)
* [enumutils] provide node kind for `Invalid node type` error

* [enumutils] add support for nnkAccQuoted in `genEnumCaseStmt`

For reasons unknown to me, when running `nim doc` on a file that uses
`parseEnum` with an enum that contains accented quotes errors at CT
with the `Invalid node for type` error. Further errors are raised,
probably because the enum parsing fails?
2021-07-29 07:47:34 +02:00
Miran
e616675c41 various small documentation improvements (#18602) 2021-07-28 14:31:13 +02:00
flywind
6f34829ee5 clean unused imports on runnableExamples (#18551) 2021-07-21 13:46:17 +02:00
Timothee Cour
923a1c6ea7 fix nativeToUnixPath (#18501) 2021-07-17 07:54:47 +02:00
Andreas Rumpf
96a7f9b31c deprecate cuchar, don't redefine it (#18505) 2021-07-16 15:50:02 +02:00
Ivan Bobev
5e6680406f Add changes required by Nimble lock file support (#12104)
Implemented support for Nimble local cache with package directories with
a checksum of the package at the end of their names. Now the compiler
supports package paths in the form:

 * /path_to_nimble_cache_dir/pkgs/package_name-1.2.3-
FEBADEAEA2345E777F0F6F8433F7F0A52EDD5D1B

 * /path_to_nimble_cache_dir/pkgs/package_name-#head-
042D4BE2B90ED0672E717D71850ABDB0A2D19CD2

 * /path_to_nimble_cache_dir/pkgs/package_name-#branch-name-
DBC1F902CB79946E990E38AF51F0BAD36ACFABD9

Related to nim-lang/nimble#127
2021-07-15 22:13:01 +02:00
Timothee Cour
d1447fe25d major improvements to std/wrapnils: optimal codegen, case objects, lvalue semantics (#18435)
* wrapnils now generates optimal code; also handles case objects
* changelog
* unsafeAddr => addr
2021-07-07 06:04:36 +02:00
Timothee Cour
36d24846b6 typo: enmRange => enumElementsAsSet (#18394) 2021-06-29 18:08:50 -07:00
Clyybber
6e74fecb42 Simplify addInt, remove digits10 (#18356)
* Simplify addInt, remove digits10

Co-authored-by: Charles Blake <charlechaud@gmail.com>

* Fix bootstrapping

* Add noInit to tmp array

* noInit -> noinit

Co-authored-by: Charles Blake <charlechaud@gmail.com>
2021-06-28 15:00:14 +02:00
Timothee Cour
8535b26a75 docs now show nimExperimentalX APIs (#18345)
* docs now show nimExperimentalX APIs

* fix for windows
2021-06-25 16:47:10 +02:00
Timothee Cour
565e07a993 enable VM tracing in user code via {.define(nimVmTrace).} (#18244)
* enable VM tracing in user code via  `{.define(nimVmTrace).}`

* add vmutils.vmTrace

* add vmTrace
2021-06-24 11:55:31 +02:00
flywind
9a81e91fa5 merge similar procs regarding digits (#18318) 2021-06-22 17:02:32 +02:00
Timothee Cour
7714ab468a make privateAccess work with generic types and generic instantiations; fix a SIGSEGV (#18260)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-06-19 11:24:46 -07:00
Timothee Cour
e1e8af535e merge BuildMode into SuccessX, remove code duplication w drnim, add useful info to successx, add gc to compilesettings (#18252)
* merge BuildMode into SuccessX, add more info

* refactor duplicated with drnim

* fixup

* address comment
2021-06-14 08:51:40 +02:00
Timothee Cour
79ded694d7 avoid re-exporting options from std/wrapnils (#18222) 2021-06-10 07:00:34 +02:00
Timothee Cour
9c6259e557 up to 20x faster jsonutils deserialization (#18183)
* up to 20x faster jsonutils deserialization

* noinline
2021-06-05 09:45:37 +02:00
Timothee Cour
654a20166e simplify extccomp.nim json logic via jsonutils; fix #18084 (#18100)
* simplify extccomp.nim json logic via jsonutils
* fix #18084
* simplify further
* workaround for bootstrap that can be removed after updating csources_v1 >= 1.2
2021-06-03 22:29:45 +02:00
Andreas Rumpf
0aa8b793a5 clarify what a 'monotonic' timestamp is (#18163) 2021-06-03 16:27:34 +02:00
Timothee Cour
369a7d1246 jsonutils.toJson now serializes JsonNode as is by default (#18097)
* jsonutils.toJson now serializes JsonNode as is (without deep copy nor treating it as a regular ref object)

* JsonNodeMode
2021-05-31 22:17:52 +02:00
Timothee Cour
7f077a76fe jsonutils: add customization for toJson via ToJsonOptions; generalize symbolName; add symbolRank (#18029)
* jsonutils: add customization for toJson via `ToJsonOptions`

* add enumutils.symbolRank

* lookup table implementation for HoleyEnum

* cleanup

* changelog

* fixup

* Update lib/std/jsonutils.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-05-18 15:10:19 +02:00
Timothee Cour
d83b25db1e fix #18007: std/json now serializes nan,inf,-inf as strings instead of invalid json (#18026)
* fix #18007: std/json now serializes nan,inf,-inf as raw strings instead of invalid json

* fix roundtrip

* fix tests

* fix changelog

* simplify

* add runnableExamples

* fix typo [skip ci]
2021-05-16 23:54:10 +02:00
Andreas Rumpf
3bc625aff1 ORC: progress (#18000)
* ORC: progress

* ORC: bugfix; don't follow acyclic data even if only at runtime the subtype is marked as acyclic

* progress

* minor style changes
2021-05-12 22:00:37 +02:00
Timothee Cour
1e080eb9b4 jsonutils: handle holey enum as regular enum, via ord (#17995) 2021-05-11 22:49:47 +02:00
Timothee Cour
a770c98e27 jsonutils: support set (#17994) 2021-05-11 21:09:17 +02:00
Timothee Cour
e60672141a improve std/tempfiles (#17920)
* improve std/tempfiles
* fixup
* fix windows
* improve test
* improve runnableExamples and tests
* address comment
2021-05-11 16:35:43 +02:00
Timothee Cour
82996aee3f misc fixes: remove forceConst (obsolete by static), add more runnableExamples to system (#17896)
* misc fixes

* add runnableExamples for compileOption

* add runnableExamples for runnableExamples

* move tconsteval => tconst

* cleanup
2021-05-01 07:26:52 +02:00
Timothee Cour
20248a68fd gitutils: add diffStrings, diffFiles, and use it in testament to compare expected vs gotten (#17892)
* gitutils: add diffStrings, diffFiles, and use it in testament to compare expected vs gotten
* refactor with createTempDir
* cleanup
* refacotr
* PRTEMP fake test spec changes to show effect of diffStrings
* add runnableExamples for experimental/diff + cross-reference with gitutils
* Revert "PRTEMP fake test spec changes to show effect of diffStrings"

This reverts commit 57dc8d642d.
2021-04-30 11:00:33 +02:00
Timothee Cour
e4db733d80 fix #17888: remove undefined behavior for posix.open; fix tempfiles.createTempFile (#17889)
* fix #17888: remove undefined behavior for posix.open; fix tempfiles.createTempFile

* fix for tests/async/tasyncfile.nim

* hide mode for now

* add notice regarding stability
2021-04-29 13:42:56 +02:00