Commit graph

36 commits

Author SHA1 Message Date
Henrik Böving
9db52c7fa6
fix: file read buffer overflow (#13392)
This PR fixes a heap buffer overflow in `lean_io_prim_handle_read` that
was triggered through an
integer overflow in the size computation of an allocation. In addition
it places several checked
arithmetic operations on all relevant allocation paths to have potential
future overflows be turned
into crashes instead. The offending code now throws an out of memory
error instead.

Closes: #13388
2026-04-13 17:56:27 +00:00
Eric Wieser
18248651a3
fix: call delete [] on array allocations (#11453)
This PR fixes undefined behavior where `delete` (instead of `delete[]`)
is called on an object allocated with `new[]`.
2025-12-10 16:51:54 +00:00
Eric Wieser
0106ca3bec
fix: undefined symbol without LEAN_USE_GMP (#9106)
This PR fixes `undefined symbol: lean::mpz::divexact(lean::mpz const&,
lean::mpz const&)` when building without `LEAN_USE_GMP`

This fixes a regression in #8089
2025-07-03 16:50:21 +00:00
Rob23oba
9f06aff834
feat: optimized division without remainder for Int and Nat (#8089)
This PR adds optimized division functions for `Int` and `Nat` when the
arguments are known to be divisible (such as when normalizing
rationals). These are backed by the gmp functions `mpz_divexact` and
`mpz_divexact_ui`. See also leanprover-community/batteries#1202.
2025-04-29 07:23:35 +00:00
Sebastian Ullrich
3b85d26af7
perf: use mimalloc for all Lean allocations (#7736) 2025-03-30 23:00:17 +00:00
Eric Wieser
6cf3402f1c
perf: use free_sized in mpz.cpp (#6825)
The performance win here is pretty negligible (and of course irrelevant
with the small allocator enabled), but this is consistent with it being
used elsewhere.

Follow-up to #6598
2025-03-03 08:47:15 +00:00
Henrik Böving
93dd6f2b36
feat: add Int16/Int32/Int64 (#5885)
This adds all fixed width integers with the exception of `ssize_t` so
the code is quick to review as everything just behaves the same.
2024-11-04 13:18:05 +00:00
Henrik Böving
193b6f2bec
feat: define Int8 (#5790) 2024-10-25 06:06:40 +00:00
Joe Hendrix
e2b3b34d14
feat: introduce native functions for Int.ediv / Int.emod (#3376)
These still need tests, but I thought I'd upstream so I can use
benchmarking and check for build errors.
2024-02-19 15:04:51 +00:00
Joachim Breitner
bd89787a87
chore: fix CPP warnings about static_assert (#3005)
else I see
```
[ 69%] Building CXX object runtime/CMakeFiles/leanrt.dir/platform.cpp.o
/home/jojo/build/lean/lean4/src/runtime/io.cpp:509:75: warning: 'static_assert' with no message is a C++17 extension [-Wc++17-extensions]
    static_assert(sizeof(std::chrono::milliseconds::rep) <= sizeof(uint64));
                                                                          ^
                                                                          , ""
/home/jojo/build/lean/lean4/src/runtime/io.cpp:517:74: warning: 'static_assert' with no message is a C++17 extension [-Wc++17-extensions]
    static_assert(sizeof(std::chrono::nanoseconds::rep) <= sizeof(uint64));
                                                                         ^
                                                                         , ""
2 warnings generated.
```
when building
2023-12-01 13:00:01 +00:00
Gabriel Ebner
3deef5d32a fix: mpz: honor LEAN_SMALL_ALLOCATOR 2023-01-24 11:37:43 -08:00
Sebastian Ullrich
3f9ba30424 fix: integer overflows 2022-11-15 07:37:54 -08:00
Sebastian Ullrich
0d03c6e319 chore: revise non-GMP interface 2022-03-16 17:32:51 -07:00
Gabriel Ebner
c7565c446a fix: casts on big-endian 2021-12-02 09:57:58 -08:00
Sebastian Ullrich
1ade96cfab fix: assertion with USE_GMP=OFF 2021-12-02 15:11:47 +01:00
Leonardo de Moura
e9e40789c1 fix: mpz::power for USE_GMP=OFF 2021-11-30 17:57:33 -08:00
Leonardo de Moura
83d6eb1c72 fix: mpz::mul2k for USE_GMP=OFF 2021-11-30 17:19:16 -08:00
Leonardo de Moura
8aca088752 feat: mpz missing methods for USE_GMP=OFF 2021-11-30 16:46:53 -08:00
Leonardo de Moura
e5b3b180dc feat: some mpz methods for LEAN_USE_GMP=OFF 2021-11-29 17:55:04 -08:00
Leonardo de Moura
ec6932fbb7 feat: some mpz methods for LEAN_USE_GMP=OFF 2021-11-29 16:01:07 -08:00
Leonardo de Moura
68fc9a9115 feat: add dummy mpz implementation for LEAN_USE_GMP=OFF 2021-11-29 11:42:08 -08:00
Leonardo de Moura
0002d8bd04 chore: missing #ifdef LEAN_USE_GMP 2021-11-29 11:35:13 -08:00
Leonardo de Moura
6396f3b2c1 chore: simplify mpz.h
Add basic support for `LEAN_USE_GMP=OFF`.
2021-11-29 11:11:49 -08:00
Leonardo de Moura
6d0fa6da7c chore: remove mpz dead code 2021-10-26 12:05:19 -07:00
Leonardo de Moura
c8406a301d chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
Joe Hendrix
9bd60c7519 feat: Nat/Fin/UInt instances of bitwise classes 2021-03-04 15:42:43 -08:00
Leonardo de Moura
2f1ec93289 chore: move runtime implementation to src/runtime 2020-05-22 14:35:16 -07:00
Leonardo de Moura
1a77ee4f89 chore: delete old runtime directory 2020-05-18 11:33:18 -07:00
Leonardo de Moura
8bdca35282 chore: use #include <lean/runtime/...> for runtime .h files 2020-05-18 11:30:07 -07:00
Sebastian Ullrich
9707672cc8 fix(runtime/mpz): fix and document size_t functions 2019-07-05 16:27:04 -07:00
Sebastian Ullrich
2c9dce6eed fix(runtime/mpz): use size_t instead of unsigned long for Windows compatibility 2019-07-05 11:24:15 +02:00
Sebastian Ullrich
956a047d1e chore(library/compiler/extern_attribute): style 2019-02-14 14:07:05 -08:00
Leonardo de Moura
425a4b70d1 feat(library/init/data/int/basic): use extern attribute, and fix div/mod mess
Now, int.div and int.mod behave like C++ `/` and `%` for int,
moreover, they satisfy

          (a/b)*b + (a%b) = a
2019-02-12 11:41:46 -08:00
Leonardo de Moura
b2f3d3f456 chore(*): remove redundant code 2018-05-22 16:46:04 -07:00
Leonardo de Moura
dfc5adbd2a feat(runtime/lean_obj): add integer primitives 2018-05-17 17:47:22 -07:00
Leonardo de Moura
0556412f8d refactor(*): add runtime folder
@kha The runtime folder includes what is needed to link a
standalone Lean program. It is still contains some unnecessary files.
We will be able to remove them after we release Lean4.
2018-05-14 14:23:56 -07:00
Renamed from src/util/mpz.cpp (Browse further)