From 413c3e10b4a046493e648686e8d355db95e8846b Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Sun, 19 Jun 2016 00:01:59 +0300
Subject: [PATCH] py/objtype: instance: Inherit protocol vtable from a base
 class.

This allows to define an  abstract base class which would translate
C-level protocol to Python method calls, and any subclass inheriting
from it will support this feature. This in particular actually enables
recently introduced machine.PinBase class.
---
 py/objtype.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/py/objtype.c b/py/objtype.c
index 2f14c387d..3020ed513 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -914,7 +914,11 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
     o->getiter = instance_getiter;
     //o->iternext = ; not implemented
     o->buffer_p.get_buffer = instance_get_buffer;
-    //o->stream_p = ; not implemented
+    // Inherit protocol from a base class. This allows to define an
+    // abstract base class which would translate C-level protocol to
+    // Python method calls, and any subclass inheriting from it will
+    // support this feature.
+    o->protocol = ((mp_obj_type_t*)MP_OBJ_TO_PTR(items[0]))->protocol;
     o->bases_tuple = MP_OBJ_TO_PTR(bases_tuple);
     o->locals_dict = MP_OBJ_TO_PTR(locals_dict);
 
-- 
GitLab