Skip to content

Commit 71e4f4e

Browse files
committed
Fix pointer-size-related compile errors in dev plugins
1 parent 41a81f9 commit 71e4f4e

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

plugins/devel/eventExample.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,26 @@ void jobCompleted(color_ostream& out, void* job) {
128128
}
129129

130130
void timePassed(color_ostream& out, void* ptr) {
131-
out.print("Time: %d\n", (int32_t)(ptr));
131+
out.print("Time: %d\n", (intptr_t)(ptr));
132132
}
133133

134134
void unitDeath(color_ostream& out, void* ptr) {
135-
out.print("Death: %d\n", (int32_t)(ptr));
135+
out.print("Death: %d\n", (intptr_t)(ptr));
136136
}
137137

138138
void itemCreate(color_ostream& out, void* ptr) {
139-
int32_t item_index = df::item::binsearch_index(df::global::world->items.all, (int32_t)ptr);
139+
int32_t item_index = df::item::binsearch_index(df::global::world->items.all, (intptr_t)ptr);
140140
if ( item_index == -1 ) {
141141
out.print("%s, %d: Error.\n", __FILE__, __LINE__);
142142
}
143143
df::item* item = df::global::world->items.all[item_index];
144144
df::item_type type = item->getType();
145145
df::coord pos = item->pos;
146-
out.print("Item created: %d, %s, at (%d,%d,%d)\n", (int32_t)(ptr), ENUM_KEY_STR(item_type, type).c_str(), pos.x, pos.y, pos.z);
146+
out.print("Item created: %d, %s, at (%d,%d,%d)\n", (intptr_t)(ptr), ENUM_KEY_STR(item_type, type).c_str(), pos.x, pos.y, pos.z);
147147
}
148148

149149
void building(color_ostream& out, void* ptr) {
150-
out.print("Building created/destroyed: %d\n", (int32_t)ptr);
150+
out.print("Building created/destroyed: %d\n", (intptr_t)ptr);
151151
}
152152

