Просмотр исходного кода

Supporting exceptions (or more, their lack of) for 3ds.

Eiyeron Fulmincendii лет назад: 9
Родитель
Сommit
0de6e1fb34
4 измененных файлов с 40 добавлено и 28 удалено
  1. 1 3
      platform/nspire/rules.mk
  2. 1 2
      platform/sfml/rules.mk
  3. 37 21
      src/piaf/Archive.cpp
  4. 1 2
      src/piaf/Exceptions.cpp

+ 1 - 3
platform/nspire/rules.mk

@@ -5,9 +5,7 @@ SRCS_CPP += $(wildcard $(nspire_LOCAL_PATH)/*.cpp)
 INCLUDE += $(nspire_LOCAL_PATH)/public
 
 LDFLAGS +=  -fuse-ld=gold
-
-
-CFLAGS_COMMON += -marm -DTARGET_NSPIRE=1
+CFLAGS_COMMON += -marm -DTARGET_NSPIRE=1 -DWRPG_EXCEPTIONS=1
 YCM_EXTRA_CFLAGS := -m32 -I$(NDLESS_GIT)/ndless-sdk/include -I$(HOME)/.ndless/include
 
 CC = nspire-gcc

+ 1 - 2
platform/sfml/rules.mk

@@ -7,8 +7,7 @@ INCLUDE += $(sfml_LOCAL_PATH)/public
 LIBS += -lstdc++ -lsfml-window -lsfml-graphics -lsfml-system
 LDFLAGS += -fuse-ld=gold
 
-
-CFLAGS_COMMON += -DTARGET_SFML=1
+CFLAGS_COMMON += -DTARGET_SFML=1 -DWRPG_EXCEPTIONS=1
 CC = clang
 CPP = clang++
 

+ 37 - 21
src/piaf/Archive.cpp

@@ -77,7 +77,9 @@ Archive::Archive(const char *filepath)
     if (filepath == nullptr)
     {
         Logger::error("%s: Null path given", __FILE__);
-        // throw PIAF::PIAFException("%s: Null path given", __FILE__);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Null path given", __FILE__);
+#endif
     }
     // Solves the absolute path for given relative path.
     // Must be needed in targets like Ndless as it doesn't support environment
@@ -90,7 +92,9 @@ Archive::Archive(const char *filepath)
     if (file == nullptr || file == NULL)
     {
         Logger::error("%s: Missing file : %s", __FILE__, filepath);
-        // throw PIAF::PIAFException("%s: Missing file : %s", __FILE__, filepath);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Missing file : %s", __FILE__, filepath);
+#endif
     }
 
     // Loading stuff happens NOW
@@ -102,8 +106,10 @@ Archive::Archive(const char *filepath)
     if (filesize < 32)
     {
         Logger::error("%s: File too small (%s): %d", __FILE__, filepath, filesize);
-        // throw PIAF::PIAFException("%s: File too small (%s): %d", __FILE__, filepath,
-        //                          filesize);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: File too small (%s): %d", __FILE__, filepath,
+                                  filesize);
+#endif
     }
 
     // Tempoary buffer to contain the header.
@@ -112,25 +118,29 @@ Archive::Archive(const char *filepath)
     if (fread(header_container, sizeof(char), 32, file) != 32)
     {
         Logger::error("%s: Errorneous header : %s", __FILE__, filepath);
-        // throw PIAF::PIAFException("%s: Errorneous header : %s", __FILE__, filepath);
-    }
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Errorneous header : %s", __FILE__, filepath);
+#endif
+  }
     // Check if the magic cookie is the same.
     // It's a first way to detect if the file is correctly an archive.
     if (strncmp(header_container, "WRPGPIAF", 8) != 0)
     {
         // TODO throw bad header
         Logger::error("%s: Magic cookie mismatch : %s", __FILE__, filepath);
-        // throw PIAF::PIAFException("%s: Magic cookie mismatch : %s", __FILE__,
-        // filepath);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Magic cookie mismatch : %s", __FILE__, filepath);
+#endif
     }
     // Checksum time! Let's check if the header hasn"t been altered.
     uint32_t expected_checksum = read_big_endian_value<uint32_t>(&header_container[8]);
     uint32_t calculated_checksum = crc32(0L, (unsigned char *) &header_container[16], 16);
     if (expected_checksum != calculated_checksum)
     {
-        // TODO throw bad checksum
         Logger::error("%s: Bad checksum : %s", __FILE__, filepath);
-        // throw PIAF::PIAFException("%s: Bad checksum : %s", __FILE__, filepath);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Bad checksum : %s", __FILE__, filepath);
+#endif
     }
 
     // TODO : version checking
@@ -141,8 +151,10 @@ Archive::Archive(const char *filepath)
         // throw up; // haha
         Logger::error("%s: Wrong(%s) : %08x is not supported by %08x", __FILE__, filepath,
                       version, ARCHIVE_VERSION);
-        // throw PIAF::PIAFException("%s: Wrong(%s) : %08x is not supported by %08x",
-        //                          __FILE__, filepath, version, ARCHIVE_VERSION);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("%s: Wrong(%s) : %08x is not supported by %08x",
+                                  __FILE__, filepath, version, ARCHIVE_VERSION);
+#endif
     }
 
 
@@ -157,10 +169,10 @@ Archive::Archive(const char *filepath)
     uint64_t calculated_data_size = filesize - 32 - 24 * nb_files;
     if (data_size != calculated_data_size)
     {
-        // fprintf(stderr, "Bad data size : expected %u, got %lld\n", data_size,
-        // calculated_data_size);
         Logger::error("Data size mismatch", __LINE__, filepath);
-        // throw PIAF::PIAFException("Data size mismatch", __LINE__, filepath);
+#ifdef WRPG_EXCEPTIONS
+        throw PIAF::PIAFException("Data size mismatch", __LINE__, filepath);
+#endif
     }
     // Check if there are files to manage.
     if (nb_files != 0)
@@ -174,16 +186,18 @@ Archive::Archive(const char *filepath)
         if (fread(file_entry_data, sizeof(char), 24 * nb_files, file) < 24 * nb_files)
         {
             Logger::error("Can't read file entry data", __LINE__, filepath);
-            //  throw PIAF::PIAFException("Can't read file entry data", __LINE__,
-            //  filepath);
+#ifdef WRPG_EXCEPTIONS
+            throw PIAF::PIAFException("Can't read file entry data", __LINE__, filepath);
+#endif
         }
         // Compare and trigger an exception if the checksum doesn't match.
         if (expected_filetable_checksum !=
             crc32(0L, (unsigned char *) file_entry_data, 24 * nb_files))
         {
-            // fprintf(stderr, "Bad filetable checksum\n");
             Logger::error("Bad Filetable checksum", __LINE__, filepath);
-            //  throw PIAF::PIAFException("Bad Filetable checksum", __LINE__, filepath);
+#ifdef WRPG_EXCEPTIONS
+            throw PIAF::PIAFException("Bad Filetable checksum", __LINE__, filepath);
+#endif
         }
         // Create the filetable.
         entries = new File[nb_files];
@@ -258,8 +272,10 @@ File Archive::get(const char *filename)
                 if (fread(data, sizeof(uint8_t), entries[index].file_size, file) !=
                     entries[index].file_size)
                 {
-                    //  throw PIAF::PIAFException("%s: couldn't load %s from an archive.",
-                    //                            filename);
+#ifdef WRPG_EXCEPTIONS
+                    throw PIAF::PIAFException("%s: couldn't load %s from an archive.",
+                                              filename);
+#endif
                 }
                 else
                 {

+ 1 - 2
src/piaf/Exceptions.cpp

@@ -13,7 +13,6 @@ PIAFException::PIAFException(const char *format, ...) : msg("")
     va_list list;
     va_start(list, format);
     vsnprintf(msg, 1024, format, list);
-    log(msg);
     va_end(list);
 }
 
@@ -24,4 +23,4 @@ PIAFException::~PIAFException()
 const char *PIAFException::what() const throw()
 {
     return msg;
-}
+}