MySQL++

Check-in [08496d4b48]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Conditionally using std::unique_ptr instead of auto_ptr on C++11 and newer versions of g++ and clang++ to avoid the warning about using a deprecated feature. Closes [97f62ef016].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:08496d4b48e24a9cf0a3e375b675b6486b27a7571dc92645b7225f2d243d35c4
User & Date: tangent 2018-07-12 20:05:09
References
2018-07-12
20:05 Closed ticket [97f62ef016]: Convert auto_ptr in lib/refcounted.h to unique_ptr plus 4 other changes artifact: 05dfac7e44 user: tangent
Context
2018-07-18
21:01
DBDriver::shutdown() now executes a SHUTDOWN query on MySQL 8.0.0 and higher due to removal of the C API function mysql_shutdown() in that release. They put it back in 8.0.1, but only due to end-user complaints, and they say it'll go away for good eventually, so we prefer to deploy and test this workaround before then. Leaf check-in: b238cd34c2 user: tangent tags: trunk
2018-07-12
21:21
Experimental fix for [eab08a87ed]: copy the list of successfully applied connection options when cloning a Connection and its underlying DBDriver so that the copy gets the same options. We currently only do this when the other connection was up at the time of cloning, but we might be swayed to change this behavior. Leaf check-in: de38699272 user: tangent tags: reapply-conn-opts-on-clone
20:05
Conditionally using std::unique_ptr instead of auto_ptr on C++11 and newer versions of g++ and clang++ to avoid the warning about using a deprecated feature. Closes [97f62ef016]. check-in: 08496d4b48 user: tangent tags: trunk
19:49
Created the MAY_THROW() macro which allows conditional throwspecs: old-style for ABI compatibility on C++14 and older versions of g++ and clang++, and new-style on C++17 and newer versions of those compilers. We'll have to expand the ifdef logic on the definition of this macro for other compilers eventually, as we learn of ones that refuse to accept throwspecs. Closes [8395aa91d1]. check-in: 799b4851e5 user: tangent tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/common.h.

145
146
147
148
149
150
151










152
153
154
155
156
157
158
// that would break the library's ABI on systems whose C++ compiler
// still supports throwspecs.
#if __cplusplus < 201703L
#	define MAY_THROW(what) throw(what)
#else
#	define MAY_THROW(junk) noexcept(false)
#endif












namespace mysqlpp {

/// \brief Alias for 'true', to make code requesting exceptions more
/// readable.
const bool use_exceptions = true;







>
>
>
>
>
>
>
>
>
>







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// that would break the library's ABI on systems whose C++ compiler
// still supports throwspecs.
#if __cplusplus < 201703L
#	define MAY_THROW(what) throw(what)
#else
#	define MAY_THROW(junk) noexcept(false)
#endif

// C++11 added unique_ptr as a replacement for auto_ptr.  We don't have
// the ABI problem above with this one, so we switch to it with the
// oldest release possible.  As with the above ifdef, this one only
// currently works for g++ and clang++.
#if __cplusplus >= 201103L
#	define UNIQUE_PTR(what) std::unique_ptr<what>
#else
#	define UNIQUE_PTR(what) std::auto_ptr<what>
#endif


namespace mysqlpp {

/// \brief Alias for 'true', to make code requesting exceptions more
/// readable.
const bool use_exceptions = true;

Changes to lib/dbdriver.cpp.

1
2
3
4
5
6
7
8
9
10
11
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***********************************************************************
 dbdriver.cpp - Implements the DBDriver class.

 Copyright (c) 2005-2009 by Educational Technology Resources, Inc.
 Others may also hold copyrights on code in this file.  See the
 CREDITS.txt file in the top directory of the distribution for details.

 This file is part of MySQL++.

 MySQL++ is free software; you can redistribute it and/or modify it
 under the terms of the GNU Lesser General Public License as published
................................................................................
}


bool
DBDriver::set_option_impl(Option* o)
{
	std::ostringstream os;
	std::auto_ptr<Option> cleanup(o);

	switch (o->set(this)) {
		case Option::err_NONE:
			applied_options_.push_back(o);
			cleanup.release();
			break;




|







 







|







1
2
3
4
5
6
7
8
9
10
11
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***********************************************************************
 dbdriver.cpp - Implements the DBDriver class.

 Copyright © 2005-2009, 2018 by Educational Technology Resources, Inc.
 Others may also hold copyrights on code in this file.  See the
 CREDITS.txt file in the top directory of the distribution for details.

 This file is part of MySQL++.

 MySQL++ is free software; you can redistribute it and/or modify it
 under the terms of the GNU Lesser General Public License as published
................................................................................
}


bool
DBDriver::set_option_impl(Option* o)
{
	std::ostringstream os;
	UNIQUE_PTR(Option) cleanup(o);

	switch (o->set(this)) {
		case Option::err_NONE:
			applied_options_.push_back(o);
			cleanup.release();
			break;

Changes to lib/refcounted.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
23
24
25
26
27
28
29


30
31
32
33
34
35
36
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/// \file refcounted.h
/// \brief Declares the RefCountedPointer template

/***********************************************************************
 Copyright (c) 2007-2011 by Educational Technology Resources, Inc. and
 (c) 2007 by Jonathan Wakely.  Others may also hold copyrights on
 code in this file.  See the CREDITS.txt file in the top directory
 of the distribution for details.

 This file is part of MySQL++.

 MySQL++ is free software; you can redistribute it and/or modify it
 under the terms of the GNU Lesser General Public License as published
................................................................................
 License along with MySQL++; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 USA
***********************************************************************/

#if !defined(MYSQLPP_REFCOUNTED_H)
#define MYSQLPP_REFCOUNTED_H



#include <memory>

#include <stddef.h>

namespace mysqlpp {

................................................................................
	/// \param c A pointer to the object to be managed.  If you pass 0,
	/// it's like calling the default ctor instead, only more work: the
	/// object's useless until you vivify it with operator =() or assign().
	explicit RefCountedPointer(T* c) :
	counted_(c),
	refs_(0)
	{
		std::auto_ptr<T> exception_guard(counted_);
		if (counted_) {
			refs_ = new size_t(1);
		}
		exception_guard.release();	// previous new didn't throw
	}

	/// \brief Copy constructor




|
|







 







>
>







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/// \file refcounted.h
/// \brief Declares the RefCountedPointer template

/***********************************************************************
 Copyright © 2007-2011, 2018 by Educational Technology Resources, Inc.
 and © 2007 by Jonathan Wakely.  Others may also hold copyrights on
 code in this file.  See the CREDITS.txt file in the top directory
 of the distribution for details.

 This file is part of MySQL++.

 MySQL++ is free software; you can redistribute it and/or modify it
 under the terms of the GNU Lesser General Public License as published
................................................................................
 License along with MySQL++; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 USA
***********************************************************************/

#if !defined(MYSQLPP_REFCOUNTED_H)
#define MYSQLPP_REFCOUNTED_H

#include "common.h"

#include <memory>

#include <stddef.h>

namespace mysqlpp {

................................................................................
	/// \param c A pointer to the object to be managed.  If you pass 0,
	/// it's like calling the default ctor instead, only more work: the
	/// object's useless until you vivify it with operator =() or assign().
	explicit RefCountedPointer(T* c) :
	counted_(c),
	refs_(0)
	{
		UNIQUE_PTR(T) exception_guard(counted_);
		if (counted_) {
			refs_ = new size_t(1);
		}
		exception_guard.release();	// previous new didn't throw
	}

	/// \brief Copy constructor