~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Parser/bitset.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
bitset
8
8
newbitset(int nbits)
9
9
{
10
 
        int nbytes = NBYTES(nbits);
11
 
        bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);
12
 
        
13
 
        if (ss == NULL)
14
 
                Py_FatalError("no mem for bitset");
15
 
        
16
 
        ss += nbytes;
17
 
        while (--nbytes >= 0)
18
 
                *--ss = 0;
19
 
        return ss;
 
10
    int nbytes = NBYTES(nbits);
 
11
    bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);
 
12
 
 
13
    if (ss == NULL)
 
14
        Py_FatalError("no mem for bitset");
 
15
 
 
16
    ss += nbytes;
 
17
    while (--nbytes >= 0)
 
18
        *--ss = 0;
 
19
    return ss;
20
20
}
21
21
 
22
22
void
23
23
delbitset(bitset ss)
24
24
{
25
 
        PyObject_FREE(ss);
 
25
    PyObject_FREE(ss);
26
26
}
27
27
 
28
28
int
29
29
addbit(bitset ss, int ibit)
30
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;
 
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
38
}
39
39
 
40
40
#if 0 /* Now a macro */
41
41
int
42
42
testbit(bitset ss, int ibit)
43
43
{
44
 
        return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
 
44
    return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
45
45
}
46
46
#endif
47
47
 
48
48
int
49
49
samebitset(bitset ss1, bitset ss2, int nbits)
50
50
{
51
 
        int i;
52
 
        
53
 
        for (i = NBYTES(nbits); --i >= 0; )
54
 
                if (*ss1++ != *ss2++)
55
 
                        return 0;
56
 
        return 1;
 
51
    int i;
 
52
 
 
53
    for (i = NBYTES(nbits); --i >= 0; )
 
54
        if (*ss1++ != *ss2++)
 
55
            return 0;
 
56
    return 1;
57
57
}
58
58
 
59
59
void
60
60
mergebitset(bitset ss1, bitset ss2, int nbits)
61
61
{
62
 
        int i;
63
 
        
64
 
        for (i = NBYTES(nbits); --i >= 0; )
65
 
                *ss1++ |= *ss2++;
 
62
    int i;
 
63
 
 
64
    for (i = NBYTES(nbits); --i >= 0; )
 
65
        *ss1++ |= *ss2++;
66
66
}