153153
void construction(color_ostream& out, void* ptr) {
@@ -168,7 +168,7 @@ void syndrome(color_ostream& out, void* ptr) {
168168
}
169169

170170
void invasion(color_ostream& out, void* ptr) {
171-
out.print("New invasion! %d\n", (int32_t)ptr);
171+
out.print("New invasion! %d\n", (intptr_t)ptr);
172172
}
173173

174174
void unitAttack(color_ostream& out, void* ptr) {

plugins/devel/memview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ size_t convert(const std::string& p,bool ishex=false)
5151
conv>>ret;
5252
return ret;
5353
}
54-
bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
54+
bool isAddr(uintptr_t *trg,vector<t_memrange> & ranges)
5555
{
5656
if(trg[0]%4==0)
5757
for(size_t i=0;i<ranges.size();i++)
@@ -74,7 +74,7 @@ void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,color_ostream
7474
{
7575
con.reset_color();
7676

77-
if(isAddr((uint32_t *)(buf+j+i),ranges))
77+
if(isAddr((uintptr_t *)(buf+j+i),ranges))
7878
con.color(COLOR_LIGHTRED); //coloring in the middle does not work
7979
//TODO make something better?
8080
}

plugins/devel/rprobe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ command_result rprobe (color_ostream &out, vector <string> & parameters)
153153
int c = sizeof(*rd) / sizeof(int32_t);
154154
for (int j = 0; j < c; j++) {
155155
if (j % 8 == 0)
156-
out << endl << setfill('0') << setw(8) << hex << (int)(rd+j) << ": ";
156+
out << endl << setfill('0') << setw(8) << hex << (intptr_t)(rd+j) << ": ";
157157
out << " " << setfill('0') << setw(8) << hex << p[j];
158158
}
159159
out << setfill(' ') << setw(0) << dec << endl;

plugins/devel/vectors.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
5050
return CR_OK;
5151
}
5252

53-
static bool hexOrDec(string &str, uint32_t &value)
53+
static bool hexOrDec(string &str, uintptr_t &value)
5454
{
5555
if (str.find("0x") == 0 && sscanf(str.c_str(), "%x", &value) == 1)
5656
return true;
@@ -69,7 +69,7 @@ static bool mightBeVec(vector<t_memrange> &ranges,
6969
// Vector length might not be a multiple of 4 if, for example,
7070
// it's a vector of uint8_t or uint16_t. However, the actual memory
7171
// allocated to the vector should be 4 byte aligned.
72-
if (((int)vec->start % 4 != 0) || ((int)vec->alloc_end % 4 != 0))
72+
if (((intptr_t)vec->start % 4 != 0) || ((intptr_t)vec->alloc_end % 4 != 0))
7373
return false;
7474

7575
for (size_t i = 0; i < ranges.size(); i++)
@@ -130,7 +130,7 @@ static void vectorsUsage(color_ostream &con)
130130
static void printVec(color_ostream &con, const char* msg, t_vecTriplet *vec,
131131
uint32_t start, uint32_t pos, std::vector<t_memrange> &ranges)
132132
{
133-
uint32_t length = (int)vec->end - (int)vec->start;
133+
uint32_t length = (intptr_t)vec->end - (intptr_t)vec->start;
134134
uint32_t offset = pos - start;
135135

136136
con.print("%8s offset %06p, addr %010p, start %010p, length %u",
@@ -158,7 +158,7 @@ command_result df_vectors (color_ostream &con, vector <string> & parameters)
158158
return CR_FAILURE;
159159
}
160160

161-
uint32_t start = 0, bytes = 0;
161+
uintptr_t start = 0, bytes = 0;
162162

163163
if (!hexOrDec(parameters[0], start))
164164
{
@@ -172,7 +172,7 @@ command_result df_vectors (color_ostream &con, vector <string> & parameters)
172172
return CR_FAILURE;
173173
}
174174

175-
uint32_t end = start + bytes;
175+
uintptr_t end = start + bytes;
176176

177177
// 4 byte alignment.
178178
while (start % 4 != 0)
@@ -200,10 +200,10 @@ command_result df_vectors (color_ostream &con, vector <string> & parameters)
200200
{
201201
con.print("Scanning %u bytes would read past end of memory "
202202
"range.\n", bytes);
203-
uint32_t diff = end - (int)range.end;
203+
size_t diff = end - (intptr_t)range.end;
204204
con.print("Cutting bytes down by %u.\n", diff);
205205

206-
end = (uint32_t) range.end;
206+
end = (uintptr_t) range.end;
207207
}
208208
startInRange = true;
209209
break;
@@ -215,11 +215,11 @@ command_result df_vectors (color_ostream &con, vector <string> & parameters)
215215
return CR_FAILURE;
216216
}
217217

218-
uint32_t pos = start;
218+
uintptr_t pos = start;
219219

220-
const uint32_t ptr_size = sizeof(void*);
220+
const size_t ptr_size = sizeof(void*);
221221

222-
for (uint32_t pos = start; pos < end; pos += ptr_size)
222+
for (uintptr_t pos = start; pos < end; pos += ptr_size)
223223
{
224224
// Is it an embeded vector?
225225
if (pos <= ( end - sizeof(t_vecTriplet) ))
@@ -238,7 +238,7 @@ command_result df_vectors (color_ostream &con, vector <string> & parameters)
238238
// Is it a vector pointer?
239239
if (pos <= (end - ptr_size))
240240
{
241-
uint32_t ptr = * ( (uint32_t*) pos);
241+
uintptr_t ptr = * ( (uintptr_t*) pos);
242242

243243
if (inAnyRange(ranges, (void *) ptr))
244244
{
@@ -275,7 +275,7 @@ command_result df_clearvec (color_ostream &con, vector <string> & parameters)
275275
return CR_FAILURE;
276276
}
277277

278-
uint32_t start = 0, bytes = 0;
278+
uintptr_t start = 0, bytes = 0;
279279

280280
if (!hexOrDec(parameters[0], start))
281281
{
@@ -301,7 +301,7 @@ command_result df_clearvec (color_ostream &con, vector <string> & parameters)
301301
for (size_t i = 0; i < parameters.size(); i++)
302302
{
303303
std::string addr_str = parameters[i];
304-
uint32_t addr;
304+
uintptr_t addr;
305305
if (!hexOrDec(addr_str, addr))
306306
{
307307
con << "'" << addr_str << "' not a number." << std::endl;
@@ -329,7 +329,7 @@ command_result df_clearvec (color_ostream &con, vector <string> & parameters)
329329
else
330330
{
331331
// Is it a pointer to a vector?
332-
addr = * ( (uint32_t*) addr);
332+
addr = * ( (uintptr_t*) addr);
333333
vec = (t_vecTriplet*) addr;
334334

335335
if (inAnyRange(ranges, (void *) addr) && mightBeVec(ranges, vec))

0 commit comments

Comments
 (0)