Skip to content

Commit b85dda9

Browse files
committed
gzip: back to pointers
1 parent fa8642b commit b85dda9

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

kernel/gzip.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ gzip_istream::ibuf::~ibuf() {
100100

101101
// Takes a successfully opened ifstream. If it's gzipped, returns an istream. Otherwise,
102102
// returns the original ifstream, rewound to the start.
103-
std::istream& uncompressed(const std::string filename, std::ios_base::openmode mode) {
104-
std::ifstream& f = *new std::ifstream();
105-
f.open(filename, mode);
106-
if (f.fail())
103+
std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) {
104+
std::ifstream* f = new std::ifstream();
105+
f->open(filename, mode);
106+
if (f->fail())
107107
return f;
108108
// Check for gzip magic
109109
unsigned char magic[3];
110110
int n = 0;
111111
while (n < 3)
112112
{
113-
int c = f.get();
113+
int c = f->get();
114114
if (c != EOF) {
115115
magic[n] = (unsigned char) c;
116116
}
@@ -122,16 +122,16 @@ std::istream& uncompressed(const std::string filename, std::ios_base::openmode m
122122
if (magic[2] != 8)
123123
log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
124124
filename.c_str(), unsigned(magic[2]));
125-
gzip_istream& s = *new gzip_istream();
126-
delete &f;
127-
s.open(filename.c_str());
125+
gzip_istream* s = new gzip_istream();
126+
delete f;
127+
s->open(filename.c_str());
128128
return s;
129129
#else
130130
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
131131
#endif // YOSYS_ENABLE_ZLIB
132132
} else {
133-
f.clear();
134-
f.seekg(0, std::ios::beg);
133+
f->clear();
134+
f->seekg(0, std::ios::beg);
135135
return f;
136136
}
137137
}

kernel/gzip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class gzip_istream final : public std::istream {
7171

7272
#endif // YOSYS_ENABLE_ZLIB
7373

74-
std::istream& uncompressed(const std::string filename, std::ios_base::openmode mode = std::ios_base::in);
74+
std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode = std::ios_base::in);
7575

7676
YOSYS_NAMESPACE_END
7777

kernel/register.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
470470
next_args.insert(next_args.end(), filenames.begin()+1, filenames.end());
471471
}
472472
yosys_input_files.insert(filename);
473-
f = &uncompressed(filename, bin_input ? std::ifstream::binary : std::ifstream::in);
473+
f = uncompressed(filename, bin_input ? std::ifstream::binary : std::ifstream::in);
474474
}
475475
if (f == NULL)
476476
log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno));

passes/techmap/clockgate.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ struct ClockgatePass : public Pass {
309309
if (!liberty_files.empty()) {
310310
LibertyMergedCells merged;
311311
for (auto path : liberty_files) {
312-
std::istream& f = uncompressed(path);
313-
if (f.fail())
312+
std::istream* f = uncompressed(path);
313+
if (f->fail())
314314
log_cmd_error("Can't open liberty file `%s': %s\n", path.c_str(), strerror(errno));
315-
LibertyParser p(f);
315+
LibertyParser p(*f);
316316
merged.merge(p);
317-
delete &f;
317+
delete f;
318318
}
319319
std::tie(pos_icg_desc, neg_icg_desc) =
320320
find_icgs(merged.cells, dont_use_cells);

passes/techmap/dfflibmap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,12 @@ struct DfflibmapPass : public Pass {
631631

632632
LibertyMergedCells merged;
633633
for (auto path : liberty_files) {
634-
std::istream& f = uncompressed(path);
635-
if (f.fail())
634+
std::istream* f = uncompressed(path);
635+
if (f->fail())
636636
log_cmd_error("Can't open liberty file `%s': %s\n", path.c_str(), strerror(errno));
637-
LibertyParser p(f);
637+
LibertyParser p(*f);
638638
merged.merge(p);
639-
delete &f;
639+
delete f;
640640
}
641641

642642
find_cell(merged.cells, ID($_DFF_N_), false, false, false, false, false, false, dont_use_cells);

0 commit comments

Comments
 (0)