Skip to content

Commit c6c5edd

Browse files
committedFeb 5, 2014
Revert "Fix settings to honor numeric conversion errors"
This reverts commit 3f376a0.
1 parent 7859e57 commit c6c5edd

8 files changed

+43
-79
lines changed
 

‎src/emerge.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
102102
// if unspecified, leave a proc for the main thread and one for
103103
// some other misc thread
104104
int nthreads = 0;
105-
if (!g_settings->getS16NoEx("num_emerge_threads", nthreads))
105+
if (!g_settings->tryGetS16("num_emerge_threads", nthreads))
106106
nthreads = porting::getNumberOfProcessors() - 2;
107107
if (nthreads < 1)
108108
nthreads = 1;
109109

110110
qlimit_total = g_settings->getU16("emergequeue_limit_total");
111-
if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", qlimit_diskonly))
111+
if (!g_settings->tryGetU16("emergequeue_limit_diskonly", qlimit_diskonly))
112112
qlimit_diskonly = nthreads * 5 + 1;
113-
if (!g_settings->getU16NoEx("emergequeue_limit_generate", qlimit_generate))
113+
if (!g_settings->tryGetU16("emergequeue_limit_generate", qlimit_generate))
114114
qlimit_generate = nthreads + 1;
115115

116116
for (int i = 0; i != nthreads; i++)
@@ -352,13 +352,13 @@ void EmergeManager::loadParamsFromSettings(Settings *settings) {
352352
std::string seed_str;
353353
const char *setname = (settings == g_settings) ? "fixed_map_seed" : "seed";
354354

355-
if (settings->getNoEx(setname, seed_str))
355+
if (settings->tryGet(setname, seed_str))
356356
params.seed = read_seed(seed_str.c_str());
357357

358-
settings->getNoEx("mg_name", params.mg_name);
359-
settings->getS16NoEx("water_level", params.water_level);
360-
settings->getS16NoEx("chunksize", params.chunksize);
361-
settings->getFlagStrNoEx("mg_flags", params.flags, flagdesc_mapgen);
358+
settings->tryGet("mg_name", params.mg_name);
359+
settings->tryGetS16("water_level", params.water_level);
360+
settings->tryGetS16("chunksize", params.chunksize);
361+
settings->tryGetFlagStr("mg_flags", params.flags, flagdesc_mapgen);
362362

363363
delete params.sparams;
364364
params.sparams = createMapgenParams(params.mg_name);

‎src/exceptions.h

-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ class SettingNotFoundException : public BaseException {
8585
SettingNotFoundException(std::string s): BaseException(s) {}
8686
};
8787

88-
class NumericException : public BaseException {
89-
public:
90-
NumericException(std::string s): BaseException(s) {}
91-
};
92-
9388
class InvalidFilenameException : public BaseException {
9489
public:
9590
InvalidFilenameException(std::string s): BaseException(s) {}

‎src/main.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1671,10 +1671,9 @@ int main(int argc, char *argv[])
16711671
//infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
16721672

16731673
address = menudata.address;
1674-
try {
1675-
port = stoi(menudata.port);
1676-
}
1677-
catch (NumericException&e) {}
1674+
int newport = stoi(menudata.port);
1675+
if(newport != 0)
1676+
port = newport;
16781677

16791678
simple_singleplayer_mode = menudata.simple_singleplayer_mode;
16801679

‎src/mapgen_indev.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ MapgenIndevParams::MapgenIndevParams() {
164164
void MapgenIndevParams::readParams(Settings *settings) {
165165
MapgenV6Params::readParams(settings);
166166

167-
settings->getS16NoEx("mgindev_float_islands", float_islands);
167+
settings->tryGetS16("mgindev_float_islands", float_islands);
168168

169169
settings->getNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base);
170170
settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);

‎src/mapgen_v6.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ MapgenV6Params::MapgenV6Params() {
112112

113113

114114
void MapgenV6Params::readParams(Settings *settings) {
115-
settings->getFlagStrNoEx("mgv6_spflags", spflags, flagdesc_mapgen_v6);
116-
settings->getFloatNoEx("mgv6_freq_desert", freq_desert);
117-
settings->getFloatNoEx("mgv6_freq_beach", freq_beach);
115+
settings->tryGetFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6);
116+
settings->tryGetFloat("mgv6_freq_desert", freq_desert);
117+
settings->tryGetFloat("mgv6_freq_beach", freq_beach);
118118

119119
settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base);
120120
settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);

‎src/mapgen_v7.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ MapgenV7Params::MapgenV7Params() {
126126

127127

128128
void MapgenV7Params::readParams(Settings *settings) {
129-
settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
129+
settings->tryGetFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7);
130130

131131
settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
132132
settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);

‎src/settings.h

+11-31
Original file line numberDiff line numberDiff line change
@@ -745,19 +745,17 @@ class Settings
745745
}
746746

747747
//////////// Try to get value, no exception thrown
748-
bool getNoEx(std::string name, std::string &val)
748+
bool tryGet(std::string name, std::string &val)
749749
{
750750
try {
751751
val = get(name);
752752
return true;
753753
} catch (SettingNotFoundException &e) {
754754
return false;
755-
} catch (NumericException &e) {
756-
return false;
757755
}
758756
}
759757

760-
bool getFlagStrNoEx(std::string name, u32 &val, FlagDesc *flagdesc)
758+
bool tryGetFlagStr(std::string name, u32 &val, FlagDesc *flagdesc)
761759
{
762760
try {
763761
val = getFlagStr(name, flagdesc);
@@ -767,111 +765,93 @@ class Settings
767765
}
768766
}
769767

