Skip to content

Commit 44926c0

Browse files
authored
Merge pull request #603 from LebedevRI/no-defaultinit
`*ArrayRef.D` shall not be default-constructible
2 parents 747d248 + 118f1e3 commit 44926c0

File tree

10 files changed

+44
-56
lines changed

10 files changed

+44
-56
lines changed

src/librawspeed/adt/Array1DRef.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace rawspeed {
3030
template <class T> class CroppedArray1DRef;
3131

3232
template <class T> class Array1DRef final {
33-
T* data = nullptr;
34-
int numElts = 0;
33+
T* data;
34+
int numElts;
3535

3636
friend Array1DRef<const T>; // We need to be able to convert to const version.
3737

@@ -45,7 +45,7 @@ template <class T> class Array1DRef final {
4545
using value_type = T;
4646
using cvless_value_type = std::remove_cv_t<value_type>;
4747

48-
Array1DRef() = default;
48+
Array1DRef() = delete;
4949

5050
Array1DRef(T* data, int numElts);
5151

src/librawspeed/adt/Array2DRef.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
namespace rawspeed {
3232

3333
template <class T> class Array2DRef final {
34-
T* _data = nullptr;
35-
int _pitch = 0;
34+
T* _data;
35+
int _pitch;
3636

3737
friend Array2DRef<const T>; // We need to be able to convert to const version.
3838

@@ -46,10 +46,10 @@ template <class T> class Array2DRef final {
4646
using value_type = T;
4747
using cvless_value_type = std::remove_cv_t<value_type>;
4848

49-
int width = 0;
50-
int height = 0;
49+
int width;
50+
int height;
5151

52-
Array2DRef() = default;
52+
Array2DRef() = delete;
5353

5454
Array2DRef(T* data, int width, int height, int pitch = 0);
5555

@@ -125,11 +125,6 @@ Array2DRef<T>::Array2DRef(T* data, const int width_, const int height_,
125125
template <class T>
126126
[[nodiscard]] inline Optional<Array1DRef<T>>
127127
Array2DRef<T>::getAsArray1DRef() const {
128-
// FIXME: this might be called for default-constructed `Array2DRef`,
129-
// and it really doesn't work for them.
130-
if (!_data)
131-
return std::nullopt;
132-
133128
establishClassInvariants();
134129
if (height == 1 || _pitch == width)
135130
return {{_data, width * height}};

src/librawspeed/adt/CroppedArray1DRef.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace rawspeed {
2929

3030
template <class T> class CroppedArray1DRef final {
3131
Array1DRef<T> base;
32-
int offset = 0;
33-
int numElts = 0;
32+
int offset;
33+
int numElts;
3434

3535
friend CroppedArray1DRef<const T>; // We need to be able to convert to const
3636
// version.
@@ -46,7 +46,7 @@ template <class T> class CroppedArray1DRef final {
4646
using value_type = T;
4747
using cvless_value_type = std::remove_cv_t<value_type>;
4848

49-
CroppedArray1DRef() = default;
49+
CroppedArray1DRef() = delete;
5050

5151
// Can not cast away constness.
5252
template <typename T2>

src/librawspeed/adt/CroppedArray2DRef.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ template <class T> class CroppedArray2DRef final {
4040
using value_type = T;
4141
using cvless_value_type = std::remove_cv_t<value_type>;
4242

43-
int offsetCols = 0;
44-
int offsetRows = 0;
45-
int croppedWidth = 0;
46-
int croppedHeight = 0;
43+
int offsetCols;
44+
int offsetRows;
45+
int croppedWidth;
46+
int croppedHeight;
4747

48-
CroppedArray2DRef() = default;
48+
CroppedArray2DRef() = delete;
4949

5050
// Can not cast away constness.
5151
template <typename T2>
@@ -60,7 +60,8 @@ template <class T> class CroppedArray2DRef final {
6060

6161
// Conversion from Array2DRef<T> to CroppedArray2DRef<T>.
6262
CroppedArray2DRef(Array2DRef<T> RHS) // NOLINT google-explicit-constructor
63-
: base(RHS), croppedWidth(base.width), croppedHeight(base.height) {}
63+
: base(RHS), offsetCols(0), offsetRows(0), croppedWidth(base.width),
64+
croppedHeight(base.height) {}
6465

6566
CroppedArray2DRef(Array2DRef<T> base_, int offsetCols_, int offsetRows_,
6667
int croppedWidth_, int croppedHeight_);

src/librawspeed/common/RawImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class RawImageData : public ErrorLog {
161161
ColorFilterArray cfa;
162162
int blackLevel = -1;
163163
std::array<int, 4> blackLevelSeparateStorage;
164-
Array2DRef<int> blackLevelSeparate;
164+
Array2DRef<int> blackLevelSeparate = {blackLevelSeparateStorage.data(), 0, 0};
165165
int whitePoint = 65536;
166166
std::vector<BlackArea> blackAreas;
167167

src/librawspeed/decoders/Cr2Decoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ void Cr2Decoder::decodeMetaDataInternal(const CameraMetaData* meta) {
498498
assert(mShiftUpScaleForExif == 0 || mShiftUpScaleForExif == 2);
499499
if (mShiftUpScaleForExif) {
500500
mRaw->blackLevel = 0;
501-
mRaw->blackLevelSeparate = {};
501+
mRaw->blackLevelSeparate = {mRaw->blackLevelSeparateStorage.data(), 0, 0};
502502
}
503503
if (mShiftUpScaleForExif != 0 && isPowerOfTwo(1 + mRaw->whitePoint))
504504
mRaw->whitePoint = ((1 + mRaw->whitePoint) << mShiftUpScaleForExif) - 1;

src/librawspeed/decompressors/FujiDecompressor.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ struct fuji_compressed_block final {
247247
const FujiDecompressor::FujiHeader& header,
248248
const fuji_compressed_params& common_info);
249249

250-
void reset(const fuji_compressed_params& params);
250+
void reset();
251251

252-
BitPumpMSB pump;
252+
Optional<BitPumpMSB> pump;
253253

254254
// tables of gradients
255255
std::array<std::array<int_pair, 41>, 3> grad_even;
@@ -297,21 +297,18 @@ struct fuji_compressed_block final {
297297
fuji_compressed_block::fuji_compressed_block(
298298
Array2DRef<uint16_t> img_, const FujiDecompressor::FujiHeader& header_,
299299
const fuji_compressed_params& common_info_)
300-
: img(img_), header(header_), common_info(common_info_) {}
301-
302-
void fuji_compressed_block::reset(const fuji_compressed_params& params) {
303-
const unsigned line_size = sizeof(uint16_t) * (params.line_width + 2);
304-
305-
linealloc.resize(ltotal * (params.line_width + 2), 0);
306-
lines = Array2DRef<uint16_t>(&linealloc[0], params.line_width + 2, ltotal);
300+
: img(img_), header(header_), common_info(common_info_),
301+
linealloc(ltotal * (common_info.line_width + 2), 0),
302+
lines(&linealloc[0], common_info.line_width + 2, ltotal) {}
307303

304+
void fuji_compressed_block::reset() {
308305
MSan::Allocated(CroppedArray2DRef(lines));
309306

310307
// Zero-initialize first two (read-only, carry-in) lines of each color,
311308
// including first and last helper columns of the second row.
312309
// This is needed for correctness.
313310
for (xt_lines color : {R0, G0, B0}) {
314-
memset(&lines(color, 0), 0, 2 * line_size);
311+
memset(&lines(color, 0), 0, 2 * sizeof(uint16_t) * lines.width);
315312

316313
// On the first row, we don't need to zero-init helper columns.
317314
MSan::Allocated(lines(color, 0));
@@ -327,9 +324,9 @@ void fuji_compressed_block::reset(const fuji_compressed_params& params) {
327324

328325
for (int j = 0; j < 3; j++) {
329326
for (int i = 0; i < 41; i++) {
330-
grad_even[j][i].value1 = params.maxDiff;
327+
grad_even[j][i].value1 = common_info.maxDiff;
331328
grad_even[j][i].value2 = 1;
332-
grad_odd[j][i].value1 = params.maxDiff;
329+
grad_odd[j][i].value1 = common_info.maxDiff;
333330
grad_odd[j][i].value2 = 1;
334331
}
335332
}
@@ -447,7 +444,7 @@ fuji_compressed_block::fuji_decode_sample(int grad, int interp_val,
447444
std::array<int_pair, 41>& grads) {
448445
int gradient = std::abs(grad);
449446

450-
int sampleBits = fuji_zerobits(pump);
447+
int sampleBits = fuji_zerobits(*pump);
451448

452449
int codeBits;
453450
int codeDelta;
@@ -460,9 +457,9 @@ fuji_compressed_block::fuji_decode_sample(int grad, int interp_val,
460457
}
461458

462459
int code = 0;
463-
pump.fill(32);
460+
pump->fill(32);
464461
if (codeBits)
465-
code = pump.getBitsNoFill(codeBits);
462+
code = pump->getBitsNoFill(codeBits);
466463
code += codeDelta;
467464

468465
if (code < 0 || code >= common_info.total_values) {
@@ -811,7 +808,7 @@ void FujiDecompressorImpl::decompressThread() const noexcept {
811808
#endif
812809
for (int block = 0; block < header.blocks_in_row; ++block) {
813810
FujiStrip strip(header, block, strips(block));
814-
block_info.reset(common_info);
811+
block_info.reset();
815812
try {
816813
block_info.pump = BitPumpMSB(strip.bs.peekRemainingBuffer());
817814
block_info.fuji_decode_strip(strip);

src/librawspeed/decompressors/VC5Decompressor.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,8 @@ struct ConvolutionParams final {
182182
VC5Decompressor::BandData VC5Decompressor::Wavelet::reconstructPass(
183183
const Array2DRef<const int16_t> high,
184184
const Array2DRef<const int16_t> low) noexcept {
185-
BandData combined;
185+
BandData combined(high.width, 2 * high.height);
186186
auto& dst = combined.description;
187-
dst = Array2DRef<int16_t>::create(combined.storage, high.width,
188-
2 * high.height);
189187

190188
auto process = [low, high, dst]<typename SegmentTy>(int row, int col) {
191189
auto lowGetter = [&row, &col, low](int delta) {
@@ -236,10 +234,8 @@ VC5Decompressor::BandData VC5Decompressor::Wavelet::combineLowHighPass(
236234
const Array2DRef<const int16_t> low, const Array2DRef<const int16_t> high,
237235
int descaleShift, bool clampUint = false,
238236
[[maybe_unused]] bool finalWavelet = false) noexcept {
239-
BandData combined;
237+
BandData combined(2 * high.width, high.height);
240238
auto& dst = combined.description;
241-
dst = Array2DRef<int16_t>::create(combined.storage, 2 * high.width,
242-
high.height);
243239

244240
auto process = [low, high, descaleShift, clampUint,
245241
dst]<typename SegmentTy>(int row, int col) {
@@ -662,10 +658,8 @@ VC5Decompressor::Wavelet::LowPassBand::LowPassBand(Wavelet& wavelet_,
662658

663659
VC5Decompressor::BandData
664660
VC5Decompressor::Wavelet::LowPassBand::decode() const noexcept {
665-
BandData lowpass;
661+
BandData lowpass(wavelet.width, wavelet.height);
666662
auto& band = lowpass.description;
667-
band = Array2DRef<int16_t>::create(lowpass.storage, wavelet.width,
668-
wavelet.height);
669663

670664
BitPumpMSB bits(input);
671665
for (auto row = 0; row < band.height; ++row) {
@@ -728,10 +722,8 @@ VC5Decompressor::Wavelet::HighPassBand::decode() const {
728722

729723
// decode highpass band
730724
DeRLVer d(*decoder, input, quant);
731-
BandData highpass;
725+
BandData highpass(wavelet.width, wavelet.height);
732726
auto& band = highpass.description;
733-
band = Array2DRef<int16_t>::create(highpass.storage, wavelet.width,
734-
wavelet.height);
735727
for (int row = 0; row != wavelet.height; ++row)
736728
for (int col = 0; col != wavelet.width; ++col)
737729
band(row, col) = d.decode();

src/librawspeed/decompressors/VC5Decompressor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class VC5Decompressor final : public AbstractDecompressor {
132132
struct BandData final {
133133
std::vector<int16_t, DefaultInitAllocatorAdaptor<int16_t>> storage;
134134
Array2DRef<int16_t> description;
135+
136+
BandData(int width, int height)
137+
: description(Array2DRef<int16_t>::create(storage, width, height)) {}
135138
};
136139

137140
class Wavelet final {

src/librawspeed/io/BitStream.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ template <typename Tag> struct BitStreamReplenisherBase {
104104
Array1DRef<const uint8_t> input;
105105
unsigned pos = 0;
106106

107-
BitStreamReplenisherBase() = default;
107+
BitStreamReplenisherBase() = delete;
108108

109109
explicit BitStreamReplenisherBase(Array1DRef<const uint8_t> input_)
110110
: input(input_) {
@@ -128,10 +128,10 @@ struct BitStreamForwardSequentialReplenisher final
128128
: public BitStreamReplenisherBase<Tag> {
129129
using Base = BitStreamReplenisherBase<Tag>;
130130

131-
BitStreamForwardSequentialReplenisher() = default;
132-
133131
using Base::BitStreamReplenisherBase;
134132

133+
BitStreamForwardSequentialReplenisher() = delete;
134+
135135
[[nodiscard]] inline typename Base::size_type getPos() const {
136136
return Base::pos;
137137
}
@@ -187,7 +187,7 @@ class BitStream final {
187187
public:
188188
using tag = Tag;
189189

190-
BitStream() = default;
190+
BitStream() = delete;
191191

192192
explicit BitStream(Array1DRef<const uint8_t> input) : replenisher(input) {}
193193

0 commit comments

Comments
 (0)