diff --git a/internal/cgen/auxiliary/base.cc b/internal/cgen/auxiliary/base.cc index 73e643ac..203d1706 100644 --- a/internal/cgen/auxiliary/base.cc +++ b/internal/cgen/auxiliary/base.cc @@ -53,6 +53,12 @@ FileInput::CopyIn(IOBuffer* dst) { // -------- +MemoryInput::MemoryInput(const char* ptr, size_t len) + : m_io(wuffs_base__ptr_u8__reader( + static_cast(static_cast(const_cast(ptr))), + len, + true)) {} + MemoryInput::MemoryInput(const uint8_t* ptr, size_t len) : m_io(wuffs_base__ptr_u8__reader(const_cast(ptr), len, true)) {} diff --git a/internal/cgen/auxiliary/base.hh b/internal/cgen/auxiliary/base.hh index e1aee481..d60d737e 100644 --- a/internal/cgen/auxiliary/base.hh +++ b/internal/cgen/auxiliary/base.hh @@ -63,6 +63,7 @@ class FileInput : public Input { // It does not take responsibility for freeing the memory when done. class MemoryInput : public Input { public: + MemoryInput(const char* ptr, size_t len); MemoryInput(const uint8_t* ptr, size_t len); virtual IOBuffer* BringsItsOwnIOBuffer(); diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index e2213e12..4bc5dc63 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -609,7 +609,7 @@ const AuxBaseCc = "" + "" + "// --------\n\nFileInput::FileInput(FILE* f) : m_f(f) {}\n\nstd::string //\nFileInput::CopyIn(IOBuffer* dst) {\n if (!m_f) {\n return \"wuffs_aux::sync_io::FileInput: nullptr file\";\n } else if (dst && !dst->meta.closed) {\n size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);\n dst->meta.wi += n;\n dst->meta.closed = feof(m_f);\n if (ferror(m_f)) {\n return \"wuffs_aux::sync_io::FileInput: error reading file\";\n }\n }\n return \"\";\n}\n\n" + "" + - "// --------\n\nMemoryInput::MemoryInput(const uint8_t* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(const_cast(ptr), len, true)) {}\n\nIOBuffer* //\nMemoryInput::BringsItsOwnIOBuffer() {\n return &m_io;\n}\n\nstd::string //\nMemoryInput::CopyIn(IOBuffer* dst) {\n if (dst && !dst->meta.closed && (dst != &m_io)) {\n size_t nd = dst->writer_length();\n size_t ns = m_io.reader_length();\n size_t n = (nd < ns) ? nd : ns;\n memcpy(dst->writer_pointer(), m_io.reader_pointer(), n);\n m_io.meta.ri += n;\n dst->meta.wi += n;\n dst->meta.closed = m_io.reader_length() == 0;\n }\n return \"\";\n}\n\n" + + "// --------\n\nMemoryInput::MemoryInput(const char* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(\n static_cast(static_cast(const_cast(ptr))),\n len,\n true)) {}\n\nMemoryInput::MemoryInput(const uint8_t* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(const_cast(ptr), len, true)) {}\n\nIOBuffer* //\nMemoryInput::BringsItsOwnIOBuffer() {\n return &m_io;\n}\n\nstd::string //\nMemoryInput::CopyIn(IOBuffer* dst) {\n if (dst && !dst->meta.closed && (dst != &m_io)) {\n size_t nd = dst->writer_length();\n size_t ns = m_io.reader_length();\n size_t n = (nd < ns) ? nd : ns;\n memcpy(dst->writer_pointer(), m_io.reader_pointer(), n);\n m_io.meta.ri += n;\n dst->meta.wi += n;\n dst->meta.closed = m_io.reader_length() == 0;\n }\n return \"\";\n}\n\n" + "" + "// --------\n\n} // namespace sync_io\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__BASE)\n" + "" @@ -621,7 +621,7 @@ const AuxBaseHh = "" + "" + "// --------\n\n// FileInput is an Input that reads from a file source.\n//\n// It does not take responsibility for closing the file when done.\nclass FileInput : public Input {\n public:\n FileInput(FILE* f);\n\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n FILE* m_f;\n\n // Delete the copy and assign constructors.\n FileInput(const FileInput&) = delete;\n FileInput& operator=(const FileInput&) = delete;\n};\n\n" + "" + - "// --------\n\n// MemoryInput is an Input that reads from an in-memory source.\n//\n// It does not take responsibility for freeing the memory when done.\nclass MemoryInput : public Input {\n public:\n MemoryInput(const uint8_t* ptr, size_t len);\n\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n IOBuffer m_io;\n\n // Delete the copy and assign constructors.\n MemoryInput(const MemoryInput&) = delete;\n MemoryInput& operator=(const MemoryInput&) = delete;\n};\n\n" + + "// --------\n\n// MemoryInput is an Input that reads from an in-memory source.\n//\n// It does not take responsibility for freeing the memory when done.\nclass MemoryInput : public Input {\n public:\n MemoryInput(const char* ptr, size_t len);\n MemoryInput(const uint8_t* ptr, size_t len);\n\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n IOBuffer m_io;\n\n // Delete the copy and assign constructors.\n MemoryInput(const MemoryInput&) = delete;\n MemoryInput& operator=(const MemoryInput&) = delete;\n};\n\n" + "" + "// --------\n\n} // namespace sync_io\n\n} // namespace wuffs_aux\n" + "" diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 301b0cd8..04f69321 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -8455,6 +8455,7 @@ class FileInput : public Input { // It does not take responsibility for freeing the memory when done. class MemoryInput : public Input { public: + MemoryInput(const char* ptr, size_t len); MemoryInput(const uint8_t* ptr, size_t len); virtual IOBuffer* BringsItsOwnIOBuffer(); @@ -28999,6 +29000,12 @@ FileInput::CopyIn(IOBuffer* dst) { // -------- +MemoryInput::MemoryInput(const char* ptr, size_t len) + : m_io(wuffs_base__ptr_u8__reader( + static_cast(static_cast(const_cast(ptr))), + len, + true)) {} + MemoryInput::MemoryInput(const uint8_t* ptr, size_t len) : m_io(wuffs_base__ptr_u8__reader(const_cast(ptr), len, true)) {}