wlav avatar wlav committed c74ba16

allow const char* returns to be NULL (-> empty string)

Comments (0)

Files changed (4)

pypy/module/cppyy/executor.py

     def execute(self, space, cppmethod, cppthis, num_args, args):
         lresult = capi.c_call_l(cppmethod, cppthis, num_args, args)
         ccpresult = rffi.cast(rffi.CCHARP, lresult)
-        result = rffi.charp2str(ccpresult)  # TODO: make it a choice to free
-        return space.wrap(result)
+        if ccpresult:
+            result = rffi.charp2str(ccpresult)  # TODO: make it a choice to free
+            return space.wrap(result)
+        return space.wrap('')
 
 
 class ConstructorExecutor(FunctionExecutor):

pypy/module/cppyy/test/datatypes.cxx

 double              cppyy_test_data::s_double = -707.;
 cppyy_test_data::what  cppyy_test_data::s_enum = cppyy_test_data::kNothing;
 
+//- strings -----------------------------------------------------------------
+const char* cppyy_test_data::get_valid_string(const char* in) { return in; }
+const char* cppyy_test_data::get_invalid_string() { return (const char*)0; }
+
 
 //= global functions ========================================================
 long get_pod_address(cppyy_test_data& c)

pypy/module/cppyy/test/datatypes.h

     float*          pass_void_array_f(void* a) { return pass_array((float*)a); }
     double*         pass_void_array_d(void* a) { return pass_array((double*)a); }
 
+// strings
+    const char* get_valid_string(const char* in);
+    const char* get_invalid_string();
+
 public:
 // basic types
     bool                 m_bool;

pypy/module/cppyy/test/test_datatypes.py

         assert gbl.kBanana == 29
         assert gbl.kCitrus == 34
 
-    def test12_copy_contructor(self):
+    def test12_string_passing(self):
+        """Test passing/returning of a const char*"""
+
+        import cppyy
+        cppyy_test_data = cppyy.gbl.cppyy_test_data
+
+        c = cppyy_test_data()
+        assert c.get_valid_string('aap') == 'aap'
+        assert c.get_invalid_string() == ''
+
+    def test13_copy_contructor(self):
         """Test copy constructor"""
 
         import cppyy
         for i in range(4):
             assert t1[i] == t3[i]
 
-    def test13_object_returns(self):
+    def test14_object_returns(self):
         """Test access to and return of PODs"""
 
         import cppyy
         assert c.get_pod_ptrref().m_int == 666
         assert c.get_pod_ptrref().m_double == 3.14
 
-    def test14_object_arguments(self):
+    def test15_object_arguments(self):
         """Test setting and returning of a POD through arguments"""
 
         import cppyy
         assert p.m_int == 888
         assert p.m_double == 3.14
 
-    def test15_respect_privacy(self):
+    def test16_respect_privacy(self):
         """Test that privacy settings are respected"""
 
         import cppyy
 
         c.destruct()
 
-    def test16_object_and_pointer_comparisons(self):
+    def test17_object_and_pointer_comparisons(self):
         """Verify object and pointer comparisons"""
     
         import cppyy 
         assert l3 != l5
         assert l5 != l3
 
-    def test17_object_validity(self):
+    def test18_object_validity(self):
         """Test object validity checking"""
         
         from cppyy import gbl
 
         assert not d2
 
-    def test18_buffer_reshaping(self):
+    def test19_buffer_reshaping(self):
         """Test usage of buffer sizing"""
 
         import cppyy
             l = list(arr)
             for i in range(self.N):
                 assert arr[i] == l[i]
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.