770-
bool getFloatNoEx(std::string name, float &val)
768+
bool tryGetFloat(std::string name, float &val)
771769
{
772770
try {
773771
val = getFloat(name);
774772
return true;
775773
} catch (SettingNotFoundException &e) {
776774
return false;
777-
} catch (NumericException &e) {
778-
return false;
779775
}
780776
}
781777

782-
bool getU16NoEx(std::string name, int &val)
778+
bool tryGetU16(std::string name, int &val)
783779
{
784780
try {
785781
val = getU16(name);
786782
return true;
787783
} catch (SettingNotFoundException &e) {
788784
return false;
789-
} catch (NumericException &e) {
790-
return false;
791785
}
792786
}
793787

794-
bool getU16NoEx(std::string name, u16 &val)
788+
bool tryGetU16(std::string name, u16 &val)
795789
{
796790
try {
797791
val = getU16(name);
798792
return true;
799793
} catch (SettingNotFoundException &e) {
800794
return false;
801-
} catch (NumericException &e) {
802-
return false;
803795
}
804796
}
805797

806-
bool getS16NoEx(std::string name, int &val)
798+
bool tryGetS16(std::string name, int &val)
807799
{
808800
try {
809801
val = getU16(name);
810802
return true;
811803
} catch (SettingNotFoundException &e) {
812804
return false;
813-
} catch (NumericException &e) {
814-
return false;
815805
}
816806
}
817807

818-
bool getS16NoEx(std::string name, s16 &val)
808+
bool tryGetS16(std::string name, s16 &val)
819809
{
820810
try {
821811
val = getS16(name);
822812
return true;
823813
} catch (SettingNotFoundException &e) {
824814
return false;
825-
} catch (NumericException &e) {
826-
return false;
827815
}
828816
}
829817

830-
bool getS32NoEx(std::string name, s32 &val)
818+
bool tryGetS32(std::string name, s32 &val)
831819
{
832820
try {
833821
val = getS32(name);
834822
return true;
835823
} catch (SettingNotFoundException &e) {
836824
return false;
837-
} catch (NumericException &e) {
838-
return false;
839825
}
840826
}
841827

842-
bool getV3FNoEx(std::string name, v3f &val)
828+
bool tryGetV3F(std::string name, v3f &val)
843829
{
844830
try {
845831
val = getV3F(name);
846832
return true;
847833
} catch (SettingNotFoundException &e) {
848834
return false;
849-
} catch (NumericException &e) {
850-
return false;
851835
}
852836
}
853837

854-
bool getV2FNoEx(std::string name, v2f &val)
838+
bool tryGetV2F(std::string name, v2f &val)
855839
{
856840
try {
857841
val = getV2F(name);
858842
return true;
859843
} catch (SettingNotFoundException &e) {
860844
return false;
861-
} catch (NumericException &e) {
862-
return false;
863845
}
864846
}
865847

866-
bool getU64NoEx(std::string name, u64 &val)
848+
bool tryGetU64(std::string name, u64 &val)
867849
{
868850
try {
869851
val = getU64(name);
870852
return true;
871853
} catch (SettingNotFoundException &e) {
872854
return false;
873-
} catch (NumericException &e) {
874-
return false;
875855
}
876856
}
877857

‎src/util/string.h

+16-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include <cstring>
2727
#include <vector>
2828
#include <sstream>
29-
#include "exceptions.h"
3029

3130
struct FlagDesc {
3231
const char *name;
@@ -146,31 +145,17 @@ inline std::string trim(const std::string &s)
146145
return s.substr(front, back - front);
147146
}
148147

149-
inline s32 mystoi(const std::string &s)
150-
{
151-
char* endptr = NULL;
152-
s32 retval = strtol(s.c_str(),&endptr,10);
153-
154-
if ((endptr == NULL) || (*endptr != 0) || (endptr == s.c_str()))
155-
throw NumericException("string to convert");
156-
157-
return retval;
158-
}
159-
160148
inline bool is_yes(const std::string &s)
161149
{
162150
std::string s2 = lowercase(trim(s));
163-
try {
164-
if(s2 == "y" || s2 == "yes" || s2 == "true" || mystoi(s2) != 0)
165-
return true;
166-
}
167-
catch(NumericException&e) {}
151+
if(s2 == "y" || s2 == "yes" || s2 == "true" || atoi(s2.c_str()) != 0)
152+
return true;
168153
return false;
169154
}
170155

171156
inline s32 mystoi(const std::string &s, s32 min, s32 max)
172157
{
173-
s32 i = mystoi(s);
158+
s32 i = atoi(s.c_str());
174159
if(i < min)
175160
i = min;
176161
if(i > max)
@@ -188,20 +173,25 @@ inline s64 stoi64(const std::string &s) {
188173
// MSVC2010 includes it's own versions of these
189174
//#if !defined(_MSC_VER) || _MSC_VER < 1600
190175

176+
inline s32 mystoi(const std::string &s)
177+
{
178+
return atoi(s.c_str());
179+
}
180+
191181
inline s32 mystoi(const std::wstring &s)
192182
{
193-
return mystoi(wide_to_narrow(s).c_str());
183+
return atoi(wide_to_narrow(s).c_str());
194184
}
195185

196186
inline float mystof(const std::string &s)
197187
{
198-
char* endptr = NULL;
199-
float retval = strtof(s.c_str(),&endptr);
200-
201-
if ((endptr == NULL) || (*endptr != 0) || (endptr == s.c_str()))
202-
throw NumericException("string to convert");
203-
204-
return retval;
188+
// This crap causes a segfault in certain cases on MinGW
189+
/*float f;
190+
std::istringstream ss(s);
191+
ss>>f;
192+
return f;*/
193+
// This works in that case
194+
return atof(s.c_str());
205195
}
206196

207197
//#endif

0 commit comments

Comments
 (0)
Please sign in to comment.