[pypy-commit] pypy reflex-support: make abstract classes uninstantiable

wlav noreply at buildbot.pypy.org
Tue Jun 28 01:09:34 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45152:868ae19fedf2
Date: 2011-06-09 14:29 -0700
http://bitbucket.org/pypy/pypy/changeset/868ae19fedf2/

Log:	make abstract classes uninstantiable

diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -460,7 +460,14 @@
         return self.space.newlist(bases)
 
     def construct(self, args_w):
-        overload = self.get_overload(self.name)
+        try:
+            overload = self.get_overload(self.name)
+        except Exception, e:
+            if e.match(self.space, self.space.w_AttributeError):
+                raise OperationError(self.space.w_TypeError,
+                                     self.space.wrap("%s is abstract" % self.name))
+            raise
+
         return overload.call(NULL_VOIDP, args_w)
 
 W_CPPType.typedef = TypeDef(
diff --git a/pypy/module/cppyy/test/advancedcpp.h b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -30,7 +30,7 @@
 class a_class {                    // for esoteric inheritance testing
 public:
    a_class() { m_a = 1; m_da = 1.1; }
-   virtual ~a_class() {}
+   ~a_class() {}
    virtual int get_value() = 0;
 
 public:
diff --git a/pypy/module/cppyy/test/advancedcpp.xml b/pypy/module/cppyy/test/advancedcpp.xml
--- a/pypy/module/cppyy/test/advancedcpp.xml
+++ b/pypy/module/cppyy/test/advancedcpp.xml
@@ -3,6 +3,13 @@
   <class name="base_class" />
   <class name="derived_class" />
 
+  <class name="a_class" />
+  <class name="b_class" />
+  <class name="c_class" />
+  <class name="c_class_1" />
+  <class name="c_class_2" />
+  <class name="d_class" />
+
   <class pattern="T1<*>" />
   <class pattern="T2<*>" />
   <class pattern="T3<*>" />
@@ -13,4 +20,7 @@
   <variable name="a_ns::g_a" />
   <variable name="a_ns::d_ns::g_d" />
 
+  <class name="some_abstract_class" />
+  <class name="some_concrete_class" />
+
 </lcgdict>
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -111,3 +111,12 @@
         t1.m_t1 = 111
         assert t1.value() == 111
         t1.destruct()
+
+    def test04_instantiation(self):
+        """Test non-instatiatability of abstract classes"""
+
+        import cppyy
+   
+        raises(TypeError, cppyy.gbl.a_class)
+        raises(TypeError, cppyy.gbl.some_abstract_class)
+


More information about the pypy-commit mailing list