summaryrefslogtreecommitdiffstats
path: root/Python/asdl.c
blob: c30d7d20599831fc9bf2ffd916c8ac60879a0dd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Python.h"
#include "asdl.h"

asdl_seq *
asdl_seq_new(int size, PyArena *arena)
{
    asdl_seq *seq = NULL;
    size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);

    /* check size is sane */
    if (size < 0 || size == INT_MIN ||
        (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
        PyErr_NoMemory();
        return NULL;
    }

    /* check if size can be added safely */
    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
        PyErr_NoMemory();
        return NULL;
    }

    n += sizeof(asdl_seq);

    seq = (asdl_seq *)PyArena_Malloc(arena, n);
    if (!seq) {
        PyErr_NoMemory();
        return NULL;
    }
    memset(seq, 0, n);
    seq->size = size;
    return seq;
}

asdl_int_seq *
asdl_int_seq_new(int size, PyArena *arena)
{
    asdl_int_seq *seq = NULL;
    size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);

    /* check size is sane */
    if (size < 0 || size == INT_MIN ||
        (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
            PyErr_NoMemory();
            return NULL;
    }

    /* check if size can be added safely */
    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
        PyErr_NoMemory();
        return NULL;
    }

    n += sizeof(asdl_seq);

    seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
    if (!seq) {
        PyErr_NoMemory();
        return NULL;
    }
    memset(seq, 0, n);
    seq->size = size;
    return seq;
}
ss='column1'>| | | | | | | | | | argument to the constructor -- defaulting to true -- which is different than Anthony's approach of using global state. parse(), parsestr(): Grow a `headersonly' argument which stops parsing once the header block has been seen, i.e. it does /not/ parse or even read the body of the message. This is used for parsing message/rfc822 type messages. We need test cases for the non-strict parsing. Anthony will supply these. _parsebody(): We can get rid of the isdigest end-of-line kludges, although we still need to know if we're parsing a multipart/digest so we can set the default type accordingly. * Add the concept of a "default type". Normally the default type isBarry Warsaw2002-07-091-0/+22 | | | | | | | | | | text/plain but the RFCs state that inside a multipart/digest, the default type is message/rfc822. To preserve idempotency, we need a separate place to define the default type than the Content-Type: header. get_default_type(), set_default_type(): Accessor and mutator methods for the default type. * __init__(): Don't attach the subparts if its an empty tuple. If theBarry Warsaw2002-07-091-2/+5 | | | | boundary was given in the arguments, call set_boundary(). * clone(): A new method for creating a clone of this generator (forBarry Warsaw2002-07-091-27/+24 | | | | | | | | | | | | | recursive generation). _dispatch(): If the message object doesn't have a Content-Type: header, check its default type instead of assuming it's text/plain. This makes for correct generation of message/rfc822 containers. _handle_multipart(): We can get rid of the isdigest kludge. Just print the message as normal and everything will work out correctly. _handle_mulitpart_digest(): We don't need this anymore either. * __init__(): Be sure to set the default type to message/rfc822.Barry Warsaw2002-07-091-0/+2 | * _structure(): A handy little debugging aid that I don't (yet) intendBarry Warsaw2002-07-091-0/+10 | | | | to make public, but that others might still find useful. * TestEmailBase.ndiffAssertEqual(): Python 2.1's difflib doesn't have anBarry Warsaw2002-07-091-32/+186 | | | | | | | | | | ndiff function, so just alias it to assertEqual in that case. Various: make sure all openfile()/read()'s are wrapped in try/finally's so the file gets closed. A bunch of new tests checking the corner cases for multipart/digest and message/rfc822. * New files which test the corners of multipart/message andBarry Warsaw2002-07-092-0/+48 | | | | message/rfc822 compliance. * With the addition of Oleg's support for RFC 2231, it's time to bumpBarry Warsaw2002-07-091-1/+1 | | | | the version number to 2.1. * SF bug 578752: COUNT_ALLOCS vs heap typesTim Peters2002-07-082-0/+17 | | | | | | | Repair segfaults and infinite loops in COUNT_ALLOCS builds in the presence of new-style (heap-allocated) classes/types. Bugfix candidate. I'll backport this to 2.2. It's irrelevant in 2.1. * The readme file said that OSX Carbon modules were only built forJack Jansen2002-07-081-29/+41 | | | | | | | -enable-framework builds, but setup.py built them anyway. Fixed. Also normalized whitespace. Bugfix candidate. * PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.Tim Peters2002-07-081-2/+7 | * Remove the configure option for disabling the reference cycle GC.Neil Schemenauer2002-07-082-42/+1 | * Fix typo reported by Kent Engström, and a bunch of broken markup.Fred Drake2002-07-081-11/+11 | * Fix typo: "an Unicode string" --> "a Unicode string"Fred Drake2002-07-081-2/+2 | | | | Clarify the return value when the parameter is a Unicode object. * Fixed a typo and updated information about using the Times fonts whenFred Drake2002-07-081-4/+5 | | | | formatting PostScript documents. Reported by Dave Kuhlman. * Added font-setting line (and associated comments) to the A4 version ofFred Drake2002-07-081-0/+12 | | | | | | | | this file; the lack of this was causing the A4 version of tutorial to use really bad Type 3 fonts instead of Type 1 fonts, which also bloated the file size substantially. I thought there was a SourceForge bug for this, but couldn't find it. * Got rid of symlink target, and in stead have "make dontinstallmacsubtree"Jack Jansen2002-07-081-8/+8 | | | | | | which uses a .pth file to add the Mac/Lib from your source tree to sys.path. Also put the Python version number in a variable.Killed by signal 2. * Change the "__ private" names to "_ protected"; this has been a pain forFred Drake2002-07-081-31/+31 | | | | subclassing so many times it should simply be changed. * Got rid of special case for Macintosh realloc slowdown: Tim fixed the problem.Jack Jansen2002-07-082-6/+1 | * Define WITH_PYMALLOC as 1Jack Jansen2002-07-081-1/+1 | * PyNode_AddChild(): Do aggressive over-allocation when the number ofTim Peters2002-07-081-8/+41 | | | | | | | | | | | | | | | | | | | | | | | | | | | | children gets large, to avoid severe platform realloc() degeneration in extreme cases (like test_longexp). Bugfix candidate. This was doing extremely timid over-allocation, just rounding up to the nearest multiple of 3. Now so long as the number of children is <= 128, it rounds up to a multiple of 4 but via a much faster method. When the number of children exceeds 128, though, and more space is needed, it doubles the capacity. This is aggressive over-allocation. SF patch <http://www.python.org/sf/578297> has Andrew MacIntyre using PyMalloc in the parser to overcome platform malloc problems in test_longexp on OS/2 EMX. Jack Jansen notes there that it didn't help him on the Mac, because the Mac has problems with frequent ever-growing reallocs, not just with gazillions of teensy mallocs. Win98 has no visible problems with test_longexp, but I tried boosting the test-case size and soon got "senseless" MemoryErrors out of it, and soon after crashed the OS: as I've seen in many other contexts before, while the Win98 realloc remains zippy in bad cases, it leads to extreme fragmentation of user address space, to the point that the OS barfs. I don't yet know whether this fixes Jack's Mac problems, but it does cure Win98's problems when boosting the test case size. It also speeds test_longexp in its unaltered state. * - Got rid if WITH_CYCLE_GCJack Jansen2002-07-073-19/+6 | | | | | - Cleaned up Python banner string, so the normal build for MacPython 2.3 will have a short banner. * Rearranged and added comments to object.h, to clarify many thingsTim Peters2002-07-073-82/+125 | | | | | | | | | | | that have taken me "too long" to reverse-engineer over the years. Vastly reduced the nesting level and redundancy of #ifdef-ery. Took a light stab at repairing comments that are no longer true. sys_gettotalrefcount(): Changed to enable under Py_REF_DEBUG. It was enabled under Py_TRACE_REFS, which was much heavier than necessary. sys.gettotalrefcount() is now available in a Py_REF_DEBUG-only build. * Fix from SF patch #527518: proxy config with user+pass authentication.Jeremy Hylton2002-07-071-3/+8 | | | | Bug fix candidate. * Removed 3 unlikely #includes that were only needed for the non-gc flavorTim Peters2002-07-071-5/+0 | | | | of the trashcan code. * Fix for SF bug #432621: httplib: multiple Set-Cookie headersJeremy Hylton2002-07-07