blob: 504e23d9a74d3e1991e747152e3c7d5667ae93fb [file] [log] [blame]
Ivan Levkivskyi38928992018-02-18 17:39:43 +00001/* ABCMeta implementation */
2
3#include "Python.h"
4#include "structmember.h"
5#include "clinic/_abc.c.h"
6
7/*[clinic input]
8module _abc
9[clinic start generated code]*/
10/*[clinic end generated code: output=da39a3ee5e6b4b0d input=964f5328e1aefcda]*/
11
12PyDoc_STRVAR(_abc__doc__,
13"Module contains faster C implementation of abc.ABCMeta");
14
15_Py_IDENTIFIER(__abstractmethods__);
16_Py_IDENTIFIER(__class__);
17_Py_IDENTIFIER(__dict__);
18_Py_IDENTIFIER(__bases__);
19_Py_IDENTIFIER(_abc_impl);
20_Py_IDENTIFIER(__subclasscheck__);
21_Py_IDENTIFIER(__subclasshook__);
22
23/* A global counter that is incremented each time a class is
24 registered as a virtual subclass of anything. It forces the
25 negative cache to be cleared before its next use.
26 Note: this counter is private. Use `abc.get_cache_token()` for
27 external code. */
28static unsigned long long abc_invalidation_counter = 0;
29
30/* This object stores internal state for ABCs.
31 Note that we can use normal sets for caches,
32 since they are never iterated over. */
33typedef struct {
34 PyObject_HEAD
35 PyObject *_abc_registry;
36 PyObject *_abc_cache; /* Normal set of weak references. */
37 PyObject *_abc_negative_cache; /* Normal set of weak references. */
38 unsigned long long _abc_negative_cache_version;
39} _abc_data;
40
41static void
42abc_data_dealloc(_abc_data *self)
43{
44 Py_XDECREF(self->_abc_registry);
45 Py_XDECREF(self->_abc_cache);
46 Py_XDECREF(self->_abc_negative_cache);
47 Py_TYPE(self)->tp_free(self);
48}
49
50static PyObject *
51abc_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
52{
53 _abc_data *self = (_abc_data *) type->tp_alloc(type, 0);
54 if (self == NULL) {
55 return NULL;
56 }
57
58 self->_abc_registry = NULL;
59 self->_abc_cache = NULL;
60 self->_abc_negative_cache = NULL;
61 self->_abc_negative_cache_version = abc_invalidation_counter;
62 return (PyObject *) self;
63}
64
65PyDoc_STRVAR(abc_data_doc,
66"Internal state held by ABC machinery.");
67
68static PyTypeObject _abc_data_type = {
69 PyVarObject_HEAD_INIT(&PyType_Type, 0)
70 "_abc_data", /*tp_name*/
71 sizeof(_abc_data), /*tp_size*/
72 .tp_dealloc = (destructor)abc_data_dealloc,
73 .tp_flags = Py_TPFLAGS_DEFAULT,
74 .tp_alloc = PyType_GenericAlloc,
75 .tp_new = abc_data_new,
76};
77
78static _abc_data *
79_get_impl(PyObject *self)
80{
81 PyObject *impl = _PyObject_GetAttrId(self, &PyId__abc_impl);
82 if (impl == NULL) {
83 return NULL;
84 }
85 if (Py_TYPE(impl) != &_abc_data_type) {
86 PyErr_SetString(PyExc_TypeError, "_abc_impl is set to a wrong type");
87 Py_DECREF(impl);
88 return NULL;
89 }
90 return (_abc_data *)impl;
91}
92
93static int
94_in_weak_set(PyObject *set, PyObject *obj)
95{
96 if (set == NULL || PySet_GET_SIZE(set) == 0) {
97 return 0;
98 }
99 PyObject *ref = PyWeakref_NewRef(obj, NULL);
100 if (ref == NULL) {
101 if (PyErr_ExceptionMatches(PyExc_TypeError)) {
102 PyErr_Clear();
103 return 0;
104 }
105 return -1;
106 }
107 int res = PySet_Contains(set, ref);
108 Py_DECREF(ref);
109 return res;
110}
111
112static PyObject *
113_destroy(PyObject *setweakref, PyObject *objweakref)
114{
115 PyObject *set;
116 set = PyWeakref_GET_OBJECT(setweakref);
117 if (set == Py_None) {
118 Py_RETURN_NONE;
119 }
120 Py_INCREF(set);
121 if (PySet_Discard(set, objweakref) < 0) {
122 Py_DECREF(set);
123 return NULL;
124 }
125 Py_DECREF(set);
126 Py_RETURN_NONE;
127}
128
129static PyMethodDef _destroy_def = {
130 "_destroy", (PyCFunction) _destroy, METH_O
131};
132
133static int
134_add_to_weak_set(PyObject **pset, PyObject *obj)
135{
136 if (*pset == NULL) {
137 *pset = PySet_New(NULL);
138 if (*pset == NULL) {
139 return -1;
140 }
141 }
142
143 PyObject *set = *pset;
144 PyObject *ref, *wr;
145 PyObject *destroy_cb;
146 wr = PyWeakref_NewRef(set, NULL);
147 if (wr == NULL) {
148 return -1;
149 }
150 destroy_cb = PyCFunction_NewEx(&_destroy_def, wr, NULL);
151 if (destroy_cb == NULL) {
152 Py_DECREF(wr);
153 return -1;
154 }
155 ref = PyWeakref_NewRef(obj, destroy_cb);
156 Py_DECREF(destroy_cb);
157 if (ref == NULL) {
158 Py_DECREF(wr);
159 return -1;
160 }
161 int ret = PySet_Add(set, ref);
162 Py_DECREF(wr);
163 Py_DECREF(ref);
164 return ret;
165}
166
167/*[clinic input]
168_abc._reset_registry
169
170 self: object
171 /
172
173Internal ABC helper to reset registry of a given class.
174
175Should be only used by refleak.py
176[clinic start generated code]*/
177
178static PyObject *
179_abc__reset_registry(PyObject *module, PyObject *self)
180/*[clinic end generated code: output=92d591a43566cc10 input=12a0b7eb339ac35c]*/
181{
182 _abc_data *impl = _get_impl(self);
183 if (impl == NULL) {
184 return NULL;
185 }
186 if (impl->_abc_registry != NULL && PySet_Clear(impl->_abc_registry) < 0) {
187 Py_DECREF(impl);
188 return NULL;
189 }
190 Py_DECREF(impl);
191 Py_RETURN_NONE;
192}
193
194/*[clinic input]
195_abc._reset_caches
196
197 self: object
198 /
199
200Internal ABC helper to reset both caches of a given class.
201
202Should be only used by refleak.py
203[clinic start generated code]*/
204
205static PyObject *
206_abc__reset_caches(PyObject *module, PyObject *self)
207/*[clinic end generated code: output=f296f0d5c513f80c input=c0ac616fd8acfb6f]*/
208{
209 _abc_data *impl = _get_impl(self);
210 if (impl == NULL) {
211 return NULL;
212 }
213 if (impl->_abc_cache != NULL && PySet_Clear(impl->_abc_cache) < 0) {
214 Py_DECREF(impl);
215 return NULL;
216 }
217 /* also the second cache */
218 if (impl->_abc_negative_cache != NULL &&
219 PySet_Clear(impl->_abc_negative_cache) < 0) {
220 Py_DECREF(impl);
221 return NULL;
222 }
223 Py_DECREF(impl);
224 Py_RETURN_NONE;
225}
226
227/*[clinic input]
228_abc._get_dump
229
230 self: object
231 /
232
233Internal ABC helper for cache and registry debugging.
234
235Return shallow copies of registry, of both caches, and
236negative cache version. Don't call this function directly,
237instead use ABC._dump_registry() for a nice repr.
238[clinic start generated code]*/
239
240static PyObject *
241_abc__get_dump(PyObject *module, PyObject *self)
242/*[clinic end generated code: output=9d9569a8e2c1c443 input=2c5deb1bfe9e3c79]*/
243{
244 _abc_data *impl = _get_impl(self);
245 if (impl == NULL) {
246 return NULL;
247 }
248 PyObject *res = Py_BuildValue("NNNK",
249 PySet_New(impl->_abc_registry),
250 PySet_New(impl->_abc_cache),
251 PySet_New(impl->_abc_negative_cache),
252 impl->_abc_negative_cache_version);
253 Py_DECREF(impl);
254 return res;
255}
256
257// Compute set of abstract method names.
258static int
259compute_abstract_methods(PyObject *self)
260{
261 int ret = -1;
262 PyObject *abstracts = PyFrozenSet_New(NULL);
263 if (abstracts == NULL) {
264 return -1;
265 }
266
267 PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error.
268
269 /* Stage 1: direct abstract methods. */
270 ns = _PyObject_GetAttrId(self, &PyId___dict__);
271 if (!ns) {
272 goto error;
273 }
274
275 // We can't use PyDict_Next(ns) even when ns is dict because
276 // _PyObject_IsAbstract() can mutate ns.
277 items = PyMapping_Items(ns);
278 if (!items) {
279 goto error;
280 }
281 assert(PyList_Check(items));
282 for (Py_ssize_t pos = 0; pos < PyList_GET_SIZE(items); pos++) {
283 PyObject *it = PySequence_Fast(
284 PyList_GET_ITEM(items, pos),
285 "items() returned non-iterable");
286 if (!it) {
287 goto error;
288 }
289 if (PySequence_Fast_GET_SIZE(it) != 2) {
290 PyErr_SetString(PyExc_TypeError,
291 "items() returned item which size is not 2");
292 Py_DECREF(it);
293 goto error;
294 }
295
296 // borrowed
297 PyObject *key = PySequence_Fast_GET_ITEM(it, 0);
298 PyObject *value = PySequence_Fast_GET_ITEM(it, 1);
299 // items or it may be cleared while accessing __abstractmethod__
300 // So we need to keep strong reference for key
301 Py_INCREF(key);
302 int is_abstract = _PyObject_IsAbstract(value);
303 if (is_abstract < 0 ||
304 (is_abstract && PySet_Add(abstracts, key) < 0)) {
305 Py_DECREF(it);
306 Py_DECREF(key);
307 goto error;
308 }
309 Py_DECREF(key);
310 Py_DECREF(it);
311 }
312
313 /* Stage 2: inherited abstract methods. */
314 bases = _PyObject_GetAttrId(self, &PyId___bases__);
315 if (!bases) {
316 goto error;
317 }
318 if (!PyTuple_Check(bases)) {
319 PyErr_SetString(PyExc_TypeError, "__bases__ is not tuple");
320 goto error;
321 }
322
323 for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) {
324 PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
325 PyObject *base_abstracts, *iter;
326
327 if (_PyObject_LookupAttrId(item, &PyId___abstractmethods__,
328 &base_abstracts) < 0) {
329 goto error;
330 }
331 if (base_abstracts == NULL) {
332 continue;
333 }
334 if (!(iter = PyObject_GetIter(base_abstracts))) {
335 Py_DECREF(base_abstracts);
336 goto error;
337 }
338 Py_DECREF(base_abstracts);
339 PyObject *key, *value;
340 while ((key = PyIter_Next(iter))) {
341 if (_PyObject_LookupAttr(self, key, &value) < 0) {
342 Py_DECREF(key);
343 Py_DECREF(iter);
344 goto error;
345 }
346 if (value == NULL) {
347 Py_DECREF(key);
348 continue;
349 }
350
351 int is_abstract = _PyObject_IsAbstract(value);
352 Py_DECREF(value);
353 if (is_abstract < 0 ||
354 (is_abstract && PySet_Add(abstracts, key) < 0))
355 {
356 Py_DECREF(key);
357 Py_DECREF(iter);
358 goto error;
359 }
360 Py_DECREF(key);
361 }
362 Py_DECREF(iter);
363 if (PyErr_Occurred()) {
364 goto error;
365 }
366 }
367
368 if (_PyObject_SetAttrId(self, &PyId___abstractmethods__, abstracts) < 0) {
369 goto error;
370 }
371
372 ret = 0;
373error:
374 Py_DECREF(abstracts);
375 Py_XDECREF(ns);
376 Py_XDECREF(items);
377 Py_XDECREF(bases);
378 return ret;
379}
380
381/*[clinic input]
382_abc._abc_init
383
384 self: object
385 /
386
387Internal ABC helper for class set-up. Should be never used outside abc module.
388[clinic start generated code]*/
389
390static PyObject *
391_abc__abc_init(PyObject *module, PyObject *self)
392/*[clinic end generated code: output=594757375714cda1 input=8d7fe470ff77f029]*/
393{
394 PyObject *data;
395 if (compute_abstract_methods(self) < 0) {
396 return NULL;
397 }
398
399 /* Set up inheritance registry. */
400 data = abc_data_new(&_abc_data_type, NULL, NULL);
401 if (data == NULL) {
402 return NULL;
403 }
404 if (_PyObject_SetAttrId(self, &PyId__abc_impl, data) < 0) {
405 Py_DECREF(data);
406 return NULL;
407 }
408 Py_DECREF(data);
409 Py_RETURN_NONE;
410}
411
412/*[clinic input]
413_abc._abc_register
414
415 self: object
416 subclass: object
417 /
418
419Internal ABC helper for subclasss registration. Should be never used outside abc module.
420[clinic start generated code]*/
421
422static PyObject *
423_abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
424/*[clinic end generated code: output=7851e7668c963524 input=ca589f8c3080e67f]*/
425{
426 if (!PyType_Check(subclass)) {
427 PyErr_SetString(PyExc_TypeError, "Can only register classes");
428 return NULL;
429 }
430 int result = PyObject_IsSubclass(subclass, self);
431 if (result > 0) {
432 Py_INCREF(subclass);
433 return subclass; /* Already a subclass. */
434 }
435 if (result < 0) {
436 return NULL;
437 }
438 /* Subtle: test for cycles *after* testing for "already a subclass";
439 this means we allow X.register(X) and interpret it as a no-op. */
440 result = PyObject_IsSubclass(self, subclass);
441 if (result > 0) {
442 /* This would create a cycle, which is bad for the algorithm below. */
443 PyErr_SetString(PyExc_RuntimeError, "Refusing to create an inheritance cycle");
444 return NULL;
445 }
446 if (result < 0) {
447 return NULL;
448 }
449 _abc_data *impl = _get_impl(self);
450 if (impl == NULL) {
451 return NULL;
452 }
453 if (_add_to_weak_set(&impl->_abc_registry, subclass) < 0) {
454 Py_DECREF(impl);
455 return NULL;
456 }
457 Py_DECREF(impl);
458
459 /* Invalidate negative cache */
460 abc_invalidation_counter++;
461
462 Py_INCREF(subclass);
463 return subclass;
464}
465
466
467/*[clinic input]
468_abc._abc_instancecheck
469
470 self: object
471 instance: object
472 /
473
474Internal ABC helper for instance checks. Should be never used outside abc module.
475[clinic start generated code]*/
476
477static PyObject *
478_abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
479 PyObject *instance)
480/*[clinic end generated code: output=b8b5148f63b6b56f input=a4f4525679261084]*/
481{
482 PyObject *subtype, *result = NULL, *subclass = NULL;
483 _abc_data *impl = _get_impl(self);
484 if (impl == NULL) {
485 return NULL;
486 }
487
488 subclass = _PyObject_GetAttrId(instance, &PyId___class__);
489 if (subclass == NULL) {
490 Py_DECREF(impl);
491 return NULL;
492 }
493 /* Inline the cache checking. */
494 int incache = _in_weak_set(impl->_abc_cache, subclass);
495 if (incache < 0) {
496 goto end;
497 }
498 if (incache > 0) {
499 result = Py_True;
500 Py_INCREF(result);
501 goto end;
502 }
503 subtype = (PyObject *)Py_TYPE(instance);
504 if (subtype == subclass) {
505 if (impl->_abc_negative_cache_version == abc_invalidation_counter) {
506 incache = _in_weak_set(impl->_abc_negative_cache, subclass);
507 if (incache < 0) {
508 goto end;
509 }
510 if (incache > 0) {
511 result = Py_False;
512 Py_INCREF(result);
513 goto end;
514 }
515 }
516 /* Fall back to the subclass check. */
517 result = _PyObject_CallMethodIdObjArgs(self, &PyId___subclasscheck__,
518 subclass, NULL);
519 goto end;
520 }
521 result = _PyObject_CallMethodIdObjArgs(self, &PyId___subclasscheck__,
522 subclass, NULL);
523 if (result == NULL) {
524 goto end;
525 }
526
527 switch (PyObject_IsTrue(result)) {
528 case -1:
529 Py_DECREF(result);
530 result = NULL;
531 break;
532 case 0:
533 Py_DECREF(result);
534 result = _PyObject_CallMethodIdObjArgs(self, &PyId___subclasscheck__,
535 subtype, NULL);
536 break;
537 case 1: // Nothing to do.
538 break;
539 default:
540 Py_UNREACHABLE();
541 }
542
543end:
544 Py_XDECREF(impl);
545 Py_XDECREF(subclass);
546 return result;
547}
548
549
550// Return -1 when exception occured.
551// Return 1 when result is set.
552// Return 0 otherwise.
553static int subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
554 PyObject **result);
555
556/*[clinic input]
557_abc._abc_subclasscheck
558
559 self: object
560 subclass: object
561 /
562
563Internal ABC helper for subclasss checks. Should be never used outside abc module.
564[clinic start generated code]*/
565
566static PyObject *
567_abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
568 PyObject *subclass)
569/*[clinic end generated code: output=b56c9e4a530e3894 input=1d947243409d10b8]*/
570{
571 PyObject *ok, *mro, *subclasses = NULL, *result = NULL;
572 Py_ssize_t pos;
573 int incache;
574 _abc_data *impl = _get_impl(self);
575 if (impl == NULL) {
576 return NULL;
577 }
578
579 /* 1. Check cache. */
580 incache = _in_weak_set(impl->_abc_cache, subclass);
581 if (incache < 0) {
582 goto end;
583 }
584 if (incache > 0) {
585 result = Py_True;
586 goto end;
587 }
588
589 /* 2. Check negative cache; may have to invalidate. */
590 if (impl->_abc_negative_cache_version < abc_invalidation_counter) {
591 /* Invalidate the negative cache. */
592 if (impl->_abc_negative_cache != NULL &&
593 PySet_Clear(impl->_abc_negative_cache) < 0)
594 {
595 goto end;
596 }
597 impl->_abc_negative_cache_version = abc_invalidation_counter;
598 }
599 else {
600 incache = _in_weak_set(impl->_abc_negative_cache, subclass);
601 if (incache < 0) {
602 goto end;
603 }
604 if (incache > 0) {
605 result = Py_False;
606 goto end;
607 }
608 }
609
610 /* 3. Check the subclass hook. */
611 ok = _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId___subclasshook__,
612 subclass, NULL);
613 if (ok == NULL) {
614 goto end;
615 }
616 if (ok == Py_True) {
617 Py_DECREF(ok);
618 if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
619 goto end;
620 }
621 result = Py_True;
622 goto end;
623 }
624 if (ok == Py_False) {
625 Py_DECREF(ok);
626 if (_add_to_weak_set(&impl->_abc_negative_cache, subclass) < 0) {
627 goto end;
628 }
629 result = Py_False;
630 goto end;
631 }
632 if (ok != Py_NotImplemented) {
633 Py_DECREF(ok);
634 PyErr_SetString(PyExc_AssertionError, "__subclasshook__ must return either"
635 " False, True, or NotImplemented");
636 goto end;
637 }
638 Py_DECREF(ok);
639
640 /* 4. Check if it's a direct subclass. */
641 mro = ((PyTypeObject *)subclass)->tp_mro;
642 assert(PyTuple_Check(mro));
643 for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
644 PyObject *mro_item = PyTuple_GET_ITEM(mro, pos);
645 if (mro_item == NULL) {
646 goto end;
647 }
648 if ((PyObject *)self == mro_item) {
649 if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
650 goto end;
651 }
652 result = Py_True;
653 goto end;
654 }
655 }
656
657 /* 5. Check if it's a subclass of a registered class (recursive). */
658 if (subclasscheck_check_registry(impl, subclass, &result)) {
659 // Exception occured or result is set.
660 goto end;
661 }
662
663 /* 6. Check if it's a subclass of a subclass (recursive). */
664 subclasses = PyObject_CallMethod(self, "__subclasses__", NULL);
665 if (!PyList_Check(subclasses)) {
666 PyErr_SetString(PyExc_TypeError, "__subclasses__() must return a list");
667 goto end;
668 }
669 for (pos = 0; pos < PyList_GET_SIZE(subclasses); pos++) {
670 PyObject *scls = PyList_GET_ITEM(subclasses, pos);
671 Py_INCREF(scls);
672 int r = PyObject_IsSubclass(subclass, scls);
673 Py_DECREF(scls);
674 if (r > 0) {
675 if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
676 goto end;
677 }
678 result = Py_True;
679 goto end;
680 }
681 if (r < 0) {
682 goto end;
683 }
684 }
685
686 /* No dice; update negative cache. */
687 if (_add_to_weak_set(&impl->_abc_negative_cache, subclass) < 0) {
688 goto end;
689 }
690 result = Py_False;
691
692end:
693 Py_XDECREF(impl);
694 Py_XDECREF(subclasses);
695 Py_XINCREF(result);
696 return result;
697}
698
699
700static int
701subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
702 PyObject **result)
703{
704 // Fast path: check subclass is in weakref directly.
705 int ret = _in_weak_set(impl->_abc_registry, subclass);
706 if (ret < 0) {
707 *result = NULL;
708 return -1;
709 }
710 if (ret > 0) {
711 *result = Py_True;
712 return 1;
713 }
714
715 if (impl->_abc_registry == NULL) {
716 return 0;
717 }
718 Py_ssize_t registry_size = PySet_Size(impl->_abc_registry);
719 if (registry_size == 0) {
720 return 0;
721 }
722 // Weakref callback may remove entry from set.
723 // So we take snapshot of registry first.
724 PyObject **copy = PyMem_Malloc(sizeof(PyObject*) * registry_size);
725 PyObject *key;
726 Py_ssize_t pos = 0;
727 Py_hash_t hash;
728 Py_ssize_t i = 0;
729
730 while (_PySet_NextEntry(impl->_abc_registry, &pos, &key, &hash)) {
731 Py_INCREF(key);
732 copy[i++] = key;
733 }
734 assert(i == registry_size);
735
736 for (i = 0; i < registry_size; i++) {
737 PyObject *rkey = PyWeakref_GetObject(copy[i]);
738 if (rkey == NULL) {
739 // Someone inject non-weakref type in the registry.
740 ret = -1;
741 break;
742 }
743 if (rkey == Py_None) {
744 continue;
745 }
746 Py_INCREF(rkey);
747 int r = PyObject_IsSubclass(subclass, rkey);
748 Py_DECREF(rkey);
749 if (r < 0) {
750 ret = -1;
751 break;
752 }
753 if (r > 0) {
754 if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
755 ret = -1;
756 break;
757 }
758 *result = Py_True;
759 ret = 1;
760 break;
761 }
762 }
763
764 for (i = 0; i < registry_size; i++) {
765 Py_DECREF(copy[i]);
766 }
767 PyMem_Free(copy);
768 return ret;
769}
770
771/*[clinic input]
772_abc.get_cache_token
773
774Returns the current ABC cache token.
775
776The token is an opaque object (supporting equality testing) identifying the
777current version of the ABC cache for virtual subclasses. The token changes
778with every call to register() on any ABC.
779[clinic start generated code]*/
780
781static PyObject *
782_abc_get_cache_token_impl(PyObject *module)
783/*[clinic end generated code: output=c7d87841e033dacc input=70413d1c423ad9f9]*/
784{
785 return PyLong_FromUnsignedLongLong(abc_invalidation_counter);
786}
787
788static struct PyMethodDef module_functions[] = {
789 _ABC_GET_CACHE_TOKEN_METHODDEF
790 _ABC__ABC_INIT_METHODDEF
791 _ABC__RESET_REGISTRY_METHODDEF
792 _ABC__RESET_CACHES_METHODDEF
793 _ABC__GET_DUMP_METHODDEF
794 _ABC__ABC_REGISTER_METHODDEF
795 _ABC__ABC_INSTANCECHECK_METHODDEF
796 _ABC__ABC_SUBCLASSCHECK_METHODDEF
797 {NULL, NULL} /* sentinel */
798};
799
800static struct PyModuleDef _abcmodule = {
801 PyModuleDef_HEAD_INIT,
802 "_abc",
803 _abc__doc__,
804 -1,
805 module_functions,
806 NULL,
807 NULL,
808 NULL,
809 NULL
810};
811
812
813PyMODINIT_FUNC
814PyInit__abc(void)
815{
816 if (PyType_Ready(&_abc_data_type) < 0) {
817 return NULL;
818 }
819 _abc_data_type.tp_doc = abc_data_doc;
820
821 return PyModule_Create(&_abcmodule);
822}