Mercurial > cpython-lru_cache-weakref
annotate Parser/bitset.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 292854c43b99 |
| children | fd25030223b0 |
| rev | line source |
|---|---|
| 145 | 1 |
| 86 | 2 /* Bitset primitives used by the parser generator */ |
| 6 | 3 |
| 86 | 4 #include "pgenheaders.h" |
| 6 | 5 #include "bitset.h" |
| 6 | |
| 7 bitset | |
| 13659 | 8 newbitset(int nbits) |
| 6 | 9 { |
| 10 int nbytes = NBYTES(nbits); | |
|
37585
292854c43b99
Fix the code in Parser/ to also compile with C++. This was mostly casts for
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37557
diff
changeset
|
11 bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) * nbytes); |
| 6 | 12 |
| 13 if (ss == NULL) | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
14 Py_FatalError("no mem for bitset"); |
| 6 | 15 |
| 16 ss += nbytes; | |
| 17 while (--nbytes >= 0) | |
| 18 *--ss = 0; | |
| 19 return ss; | |
| 20 } | |
| 21 | |
| 22 void | |
| 13659 | 23 delbitset(bitset ss) |
| 6 | 24 { |
|
37557
6ae4adefc573
SF patch #1467512, fix double free with triple quoted string in standard build.
Neal Norwitz <nnorwitz@gmail.com>
parents:
14375
diff
changeset
|
25 PyObject_FREE(ss); |
| 6 | 26 } |
| 27 | |
| 28 int | |
| 13659 | 29 addbit(bitset ss, int ibit) |
| 6 | 30 { |
| 31 int ibyte = BIT2BYTE(ibit); | |
| 32 BYTE mask = BIT2MASK(ibit); | |
| 33 | |
| 34 if (ss[ibyte] & mask) | |
| 35 return 0; /* Bit already set */ | |
| 36 ss[ibyte] |= mask; | |
| 37 return 1; | |
| 38 } | |
| 39 | |
| 40 #if 0 /* Now a macro */ | |
| 41 int | |
| 13659 | 42 testbit(bitset ss, int ibit) |
| 6 | 43 { |
| 44 return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0; | |
| 45 } | |
| 46 #endif | |
| 47 | |
| 48 int | |
| 13659 | 49 samebitset(bitset ss1, bitset ss2, int nbits) |
| 6 | 50 { |
| 51 int i; | |
| 52 | |
| 53 for (i = NBYTES(nbits); --i >= 0; ) | |
| 54 if (*ss1++ != *ss2++) | |
| 55 return 0; | |
| 56 return 1; | |
| 57 } | |
| 58 | |
| 59 void | |
| 13659 | 60 mergebitset(bitset ss1, bitset ss2, int nbits) |
| 6 | 61 { |
| 62 int i; | |
| 63 | |
| 64 for (i = NBYTES(nbits); --i >= 0; ) | |
| 65 *ss1++ |= *ss2++; | |
| 66 } |
