Commit Graph

112 Commits

Author SHA1 Message Date
Mamy Ratsimbazafy b4b3841a85
Revert "Allow comparing Result[void, E] (#71)" (#73)
This reverts commit 068412ff4e.
2021-01-26 14:20:09 +01:00
Mamy Ratsimbazafy 068412ff4e
Allow comparing Result[void, E] (#71) 2021-01-26 14:12:08 +01:00
Jacek Sieka 5cf4feabea
leb128 + bitops fixes (#66)
Leb128 is a variable-length encoding for unsigned integers that is used
in a number of contexts - in particular, wasm, dwarf and protobuf.

This is an optimized low-level implementation that unrolls the loop
reading/writing the buffer - it is suitable to use as base for a more
specific API - no memory allocations, no exceptions.

This PR also fixes bitops2 to not raise on certaing uint->int
conversions, adapting bitops to nim 1.0 conversion rules by using a cast
instead of raising on uint->int conversion
2020-12-15 17:07:20 +02:00
Jacek Sieka d8d914332d
random helpers (#64)
* random helpers

* arrayops as a home for small array/openArray utilities
* assign2 - a replacement for genericAssign and assignment operators in
general which in nim are very slow
* use assign2 in a few places to speed things up

* fixes

* fixes
2020-12-10 12:05:22 +01:00
Jacek Sieka e15c1ae012
results: prevent dangling cstring pointers in result (#63) 2020-12-09 17:21:12 +01:00
Eugene Kabanov ff524ed832
Fix getCurrentDir() gcc compilation warning. (#61)
* Fix GCC warning on getcwd usage.
* Check returned value of getCurrentDir() in tests.
2020-11-04 15:22:38 +02:00
Eugene Kabanov bc3b4cf2de
Fix inherited objects problem. (#59) 2020-10-20 17:43:38 +03:00
Eugene Kabanov 7018fb0b5e
Procedures to set user-only Windows ACL settings for files and folders. (#58)
* Initial commit of UserOnly Windows ACL settings for files and folders.

* Move ACL procedures to windows/acl.
Move ACL tests to test_winacl.nim.

* Add test_winacl.nim

* Fix *nix compilation problem.

* More proper fix for *nix targets.
2020-10-15 14:27:58 +02:00
jangko 999d3ca7ce
fixes bitops2: 'countOnesBuiltin' and 'parityBuiltin' when feeded 'unsigned' on 32 bit platform 2020-09-30 18:28:36 +07:00
Eugene Kabanov 7a2b6dbdda
IO2 (#53)
* Initial commit of io2 module

* Rename to io2.
Add createPath with permissions.
Add writeFile with permissions.
Add tests.

* Add test_io2 to all tests.

* Add posix permissions.

* Add toString procedure for set[Permission] and tests.

* Remove safeio.nim

* Add setPermissions procedures.
Fix writeFile() to change permissions.
Add more writeFile() tests.

* Change C ReadOnly/WriteOnly/ReadWrite to pair of Read/Write.
Add tests for openFile.

* File handles is no inherited by default, with option to turn on inheritance.

* Review comments fixes.
More tests.

* Fix x86 compilation problems.

* Rename toSet -> toPermissions.

* Avoid race condition on writeFile permissions.
2020-09-22 08:53:00 +03:00
Eugene Kabanov 4c695e5933
Allow any integer type to use CT.isEqual(). (#51)
* Allow any integer type to use CT.isEqual().
* Add tests for different integer types.
2020-07-30 20:09:49 +03:00
cheatfate a5560c1ea6
Add constant isEqual operation for openarrays. 2020-07-29 01:43:09 +03:00
Jacek Sieka ec2f52b0ce
results: make `?` work with void (#50) 2020-07-13 18:09:45 +02:00
Zahary Karadjov 32b86bfd1f
Faux closures: a facility for creating closure-like non-closure procs
This code is extracted from the error-handling proposal where it's
used to implement `Try` blocks (Faux closures are created there in
order to assign raises lists to them). The desktop team faced a
similar problem where the `spawn` API doesn't support closures,
but the restriction can be easily worked-around with faux closures.
2020-07-07 20:29:04 +03:00
Zahary Karadjov 61d5cfc376
Add array[N, byte].fromHex(string) 2020-07-02 18:00:39 +03:00
Zahary Karadjov 152eb1b58c Add 'checkedEnumAssign' for validating tainted enum inputs 2020-06-24 14:15:45 +03:00
jangko e1b6d5c92f
add test for vcc compiler 2020-06-15 21:09:41 +07:00
Zahary Karadjov b9e847a143
Add bitops2.getBitsBE 2020-06-01 19:49:46 +03:00
Zahary Karadjov a99dafab42
Handle another corner case in recordFields 2020-05-27 11:30:56 +03:00
Zahary Karadjov 4ffd3e1f59
Support type hierarchies in recordFields 2020-05-26 18:56:41 +03:00
Zahary Karadjov f003557674
typedParams will now handle parameters with pragmas 2020-05-23 20:12:56 +03:00
Zahary Karadjov d0f5be4971
Fix a compilation error when using a 32-bit varint parser 2020-05-12 22:59:46 +03:00
Zahary Karadjov c500d3dda1
Some renames to cater to the latest FastStreams API 2020-05-12 15:02:06 +03:00
Jacek Sieka f125f6e8d1 space 2020-05-08 18:54:36 +03:00
Jacek Sieka 2d9226464d heterogenous `or`
Useful for translating `error` results
2020-05-08 18:54:36 +03:00
Jacek Sieka 720f1a254d
byteutils: compile-time to/fromBytes (#35) 2020-05-06 15:51:07 +02:00
Zahary Karadjov 1eed7a72b7
Make any accidental "run-time" usage of declval an error 2020-04-22 16:34:11 +03:00
Zahary Karadjov 9a0cded592
Add objects.declval 2020-04-22 15:41:42 +03:00
Jacek Sieka ff755bbf75
change get/[] to always raise Defect and tryGet to do eh bridge mode (#30)
* also sprinkle mixin randomly across the codebase
2020-04-16 18:23:12 +02:00
Jacek Sieka 805ef4f1b2
result: cleanups
* fix defect raising without `$`
* doc updates
* better `?` that doesn't cause raises effect (it should, because of
FieldError but...)
2020-04-11 16:22:37 +02:00
Jacek Sieka 5512e89d4c a few more cleanups
* add raises to endians2, bitops2 since they sometimes call C functions
2020-04-10 22:40:00 +03:00
Jacek Sieka 87ccf8e66b hex byte: raise instead of assert on hex-to-byte odd lengths 2020-04-10 22:40:00 +03:00
Jacek Sieka b06a5b6e32
result -> results (#27) 2020-04-07 11:43:07 +02:00
Jacek Sieka 9414202d53 result: `and` can deal with heterogenous values 2020-04-04 00:28:46 +03:00
Jacek Sieka 86739f99c4
Use defect for normal errors, document exception bridge mode (#20)
Co-authored-by: Zahary Karadjov <zahary@gmail.com>
2020-04-02 11:39:11 +02:00
Jacek Sieka 7287fffebe
result: add `expect` helper (#23)
* result: add `expect` helper

* result: use explicit conversion in mapConvert
2020-04-01 14:16:20 +02:00
Jacek Sieka d622c07a08
result: cleanups (#22)
* fix ResultError type
* add/fix documentation
* clean up raises (in preparation for better Defect handling)
* fix toException mixin
* work around compiler bug with more explicit types
* fix capture exception type
* fix result type on `?`
2020-03-30 22:49:13 +02:00
Ștefan Talpalaru 09e55cd375
stew/objects: add baseType() 2020-03-29 17:34:45 +02:00
Jacek Sieka 76beeb769e
fix fromBytes for zero length arrays 2020-03-07 23:29:46 +01:00
Jacek Sieka ca8fb7ebd0 add slice assignment for openarray 2020-03-05 12:11:25 +02:00
Jacek Sieka 598fe151f8 non-cast implementation of toBytes, add fromBytes 2020-03-05 12:11:25 +02:00
Jacek Sieka f5be0ab63a
add nim-result 2020-01-23 17:35:30 +01:00
Jacek Sieka 1edeabb453
Renames (#17)
* renames and warning fixes
* gitignore: nimcache
2019-12-20 13:23:30 +01:00
Jacek Sieka a36df61d2b
set, clear, toggle and change bits
* use standard bit manipulation naming
* fix signed overflow on large shifts
* add toggle
* add smoke tests
* branch-free changeBit
2019-12-20 12:49:20 +01:00
Jacek Sieka d8c2a64055
Merge pull request #16 from status-im/comparebyte
byteutils: lexicographical less than
2019-12-20 12:48:10 +01:00
Jacek Sieka 9c18a1cc55
byteutils: lexicographical less than 2019-12-19 13:29:38 +01:00
Yuriy Glukhov 1c1195dba3 Copied base32, 58, 64 from libp2p 2019-12-13 15:31:19 +02:00
Jacek Sieka e9d75c05f6
fix 1.0 test compat 2019-12-10 15:50:02 +01:00
andri lim 53c1ebe9d4 fixes 'nimFirstOne' for Nim v1.0.2 2019-10-23 09:36:16 +09:00
Zahary Karadjov 11b6a831cb Prepare for Nim v1.0.2 2019-10-23 09:36:16 +09:00
Jacek Sieka 5ada369741 ptrops: add 2019-09-26 18:25:19 +03:00
Zahary Karadjov 5f1dc751ca
Convenience varints API going from int straight to openarray 2019-09-08 22:33:03 -04:00
Zahary Karadjov 888a5aa82d Fix the failing overlaps test 2019-08-19 18:43:25 +03:00
Jacek Sieka 3689c58d1b bitseq failing test 2019-08-19 18:43:25 +03:00
Zahary Karadjov 19fd0cc489
Hide the complexity of dealing with the BitSeq marker bit inside an efficient machine words iterator 2019-08-06 21:02:03 +03:00
Zahary Karadjov 6be00f7c4b
Extract the varints code being used in the latest LibP2P back-end
Originally, this code was taken from
https://github.com/status-im/nim-libp2p/blob/master/libp2p/varint.nim

The API was refactored to make it easier to use in the networking
back-ends where the data is being consumed byte by byte.
2019-08-01 17:21:14 +03:00
Zahary Karadjov 2334aa0fb3
More code migrated from the beacon-chain repo 2019-07-31 02:25:12 +03:00
Zahary Karadjov 3fce87f0f5
Refactor the bitranges module
* The bit procs defined over number values and openarray are now part of
  the bitops2 module and use the more traditional LittleEndian indexing.

* Added BitSeq and BitArray types as defined in the ETH2 spec.
2019-07-31 02:20:49 +03:00
Jacek Sieka 7a87693eaf
refactor bitops2, add endians2 2019-07-06 20:47:08 +02:00
Jacek Sieka 904f84c8e0
add ranges 2019-07-06 20:45:27 +02:00
Jacek Sieka c95cee45bc
add byteutils 2019-07-06 20:07:41 +02:00
Jacek Sieka a9612d7320
add docs/appveyor/travis/test runner 2019-07-06 20:00:37 +02:00