Commits

wlav committed 9b5b81b Merge

merge reflex-support to fix 1561 and 1563

Comments (0)

Files changed (3)

pypy/module/cppyy/interp_cppyy.py

 
     def get(self, w_cppinstance, w_pycppclass):
         cppinstance = self.space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=True)
+        if not cppinstance:
+            raise OperationError(self.space.w_ReferenceError, self.space.wrap("attribute access requires an instance")) 
         offset = self._get_offset(cppinstance)
         return self.converter.from_memory(self.space, w_cppinstance, w_pycppclass, offset)
 
     def set(self, w_cppinstance, w_value):
         cppinstance = self.space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=True)
+        if not cppinstance:
+            raise OperationError(self.space.w_ReferenceError, self.space.wrap("attribute access requires an instance"))
         offset = self._get_offset(cppinstance)
         self.converter.to_memory(self.space, w_cppinstance, w_value, offset)
         return self.space.w_None

pypy/module/cppyy/pythonify.py

     # mostly for the benefit of the CINT backend, which treats std as special
     gbl.std = make_cppnamespace(None, "std", None, False)
 
+    # install a type for enums to refer to
+    # TODO: this is correct for C++98, not for C++11 and in general there will
+    # be the same issue for all typedef'd builtin types
+    setattr(gbl, 'unsigned int', int)
+
     # install for user access
     cppyy.gbl = gbl
 

pypy/module/cppyy/test/test_datatypes.py

         raises(IndexError, c.m_float_array.__getitem__,  self.N)
         raises(IndexError, c.m_double_array.__getitem__, self.N)
 
+        # can not access an instance member on the class
+        raises(ReferenceError, getattr, cppyy_test_data, 'm_bool')
+        raises(ReferenceError, getattr, cppyy_test_data, 'm_int')
+
+        assert not hasattr(cppyy_test_data, 'm_bool')
+        assert not hasattr(cppyy_test_data, 'm_int')
+
         c.destruct()
 
     def test03_instance_data_write_access(self):
         c = cppyy_test_data()
         assert isinstance(c, cppyy_test_data)
 
-        # TODO: test that the enum is accessible as a type
+        # test that the enum is accessible as a type
+        assert cppyy_test_data.what
 
         assert cppyy_test_data.kNothing   ==   6
         assert cppyy_test_data.kSomething == 111
         assert cppyy_test_data.kLots      ==  42
 
+        assert cppyy_test_data.what(cppyy_test_data.kNothing) == cppyy_test_data.kNothing
+        assert cppyy_test_data.what(6) == cppyy_test_data.kNothing
+        # TODO: only allow instantiations with correct values (C++11)
+
         assert c.get_enum() == cppyy_test_data.kNothing
         assert c.m_enum == cppyy_test_data.kNothing
 
         assert cppyy_test_data.s_enum == cppyy_test_data.kSomething
 
         # global enums
+        assert gbl.fruit          # test type accessible
         assert gbl.kApple  == 78
         assert gbl.kBanana == 29
         assert gbl.kCitrus == 34