Skip to content

Commit

Permalink
Ban duplicates of parity-uil-mem from being linked into the same prog…
Browse files Browse the repository at this point in the history
…ram (#363)

* Prevent multiple versions of parity-uil-mem from being linked into the same program

* fmt

* parity-util-mem: add a warning about defining global allocs

* parity-util-mem: document empty build script

* parity-util-mem: extend the warning based on David comments
  • Loading branch information
ordian authored Mar 25, 2020
1 parent 791f552 commit 8a29232
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parity-util-mem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
### Breaking
- Prevent multiple versions from being linked into the same program. [#363](https://github.com/paritytech/parity-common/pull/363)

## [0.6.0] - 2020-03-13
- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361)
Expand Down
7 changes: 7 additions & 0 deletions parity-util-mem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ description = "Collection of memory related utilities"
license = "MIT OR Apache-2.0"
edition = "2018"

# Prevent multiple versions from being linked into the same program.
links = "parity-util-mem-ban-duplicates"
# `links` requires a build script to be present:
# https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
# so we use an empty build script
build = "build.rs"

[dependencies]
cfg-if = "0.1.10"
dlmalloc = { version = "0.1.3", features = ["global"], optional = true }
Expand Down
14 changes: 14 additions & 0 deletions parity-util-mem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Collection of memory related utilities.

## WARNING

When `parity-util-mem` is used as a dependency with any of the global allocator features enabled,
it must be the sole place where a global allocator is defined.
The only exception to this rule is when used in a `no_std` context or when the `estimate-heapsize` feature is used.

Because of that, it must be present in the dependency tree with a single version.
Starting from version 0.7, having duplicate versions of `parity-util-mem` will lead
to a compile-time error. It still will be possible to have 0.6 and 0.7 versions in the same binary though.

Unless heeded you risk UB; see discussion in [issue 364].

[issue 364]: https://github.com/paritytech/parity-common/issues/364

## Features

- estimate-heapsize : Do not use allocator, but `size_of` or `size_of_val`.
Expand Down
1 change: 1 addition & 0 deletions parity-util-mem/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}

0 comments on commit 8a29232

Please sign in to comment.