use unique_ptr instead of auto_ptr in c++11 mode (issue 78010043)

24 views
Skip to first unread message

mos...@opera.com

unread,
Mar 19, 2014, 7:11:06 PM3/19/14
to mos...@opera.com, open-...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: ,

Message:
Please take a look...

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/78010043/

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


Index: src/blockhash_test.cc
===================================================================
--- src/blockhash_test.cc (revision 43)
+++ src/blockhash_test.cc (working copy)
@@ -18,10 +18,11 @@
#include <limits.h> // INT_MIN
#include <string.h> // memcpy, memcmp, strlen
#include <iostream>
-#include <memory> // auto_ptr
+#include <memory> // auto_ptr, unique_ptr
#include "encodetable.h"
#include "rolling_hash.h"
#include "testing.h"
+#include "unique_ptr.h"

namespace open_vcdiff {

@@ -231,10 +232,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,11 @@
+#ifndef UNIQUE_PTR_H
+#define UNIQUE_PTR_H
+
+#if __cplusplus >= 201103L
+// C++11
+#define UNIQUE_PTR std::unique_ptr
+#else
+#define UNIQUE_PTR std::auto_ptr
+#endif
+
+#endif // UNIQUE_PTR_H
Index: src/vcdecoder.cc
===================================================================
--- src/vcdecoder.cc (revision 43)
+++ src/vcdecoder.cc (working copy)
@@ -32,7 +32,7 @@
#include <stddef.h> // size_t, ptrdiff_t
#include <stdint.h> // int32_t
#include <string.h> // memcpy, memset
-#include <memory> // auto_ptr
+#include <memory> // auto_ptr, unique_ptr
#include <string>
#include "addrcache.h"
#include "checksum.h"
@@ -43,6 +43,7 @@
#include "google/output_string.h"
#include "varint_bigendian.h"
#include "vcdiff_defs.h"
+#include "unique_ptr.h"

namespace open_vcdiff {

@@ -549,10 +550,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 +562,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,13 @@
#include <stdio.h>
#include <string.h> // strerror
#include <iostream>
-#include <memory>
+#include <memory> // auto_ptr, unique_ptr
#include <string>
#include <vector>
#include "gflags/gflags.h"
#include "google/vcdecoder.h"
#include "google/vcencoder.h"
+#include "unique_ptr.h"

#ifndef HAS_GLOBAL_STRING
using std::string;
@@ -154,7 +155,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,13 +28,14 @@
// encoders or accepted by other decoders.

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

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

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

const VCDiffFormatExtensionFlags format_extensions_;



Reply all
Reply to author
Forward
0 new messages