]> git.donarmstrong.com Git - bamtools.git/commitdiff
Fix Visual Studio compiler errors.
authorAlec Chapman <achapman@alumni.princeton.edu>
Tue, 28 Jun 2011 01:58:30 +0000 (21:58 -0400)
committerAlec Chapman <achapman@alumni.princeton.edu>
Tue, 28 Jun 2011 01:58:30 +0000 (21:58 -0400)
Don't use dynamic stack allocation (variable length arrays).
Rename bamtools target to bamtools_cmd to not conflict with BamTools target (they differ only in case).
bamtools_cmd only compiles if I remove bamtools_filter.cpp, which I haven't committed.
I also had to manually configure the include directory for zlib,
but that's probably due to having multiple copies floating around my machine.

CMakeLists.txt
src/api/BamAlignment.cpp
src/api/CMakeLists.txt
src/toolkit/CMakeLists.txt
src/utils/bamtools_fasta.cpp
src/utils/bamtools_utilities.cpp

index 65c450b82cbcbb6b622e5a165ae7f291c10aada1..88beb4edc1160c24e84af7dc43e8d1a72bc6fcc1 100644 (file)
@@ -39,7 +39,8 @@ set (EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
 set (LIBRARY_OUTPUT_PATH    "${CMAKE_SOURCE_DIR}/lib")
 
 # define compiler flags for all code
-add_definitions (-Wall -O2 -D_FILE_OFFSET_BITS=64)
+set (CMAKE_BUILD_TYPE Release)
+add_definitions (-Wall -D_FILE_OFFSET_BITS=64)
 
 # add our includes root path
 include_directories (src)
index c6665598a01159a0d20ab89d3998b15c4222543f..0077f64a9eb5306033811a6e49261cebfacb5969 100644 (file)
@@ -154,16 +154,18 @@ bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const
     // otherwise, copy tag data to temp buffer
     string newTag = tag + type + value;
     const int newTagDataLength = tagDataLength + newTag.size() + 1; // leave room for null-term
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength + 1);    // '+1' for TagData null-term
-    
+
     // append newTag
     strcat(originalTagData + tagDataLength, newTag.data());  // removes original null-term, appends newTag + null-term
-    
+
     // store temp buffer back in TagData
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
     
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -213,7 +215,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const
     // copy original tag data to temp buffer
     string newTag = tag + type;
     const int newTagDataLength = tagDataLength + newTag.size() + 4; // leave room for new integer
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength + 1);    // '+1' for TagData null-term
     
     // append newTag
@@ -223,6 +225,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const
     // store temp buffer back in TagData
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
+    delete[] originalTagData;
     
     // return success
     return true;
@@ -288,7 +291,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const
     // copy original tag data to temp buffer
     string newTag = tag + type;
     const int newTagDataLength = tagDataLength + newTag.size() + 4; // leave room for new float
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength + 1);    // '+1' for TagData null-term
     
     // append newTag
