| 1 | Step 1: Use "`using namespace std`", polluting your global namespace. |
| 2 | Step 2: Define identifiers like "`hash`" and "`runtime_error`". |
| 3 | Step 3: Wait years for C++ to incorporate those identifiers. |
| 4 | Step 4: Watch modern compilers trip over the resulting collisions. |
| 5 | Step 5: ??? |
| 6 | Step 6: Profit! |
| 7 | |
| 8 | Index: src/instance.cc |
| 9 | =================================================================== |
| 10 | --- src/instance.cc.orig |
| 11 | +++ src/instance.cc |
| 12 | @@ -287,7 +287,7 @@ void HashSet::Clear(int new_ar) |
| 13 | } |
| 14 | |
| 15 | /* the hash algorithm is from |
| 16 | - http://ourworld.compuserve.com/homepages/bob_jenkins/evahash.htm */ |
| 17 | + https://web.archive.org/web/19990218144446/http://ourworld.compuserve.com/homepages/bob_jenkins/evahash.htm */ |
| 18 | |
| 19 | |
| 20 | /* The mixing step */ |
| 21 | @@ -305,7 +305,7 @@ void HashSet::Clear(int new_ar) |
| 22 | } |
| 23 | |
| 24 | |
| 25 | -unsigned long hash(const char *key, unsigned long length, |
| 26 | +unsigned long lparseHash(const char *key, unsigned long length, |
| 27 | unsigned long initval) |
| 28 | { |
| 29 | u4 a, b, c; /* internal state */ |
| 30 | @@ -362,9 +362,9 @@ unsigned long HashSet::FindIndex(Instanc |
| 31 | else |
| 32 | table = items; |
| 33 | |
| 34 | - ind1 = hash((char *)key, arity*4, SEED_1) % mask; |
| 35 | + ind1 = lparseHash((char *)key, arity*4, SEED_1) % mask; |
| 36 | if (table[ind1] && !equal_item(key, table[ind1], arity)) |
| 37 | - ind2 = (hash((char *)key, arity*4, SEED_2) % mask) + 1; |
| 38 | + ind2 = (lparseHash((char *)key, arity*4, SEED_2) % mask) + 1; |
| 39 | else |
| 40 | return ind1; |
| 41 | |
| 42 | Index: src/error.h |
| 43 | =================================================================== |
| 44 | --- src/error.h.orig |
| 45 | +++ src/error.h |
| 46 | @@ -98,6 +98,6 @@ const char *error_file_and_line(long lin |
| 47 | // target system. |
| 48 | |
| 49 | #include "term.h" |
| 50 | -void runtime_error(InternalFunction f, ErrorType t, long a1 = 0, long a2 = 0); |
| 51 | +void lparse_runtime_error(InternalFunction f, ErrorType t, long a1 = 0, long a2 = 0); |
| 52 | |
| 53 | #endif |
| 54 | Index: src/library.cc |
| 55 | =================================================================== |
| 56 | --- src/library.cc.orig |
| 57 | +++ src/library.cc |
| 58 | @@ -164,7 +164,7 @@ long int_plus(int nargs, long *args ) |
| 59 | |
| 60 | for (i=0; i < nargs; i++) { |
| 61 | if (IS_CONSTANT(args[i])) |
| 62 | - runtime_error(FUN_PLUS, ERR_ARGUMENT, args[i]); |
| 63 | + lparse_runtime_error(FUN_PLUS, ERR_ARGUMENT, args[i]); |
| 64 | |
| 65 | result += args[i]; |
| 66 | } |
| 67 | @@ -175,25 +175,25 @@ long int_plus(int nargs, long *args ) |
| 68 | long int_exp(int nargs, long *args ) |
| 69 | { |
| 70 | if (nargs != 2) { |
| 71 | - runtime_error(FUN_EXP, ERR_NUMARGS, 2); |
| 72 | + lparse_runtime_error(FUN_EXP, ERR_NUMARGS, 2); |
| 73 | } |
| 74 | long base = args[0]; |
| 75 | long power = args[1]; |
| 76 | long result = 1; |
| 77 | |
| 78 | if (IS_CONSTANT(args[0])) |
| 79 | - runtime_error(FUN_EXP, ERR_ARGUMENT, args[0]); |
| 80 | + lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[0]); |
| 81 | |
| 82 | if (IS_CONSTANT(args[1])) |
| 83 | - runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]); |
| 84 | + lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]); |
| 85 | |
| 86 | if (power < 0) |
| 87 | - runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]); |
| 88 | + lparse_runtime_error(FUN_EXP, ERR_ARGUMENT, args[1]); |
| 89 | |
| 90 | while (power--) { |
| 91 | result *= base; |
| 92 | if (IS_CONSTANT(result)) |
| 93 | - runtime_error(FUN_EXP, ERR_OVERFLOW, 0); |
| 94 | + lparse_runtime_error(FUN_EXP, ERR_OVERFLOW, 0); |
| 95 | } |
| 96 | return result; |
| 97 | } |
| 98 | @@ -201,16 +201,16 @@ long int_exp(int nargs, long *args ) |
| 99 | long int_norm(int nargs, long *args) |
| 100 | { |
| 101 | if (nargs != 1) { |
| 102 | - runtime_error(FUN_NORM, ERR_NUMARGS, 1); |
| 103 | + lparse_runtime_error(FUN_NORM, ERR_NUMARGS, 1); |
| 104 | } |
| 105 | |
| 106 | if (args[0] < 0 || args[0] > predicate_table->Size()) |
| 107 | - runtime_error(FUN_NORM, ERR_RANGE, args[0]); |
| 108 | + lparse_runtime_error(FUN_NORM, ERR_RANGE, args[0]); |
| 109 | |
| 110 | long p = args[0]; |
| 111 | |
| 112 | if (!predicates[p]->DomainPredicate()) |
| 113 | - runtime_error(FUN_NORM, ERR_NONFIXED_EXTENSION, args[0]); |
| 114 | + lparse_runtime_error(FUN_NORM, ERR_NONFIXED_EXTENSION, args[0]); |
| 115 | |
| 116 | if (predicates[p]->atoms) |
| 117 | return predicates[p]->atoms->Size(); |
| 118 | @@ -258,11 +258,11 @@ long int_minus(int nargs, long *args) |
| 119 | result = args[0]; |
| 120 | |
| 121 | if (IS_CONSTANT(result)) |
| 122 | - runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]); |
| 123 | + lparse_runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]); |
| 124 | |
| 125 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 126 | if (IS_CONSTANT(args[i])) |
| 127 | - runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]); |
| 128 | + lparse_runtime_error(FUN_MINUS, ERR_ARGUMENT, args[i]); |
| 129 | |
| 130 | result -= args[i]; |
| 131 | } |
| 132 | @@ -277,7 +277,7 @@ long int_abs(int, long *args) |
| 133 | result = args[0]; |
| 134 | |
| 135 | if (IS_CONSTANT(result)) |
| 136 | - runtime_error(FUN_ABS, ERR_ARGUMENT, result); |
| 137 | + lparse_runtime_error(FUN_ABS, ERR_ARGUMENT, result); |
| 138 | |
| 139 | |
| 140 | if (result < 0) |
| 141 | @@ -300,7 +300,7 @@ long int_le(int nargs, long *args) |
| 142 | |
| 143 | for (i = 1 ; i < nargs; i++ ) { // '1' intentional |
| 144 | if (IS_CONSTANT(args[i])) |
| 145 | - runtime_error(FUN_LE, ERR_INVALID_COMPARE, args[0], args[i]); |
| 146 | + lparse_runtime_error(FUN_LE, ERR_INVALID_COMPARE, args[0], args[i]); |
| 147 | |
| 148 | if (args[i] < prior_value) { |
| 149 | result = 0; |
| 150 | @@ -324,7 +324,7 @@ long int_ge(int nargs, long *args) |
| 151 | |
| 152 | for (i = 1 ; i < nargs; i++ ) { // '1' intentional |
| 153 | if (IS_CONSTANT(args[i])) |
| 154 | - runtime_error(FUN_GE, ERR_INVALID_COMPARE, args[0],args[i]); |
| 155 | + lparse_runtime_error(FUN_GE, ERR_INVALID_COMPARE, args[0],args[i]); |
| 156 | |
| 157 | |
| 158 | if (args[i] > prior_value) { |
| 159 | @@ -349,7 +349,7 @@ long int_gt(int nargs, long *args) |
| 160 | |
| 161 | for (i = 1 ; i < nargs; i++ ) { // '1' intentional |
| 162 | if (IS_CONSTANT(args[i])) |
| 163 | - runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]); |
| 164 | + lparse_runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]); |
| 165 | |
| 166 | if (args[i] >= prior_value) { |
| 167 | result = 0; |
| 168 | @@ -373,7 +373,7 @@ long int_lt(int nargs, long *args) |
| 169 | |
| 170 | for (i = 1 ; i < nargs; i++ ) { // '1' intentional |
| 171 | if (IS_CONSTANT(args[i])) |
| 172 | - runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]); |
| 173 | + lparse_runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]); |
| 174 | |
| 175 | if (args[i] <= prior_value) { |
| 176 | result = 0; |
| 177 | @@ -408,11 +408,11 @@ long int_times(int nargs, long *args) |
| 178 | int i = 0; |
| 179 | |
| 180 | if (IS_CONSTANT(result)) |
| 181 | - runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]); |
| 182 | + lparse_runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]); |
| 183 | |
| 184 | for (i = 0; i < nargs; i++) { |
| 185 | if (IS_CONSTANT(args[i])) |
| 186 | - runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]); |
| 187 | + lparse_runtime_error(FUN_TIMES, ERR_ARGUMENT, args[i]); |
| 188 | |
| 189 | result *= args[i]; |
| 190 | } |
| 191 | @@ -425,14 +425,14 @@ long int_div(int nargs, long *args) |
| 192 | int i = 0; |
| 193 | |
| 194 | if (IS_CONSTANT(result)) |
| 195 | - runtime_error(FUN_DIV, ERR_ARGUMENT, args[i]); |
| 196 | + lparse_runtime_error(FUN_DIV, ERR_ARGUMENT, args[i]); |
| 197 | |
| 198 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 199 | if (IS_CONSTANT(args[i])) |
| 200 | - runtime_error(FUN_DIV,ERR_ARGUMENT, args[i]); |
| 201 | + lparse_runtime_error(FUN_DIV,ERR_ARGUMENT, args[i]); |
| 202 | |
| 203 | if (args[i] == 0) { |
| 204 | - runtime_error(FUN_DIV,ERR_DIVIDE_BY_ZERO, 0); |
| 205 | + lparse_runtime_error(FUN_DIV,ERR_DIVIDE_BY_ZERO, 0); |
| 206 | } else { |
| 207 | result /= args[i]; |
| 208 | } |
| 209 | @@ -446,14 +446,14 @@ long int_mod(int nargs, long *args) |
| 210 | int i = 0; |
| 211 | |
| 212 | if (IS_CONSTANT(result)) |
| 213 | - runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]); |
| 214 | + lparse_runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]); |
| 215 | |
| 216 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 217 | if (IS_CONSTANT(args[i])) |
| 218 | - runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]); |
| 219 | + lparse_runtime_error(FUN_MOD, ERR_ARGUMENT, args[i]); |
| 220 | |
| 221 | if (args[i] == 0) { |
| 222 | - runtime_error(FUN_MOD, ERR_DIVIDE_BY_ZERO, 0); |
| 223 | + lparse_runtime_error(FUN_MOD, ERR_DIVIDE_BY_ZERO, 0); |
| 224 | } else { |
| 225 | result %= args[i]; |
| 226 | if (result < 0) |
| 227 | @@ -469,11 +469,11 @@ long int_and(int nargs, long *args) |
| 228 | int i = 0; |
| 229 | |
| 230 | if (IS_CONSTANT(result)) |
| 231 | - runtime_error(FUN_AND, ERR_ARGUMENT, args[i]); |
| 232 | + lparse_runtime_error(FUN_AND, ERR_ARGUMENT, args[i]); |
| 233 | |
| 234 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 235 | if (IS_CONSTANT(args[i])) |
| 236 | - runtime_error(FUN_AND, ERR_ARGUMENT, args[i]); |
| 237 | + lparse_runtime_error(FUN_AND, ERR_ARGUMENT, args[i]); |
| 238 | |
| 239 | result &= args[i]; |
| 240 | } |
| 241 | @@ -486,11 +486,11 @@ long int_or(int nargs, long *args) |
| 242 | int i = 0; |
| 243 | |
| 244 | if (IS_CONSTANT(result)) |
| 245 | - runtime_error(FUN_OR, ERR_ARGUMENT, args[i]); |
| 246 | + lparse_runtime_error(FUN_OR, ERR_ARGUMENT, args[i]); |
| 247 | |
| 248 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 249 | if (IS_CONSTANT(args[i])) |
| 250 | - runtime_error(FUN_OR, ERR_ARGUMENT, args[i]); |
| 251 | + lparse_runtime_error(FUN_OR, ERR_ARGUMENT, args[i]); |
| 252 | |
| 253 | result |= args[i]; |
| 254 | } |
| 255 | @@ -503,11 +503,11 @@ long int_xor(int nargs, long *args) |
| 256 | int i = 0; |
| 257 | |
| 258 | if (IS_CONSTANT(result)) |
| 259 | - runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]); |
| 260 | + lparse_runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]); |
| 261 | |
| 262 | for (i = 1; i < nargs; i++) { // '1' intentional |
| 263 | if (IS_CONSTANT(args[i])) |
| 264 | - runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]); |
| 265 | + lparse_runtime_error(FUN_XOR, ERR_ARGUMENT, args[i]); |
| 266 | |
| 267 | result ^= args[i]; |
| 268 | } |
| 269 | @@ -520,7 +520,7 @@ long int_not(int, long *args) |
| 270 | long result = args[0]; |
| 271 | |
| 272 | if (IS_CONSTANT(result)) |
| 273 | - runtime_error(FUN_NOT, ERR_ARGUMENT, result); |
| 274 | + lparse_runtime_error(FUN_NOT, ERR_ARGUMENT, result); |
| 275 | |
| 276 | result = ~result; |
| 277 | return result; |
| 278 | @@ -540,7 +540,7 @@ long lt_string(int nargs, long *args) |
| 279 | for (int i = 1; i < nargs; i++) { |
| 280 | second = constant_table->LookupByValue(args[i]); |
| 281 | if (!second) |
| 282 | - runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]); |
| 283 | + lparse_runtime_error(FUN_LT, ERR_INVALID_COMPARE, args[0], args[i]); |
| 284 | |
| 285 | if (strcmp(first, second) >= 0) { |
| 286 | result = 0; |
| 287 | @@ -564,7 +564,7 @@ long le_string(int nargs, long *args) |
| 288 | for (int i = 1; i < nargs; i++) { |
| 289 | second = constant_table->LookupByValue(args[i]); |
| 290 | if (!second) |
| 291 | - runtime_error(FUN_LE, ERR_INVALID_COMPARE,args[0], args[i]); |
| 292 | + lparse_runtime_error(FUN_LE, ERR_INVALID_COMPARE,args[0], args[i]); |
| 293 | |
| 294 | if (strcmp(first, second) > 0) { |
| 295 | result = 0; |
| 296 | @@ -589,7 +589,7 @@ long gt_string(int nargs, long *args) |
| 297 | for (int i = 1; i < nargs; i++) { |
| 298 | second = constant_table->LookupByValue(args[i]); |
| 299 | if (!second) |
| 300 | - runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]); |
| 301 | + lparse_runtime_error(FUN_GT, ERR_INVALID_COMPARE, args[0],args[i]); |
| 302 | |
| 303 | if (strcmp(first, second) <= 0) { |
| 304 | result = 0; |
| 305 | @@ -614,7 +614,7 @@ long ge_string(int nargs, long *args) |
| 306 | for (int i = 1; i < nargs; i++) { |
| 307 | second = constant_table->LookupByValue(args[i]); |
| 308 | if (!second) |
| 309 | - runtime_error(FUN_GE, ERR_INVALID_COMPARE,args[0], args[i]); |
| 310 | + lparse_runtime_error(FUN_GE, ERR_INVALID_COMPARE,args[0], args[i]); |
| 311 | |
| 312 | if (strcmp(first, second) < 0) { |
| 313 | result = 0; |
| 314 | Index: src/extern.h |
| 315 | =================================================================== |
| 316 | --- src/extern.h.orig |
| 317 | +++ src/extern.h |
| 318 | @@ -76,7 +76,7 @@ extern LongList *command_line_constants; |
| 319 | |
| 320 | extern LiteralList *implicit_domain_list; |
| 321 | |
| 322 | -unsigned long hash(const char *key, unsigned long length, |
| 323 | +unsigned long lparseHash(const char *key, unsigned long length, |
| 324 | unsigned long initval); |
| 325 | |
| 326 | // replacement of strdup that is not standard |
| 327 | Index: src/symbol.cc |
| 328 | =================================================================== |
| 329 | --- src/symbol.cc.orig |
| 330 | +++ src/symbol.cc |
| 331 | @@ -127,9 +127,9 @@ unsigned long SymbolTable::FindIndex(con |
| 332 | else |
| 333 | table = items; |
| 334 | |
| 335 | - ind1 = hash(key, strlen(key), SEED_1) % mask; |
| 336 | + ind1 = lparseHash(key, strlen(key), SEED_1) % mask; |
| 337 | if (table[ind1] && strcmp(key, table[ind1]->symbol)) |
| 338 | - ind2 = (hash(key, strlen(key), SEED_2) % mask) + 1; |
| 339 | + ind2 = (lparseHash(key, strlen(key), SEED_2) % mask) + 1; |
| 340 | else |
| 341 | return ind1; |
| 342 | |
| 343 | @@ -398,9 +398,9 @@ unsigned long FunctionTable::FindIndex(c |
| 344 | else |
| 345 | table = items; |
| 346 | |
| 347 | - ind1 = hash(key, strlen(key), SEED_1) % mask; |
| 348 | + ind1 = lparseHash(key, strlen(key), SEED_1) % mask; |
| 349 | if (table[ind1] && strcmp(key, table[ind1]->symbol)) |
| 350 | - ind2 = (hash(key, strlen(key), SEED_2) % mask) + 1; |
| 351 | + ind2 = (lparseHash(key, strlen(key), SEED_2) % mask) + 1; |
| 352 | else |
| 353 | return ind1; |
| 354 | |
| 355 | Index: src/error.cc |
| 356 | =================================================================== |
| 357 | --- src/error.cc.orig |
| 358 | +++ src/error.cc |
| 359 | @@ -343,7 +343,7 @@ void RuntimeError::Print() |
| 360 | output(cerr, "\n"); |
| 361 | } |
| 362 | |
| 363 | -void runtime_error(InternalFunction, ErrorType t, long a1, long a2) |
| 364 | +void lparse_runtime_error(InternalFunction, ErrorType t, long a1, long a2) |
| 365 | { |
| 366 | RuntimeError rt(t, a1, a2); |
| 367 | throw rt; |