Use unique_ptr instead of auto_ptr in c++11 mode. (issue 92310046)

14 views
Skip to first unread message

mos...@opera.com

unread,
May 14, 2014, 4:49:08 AM5/14/14
to tha...@chromium.org, joc...@chromium.org, openv...@gmail.com, open-...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: thakis, jochen1, Lincoln,

Message:
@Lincoln: this is a version of https://codereview.appspot.com/78010043/
with the change you requested.

Description:
Use unique_ptr instead of auto_ptr in c++11 mode.

Tested with gcc 4.8.1 on linux with -std=gnu+=11 and -std=c++11.

Please review this at https://codereview.appspot.com/92310046/

Affected files (+45, -14 lines):
M THANKS
M src/blockhash_test.cc
A src/unique_ptr.h
M src/vcdecoder.cc
M src/vcdiff_main.cc
M src/vcencoder.cc


Index: THANKS
===================================================================
--- THANKS (revision 43)
+++ THANKS (working copy)
@@ -43,4 +43,4 @@
Todd Turnidge
Linus Upson
Xianzhu Wang
-
+Mostyn Bramley-Moore
Index: src/blockhash_test.cc
===================================================================
--- src/blockhash_test.cc (revision 43)
+++ src/blockhash_test.cc (working copy)
@@ -18,10 +18,10 @@
#include <limits.h> // INT_MIN
#include <string.h> // memcpy, memcmp, strlen
#include <iostream>
-#include <memory> // auto_ptr
#include "encodetable.h"
#include "rolling_hash.h"
#include "testing.h"
+#include "unique_ptr.h" // auto_ptr, unique_ptr

