Ver código fonte

Fix linker issue on Windows

rdb 10 anos atrás
pai
commit
5bf0d44735

+ 2 - 4
panda/src/downloader/stringStream.I

@@ -16,7 +16,7 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: StringStream::Constructor
 //     Function: StringStream::Constructor
 //       Access: Published
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE StringStream::
 INLINE StringStream::
 StringStream() : iostream(&_buf) {
 StringStream() : iostream(&_buf) {
@@ -80,9 +80,7 @@ INLINE void StringStream::
 set_data(const string &data) {
 set_data(const string &data) {
   _buf.clear();
   _buf.clear();
   if (!data.empty()) {
   if (!data.empty()) {
-    pvector<unsigned char> pv;
-    pv.insert(pv.end(), (const unsigned char *)&data[0], (const unsigned char *)&data[0] + data.size());
-    _buf.swap_data(pv);
+    set_data((const unsigned char *)data.data(), data.size());
   }
   }
 }
 }
 
 

+ 14 - 0
panda/src/downloader/stringStream.cxx

@@ -13,3 +13,17 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "stringStream.h"
 #include "stringStream.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: StringStream::set_data
+//       Access: Public
+//  Description: Replaces the contents of the data stream.  This
+//               implicitly reseeks to 0.
+////////////////////////////////////////////////////////////////////
+void StringStream::
+set_data(const unsigned char *data, size_t size) {
+  _buf.clear();
+  pvector<unsigned char> pv;
+  pv.insert(pv.end(), data, data + size);
+  _buf.swap_data(pv);
+}

+ 1 - 1
panda/src/downloader/stringStream.h

@@ -46,6 +46,7 @@ public:
 #ifndef CPPPARSER
 #ifndef CPPPARSER
   INLINE string get_data();
   INLINE string get_data();
   INLINE void set_data(const string &data);
   INLINE void set_data(const string &data);
+  void set_data(const unsigned char *data, size_t size);
 #endif
 #endif
 
 
   INLINE void swap_data(pvector<unsigned char> &data);
   INLINE void swap_data(pvector<unsigned char> &data);
@@ -59,4 +60,3 @@ private:
 #include "stringStream.I"
 #include "stringStream.I"
 
 
 #endif
 #endif
-

+ 2 - 6
panda/src/downloader/stringStream_ext.cxx

@@ -71,9 +71,7 @@ set_data(PyObject *data) {
                       "StringStream requires a contiguous buffer");
                       "StringStream requires a contiguous buffer");
       return;
       return;
     }
     }
-    pvector<unsigned char> pv;
-    pv.insert(pv.end(), (const unsigned char *)view.buf, (const unsigned char *)view.buf + view.len);
-    _this->_buf.swap_data(pv);
+    _this->set_data((const unsigned char *)view.buf, view.len);
     PyBuffer_Release(&view);
     PyBuffer_Release(&view);
     return;
     return;
   }
   }
@@ -84,9 +82,7 @@ set_data(PyObject *data) {
     char *buffer;
     char *buffer;
     Py_ssize_t length;
     Py_ssize_t length;
     if (PyString_AsStringAndSize(data, &buffer, &length) != -1) {
     if (PyString_AsStringAndSize(data, &buffer, &length) != -1) {
-      pvector<unsigned char> pv;
-      pv.insert(pv.end(), (const unsigned char *)buffer, (const unsigned char *)buffer + length);
-      _this->_buf.swap_data(pv);
+      _this->set_data((const unsigned char *)buffer, (size_t)length);
     }
     }
     return;
     return;
   }
   }