Author: Wim Lavrijsen <[email protected]>
Branch: cling-support
Changeset: r85670:76d09d04588d
Date: 2016-07-12 11:15 -0700
http://bitbucket.org/pypy/pypy/changeset/76d09d04588d/

Log:    pass length when converting char* to std::string

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -541,12 +541,12 @@
 
 _c_charp2stdstring = rffi.llexternal(
     "cppyy_charp2stdstring",
-    [rffi.CCHARP], C_OBJECT,
+    [rffi.CCHARP, rffi.SIZE_T], C_OBJECT,
     releasegil=ts_helper,
     compilation_info=backend.eci)
-def c_charp2stdstring(space, svalue):
+def c_charp2stdstring(space, svalue, sz):
     charp = rffi.str2charp(svalue)
-    result = _c_charp2stdstring(charp)
+    result = _c_charp2stdstring(charp, sz)
     rffi.free_charp(charp)
     return result
 _c_stdstring2stdstring = rffi.llexternal(
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -216,7 +216,7 @@
             'strtoull'                 : ([c_ccharp],                 
c_ullong),
             'free'                     : ([c_voidp],                  c_void),
 
-            'charp2stdstring'          : ([c_ccharp],                 
c_object),
+            'charp2stdstring'          : ([c_ccharp, c_size_t],       
c_object),
             'stdstring2stdstring'      : ([c_object],                 
c_object),
         }
 
@@ -517,8 +517,9 @@
     c_free(space, rffi.cast(rffi.VOIDP, charp))
     return pystr
 
-def c_charp2stdstring(space, svalue):
-    return _cdata_to_cobject(space, call_capi(space, 'charp2stdstring', 
[_Arg(s=svalue)]))
+def c_charp2stdstring(space, svalue, sz):
+    return _cdata_to_cobject(
+        space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(l=sz)]))
 def c_stdstring2stdstring(space, cppobject):
     return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', 
[_Arg(h=cppobject)]))
 
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -563,7 +563,7 @@
             arg = InstanceConverter._unwrap_object(self, space, w_obj)
             return capi.c_stdstring2stdstring(space, arg)
         else:
-            return capi.c_charp2stdstring(space, space.str_w(w_obj))
+            return capi.c_charp2stdstring(space, space.str_w(w_obj), 
space.len_w(w_obj))
 
     def to_memory(self, space, w_obj, w_value, offset):
         try:
diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h
--- a/pypy/module/cppyy/include/capi.h
+++ b/pypy/module/cppyy/include/capi.h
@@ -177,7 +177,7 @@
     void cppyy_free(void* ptr);
 
     RPY_EXTERN
-    cppyy_object_t cppyy_charp2stdstring(const char* str);
+    cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz);
     RPY_EXTERN
     cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr);
 
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -1405,8 +1405,8 @@
     free(ptr);
 }
 
-cppyy_object_t cppyy_charp2stdstring(const char* str){
-    return (cppyy_object_t)new std::string(str);
+cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz){
+    return (cppyy_object_t)new std::string(str, sz);
 }
 
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr){
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to