Eliminate SkFILE: it always is the same as FILE.
authorhalcanary <halcanary@google.com>
Fri, 20 Nov 2015 21:47:49 +0000 (13:47 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 20 Nov 2015 21:47:49 +0000 (13:47 -0800)
Review URL: https://codereview.chromium.org/1467533003

13 files changed:
include/core/SkData.h
include/core/SkOSFile.h
include/core/SkStream.h
src/core/SkData.cpp
src/core/SkStream.cpp
src/ports/SkOSFile_posix.cpp
src/ports/SkOSFile_stdio.cpp
src/ports/SkOSFile_win.cpp
src/utils/SkRTConf.cpp
src/utils/SkWhitelistTypefaces.cpp
tests/DataRefTest.cpp
tests/PathOpsSkpClipTest.cpp
tools/chrome_fuzz.cpp

index 28bf515..60a98e0 100644 (file)
@@ -8,9 +8,10 @@
 #ifndef SkData_DEFINED
 #define SkData_DEFINED
 
+#include <stdio.h>
+
 #include "SkRefCnt.h"
 
-struct SkFILE;
 class SkStream;
 
 /**
@@ -119,13 +120,13 @@ public:
     static SkData* NewFromFileName(const char path[]);
 
     /**
-     *  Create a new dataref from a SkFILE.
-     *  This does not take ownership of the SkFILE, nor close it.
-     *  The caller is free to close the SkFILE at its convenience.
-     *  The SkFILE must be open for reading only.
+     *  Create a new dataref from a stdio FILE.
+     *  This does not take ownership of the FILE, nor close it.
+     *  The caller is free to close the FILE at its convenience.
+     *  The FILE must be open for reading only.
      *  Returns NULL on failure.
      */
-    static SkData* NewFromFILE(SkFILE* f);
+    static SkData* NewFromFILE(FILE* f);
 
     /**
      *  Create a new dataref from a file descriptor.
index 3ee3aa4..39a1646 100644 (file)
@@ -12,9 +12,9 @@
 #ifndef SkOSFile_DEFINED
 #define SkOSFile_DEFINED
 
-#include "SkString.h"
+#include <stdio.h>
 
-struct SkFILE;
+#include "SkString.h"
 
 enum SkFILE_Flags {
     kRead_SkFILE_Flag   = 0x01,
@@ -27,30 +27,30 @@ const static char SkPATH_SEPARATOR = '\\';
 const static char SkPATH_SEPARATOR = '/';
 #endif
 
-SkFILE* sk_fopen(const char path[], SkFILE_Flags);
-void    sk_fclose(SkFILE*);
+FILE* sk_fopen(const char path[], SkFILE_Flags);
+void    sk_fclose(FILE*);
 
-size_t  sk_fgetsize(SkFILE*);
+size_t  sk_fgetsize(FILE*);
 /** Return true if the file could seek back to the beginning
 */
-bool    sk_frewind(SkFILE*);
+bool    sk_frewind(FILE*);
 
-size_t  sk_fread(void* buffer, size_t byteCount, SkFILE*);
-size_t  sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
+size_t  sk_fread(void* buffer, size_t byteCount, FILE*);
+size_t  sk_fwrite(const void* buffer, size_t byteCount, FILE*);
 
-char*   sk_fgets(char* str, int size, SkFILE* f);
+char*   sk_fgets(char* str, int size, FILE* f);
 
-void    sk_fflush(SkFILE*);
+void    sk_fflush(FILE*);
 
-bool    sk_fseek(SkFILE*, size_t);
-bool    sk_fmove(SkFILE*, long);
-size_t  sk_ftell(SkFILE*);
+bool    sk_fseek(FILE*, size_t);
+bool    sk_fmove(FILE*, long);
+size_t  sk_ftell(FILE*);
 
 /** Maps a file into memory. Returns the address and length on success, NULL otherwise.
  *  The mapping is read only.
  *  When finished with the mapping, free the returned pointer with sk_fmunmap.
  */
-void*   sk_fmmap(SkFILE* f, size_t* length);
+void*   sk_fmmap(FILE* f, size_t* length);
 
 /** Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise.
  *  The mapping is read only.
@@ -64,12 +64,12 @@ void*   sk_fdmmap(int fd, size_t* length);
 void    sk_fmunmap(const void* addr, size_t length);
 
 /** Returns true if the two point at the exact same filesystem object. */
-bool    sk_fidentical(SkFILE* a, SkFILE* b);
+bool    sk_fidentical(FILE* a, FILE* b);
 
 /** Returns the underlying file descriptor for the given file.
  *  The return value will be < 0 on failure.
  */
-int     sk_fileno(SkFILE* f);
+int     sk_fileno(FILE* f);
 
 /** Returns true if something (file, directory, ???) exists at this path,
  *  and has the specified access flags.
@@ -80,7 +80,7 @@ bool    sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
 bool    sk_isdir(const char *path);
 
 // Have we reached the end of the file?
-int sk_feof(SkFILE *);
+int sk_feof(FILE *);
 
 
 // Create a new directory at this path; returns true if successful.
index 6767778..2279f9f 100644 (file)
@@ -224,8 +224,6 @@ public:
 #include "SkString.h"
 #include <stdio.h>
 
-struct SkFILE;
-
 /** A stream that wraps a C FILE* file stream. */
 class SK_API SkFILEStream : public SkStreamAsset {
 public:
@@ -271,7 +269,7 @@ public:
     const void* getMemoryBase() override;
 
 private:
-    SkFILE*     fFILE;
+    FILE*     fFILE;
     SkString    fName;
     Ownership   fOwnership;
     // fData is lazilly initialized when needed.
@@ -364,7 +362,7 @@ public:
     size_t bytesWritten() const override;
 
 private:
-    SkFILE* fFILE;
+    FILE* fFILE;
 
     typedef SkWStream INHERITED;
 };
index 017c397..5bf833e 100644 (file)
@@ -113,7 +113,7 @@ static void sk_mmap_releaseproc(const void* addr, void* ctx) {
     sk_fmunmap(addr, length);
 }
 
-SkData* SkData::NewFromFILE(SkFILE* f) {
+SkData* SkData::NewFromFILE(FILE* f) {
     size_t size;
     void* addr = sk_fmmap(f, &size);
     if (nullptr == addr) {
@@ -124,7 +124,7 @@ SkData* SkData::NewFromFILE(SkFILE* f) {
 }
 
 SkData* SkData::NewFromFileName(const char path[]) {
-    SkFILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr;
+    FILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr;
     if (nullptr == f) {
         return nullptr;
     }
index 20e2ae9..05867d9 100644 (file)
@@ -185,7 +185,7 @@ SkFILEStream::SkFILEStream(const char file[]) : fName(file), fOwnership(kCallerP
 }
 
 SkFILEStream::SkFILEStream(FILE* file, Ownership ownership)
-    : fFILE((SkFILE*)file)
+    : fFILE(file)
     , fOwnership(ownership) {
 }
 
@@ -850,7 +850,7 @@ bool SkDebugWStream::write(const void* buffer, size_t size)
 
 
 static SkData* mmap_filename(const char path[]) {
-    SkFILE* file = sk_fopen(path, kRead_SkFILE_Flag);
+    FILE* file = sk_fopen(path, kRead_SkFILE_Flag);
     if (nullptr == file) {
         return nullptr;
     }
index 58662f3..396de68 100644 (file)
@@ -35,8 +35,8 @@ typedef struct {
     ino_t ino;
 } SkFILEID;
 
-static bool sk_ino(SkFILE* a, SkFILEID* id) {
-    int fd = fileno((FILE*)a);
+static bool sk_ino(FILE* a, SkFILEID* id) {
+    int fd = fileno(a);
     if (fd < 0) {
         return 0;
     }
@@ -49,7 +49,7 @@ static bool sk_ino(SkFILE* a, SkFILEID* id) {
     return true;
 }
 
-bool sk_fidentical(SkFILE* a, SkFILE* b) {
+bool sk_fidentical(FILE* a, FILE* b) {
     SkFILEID aID, bID;
     return sk_ino(a, &aID) && sk_ino(b, &bID)
            && aID.ino == bID.ino
@@ -82,11 +82,11 @@ void* sk_fdmmap(int fd, size_t* size) {
     return addr;
 }
 
-int sk_fileno(SkFILE* f) {
-    return fileno((FILE*)f);
+int sk_fileno(FILE* f) {
+    return fileno(f);
 }
 
-void* sk_fmmap(SkFILE* f, size_t* size) {
+void* sk_fmmap(FILE* f, size_t* size) {
     int fd = sk_fileno(f);
     if (fd < 0) {
         return nullptr;
index 53a2bb4..3371bb7 100644 (file)
@@ -45,7 +45,7 @@ static FILE* ios_open_from_bundle(const char path[], const char* perm) {
 #endif
 
 
-SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
+FILE* sk_fopen(const char path[], SkFILE_Flags flags) {
     char    perm[4];
     char*   p = perm;
 
@@ -60,16 +60,16 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
     
     //TODO: on Windows fopen is just ASCII or the current code page,
     //convert to utf16 and use _wfopen
-    SkFILE* file = nullptr;
+    FILE* file = nullptr;
 #ifdef SK_BUILD_FOR_IOS
     // if read-only, try to open from bundle first
     if (kRead_SkFILE_Flag == flags) {
-        file = (SkFILE*)ios_open_from_bundle(path, perm);
+        file = ios_open_from_bundle(path, perm);
     }
     // otherwise just read from the Documents directory (default)
     if (!file) {
 #endif
-        file = (SkFILE*)::fopen(path, perm);
+        file = ::fopen(path, perm);
 #ifdef SK_BUILD_FOR_IOS
     }
 #endif
@@ -80,90 +80,90 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) {
     return file;
 }
 
-char* sk_fgets(char* str, int size, SkFILE* f) {
+char* sk_fgets(char* str, int size, FILE* f) {
     return ::fgets(str, size, (FILE *)f);
 }
 
-int sk_feof(SkFILE *f) {
+int sk_feof(FILE *f) {
     // no :: namespace qualifier because it breaks android
     return feof((FILE *)f);
 }
 
-size_t sk_fgetsize(SkFILE* f) {
+size_t sk_fgetsize(FILE* f) {
     SkASSERT(f);
 
-    long curr = ::ftell((FILE*)f); // remember where we are
+    long curr = ::ftell(f); // remember where we are
     if (curr < 0) {
         return 0;
     }
 
-    ::fseek((FILE*)f, 0, SEEK_END); // go to the end
-    long size = ::ftell((FILE*)f); // record the size
+    ::fseek(f, 0, SEEK_END); // go to the end
+    long size = ::ftell(f); // record the size
     if (size < 0) {
         size = 0;
     }
 
-    ::fseek((FILE*)f, curr, SEEK_SET); // go back to our prev location
+    ::fseek(f, curr, SEEK_SET); // go back to our prev location
     return size;
 }
 
-bool sk_frewind(SkFILE* f) {
+bool sk_frewind(FILE* f) {
     SkASSERT(f);
-    ::rewind((FILE*)f);
+    ::rewind(f);
     return true;
 }
 
-size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f) {
+size_t sk_fread(void* buffer, size_t byteCount, FILE* f) {
     SkASSERT(f);
     if (buffer == nullptr) {
-        size_t curr = ::ftell((FILE*)f);
+        size_t curr = ::ftell(f);
         if ((long)curr == -1) {
-            SkDEBUGF(("sk_fread: ftell(%p) returned -1 feof:%d ferror:%d\n", f, feof((FILE*)f), ferror((FILE*)f)));
+            SkDEBUGF(("sk_fread: ftell(%p) returned -1 feof:%d ferror:%d\n", f, feof(f), ferror(f)));
             return 0;
         }
-        int err = ::fseek((FILE*)f, (long)byteCount, SEEK_CUR);
+        int err = ::fseek(f, (long)byteCount, SEEK_CUR);
         if (err != 0) {
             SkDEBUGF(("sk_fread: fseek(%d) tell:%d failed with feof:%d ferror:%d returned:%d\n",
-                        byteCount, curr, feof((FILE*)f), ferror((FILE*)f), err));
+                        byteCount, curr, feof(f), ferror(f), err));
             return 0;
         }
         return byteCount;
     }
     else
-        return ::fread(buffer, 1, byteCount, (FILE*)f);
+        return ::fread(buffer, 1, byteCount, f);
 }
 
-size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) {
+size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* f) {
     SkASSERT(f);
-    return ::fwrite(buffer, 1, byteCount, (FILE*)f);
+    return ::fwrite(buffer, 1, byteCount, f);
 }
 
-void sk_fflush(SkFILE* f) {
+void sk_fflush(FILE* f) {
     SkASSERT(f);
-    ::fflush((FILE*)f);
+    ::fflush(f);
 }
 
-bool sk_fseek(SkFILE* f, size_t byteCount) {
-    int err = ::fseek((FILE*)f, (long)byteCount, SEEK_SET);
+bool sk_fseek(FILE* f, size_t byteCount) {
+    int err = ::fseek(f, (long)byteCount, SEEK_SET);
     return err == 0;
 }
 
-bool sk_fmove(SkFILE* f, long byteCount) {
-    int err = ::fseek((FILE*)f, byteCount, SEEK_CUR);
+bool sk_fmove(FILE* f, long byteCount) {
+    int err = ::fseek(f, byteCount, SEEK_CUR);
     return err == 0;
 }
 
-size_t sk_ftell(SkFILE* f) {
-    long curr = ::ftell((FILE*)f);
+size_t sk_ftell(FILE* f) {
+    long curr = ::ftell(f);
     if (curr < 0) {
         return 0;
     }
     return curr;
 }
 
-void sk_fclose(SkFILE* f) {
+void sk_fclose(FILE* f) {
     SkASSERT(f);
-    ::fclose((FILE*)f);
+    ::fclose(f);
 }
 
 bool sk_isdir(const char *path) {
index 395a3c8..6bdf9ab 100644 (file)
@@ -33,7 +33,7 @@ typedef struct {
     ULONGLONG fMsbSize;
 } SkFILEID;
 
-static bool sk_ino(SkFILE* f, SkFILEID* id) {
+static bool sk_ino(FILE* f, SkFILEID* id) {
     int fileno = _fileno((FILE*)f);
     if (fileno < 0) {
         return false;
@@ -56,7 +56,7 @@ static bool sk_ino(SkFILE* f, SkFILEID* id) {
     return true;
 }
 
-bool sk_fidentical(SkFILE* a, SkFILE* b) {
+bool sk_fidentical(FILE* a, FILE* b) {
     SkFILEID aID, bID;
     return sk_ino(a, &aID) && sk_ino(b, &bID)
            && aID.fLsbSize == bID.fLsbSize
@@ -111,11 +111,11 @@ void* sk_fdmmap(int fileno, size_t* length) {
     return addr;
 }
 
-int sk_fileno(SkFILE* f) {
+int sk_fileno(FILE* f) {
     return _fileno((FILE*)f);
 }
 
-void* sk_fmmap(SkFILE* f, size_t* length) {
+void* sk_fmmap(FILE* f, size_t* length) {
     int fileno = sk_fileno(f);
     if (fileno < 0) {
         return nullptr;
index 9c076cb..2dfa47e 100644 (file)
@@ -12,7 +12,7 @@
 
 SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) {
 
-    SkFILE *fp = sk_fopen(configFileLocation(), kRead_SkFILE_Flag);
+    FILE *fp = sk_fopen(configFileLocation(), kRead_SkFILE_Flag);
 
     if (!fp) {
         return;
@@ -77,7 +77,7 @@ const char *SkRTConfRegistry::configFileLocation() const {
 // to trigger this, make a config file of zero size.
 void SkRTConfRegistry::possiblyDumpFile() const {
     const char *path = configFileLocation();
-    SkFILE *fp = sk_fopen(path, kRead_SkFILE_Flag);
+    FILE *fp = sk_fopen(path, kRead_SkFILE_Flag);
     if (!fp) {
         return;
     }
index db15ee2..d3ffe98 100644 (file)
@@ -247,7 +247,7 @@ const char checksumTrailer[] =
 #include "SkOSFile.h"
 
 bool GenerateChecksums() {
-    SkFILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag);
+    FILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag);
     if (!file) {
         SkDebugf("Can't open %s for writing.\n", checksumFileName);
         return false;
index 177c9d3..0c7d5f4 100644 (file)
@@ -191,7 +191,7 @@ static void test_files(skiatest::Reporter* reporter) {
         writer.write(s, 26);
     }
 
-    SkFILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
+    FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
     SkAutoTUnref<SkData> r1(SkData::NewFromFILE(file));
     REPORTER_ASSERT(reporter, r1.get() != nullptr);
     REPORTER_ASSERT(reporter, r1->size() == 26);
index 7b63c1c..f82d75d 100644 (file)
@@ -683,7 +683,7 @@ static void testSkpClip(TestState* data) {
         return;
     }
     statusFile.appendf("%s%s", PATH_SLASH, statName.c_str());
-    SkFILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag);
+    FILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag);
     if (!file) {
             SkDebugf("failed to create %s", statusFile.c_str());
             return;
index f05c646..f49e126 100644 (file)
@@ -11,7 +11,7 @@
 static const int kBitmapSize = 24;
 
 static bool read_test_case(const char* filename, SkString* testdata) {
-  SkFILE* file = sk_fopen(filename, kRead_SkFILE_Flag);
+  FILE* file = sk_fopen(filename, kRead_SkFILE_Flag);
   if (!file) {
     SkDebugf("couldn't open file %s\n", filename);
     return false;