Skip to content

Instantly share code, notes, and snippets.

@undingen
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save undingen/74f15bbbe2ebbf9fe442 to your computer and use it in GitHub Desktop.
Save undingen/74f15bbbe2ebbf9fe442 to your computer and use it in GitHub Desktop.
same_slots_added
static int same_slots_added(PyTypeObject* a, PyTypeObject* b) noexcept {
PyTypeObject* base = a->tp_base;
Py_ssize_t size;
PyObject* slots_a, *slots_b;
assert(base == b->tp_base);
size = base->tp_basicsize;
if (a->tp_dictoffset == size && b->tp_dictoffset == size)
size += sizeof(PyObject*);
// Pyston change: have to check attrs_offset
if (a->attrs_offset == size && b->attrs_offset == size)
size += sizeof(HCAttrs);
if (a->tp_weaklistoffset == size && b->tp_weaklistoffset == size)
size += sizeof(PyObject*);
/* Check slots compliance */
slots_a = ((PyHeapTypeObject*)a)->ht_slots;
slots_b = ((PyHeapTypeObject*)b)->ht_slots;
if (slots_a && slots_b) {
if (PyObject_Compare(slots_a, slots_b) != 0)
return 0;
size += sizeof(PyObject*) * PyTuple_GET_SIZE(slots_a);
}
return size == a->tp_basicsize && size == b->tp_basicsize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment