[Python-3000] C API changes? [Was: Python 3000 Process]
"Martin v. Löwis"
martin at v.loewis.de
Wed Mar 22 19:31:30 CET 2006
Thomas Wouters wrote:
> For the old and ignorant among us (although I concede I may be the only
> one) could someone explain 'designated initializers' and how the code
> would look?
These are like keyword arguments. To initialize
mmapmodule.c:mmap_object_type, you would write
static PyTypeObject mmap_object_type = {
PyObject_HEAD_INIT(0)
.tp_name = "mmap.mmap",
.tp_size = sizeof(mmap_object),
.tp_dealloc = mmap_object_dealloc,
.tp_getattr = mmap_object_getattr,
.tp_as_sequence = &mmap_as_sequence,
.tp_as_buffer = &mmap_as_buffer,
.tp_flags = Py_TPFLAGS_HAVE_GETCHARBUFFER,
};
Everything not mentioned is null-initialized; order of fields does
not matter.
FWIW, the same is also available for arrays:
char *hash[1000] = { [317] = "foo", [220] = "bar" };
Regards,
Martin
More information about the Python-3000
mailing list