Skip to content

Commit e9dc137

Browse files
vpatakottuVarshita Patakottu
andauthored
[boost-container] Fix C4146 warnings in dlmalloc_2_8_6.c and dlmalloc_ext_2_8_6.c (#47091)
Co-authored-by: Varshita Patakottu <vpatakottu@microsoft.com>
1 parent 120deac commit e9dc137

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
diff --git a/include/boost/container/detail/config_begin.hpp b/include/boost/container/detail/config_begin.hpp
2+
index d459a06..693bb14 100644
3+
--- a/include/boost/container/detail/config_begin.hpp
4+
+++ b/include/boost/container/detail/config_begin.hpp
5+
@@ -19,7 +19,6 @@
6+
#pragma warning (push)
7+
#pragma warning (disable : 4619) // there is no warning number 'XXXX'
8+
#pragma warning (disable : 4127) // conditional expression is constant
9+
- #pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
10+
#pragma warning (disable : 4197) // top-level volatile in cast is ignored
11+
#pragma warning (disable : 4251) // "identifier" : class "type" needs to have dll-interface to be used by clients of class "type2"
12+
#pragma warning (disable : 4275) // non DLL-interface classkey "identifier" used as base for DLL-interface classkey "identifier"
13+
diff --git a/src/dlmalloc_2_8_6.c b/src/dlmalloc_2_8_6.c
14+
index 4a5c241..f530927 100644
15+
--- a/src/dlmalloc_2_8_6.c
16+
+++ b/src/dlmalloc_2_8_6.c
17+
@@ -1429,9 +1429,6 @@ DLMALLOC_EXPORT int mspace_mallopt(int, int);
18+
19+
/*------------------------------ internal #includes ---------------------- */
20+
21+
-#ifdef _MSC_VER
22+
-#pragma warning( disable : 4146 ) /* no "unsigned" warnings */
23+
-#endif /* _MSC_VER */
24+
#if !NO_MALLOC_STATS
25+
#include <stdio.h> /* for printing in malloc_stats */
26+
#endif /* NO_MALLOC_STATS */
27+
@@ -2219,7 +2216,7 @@ typedef unsigned int flag_t; /* The type of various bit flag sets */
28+
#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A)))
29+
30+
/* Bounds on request (not chunk) sizes. */
31+
-#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2)
32+
+#define MAX_REQUEST ((0 - MIN_CHUNK_SIZE) << 2)
33+
#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
34+
35+
/* pad request bytes into a usable size */
36+
@@ -2922,13 +2919,13 @@ static size_t traverse_and_check(mstate m);
37+
#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i))
38+
39+
/* isolate the least set bit of a bitmap */
40+
-#define least_bit(x) ((x) & -(x))
41+
+#define least_bit(x) ((x) & (0 - (x)))
42+
43+
/* mask with all bits to left of least bit of x on */
44+
-#define left_bits(x) ((x<<1) | -(x<<1))
45+
+#define left_bits(x) (((x)<<1) | (0 - ((x)<<1)))
46+
47+
/* mask with all bits to left of or equal to least bit of x on */
48+
-#define same_or_left_bits(x) ((x) | -(x))
49+
+#define same_or_left_bits(x) ((x) | (0 - (x)))
50+
51+
/* index corresponding to given bit. Use x86 asm if possible */
52+
53+
@@ -4429,7 +4426,7 @@ static void dispose_chunk(mstate m, mchunkptr p, size_t psize) {
54+
/* allocate a large request from the best fitting chunk in a treebin */
55+
static void* tmalloc_large(mstate m, size_t nb) {
56+
tchunkptr v = 0;
57+
- size_t rsize = -nb; /* Unsigned negation */
58+
+ size_t rsize = 0 - nb; /* Unsigned negation */
59+
tchunkptr t;
60+
bindex_t idx;
61+
compute_tree_index(nb, idx);
62+
@@ -4916,7 +4913,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
63+
*/
64+
char* br = (char*)mem2chunk((size_t)(((size_t)((char*)mem + alignment -
65+
SIZE_T_ONE)) &
66+
- -alignment));
67+
+ (0 - alignment)));
68+
char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)?
69+
br : br+alignment;
70+
mchunkptr newp = (mchunkptr)pos;
71+
@@ -5420,7 +5417,7 @@ mspace create_mspace(size_t capacity, int locked) {
72+
size_t msize;
73+
ensure_initialization();
74+
msize = pad_request(sizeof(struct malloc_state));
75+
- if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) {
76+
+ if (capacity < (size_t) (0 - (msize + TOP_FOOT_SIZE + mparams.page_size))) {
77+
size_t rs = ((capacity == 0)? mparams.granularity :
78+
(capacity + TOP_FOOT_SIZE + msize));
79+
size_t tsize = granularity_align(rs);
80+
@@ -5440,7 +5437,7 @@ mspace create_mspace_with_base(void* base, size_t capacity, int locked) {
81+
ensure_initialization();
82+
msize = pad_request(sizeof(struct malloc_state));
83+
if (capacity > msize + TOP_FOOT_SIZE &&
84+
- capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) {
85+
+ capacity < (size_t) (0 - (msize + TOP_FOOT_SIZE + mparams.page_size))) {
86+
m = init_user_mstate((char*)base, capacity);
87+
m->seg.sflags = EXTERN_BIT;
88+
set_lock(m, locked);
89+
diff --git a/test/expand_bwd_test_template.hpp b/test/expand_bwd_test_template.hpp
90+
index e86a413..8ad7e47 100644
91+
--- a/test/expand_bwd_test_template.hpp
92+
+++ b/test/expand_bwd_test_template.hpp
93+
@@ -98,7 +98,7 @@ bool test_insert_with_expand_bwd()
94+
Vect data_to_insert;
95+
data_to_insert.resize(InsertSize[iteration]);
96+
for(unsigned int i = 0; i < InsertSize[iteration]; ++i){
97+
- data_to_insert[i] = static_cast<value_type>((int)-i);
98+
+ data_to_insert[i] = static_cast<value_type>((int)(0-i));
99+
}
100+
101+
if(!life_count<value_type>::check(InitialSize[iteration]+InsertSize[iteration]))
102+
@@ -161,7 +161,7 @@ bool test_assign_with_expand_bwd()
103+
std::vector<value_type> data_to_insert;
104+
data_to_insert.resize(InsertSize[iteration]);
105+
for(unsigned int i = 0; i < InsertSize[iteration]; ++i){
106+
- data_to_insert[i] = static_cast<value_type>((int)-i);
107+
+ data_to_insert[i] = static_cast<value_type>((int)(0-i));
108+
}
109+
110+
//Insert initial data to the vector to test

ports/boost-container/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vcpkg_from_github(
88
HEAD_REF master
99
PATCHES
1010
posix-threads.diff
11+
fix_msvc_c4146_warnings.diff
1112
)
1213

1314
set(FEATURE_OPTIONS "")

ports/boost-container/vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$comment": "Automatically generated by scripts/boost/generate-ports.ps1",
33
"name": "boost-container",
44
"version": "1.88.0",
5+
"port-version": 1,
56
"description": "Boost container module",
67
"homepage": "https://www.boost.org/libs/container",
78
"license": "BSL-1.0",

scripts/boost/generate-ports.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ $defaultPortVersion = 0
3131
$portVersions = @{
3232
'boost-charconv' = 1;
3333
'boost-locale' = 1;
34+
'boost-container' = 1;
3435
}
3536

3637
function Get-PortVersion {

versions/b-/boost-container.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "a229975f097e1c17a2d13161cf3cb3706525f62c",
5+
"version": "1.88.0",
6+
"port-version": 1
7+
},
38
{
49
"git-tree": "718d272c732f63acb5fd80814fc85563f171c735",
510
"version": "1.88.0",

versions/baseline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@
890890
},
891891
"boost-container": {
892892
"baseline": "1.88.0",
893-
"port-version": 0
893+
"port-version": 1
894894
},
895895
"boost-container-hash": {
896896
"baseline": "1.88.0",

0 commit comments

Comments
 (0)