Author eryksun
Recipients eryksun, spearsem@gmail.com
Date 2015-11-18.19:17:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1447874264.7.0.548804167734.issue25659@psf.upfronthosting.co.za>
In-reply-to
Content
You have to subclass ctypes.Array with a _type_ and _length_. But ctypes types also implement sequence repetition (*) to facilitate creating array types. For example:

    import array, ctypes
    a1 = array.array('l')
    a1.fromlist(range(10))
    c1 = (ctypes.c_long * 10).from_buffer(a1)

    >>> c1[:]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> c1[0] = 42
    >>> a1[0]
    42

That said, it's way too easy to segfault this. Why not simply fail the call in this case? e.g.

    StgDictObject *dict = PyType_stgdict(type);
    if (!dict) {
        PyErr_SetString(PyExc_TypeError,
                    "abstract class");
        return NULL;
    }
History
Date User Action Args
2015-11-18 19:17:44eryksunsetrecipients: + eryksun, spearsem@gmail.com
2015-11-18 19:17:44eryksunsetmessageid: <1447874264.7.0.548804167734.issue25659@psf.upfronthosting.co.za>
2015-11-18 19:17:44eryksunlinkissue25659 messages
2015-11-18 19:17:44eryksuncreate