[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Oct 2 12:33:22 EDT 2009


changeset 9cc231fa216f in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=9cc231fa216f
summary: backport rA8bffdcfc4197 to ensure that the header's dataoffset is rewritten if we've changed it

changeset e0723b684248 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=e0723b684248
summary: return types for those functions returning char *'s.  It's unclear who's freeing them.  ctypes seems to choke when I manually free them, so I wonder if it is doing it as it makes the returned string

diffstat:

 python/liblas/core.py   |  25 +++++++++++++++----------
 src/detail/writer10.cpp |   8 ++++++++
 src/detail/writer11.cpp |   8 ++++++++
 src/detail/writer12.cpp |   8 ++++++++
 4 files changed, 39 insertions(+), 10 deletions(-)

diffs (156 lines):

diff -r 81747c159eba -r e0723b684248 python/liblas/core.py
--- a/python/liblas/core.py	Fri Oct 02 09:52:23 2009 -0500
+++ b/python/liblas/core.py	Fri Oct 02 11:28:12 2009 -0500
@@ -93,23 +93,19 @@
         las.LASError_Reset()
         raise LASException(msg)
     retval = ctypes.string_at(result)[:]
-    free(result)
+
+    # these might end up being double frees, I don't know why
+    # free(result)
     return retval
 
 def free_returned_char_p(result, func, cargs):
 
     size = ctypes.c_int()
     retvalue = ctypes.string_at(result)
-    free(result)
+    
+    # these might end up being double frees, I don't know why
+    # free(result)
     return retvalue
-    
-    
-
-try:
-    from numpy import array, ndarray
-    HAS_NUMPY = True
-except ImportError:
-    HAS_NUMPY = False
 
 if os.name == 'nt':
     # stolen from Shapely
@@ -302,6 +298,7 @@
 
 las.LASHeader_GetFileSignature.argtypes = [ctypes.c_void_p]
 las.LASHeader_GetFileSignature.errcheck = check_value_free
+las.LASHeader_GetFileSignature.restype = ctypes.c_char_p
 
 las.LASHeader_GetFileSourceId.restype = ctypes.c_ushort
 las.LASHeader_GetFileSourceId.argtypes = [ctypes.c_void_p]
@@ -309,6 +306,7 @@
 
 las.LASHeader_GetProjectId.argtypes = [ctypes.c_void_p]
 las.LASHeader_GetProjectId.errcheck = check_value_free
+las.LASHeader_GetProjectId.restype = ctypes.c_char_p
 
 las.LASHeader_GetVersionMajor.restype = ctypes.c_ubyte
 las.LASHeader_GetVersionMajor.argtypes = [ctypes.c_void_p]
@@ -326,12 +324,14 @@
 
 las.LASHeader_GetSystemId.argtypes = [ctypes.c_void_p]
 las.LASHeader_GetSystemId.errcheck = check_value_free
+las.LASHeader_GetSystemId.restype = ctypes.c_char_p
 las.LASHeader_SetSystemId.restype = ctypes.c_int
 las.LASHeader_SetSystemId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASHeader_SetSystemId.errcheck = check_return
 
 las.LASHeader_GetSoftwareId.argtypes = [ctypes.c_void_p]
 las.LASHeader_GetSoftwareId.errcheck = check_value_free
+las.LASHeader_GetSoftwareId.restype = ctypes.c_char_p
 las.LASHeader_SetSoftwareId.restype = ctypes.c_int
 las.LASHeader_SetSoftwareId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASHeader_SetSoftwareId.errcheck = check_return
@@ -483,6 +483,7 @@
 
 las.LASGuid_AsString.argtypes = [ctypes.c_void_p]
 las.LASGuid_AsString.errcheck = check_value_free
+las.LASGuid_AsString.restype = ctypes.c_char_p
 
 las.LASGuid_Equals.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
 las.LASGuid_Equals.restype = ctypes.c_int
@@ -511,12 +512,14 @@
 
 las.LASVLR_GetUserId.argtypes = [ctypes.c_void_p]
 las.LASVLR_GetUserId.errcheck = check_value_free
+las.LASVLR_GetUserId.restype = ctypes.c_char_p
 las.LASVLR_SetUserId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASVLR_SetUserId.errcheck = check_return
 las.LASVLR_SetUserId.restype = ctypes.c_int
 
 las.LASVLR_GetDescription.argtypes = [ctypes.c_void_p]
 las.LASVLR_GetDescription.errcheck = check_value_free
+las.LASVLR_GetDescription.restype = ctypes.c_char_p
 las.LASVLR_SetDescription.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASVLR_SetDescription.errcheck = check_return
 las.LASVLR_SetDescription.restype = ctypes.c_int
@@ -595,12 +598,14 @@
 
 las.LASSRS_GetProj4.argtypes = [ctypes.c_void_p]
 las.LASSRS_GetProj4.errcheck = check_value_free
+las.LASSRS_GetProj4.restype = ctypes.c_char_p
 las.LASSRS_SetProj4.restype = ctypes.c_int
 las.LASSRS_SetProj4.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASSRS_SetProj4.errcheck = check_return
 
 las.LASSRS_GetWKT.argtypes = [ctypes.c_void_p]
 las.LASSRS_GetWKT.errcheck = check_value_free
+las.LASSRS_GetWKT.restype = ctypes.c_char_p
 las.LASSRS_SetWKT.restype = ctypes.c_int
 las.LASSRS_SetWKT.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 las.LASSRS_SetWKT.errcheck = check_return
diff -r 81747c159eba -r e0723b684248 src/detail/writer10.cpp
--- a/src/detail/writer10.cpp	Fri Oct 02 09:52:23 2009 -0500
+++ b/src/detail/writer10.cpp	Fri Oct 02 11:28:12 2009 -0500
@@ -227,6 +227,14 @@
     // the offset because we were too small to write the VLRs, this will 
     // end up being header.GetDataOffset() + difference + 2 (see above).
     header.SetDataOffset(header.GetDataOffset() + 2);
+
+    // Make sure to rewrite the dataoffset in the header portion now that
+    // we've changed it.
+    std::streamsize const current_pos = m_ofs.tellp();
+    std::streamsize const offset_pos = 96; 
+    m_ofs.seekp(offset_pos, std::ios::beg);
+    detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+    m_ofs.seekp(current_pos, std::ios::beg);        
     
     // If we already have points, we're going to put it at the end of the file.  
     // If we don't have any points,  we're going to leave it where it is.
diff -r 81747c159eba -r e0723b684248 src/detail/writer11.cpp
--- a/src/detail/writer11.cpp	Fri Oct 02 09:52:23 2009 -0500
+++ b/src/detail/writer11.cpp	Fri Oct 02 11:28:12 2009 -0500
@@ -216,6 +216,14 @@
     if (difference < 0) {
         header.SetDataOffset(header.GetDataOffset() + abs(difference) );
         WriteVLR(header);
+
+        // Make sure to rewrite the dataoffset in the header portion now that
+        // we've changed it.
+        std::streamsize const current_pos = m_ofs.tellp();
+        std::streamsize const offset_pos = 96; 
+        m_ofs.seekp(offset_pos, std::ios::beg);
+        detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+        m_ofs.seekp(current_pos, std::ios::beg);        
     }
 
     // If we already have points, we're going to put it at the end of the file.  
diff -r 81747c159eba -r e0723b684248 src/detail/writer12.cpp
--- a/src/detail/writer12.cpp	Fri Oct 02 09:52:23 2009 -0500
+++ b/src/detail/writer12.cpp	Fri Oct 02 11:28:12 2009 -0500
@@ -218,6 +218,14 @@
     if (difference < 0) {
         header.SetDataOffset(header.GetDataOffset() + abs(difference) );
         WriteVLR(header);
+
+        // Make sure to rewrite the dataoffset in the header portion now that
+        // we've changed it.
+        std::streamsize const current_pos = m_ofs.tellp();
+        std::streamsize const offset_pos = 96; 
+        m_ofs.seekp(offset_pos, std::ios::beg);
+        detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+        m_ofs.seekp(current_pos, std::ios::beg);        
     }
 
     // If we already have points, we're going to put it at the end of the file.  


More information about the Liblas-commits mailing list