mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
This commit is contained in:
parent
f4153bcbde
commit
bd5067b5a0
@ -90,4 +90,7 @@ template <typename T> FORCEINLINE T* ReallocT(T *t_ptr, size_t num_elements)
|
|||||||
return t_ptr;
|
return t_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** alloca() has to be called in the parent function, so define AllocaM() as a macro */
|
||||||
|
#define AllocaM(T, num_elements) ((T*)alloca((num_elements) * sizeof(T)))
|
||||||
|
|
||||||
#endif /* ALLOC_FUNC_HPP */
|
#endif /* ALLOC_FUNC_HPP */
|
||||||
|
@ -2946,7 +2946,7 @@ static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineID *engines = (EngineID*)alloca(idcount * sizeof(*engines));
|
EngineID *engines = AllocaM(EngineID, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
engines[i] = GetNewEngine(_cur_grffile, (VehicleType)feature, grf_load_byte(&buf))->index;
|
engines[i] = GetNewEngine(_cur_grffile, (VehicleType)feature, grf_load_byte(&buf))->index;
|
||||||
if (!wagover) last_engines[i] = engines[i];
|
if (!wagover) last_engines[i] = engines[i];
|
||||||
@ -2996,7 +2996,7 @@ static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount)
|
|||||||
|
|
||||||
static void CanalMapSpriteGroup(byte *buf, uint8 idcount)
|
static void CanalMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
CanalFeature *cfs = (CanalFeature*)alloca(idcount * sizeof(*cfs));
|
CanalFeature *cfs = AllocaM(CanalFeature, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
cfs[i] = (CanalFeature)grf_load_byte(&buf);
|
cfs[i] = (CanalFeature)grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
@ -3022,7 +3022,7 @@ static void CanalMapSpriteGroup(byte *buf, uint8 idcount)
|
|||||||
|
|
||||||
static void StationMapSpriteGroup(byte *buf, uint8 idcount)
|
static void StationMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
uint8 *stations = (uint8*)alloca(idcount * sizeof(*stations));
|
uint8 *stations = AllocaM(uint8, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
stations[i] = grf_load_byte(&buf);
|
stations[i] = grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
@ -3069,7 +3069,7 @@ static void StationMapSpriteGroup(byte *buf, uint8 idcount)
|
|||||||
|
|
||||||
static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount)
|
static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
uint8 *houses = (uint8*)alloca(idcount * sizeof(*houses));
|
uint8 *houses = AllocaM(uint8, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
houses[i] = grf_load_byte(&buf);
|
houses[i] = grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
@ -3095,7 +3095,7 @@ static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount)
|
|||||||
|
|
||||||
static void IndustryMapSpriteGroup(byte *buf, uint8 idcount)
|
static void IndustryMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
uint8 *industries = (uint8*)alloca(idcount * sizeof(*industries));
|
uint8 *industries = AllocaM(uint8, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
industries[i] = grf_load_byte(&buf);
|
industries[i] = grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
@ -3121,7 +3121,7 @@ static void IndustryMapSpriteGroup(byte *buf, uint8 idcount)
|
|||||||
|
|
||||||
static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount)
|
static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
uint8 *indtiles = (uint8*)alloca(idcount * sizeof(*indtiles));
|
uint8 *indtiles = AllocaM(uint8, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
indtiles[i] = grf_load_byte(&buf);
|
indtiles[i] = grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
@ -3147,7 +3147,7 @@ static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount)
|
|||||||
|
|
||||||
static void CargoMapSpriteGroup(byte *buf, uint8 idcount)
|
static void CargoMapSpriteGroup(byte *buf, uint8 idcount)
|
||||||
{
|
{
|
||||||
CargoID *cargos = (CargoID*)alloca(idcount * sizeof(*cargos));
|
CargoID *cargos = AllocaM(CargoID, idcount);
|
||||||
for (uint i = 0; i < idcount; i++) {
|
for (uint i = 0; i < idcount; i++) {
|
||||||
cargos[i] = grf_load_byte(&buf);
|
cargos[i] = grf_load_byte(&buf);
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
uint num_vehicles = 1 + CountArticulatedParts(p1, false);
|
uint num_vehicles = 1 + CountArticulatedParts(p1, false);
|
||||||
|
|
||||||
/* Allow for the front and the articulated parts, plus one to "terminate" the list. */
|
/* Allow for the front and the articulated parts, plus one to "terminate" the list. */
|
||||||
Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
|
Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
|
||||||
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
||||||
|
|
||||||
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
||||||
|
@ -1013,7 +1013,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
|
|||||||
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
||||||
track = AxisToTrack(axis);
|
track = AxisToTrack(axis);
|
||||||
|
|
||||||
layout_ptr = (byte*)alloca(numtracks * plat_len);
|
layout_ptr = AllocaM(byte, numtracks * plat_len);
|
||||||
GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
|
GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
|
||||||
|
|
||||||
numtracks_orig = numtracks;
|
numtracks_orig = numtracks;
|
||||||
|
@ -549,7 +549,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
|
|||||||
if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
||||||
|
|
||||||
/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
|
/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
|
||||||
Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
|
Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
|
||||||
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
||||||
|
|
||||||
if (!Vehicle::AllocateList(vl, num_vehicles))
|
if (!Vehicle::AllocateList(vl, num_vehicles))
|
||||||
@ -716,7 +716,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||||||
if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
||||||
|
|
||||||
/* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */
|
/* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */
|
||||||
Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
|
Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
|
||||||
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
||||||
|
|
||||||
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
||||||
|
@ -474,7 +474,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
|||||||
|
|
||||||
_ident = GetTickCount(); // something pretty unique
|
_ident = GetTickCount(); // something pretty unique
|
||||||
|
|
||||||
MakeCRCTable((uint32*)alloca(256 * sizeof(uint32)));
|
MakeCRCTable(AllocaM(uint32, 256));
|
||||||
_crash_msg = output = (char*)LocalAlloc(LMEM_FIXED, 8192);
|
_crash_msg = output = (char*)LocalAlloc(LMEM_FIXED, 8192);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user