Staging
v0.5.1
https://github.com/python/cpython
Revision 3b3be1fe10f6c15e57360cac9d9dbc660666e655 authored by Miss Islington (bot) on 17 April 2018, 21:58:34 UTC, committed by GitHub on 17 April 2018, 21:58:34 UTC
(cherry picked from commit c127a86e1862df88ec6f9d15b79c627fc616766e)

Co-authored-by: Aaron Ang <aaronang@users.noreply.github.com>
1 parent 902bb62
Raw File
Tip revision: 3b3be1fe10f6c15e57360cac9d9dbc660666e655 authored by Miss Islington (bot) on 17 April 2018, 21:58:34 UTC
bpo-11594: Ensure line-endings are respected when using 2to3 (GH-6483)
Tip revision: 3b3be1f
asdl.c
#include "Python.h"
#include "asdl.h"

asdl_seq *
_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
{
    asdl_seq *seq = NULL;
    size_t n;

    /* check size is sane */
    if (size < 0 ||
        (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
        PyErr_NoMemory();
        return NULL;
    }
    n = (size ? (sizeof(void *) * (size - 1)) : 0);

    /* check if size can be added safely */
    if (n > 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 *
_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
{
    asdl_int_seq *seq = NULL;
    size_t n;

    /* check size is sane */
    if (size < 0 ||
        (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
            PyErr_NoMemory();
            return NULL;
    }
    n = (size ? (sizeof(void *) * (size - 1)) : 0);

    /* check if size can be added safely */
    if (n > 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;
}
back to top