namespace open_vcdiff {

@@ -231,10 +231,9 @@
static uint32_t hashed_unaligned_e;
static uint32_t hashed_all_Qs;

- // Boost scoped_ptr, if available, could be used instead of
std::auto_ptr.
- std::auto_ptr<const BlockHash> dh_; // hash table is populated at
startup
- std::auto_ptr<BlockHash> th_; // hash table not populated;
- // used to test incremental adds
+ UNIQUE_PTR<const BlockHash> dh_; // hash table is populated at startup
+ UNIQUE_PTR<BlockHash> th_; // hash table not populated;
+ // used to test incremental adds

BlockHash::Match best_match_;
char* compare_buffer_1_;
Index: src/unique_ptr.h
===================================================================
--- src/unique_ptr.h (revision 0)
+++ src/unique_ptr.h (working copy)
@@ -0,0 +1,32 @@
+// Copyright 2014 The open-vcdiff Authors. All Rights Reserved.
+// Author: Mostyn Bramley-Moore
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef OPEN_VCDIFF_UNIQUE_PTR_H_
+#define OPEN_VCDIFF_UNIQUE_PTR_H_
+
+// std::auto_ptr is deprecated in C++11, in favor of std::unique_ptr.
+// Since C++11 is not widely available yet, the macro below is used to
+// select the best available option.
+
+#include <memory>
+
+#if __cplusplus >= 201103L
+// C++11
+#define UNIQUE_PTR std::unique_ptr
+#else
+#define UNIQUE_PTR std::auto_ptr
+#endif
+
+#endif // OPEN_VCDIFF_UNIQUE_PTR_H_
Index: src/vcdecoder.cc
===================================================================
--- src/vcdecoder.cc (revision 43)
+++ src/vcdecoder.cc (working copy)
@@ -32,7 +32,6 @@
#include <stddef.h> // size_t, ptrdiff_t
#include <stdint.h> // int32_t
#include <string.h> // memcpy, memset
-#include <memory> // auto_ptr
#include <string>
#include "addrcache.h"
#include "checksum.h"
@@ -41,6 +40,7 @@
#include "headerparser.h"
#include "logging.h"
#include "google/output_string.h"
+#include "unique_ptr.h" // auto_ptr, unique_ptr
#include "varint_bigendian.h"
#include "vcdiff_defs.h"

@@ -549,10 +549,10 @@

VCDiffDeltaFileWindow delta_window_;

- std::auto_ptr<VCDiffAddressCache> addr_cache_;
+ UNIQUE_PTR<VCDiffAddressCache> addr_cache_;

// Will be NULL unless a custom code table has been defined.
- std::auto_ptr<VCDiffCodeTableData> custom_code_table_;
+ UNIQUE_PTR<VCDiffCodeTableData> custom_code_table_;

// Used to receive the decoded custom code table.
string custom_code_table_string_;
@@ -561,7 +561,7 @@
// as an embedded VCDIFF delta file which uses the default code table
// as the source file (dictionary). Use a child decoder object
// to decode that delta file.
- std::auto_ptr<VCDiffStreamingDecoderImpl> custom_code_table_decoder_;
+ UNIQUE_PTR<VCDiffStreamingDecoderImpl> custom_code_table_decoder_;

// If set, then the decoder is expecting *exactly* this number of
// target bytes to be decoded from one or more delta file windows.
Index: src/vcdiff_main.cc
===================================================================
--- src/vcdiff_main.cc (revision 43)
+++ src/vcdiff_main.cc (working copy)
@@ -25,12 +25,12 @@
#include <stdio.h>
#include <string.h> // strerror
#include <iostream>
-#include <memory>
#include <string>
#include <vector>
#include "gflags/gflags.h"
#include "google/vcdecoder.h"
#include "google/vcencoder.h"
+#include "unique_ptr.h" // auto_ptr, unique_ptr

#ifndef HAS_GLOBAL_STRING
using std::string;
@@ -154,7 +154,7 @@
// Dictionary contents. The entire dictionary file will be read into
memory.
std::vector<char> dictionary_;

- std::auto_ptr<open_vcdiff::HashedDictionary> hashed_dictionary_;
+ UNIQUE_PTR<open_vcdiff::HashedDictionary> hashed_dictionary_;

// These should be set to either "delta" or "target". They are only
// used in log messages such as "Error opening delta file..."
Index: src/vcencoder.cc
===================================================================
--- src/vcencoder.cc (revision 43)
+++ src/vcencoder.cc (working copy)
@@ -28,7 +28,6 @@
// encoders or accepted by other decoders.

#include <config.h>
-#include <memory> // auto_ptr
#include "checksum.h"
#include "encodetable.h"
#include "google/output_string.h"
@@ -35,6 +34,7 @@
#include "google/vcencoder.h"
#include "jsonwriter.h"
#include "logging.h"
+#include "unique_ptr.h" // auto_ptr, unique_ptr
#include "vcdiffengine.h"

namespace open_vcdiff {
@@ -66,7 +66,7 @@
private:
const VCDiffEngine* engine_;

- std::auto_ptr<CodeTableWriterInterface> coder_;
+ UNIQUE_PTR<CodeTableWriterInterface> coder_;

const VCDiffFormatExtensionFlags format_extensions_;



openv...@gmail.com

unread,
May 14, 2014, 12:49:44 PM5/14/14
to mos...@opera.com, tha...@chromium.org, joc...@chromium.org, open-...@googlegroups.com, re...@codereview-hr.appspotmail.com
LGTM

Thank you very much for contributing to open-vcdiff! I will include the
patch in the next release.


https://codereview.appspot.com/92310046/diff/1/THANKS
File THANKS (right):

https://codereview.appspot.com/92310046/diff/1/THANKS#newcode46
THANKS:46: Mostyn Bramley-Moore
Nit: This is alphabetized by last name. I can take care of this when
merging the patch into the next release.

https://codereview.appspot.com/92310046/

openv...@gmail.com

unread,
May 14, 2014, 7:23:11 PM5/14/14
to mos...@opera.com, tha...@chromium.org, joc...@chromium.org, open-...@googlegroups.com, re...@codereview-hr.appspotmail.com
Included in open-vcdiff version 0.8.4.

https://codereview.appspot.com/92310046/
Reply all
Reply to author
Forward
0 new messages