Skip to content

Fix to ensure the custom deallocator for zint_symbol is used for std::shared_ptr's too #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/Barcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#ifdef ZXING_USE_ZINT
#include <zint.h>
void zint_symbol_deleter::operator()(zint_symbol* p) const noexcept
{
ZBarcode_Delete(p);
}
#else
struct zint_symbol {};
#endif
Expand Down Expand Up @@ -150,7 +154,7 @@ ImageView Result::symbol() const
return {_symbol->row(0).begin(), _symbol->width(), _symbol->height(), ImageFormat::Lum};
}

void Result::zint(std::unique_ptr<zint_symbol>&& z)
void Result::zint(unique_zint_symbol&& z)
{
_zint = std::shared_ptr(std::move(z));
}
Expand Down
8 changes: 7 additions & 1 deletion core/src/Barcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ extern "C" struct zint_symbol;
namespace ZXing {
class BitMatrix;
}

struct zint_symbol_deleter
{
void operator()(zint_symbol* p) const noexcept;
};
using unique_zint_symbol = std::unique_ptr<zint_symbol, zint_symbol_deleter>;
#endif

#include <string>
Expand Down Expand Up @@ -171,7 +177,7 @@ class Result
#ifdef ZXING_EXPERIMENTAL_API
void symbol(BitMatrix&& bits);
ImageView symbol() const;
void zint(std::unique_ptr<zint_symbol>&& z);
void zint(unique_zint_symbol&& z);
zint_symbol* zint() const { return _zint.get(); }
#endif

Expand Down
7 changes: 1 addition & 6 deletions core/src/WriteBarcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
#ifdef ZXING_USE_ZINT

#include <zint.h>
template <>
struct std::default_delete<zint_symbol>
{
void operator()(zint_symbol* p) const noexcept { ZBarcode_Delete(p); }
};

#else

Expand All @@ -41,7 +36,7 @@ struct CreatorOptions::Data
// symbol size (qrcode, datamatrix, etc), map from I, 'WxH'
// structured_append (idx, cnt, ID)

mutable std::unique_ptr<zint_symbol> zint;
mutable unique_zint_symbol zint;

#if __cplusplus <= 201703L || defined(__APPLE__)
Data(BarcodeFormat f) : format(f) {}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy