comparison src/regex.c @ 456:e7ef97881643 r21-2-43

Import from CVS: tag r21-2-43
author cvs
date Mon, 13 Aug 2007 11:41:24 +0200
parents 98528da0b7fc
children c33ae14dd6d0
comparison
equal deleted inserted replaced
455:5b97c1cd6ed0 456:e7ef97881643
1250 declared. 1250 declared.
1251 1251
1252 Does `return FAILURE_CODE' if runs out of memory. */ 1252 Does `return FAILURE_CODE' if runs out of memory. */
1253 1253
1254 #if !defined (REGEX_MALLOC) && !defined (REL_ALLOC) 1254 #if !defined (REGEX_MALLOC) && !defined (REL_ALLOC)
1255 #define DECLARE_DESTINATION char *destination; 1255 #define DECLARE_DESTINATION char *destination
1256 #else 1256 #else
1257 #define DECLARE_DESTINATION 1257 #define DECLARE_DESTINATION DECLARE_NOTHING
1258 #endif 1258 #endif
1259 1259
1260 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ 1260 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
1261 do { \ 1261 do { \
1262 DECLARE_DESTINATION \ 1262 DECLARE_DESTINATION; \
1263 /* Must be int, so when we don't save any registers, the arithmetic \ 1263 /* Must be int, so when we don't save any registers, the arithmetic \
1264 of 0 + -1 isn't done as unsigned. */ \ 1264 of 0 + -1 isn't done as unsigned. */ \
1265 int this_reg; \ 1265 int this_reg; \
1266 \
1267 DEBUG_STATEMENT (failure_id++); \
1268 DEBUG_STATEMENT (nfailure_points_pushed++); \
1269 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
1270 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
1271 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
1272 \ 1266 \
1273 DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ 1267 DEBUG_STATEMENT (failure_id++); \
1274 DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ 1268 DEBUG_STATEMENT (nfailure_points_pushed++); \
1269 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
1270 DEBUG_PRINT2 (" Before push, next avail: %lu\n", \
1271 (unsigned long) (fail_stack).avail); \
1272 DEBUG_PRINT2 (" size: %lu\n", \
1273 (unsigned long) (fail_stack).size); \
1275 \ 1274 \
1276 /* Ensure we have enough space allocated for what we will push. */ \ 1275 DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
1277 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ 1276 DEBUG_PRINT2 (" available: %ld\n", \
1278 { \ 1277 (long) REMAINING_AVAIL_SLOTS); \
1279 if (!DOUBLE_FAIL_STACK (fail_stack)) \
1280 return failure_code; \
1281 \ 1278 \
1282 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ 1279 /* Ensure we have enough space allocated for what we will push. */ \
1283 (fail_stack).size); \ 1280 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
1284 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ 1281 { \
1285 } \ 1282 if (!DOUBLE_FAIL_STACK (fail_stack)) \
1283 return failure_code; \
1286 \ 1284 \
1287 /* Push the info, starting with the registers. */ \ 1285 DEBUG_PRINT2 ("\n Doubled stack; size now: %lu\n", \
1288 DEBUG_PRINT1 ("\n"); \ 1286 (unsigned long) (fail_stack).size); \
1287 DEBUG_PRINT2 (" slots available: %ld\n", \
1288 (long) REMAINING_AVAIL_SLOTS); \
1289 } \
1289 \ 1290 \
1290 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ 1291 /* Push the info, starting with the registers. */ \
1291 this_reg++) \ 1292 DEBUG_PRINT1 ("\n"); \
1292 { \
1293 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
1294 DEBUG_STATEMENT (num_regs_pushed++); \
1295 \ 1293 \
1296 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \ 1294 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
1297 PUSH_FAILURE_POINTER (regstart[this_reg]); \ 1295 this_reg++) \
1298 \ 1296 { \
1299 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \ 1297 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
1300 PUSH_FAILURE_POINTER (regend[this_reg]); \ 1298 DEBUG_STATEMENT (num_regs_pushed++); \
1301 \ 1299 \
1302 DEBUG_PRINT2 (" info: 0x%lx\n ", \ 1300 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
1303 * (long *) (&reg_info[this_reg])); \ 1301 PUSH_FAILURE_POINTER (regstart[this_reg]); \
1304 DEBUG_PRINT2 (" match_null=%d", \
1305 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
1306 DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
1307 DEBUG_PRINT2 (" matched_something=%d", \
1308 MATCHED_SOMETHING (reg_info[this_reg])); \
1309 DEBUG_PRINT2 (" ever_matched=%d", \
1310 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
1311 DEBUG_PRINT1 ("\n"); \
1312 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
1313 } \
1314 \ 1302 \
1315 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ 1303 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
1316 PUSH_FAILURE_INT (lowest_active_reg); \ 1304 PUSH_FAILURE_POINTER (regend[this_reg]); \
1317 \ 1305 \
1318 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ 1306 DEBUG_PRINT2 (" info: 0x%lx\n ", \
1319 PUSH_FAILURE_INT (highest_active_reg); \ 1307 * (long *) (&reg_info[this_reg])); \
1308 DEBUG_PRINT2 (" match_null=%d", \
1309 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
1310 DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
1311 DEBUG_PRINT2 (" matched_something=%d", \
1312 MATCHED_SOMETHING (reg_info[this_reg])); \
1313 DEBUG_PRINT2 (" ever_matched_something=%d", \
1314 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
1315 DEBUG_PRINT1 ("\n"); \
1316 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
1317 } \
1320 \ 1318 \
1321 DEBUG_PRINT2 (" Pushing pattern 0x%lx: \n", (long) pattern_place); \ 1319 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg); \
1322 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ 1320 PUSH_FAILURE_INT (lowest_active_reg); \
1323 PUSH_FAILURE_POINTER (pattern_place); \
1324 \ 1321 \
1325 DEBUG_PRINT2 (" Pushing string 0x%lx: `", (long) string_place); \ 1322 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg); \
1326 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ 1323 PUSH_FAILURE_INT (highest_active_reg); \
1327 size2); \
1328 DEBUG_PRINT1 ("'\n"); \
1329 PUSH_FAILURE_POINTER (string_place); \
1330 \ 1324 \
1331 DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ 1325 DEBUG_PRINT2 (" Pushing pattern 0x%lx: \n", (long) pattern_place); \
1332 DEBUG_PUSH (failure_id); \ 1326 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
1333 } while (0) 1327 PUSH_FAILURE_POINTER (pattern_place); \
1328 \
1329 DEBUG_PRINT2 (" Pushing string 0x%lx: `", (long) string_place); \
1330 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
1331 size2); \
1332 DEBUG_PRINT1 ("'\n"); \
1333 PUSH_FAILURE_POINTER (string_place); \
1334 \
1335 DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
1336 DEBUG_PUSH (failure_id); \
1337 } while (0)
1334 1338
1335 /* This is the number of items that are pushed and popped on the stack 1339 /* This is the number of items that are pushed and popped on the stack
1336 for each register. */ 1340 for each register. */
1337 #define NUM_REG_ITEMS 3 1341 #define NUM_REG_ITEMS 3
1338 1342
1368 REG_INFO -- array of information about each subexpression. 1372 REG_INFO -- array of information about each subexpression.
1369 1373
1370 Also assumes the variables `fail_stack' and (if debugging), `bufp', 1374 Also assumes the variables `fail_stack' and (if debugging), `bufp',
1371 `pend', `string1', `size1', `string2', and `size2'. */ 1375 `pend', `string1', `size1', `string2', and `size2'. */
1372 1376
1373 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ 1377 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, \
1374 { \ 1378 regstart, regend, reg_info) \
1379 do { \
1375 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \ 1380 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \
1376 int this_reg; \ 1381 int this_reg; \
1377 const unsigned char *string_temp; \ 1382 const unsigned char *string_temp; \
1378 \ 1383 \
1379 assert (!FAIL_STACK_EMPTY ()); \ 1384 assert (!FAIL_STACK_EMPTY ()); \
1380 \ 1385 \
1381 /* Remove failure points and point to how many regs pushed. */ \ 1386 /* Remove failure points and point to how many regs pushed. */ \
1382 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ 1387 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
1383 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ 1388 DEBUG_PRINT2 (" Before pop, next avail: %lu\n", \
1384 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ 1389 (unsigned long) fail_stack.avail); \
1390 DEBUG_PRINT2 (" size: %lu\n", \
1391 (unsigned long) fail_stack.size); \
1385 \ 1392 \
1386 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ 1393 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
1387 \ 1394 \
1388 DEBUG_POP (&ffailure_id.integer); \ 1395 DEBUG_POP (&ffailure_id.integer); \
1389 DEBUG_PRINT2 (" Popping failure id: %u\n", \ 1396 DEBUG_PRINT2 (" Popping failure id: %u\n", \
1426 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \ 1433 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
1427 } \ 1434 } \
1428 \ 1435 \
1429 set_regs_matched_done = 0; \ 1436 set_regs_matched_done = 0; \
1430 DEBUG_STATEMENT (nfailure_points_popped++); \ 1437 DEBUG_STATEMENT (nfailure_points_popped++); \
1431 } /* POP_FAILURE_POINT */ 1438 } while (0) /* POP_FAILURE_POINT */
1432 1439
1433 1440
1434 1441
1435 /* Structure for per-register (a.k.a. per-group) information. 1442 /* Structure for per-register (a.k.a. per-group) information.
1436 Other register information, such as the 1443 Other register information, such as the
3393 { 3400 {
3394 int j, k; 3401 int j, k;
3395 #ifdef MATCH_MAY_ALLOCATE 3402 #ifdef MATCH_MAY_ALLOCATE
3396 fail_stack_type fail_stack; 3403 fail_stack_type fail_stack;
3397 #endif 3404 #endif
3398 DECLARE_DESTINATION 3405 DECLARE_DESTINATION;
3399 /* We don't push any register information onto the failure stack. */ 3406 /* We don't push any register information onto the failure stack. */
3400 3407
3401 REGISTER char *fastmap = bufp->fastmap; 3408 REGISTER char *fastmap = bufp->fastmap;
3402 unsigned char *pattern = bufp->buffer; 3409 unsigned char *pattern = bufp->buffer;
3403 unsigned long size = bufp->used; 3410 unsigned long size = bufp->used;