@@ -299,6 +302,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
     
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -346,7 +351,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint8_t>& va
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(uint8_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -364,6 +369,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint8_t>& va
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -411,7 +418,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int8_t>& val
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(int8_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -429,6 +436,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int8_t>& val
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -476,7 +485,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint16_t>& v
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(uint16_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -494,6 +503,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint16_t>& v
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -541,7 +552,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int16_t>& va
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(int16_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -559,6 +570,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int16_t>& va
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -606,7 +619,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint32_t>& v
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(uint32_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -624,6 +637,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint32_t>& v
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -671,7 +686,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int32_t>& va
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(int32_t);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -689,6 +704,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<int32_t>& va
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -736,7 +753,7 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<float>& valu
     const int newTagDataLength = tagDataLength +
                                  Constants::BAM_TAG_ARRAYBASE_SIZE +
                                  numElements*sizeof(float);
-    char originalTagData[newTagDataLength];
+    char* originalTagData = new char[newTagDataLength];
     memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
 
     // write newTagBase (removes old null term)
@@ -754,6 +771,8 @@ bool BamAlignment::AddTag(const std::string& tag, const std::vector<float>& valu
     const char* newTagData = (const char*)originalTagData;
     TagData.assign(newTagData, newTagDataLength);
 
+    delete[] originalTagData;
+
     // return success
     return true;
 }
@@ -1024,7 +1043,7 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
     if ( FindTag(tag, pTagData, originalTagDataLength, numBytesParsed) ) {
         
         // make sure array is more than big enough
-        char newTagData[originalTagDataLength + value.size()];  
+        char* newTagData = new char[originalTagDataLength + value.size()];  
 
         // copy original tag data up til desired tag
         const unsigned int beginningTagDataLength = numBytesParsed;
@@ -1051,6 +1070,9 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
         
         // save new tag data
         TagData.assign(newTagData, endTagOffset + endTagDataLength);
+
+        delete[] newTagData;
+
         return true;
     }
     
@@ -1100,7 +1122,7 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
     if ( FindTag(tag, pTagData, originalTagDataLength, numBytesParsed) ) {
         
         // make sure array is more than big enough
-        char newTagData[originalTagDataLength + sizeof(value)];  
+        char* newTagData = new char[originalTagDataLength + sizeof(value)];  
 
         // copy original tag data up til desired tag
         const unsigned int beginningTagDataLength = numBytesParsed;
@@ -1128,6 +1150,9 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
         
         // save new tag data
         TagData.assign(newTagData, endTagOffset + endTagDataLength);
+
+        delete[] newTagData;
+
         return true;
     }
     
@@ -1194,7 +1219,7 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
     if ( FindTag(tag, pTagData, originalTagDataLength, numBytesParsed) ) {
         
         // make sure array is more than big enough
-        char newTagData[originalTagDataLength + sizeof(value)];  
+        char* newTagData = new char[originalTagDataLength + sizeof(value)];  
 
         // copy original tag data up til desired tag
         const unsigned int beginningTagDataLength = numBytesParsed;
@@ -1222,6 +1247,9 @@ bool BamAlignment::EditTag(const std::string& tag, const std::string& type, cons
         
         // save new tag data
         TagData.assign(newTagData, endTagOffset + endTagDataLength);
+
+        delete[] newTagData;
+
         return true;
     }
     
@@ -2154,7 +2182,7 @@ bool BamAlignment::RemoveTag(const std::string& tag) {
     // if tag found
     if ( FindTag(tag, pTagData, originalTagDataLength, numBytesParsed) ) {
         
-        char newTagData[originalTagDataLength];
+        char* newTagData = new char[originalTagDataLength];
 
         // copy original tag data up til desired tag
         pTagData       -= 3;
@@ -2177,6 +2205,9 @@ bool BamAlignment::RemoveTag(const std::string& tag) {
         
         // save new tag data
         TagData.assign(newTagData, beginningTagDataLength + endTagDataLength);
+
+        delete[] newTagData;
+
         return true;
     }
     
index 39864c707ec0ea196f573735d08cd2b22919720e..10c46d6bd36da18d8644ee8dbe64d1aa4e795af1 100644 (file)
@@ -54,7 +54,7 @@ target_link_libraries( BamTools z )
 target_link_libraries( BamTools-static z )
 
 # set library install destinations
-install( TARGETS BamTools LIBRARY DESTINATION "lib/bamtools")
+install( TARGETS BamTools LIBRARY DESTINATION "lib/bamtools" RUNTIME DESTINATION "bin")
 install( TARGETS BamTools-static ARCHIVE DESTINATION "lib/bamtools")
 
 # export API headers
index 37ab415e89610e02863d9167ec571ec277290363..e2a251b5ddcc2e8b7084fd1c6ef8b11d3d352b6c 100644 (file)
@@ -12,7 +12,7 @@ include_directories ( ${BamTools_SOURCE_DIR}/src/api
                     )
 
 # compile main bamtools application
-add_executable ( bamtools
+add_executable ( bamtools_cmd
                  bamtools_convert.cpp
                  bamtools_count.cpp
                  bamtools_coverage.cpp
@@ -22,7 +22,7 @@ add_executable ( bamtools
                  bamtools_merge.cpp
                  bamtools_random.cpp
                  bamtools_resolve.cpp
-                        bamtools_revert.cpp
+                 bamtools_revert.cpp
                  bamtools_sort.cpp
                  bamtools_split.cpp
                  bamtools_stats.cpp
@@ -30,14 +30,15 @@ add_executable ( bamtools
                )
 
 # set BamTools application properties
-set_target_properties( BamTools PROPERTIES
+set_target_properties( bamtools_cmd PROPERTIES
                        VERSION  1.0.2
+                       OUTPUT_NAME "bamtools"
                      )
 # make version info available in application
 configure_file(bamtools_version.h.in ${BamTools_SOURCE_DIR}/src/toolkit/bamtools_version.h)
 
 # define libraries to link
-target_link_libraries ( bamtools BamTools BamTools-utils jsoncpp )
+target_link_libraries ( bamtools_cmd BamTools BamTools-utils jsoncpp )
 
 # set application install destinations
-install( TARGETS bamtools DESTINATION "bin")
+install( TARGETS bamtools_cmd DESTINATION "bin")
index 3a72d7d4ebe5612331befefe74f6865e045f9606..f6434d344041b154c9f182499bbdb62d2e6350a8 100644 (file)
@@ -20,6 +20,11 @@ using namespace BamTools;
 #include <vector>
 using namespace std;
 
+#ifdef _MSC_VER
+       #define ftello _ftelli64
+       #define fseeko _fseeki64
+#endif
+
 struct Fasta::FastaPrivate {
   
     struct FastaIndexData {
index 3b6d46a1063a2add5abdb00cf9ac03ff8405eb95..1d5e00d3a5f62ef419667e38df90971295987fb5 100644 (file)
@@ -309,7 +309,7 @@ vector<string> Utilities::Split(const string& source, const string& delims) {
     vector<string> fields;
 
     char* tok;
-    char cchars [source.size()+1];
+    char* cchars = new char[source.size()+1];
     char* cstr = &cchars[0];
     strcpy(cstr, source.c_str());
     tok = strtok(cstr, delims.c_str());
@@ -318,6 +318,8 @@ vector<string> Utilities::Split(const string& source, const string& delims) {
         tok = strtok(NULL, delims.c_str());
     }
 
+    delete[] cchars;
+
     return fields;
 }