Commit Graph

311 Commits

Author SHA1 Message Date
tersec 1c9190a632
work around pointless copy in isZeroMemory due to https://github.com/nim-lang/Nim/issues/24093 (#233) 2024-09-26 17:49:08 +02:00
Jacek Sieka 41f48efee9
staticfor: compile-time loop unrolling (#232)
* staticfor: compile-time loop unrolling

* better code, preserve line info

* one more line info

* license
2024-09-24 10:36:50 +02:00
Jacek Sieka 68e8ae6413
arraybuf: fix iterator, setLen (#231) 2024-09-17 11:54:28 +00:00
Miran 90a9bfd843
update ci.yml to test Nim 2.2; also test gcc-14 (#230)
* update ci.yml to test Nim 2.2; also test gcc-14

* the installation of openssl 1.1 is maybe not needed?
2024-09-11 00:30:21 +00:00
Eugene Kabanov d4634c5405
Add updateFilePos() primitive and tests. (#229) 2024-09-04 03:12:02 +00:00
Eugene Kabanov 4d4dfb7b32
Add cross-platform fsync() primitive and improve Direct mode. (#228) 2024-09-03 21:15:41 +00:00
Jacek Sieka fc09b2e023
arraybuf: seq-like fixed-capacity container stored on the stack (#227)
Also includes `evalOnceAs`, a handy utility for avoiding creating a
temporary in templates when seeking to avoid double-evaluation of
parameters.
2024-09-02 13:02:11 +02:00
Eugene Kabanov af07b0a70d
Fix OpenFlags.Append mode for io2.openFile() (#226)
* Initial commit.

* Fix Windows version.

* Remove debugging echoes.

* Fix Posix version.

* Add one more test.
2024-08-02 05:32:31 +00:00
Eugene Kabanov 8e0e344f0f
Add truncate()/ftruncate() cross-platform implementation. (#225) 2024-07-28 23:03:43 +00:00
andri lim 54cc67cbb8
Reduce declared but unused warnings in keyed-queue (#224) 2024-07-19 09:30:22 +02:00
tersec e00fea1f6e
fix deprecation warnings from results; deprecate shims/io module; rm deprecated shims/os module (#223) 2024-06-27 11:48:32 +00:00
Eugene Kabanov bb086e69da
Fix Windows ACL flakiness issue (Windows error 1336). (#221)
* Add getHomePath(), getConfigPath() and getCachePath() implementations.
Fix ACL flakiness issue.
Add tests.

* Add getTempPath().
Normalize path endings for all xxPath() functions.

* Fix 2.0/devel compilation errors.
2024-06-17 07:04:14 +00:00
Jacek Sieka 28743363ff
keyed_queue: avoid copies, lookups (#220)
This change avoids many superfluous data copies and lookups by
exploiting `withValue` thus performing only one lookup with the same key
(instead of hasKey + actual lookup).

We also avoid several copies of the value which often is copied even
though only the next/prev pointers from the item are needed, for examle
during shifting and lru-appending.
2024-06-11 08:43:41 +02:00
tersec a0a53c9116
deprecate stew/results (#219)
* deprecate stew/results

* Update stew/results.nim

* use evergreen OS image versions in GitHub Actions CI

* revert macos-latest
2024-06-10 19:11:33 +00:00
tersec 72aab089a2
rm deprecated pre-Nim 1.6 shims (#218) 2024-06-10 00:31:18 +00:00
andri lim 5284cce92e
Upgrade github actions to v4 (#213) 2024-06-01 21:32:57 +00:00
Jordan Hrycaj 104132fd02
Update LRU directives (#217)
why:
  Clarify pre-conditions needed for `lruAppend()` to work properly. In a
  nutshell, it needs to be used in concert with `lruFetch()` or
  `lruUpdate()`.
2024-04-22 16:10:23 +00:00
Jacek Sieka a0c085a51f
strformat: compile-time format string parser (backport Nim 2.2) (#216)
https://github.com/nim-lang/Nim/pull/23356
2024-03-13 09:45:09 +01:00
Etan Kissling 1662762c01
rename `RangeError` -> `RangeDefect` in test name (#214)
The `Allocating with a negative size throws a RangeError` test actually
tests for `RangeDefect`, so rename the test accordingly.
2024-02-17 19:31:52 +00:00
andri lim 5a792e762f
Add push raises to shims/macros module (#212) 2024-02-12 12:20:12 +07:00
tersec 3aa92ab843
mark stew/shims/net as deprecated (#211) 2024-01-20 20:57:08 +00:00
Jacek Sieka 2c2544aec1
byteutils: `openArray[char]` version of `toBytes` (#210)
and compile-time tests
2023-11-14 11:53:47 +01:00
tersec 49ab3c1d59
don't require init on `ValidIpAddress` (#209)
* don't require init on ValidIpAddress

* Update stew/shims/net.nim

Co-authored-by: Jacek Sieka <jacek@status.im>

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
2023-11-08 01:55:31 +00:00
Etan Kissling 3159137d9a
workaround codegen error for `Base10.decode` (#111)
Calling `Base10.decode` may lead to different structures being generated
for use with `uint64`.

The one normally generated is:

```
struct tyObject_Result__559ckyoL0ZZBsNFIYXjaoeg {NIM_BOOL o;
union{
struct {NCSTRING e;
} _o_1;
struct {unsigned long long v;
} _o_2;
};
```

But sometimes, it may be generated as:

```
struct tyObject_Result__xZhi1m1g75ioXsKjx9bN5bg {NIM_BOOL o;
union{
struct {NCSTRING e;
} _o_1;
struct {NU64 v;
} _o_2;
};
```

When the latter is generated, the compiler throws with:
```
error: passing 'tyObject_Result__xZhi1m1g75ioXsKjx9bN5bg' (aka 'struct tyObject_Result__xZhi1m1g75ioXsKjx9bN5bg') to parameter of incompatible type 'tyObject_Result__559ckyoL0ZZBsNFIYXjaoeg' (aka 'struct tyObject_Result__559ckyoL0ZZBsNFIYXjaoeg')
```
for
```
proc getInt*(ht: HttpTables, key: string): uint64 =
  let res = Base10.decode(uint64, ht.getString(key))
  if res.isOk():
    res.get()    # This line may lead to the compiler error above
  else:
    0'u64
```

By passing the type as a generic param, the `unsigned long long` version
gets consistently generated / used regardless of include order.

Minimal POC to trigger the bug, from `nimbus-eth2` root:
```
echo 'import beacon_chain/conf, beacon_chain/sync/sync_manager' >x.nim
nim c -d:"libp2p_pki_schemes=secp256k1" -r x
```
Swapping include order (`conf` after `sync_manager`) works.
2023-08-25 00:04:33 +02:00
Jordan Hrycaj b17ac2e753
Disentangle cascaded unit tests for interval sets (#208)
why:
  Some sub-tests failed when run directly
2023-08-22 10:38:16 +01:00
tersec 326ef09a46
remove dead code under Nim 1.6+ (#206) 2023-07-31 21:07:48 +00:00
Jacek Sieka 02f0929fc4
avoid zeroMem (#207)
on cached data, it doubles read time (!)
2023-07-21 08:01:07 +02:00
tersec 7afe7e3c07
deprecate pre-1.6 shims (#205)
* deprecate pre-1.6 shims

* revert stddefects shim deprecation until CI stops testing 1.2
2023-07-15 17:17:27 +00:00
tersec 422b6e1435
remove Nim 1.2 and 1.4 support (#204) 2023-07-05 13:13:50 +00:00
Jacek Sieka 2cf408b960
Graduate stew/results -> results (#185)
Since the results package has seen "stable" use for quite a while now,
it's as good time a time as any to release 1.0 and migrate it out of
stew, thus signalling API stability of some sort.

Part of that "stabilization" is underway in the nim-results [issue
tracker](https://github.com/arnetheduck/nim-results/issues/30).
2023-07-05 12:50:21 +02:00
andri lim 5c519d8582
fix results compiletime regression (#203)
* fix results compiletime regression

* disable results.value compiletime test for pre 1.6 nim
2023-07-05 10:07:17 +02:00
Jacek Sieka 8bb07fac39
results: fix `catch` template for statements (#201)
* results: fix `catch` template for statements

* disable void catch tests on pre-1.6
2023-06-28 10:57:00 +02:00
Jacek Sieka d085e48e89
results: add `mapConvertErr`, `mapCastErr` (#178)
We already have `mapConvert` and `mapCast` - this completes the API with
corresponding `Err` versions similar to `mapErr`.

The `Convert` / `Cast` operators are of somewhat dubious value - ie
they exist as "efficiency" shortcuts for `map` for the case that the
mapping should be done as a simple cast / conversion - an alternative
would be to deprecate these features and aim for some other, more
generic version that involves a type conversion library such as
https://github.com/status-im/nim-stew/pull/34, though this inherently,
and perhaps rightly, would be limited to "error-free" conversions.

Regardless, these helpers provide balance to the existing API.
2023-06-28 10:27:45 +02:00
tersec 9958aac68a
remove workaround for unsupported Nim 0.19 and earlier (#200)
* remove workaround for unsupported Nim 0.19 and earlier

* replace some proc with func
2023-06-15 13:13:41 +00:00
tersec 65ce2203f0
unconditionally pass through std/os and deprecate shim/os (#199) 2023-06-15 14:55:16 +02:00
tersec 607059fe31
rm copy of parseHex() from 1.2+ stdlib; some proc -> func (#197) 2023-06-15 14:21:51 +02:00
Jacek Sieka 273ce152a6
bitops2: fix resizing casts (#194) 2023-06-15 13:52:54 +02:00
Etan Kissling 500a614310
fix `ProveField` warnings in `results` (#198)
Nim emits `ProveField` warnings with `if` on case object discriminator.
Replace with `case` instead to avoid those warnings.
Note we currently have `ProveField` disabled but it keeps showing up
sometimes when compiling with `nim c` instead of `make`.
2023-06-15 12:02:54 +02:00
Jacek Sieka ebbb391b9e
ptrops: add makeUncheckedArray (#193)
turns a pointer into an array pointer of the same type
2023-06-12 14:13:18 +02:00
Jacek Sieka 36e0eb8d89
varints: remove (#195) 2023-06-12 11:42:27 +02:00
tersec d9400ddea0
unconditionally pass through std/atomics and deprecate shim/atomics (#196) 2023-06-10 23:14:12 +02:00
Jacek Sieka 6c97f11c7c
results: work around nim codegen bug (#192)
https://github.com/nim-lang/Nim/issues/22049
2023-06-08 17:24:19 +02:00
Jacek Sieka 13e55ed27a
results: collections integration (#179)
This set of helpers allows treating Result and Opt as collections of 0
or 1 item, allowing iterating over them and checking "membership" - such
integration is useful in generic code which can then be generalised to
handle more complex cases - the integration is most useful with Opt.

One design tradeoff here is the "explicitness" of `items` vs `values`
for `Result` - technically error and value are "equal" and therefore we
shouldn't give preference to the value, but there exists a convenience
argument to treat the value as the "default" and therefore define
`items` / `contains` for `Result` as well - this PR chooses the more
conservative and explicit approach - a more liberal version can easily
be added later should motivating examples emerge.
2023-06-07 16:45:53 +02:00
Jacek Sieka 000eeb14a3
result: void-ness tightenings (#191)
* better error messages and less pollution
2023-06-07 13:34:50 +02:00
Jacek Sieka fc349393f6
results: prefer `value` as canonical name for getting value (#188)
A `Result` has a `value` and an `error`, while `get` exists for `Option`
comptibility mainly - thus, use `value` more consistently.
2023-06-07 10:40:03 +02:00
Etan Kissling 7b4c9407f2
add `enumStyle` helper macro (#189)
For serialization and parsing, distinguishing enums with numeric values
from enums with associated strings for each value is useful. This adds
foundational helpers to allow such distinction.
2023-05-26 15:41:13 +03:00
diegomrsantos 003fe9f0c8
remove cast warnings (#186) 2023-05-23 11:05:55 +02:00
Jacek Sieka 266e9002f3
results: Add Opt/Result converters (#177)
Add `optError`, `optValue`, to convert back and forth between Opt and Result
These conversions end up being more common than others since "trivial"  success/fail-style API often use Opt while combining such API into combined operations tends to prefer richer error reporting.
2023-05-11 16:34:41 +03:00
Jacek Sieka 111d939940
assign2: guard against self-assignment / overlapping openArray (#182) 2023-04-25 21:32:22 +02:00
diegomrsantos 8caa977199
remove HoleEnumConv warning (#184) 2023-04-25 18:16:50 +02:00