From a68703b07e928be0eeb909c0e777e13e88cbf86d Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 9 Apr 2022 14:35:56 -0400 Subject: Replace PointerHolder with std::shared_ptr in library sources only (patrepl and cleanpatch are my own utilities) patrepl s/PointerHolder/std::shared_ptr/g {include,libqpdf}/qpdf/*.hh patrepl s/PointerHolder/std::shared_ptr/g libqpdf/*.cc patrepl s/make_pointer_holder/std::make_shared/g libqpdf/*.cc patrepl s/make_array_pointer_holder/QUtil::make_shared_array/g libqpdf/*.cc patrepl s,qpdf/std::shared_ptr,qpdf/PointerHolder, **/*.cc **/*.hh git restore include/qpdf/PointerHolder.hh cleanpatch ./format-code --- libqpdf/QUtil.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'libqpdf/QUtil.cc') diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 11ced38d..42b9e017 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -445,7 +445,7 @@ QUtil::os_wrapper(std::string const& description, int status) } #ifdef _WIN32 -static PointerHolder +static std::shared_ptr win_convert_filename(char const* filename) { // Convert the utf-8 encoded filename argument to wchar_t*. First, @@ -454,7 +454,7 @@ win_convert_filename(char const* filename) std::string u16 = QUtil::utf8_to_utf16(filename); size_t len = u16.length(); size_t wlen = (len / 2) - 1; - PointerHolder wfilenamep(true, new wchar_t[wlen + 1]); + auto wfilenamep = QUtil::make_shared_array(wlen + 1); wchar_t* wfilename = wfilenamep.get(); wfilename[wlen] = 0; for (unsigned int i = 2; i < len; i += 2) { @@ -471,9 +471,9 @@ QUtil::safe_fopen(char const* filename, char const* mode) { FILE* f = 0; #ifdef _WIN32 - PointerHolder wfilenamep = win_convert_filename(filename); + std::shared_ptr wfilenamep = win_convert_filename(filename); wchar_t* wfilename = wfilenamep.get(); - PointerHolder wmodep(true, new wchar_t[strlen(mode) + 1]); + auto wmodep = QUtil::make_shared_array(strlen(mode) + 1); wchar_t* wmode = wmodep.get(); wmode[strlen(mode)] = 0; for (size_t i = 0; i < strlen(mode); ++i) { @@ -612,7 +612,7 @@ void QUtil::remove_file(char const* path) { #ifdef _WIN32 - PointerHolder wpath = win_convert_filename(path); + std::shared_ptr wpath = win_convert_filename(path); os_wrapper(std::string("remove ") + path, _wunlink(wpath.get())); #else os_wrapper(std::string("remove ") + path, unlink(path)); @@ -628,8 +628,8 @@ QUtil::rename_file(char const* oldname, char const* newname) } catch (QPDFSystemError&) { // ignore } - PointerHolder wold = win_convert_filename(oldname); - PointerHolder wnew = win_convert_filename(newname); + std::shared_ptr wold = win_convert_filename(oldname); + std::shared_ptr wnew = win_convert_filename(newname); os_wrapper( std::string("rename ") + oldname + " " + newname, _wrename(wold.get(), wnew.get())); @@ -824,7 +824,7 @@ QUtil::get_env(std::string const& var, std::string* value) } if (value) { - PointerHolder t = PointerHolder(true, new char[len + 1]); + auto t = QUtil::make_shared_array(len + 1); ::GetEnvironmentVariable(var.c_str(), t.get(), len); *value = t.get(); } @@ -1173,14 +1173,14 @@ QUtil::is_number(char const* p) void QUtil::read_file_into_memory( - char const* filename, PointerHolder& file_buf, size_t& size) + char const* filename, std::shared_ptr& file_buf, size_t& size) { FILE* f = safe_fopen(filename, "rb"); FileCloser fc(f); fseek(f, 0, SEEK_END); size = QIntC::to_size(QUtil::tell(f)); fseek(f, 0, SEEK_SET); - file_buf = make_array_pointer_holder(size); + file_buf = QUtil::make_shared_array(size); char* buf_p = file_buf.get(); size_t bytes_read = 0; size_t len = 0; -- cgit v1.2.3-54-g00ecf