MySQL++

Check-in [799b4851e5]
Login

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

Overview
Comment: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].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:799b4851e5ab74b36b8b1fa5bc3d545df6f49c5480452a7afe3244e88be475ea
User & Date: tangent 2018-07-12 19:49:16
References
2018-07-12
19:50 Closed ticket [8395aa91d1]: C++17 does not allow dynamic exception specifications plus 4 other changes artifact: 91315eae6b user: tangent
Context
2018-07-12
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
18:35
"make dist" now uses the -h option with tar to dereference any symlinks in the dist tree, so the machine the tarball is unpacked on doesn't have to have the target files. This closes [f0505cba03] where ltmain.sh at the top level may point at a file on the target machine that doesn't exist, requiring a re-bootstrap on that system to fix the link. check-in: ce2fefae8a user: tangent tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/beemutex.cpp.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/***********************************************************************
 beemutex.cpp - Implements the BeecryptMutex class.  The name comes
	from the fact that we lifted this essentially intact from the
	Beecrypt library, which is also LGPL.  See beecrypt.h for the list
	of changes we made on integrating it into MySQL++.

 Copyright (c) 2004 Beeyond Software Holding BV and (c) 2007 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
................................................................................
#	if defined(MYSQLPP_PLATFORM_WINDOWS)
		static bc_mutex_t impl_val(void* p)
				{ return *static_cast<bc_mutex_t*>(p); }
#	endif
#endif


BeecryptMutex::BeecryptMutex() throw (MutexFailed)
#if defined(ACTUALLY_DOES_SOMETHING)
	: pmutex_(new bc_mutex_t)
#endif
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	*impl_ptr(pmutex_) = CreateMutex((LPSECURITY_ATTRIBUTES) 0, FALSE,
			(LPCTSTR) 0);
................................................................................

	delete impl_ptr(pmutex_);
#endif
}


void
BeecryptMutex::lock() throw (MutexFailed)
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	if (WaitForSingleObject(impl_val(pmutex_), INFINITE) == WAIT_OBJECT_0)
		return;
	throw MutexFailed("WaitForSingleObject failed");
#else
#	if HAVE_SYNCH_H || HAVE_PTHREAD
................................................................................
			throw MutexFailed(strerror(rc));
#	endif
#endif
}


bool
BeecryptMutex::trylock() throw (MutexFailed)
{
#if defined(ACTUALLY_DOES_SOMETHING)
#	if defined(MYSQLPP_PLATFORM_WINDOWS)
		switch (WaitForSingleObject(impl_val(pmutex_), 0)) {
			case WAIT_TIMEOUT:
				return false;
			case WAIT_OBJECT_0:
................................................................................
#else
	return true;		// no-op build, so always succeed
#endif
}


void
BeecryptMutex::unlock() throw (MutexFailed)
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	if (!ReleaseMutex(impl_val(pmutex_)))
		throw MutexFailed("ReleaseMutex failed");
#else
#	if HAVE_SYNCH_H || HAVE_PTHREAD
		int rc;






|







 







|







 







|







 







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/***********************************************************************
 beemutex.cpp - Implements the BeecryptMutex class.  The name comes
	from the fact that we lifted this essentially intact from the
	Beecrypt library, which is also LGPL.  See beecrypt.h for the list
	of changes we made on integrating it into MySQL++.

 Copyright © 2004 Beeyond Software Holding BV and © 2007, 2018
 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
................................................................................
#	if defined(MYSQLPP_PLATFORM_WINDOWS)
		static bc_mutex_t impl_val(void* p)
				{ return *static_cast<bc_mutex_t*>(p); }
#	endif
#endif


BeecryptMutex::BeecryptMutex() MAY_THROW(MutexFailed)
#if defined(ACTUALLY_DOES_SOMETHING)
	: pmutex_(new bc_mutex_t)
#endif
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	*impl_ptr(pmutex_) = CreateMutex((LPSECURITY_ATTRIBUTES) 0, FALSE,
			(LPCTSTR) 0);
................................................................................

	delete impl_ptr(pmutex_);
#endif
}


void
BeecryptMutex::lock() MAY_THROW(MutexFailed)
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	if (WaitForSingleObject(impl_val(pmutex_), INFINITE) == WAIT_OBJECT_0)
		return;
	throw MutexFailed("WaitForSingleObject failed");
#else
#	if HAVE_SYNCH_H || HAVE_PTHREAD
................................................................................
			throw MutexFailed(strerror(rc));
#	endif
#endif
}


bool
BeecryptMutex::trylock() MAY_THROW(MutexFailed)
{
#if defined(ACTUALLY_DOES_SOMETHING)
#	if defined(MYSQLPP_PLATFORM_WINDOWS)
		switch (WaitForSingleObject(impl_val(pmutex_), 0)) {
			case WAIT_TIMEOUT:
				return false;
			case WAIT_OBJECT_0:
................................................................................
#else
	return true;		// no-op build, so always succeed
#endif
}


void
BeecryptMutex::unlock() MAY_THROW(MutexFailed)
{
#if defined(MYSQLPP_PLATFORM_WINDOWS)
	if (!ReleaseMutex(impl_val(pmutex_)))
		throw MutexFailed("ReleaseMutex failed");
#else
#	if HAVE_SYNCH_H || HAVE_PTHREAD
		int rc;

Changes to lib/beemutex.h.

11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26
27
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/// - throwing MutexFailed instead of \c char*
/// - moved all method implementations from inline in the .h file to
///   a .cpp file so we don't have to make the header depend on config.h
///   on autoconf-using systems
/// - made private mutex member a void* so we don't have to define the
///   full type in the .h file, due to previous item
/// - added more Doxygen comments, and changed some existing comments



/***********************************************************************
 Copyright (c) 2004 Beeyond Software Holding BV and (c) 2007-2008
 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
................................................................................
class MYSQLPP_EXPORT BeecryptMutex
{
public:
	/// \brief Create the mutex object
	///
	/// Throws a MutexFailed exception if we can't acquire the lock for
	/// some reason.  The exception contains a message saying why.
	BeecryptMutex() throw (MutexFailed);

	/// \brief Destroy the mutex
	///
	/// Failures are quietly ignored.
	~BeecryptMutex();

	/// \brief Acquire the mutex, blocking if it can't be acquired
	/// immediately.
	void lock() throw (MutexFailed);

	/// \brief Acquire the mutex immediately and return true, or return
	/// false if it would have to block to acquire the mutex.
	bool trylock() throw (MutexFailed);

	/// \brief Release the mutex
	void unlock() throw (MutexFailed);

private:
	void* pmutex_;
};


/// \brief Wrapper around BeecryptMutex to add scope-bound locking







>
>


|







 







|








|



|


|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/// - throwing MutexFailed instead of \c char*
/// - moved all method implementations from inline in the .h file to
///   a .cpp file so we don't have to make the header depend on config.h
///   on autoconf-using systems
/// - made private mutex member a void* so we don't have to define the
///   full type in the .h file, due to previous item
/// - added more Doxygen comments, and changed some existing comments
/// - using MAY_THROW() from MySQL++'s common.h to allow it to compile
///   on C++17 and newer compilers

/***********************************************************************
 Copyright © 2004 Beeyond Software Holding BV and © 2007-2008, 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
................................................................................
class MYSQLPP_EXPORT BeecryptMutex
{
public:
	/// \brief Create the mutex object
	///
	/// Throws a MutexFailed exception if we can't acquire the lock for
	/// some reason.  The exception contains a message saying why.
	BeecryptMutex() MAY_THROW(MutexFailed);

	/// \brief Destroy the mutex
	///
	/// Failures are quietly ignored.
	~BeecryptMutex();

	/// \brief Acquire the mutex, blocking if it can't be acquired
	/// immediately.
	void lock() MAY_THROW(MutexFailed);

	/// \brief Acquire the mutex immediately and return true, or return
	/// false if it would have to block to acquire the mutex.
	bool trylock() MAY_THROW(MutexFailed);

	/// \brief Release the mutex
	void unlock() MAY_THROW(MutexFailed);

private:
	void* pmutex_;
};


/// \brief Wrapper around BeecryptMutex to add scope-bound locking

Changes to lib/common.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
125
126
127
128
129
130
131





















132
133
134
135
136
137
138
/// \file common.h
/// \brief This file includes top-level definitions for use both
/// internal to the library, and outside it.  Contrast mysql++.h
///
/// This file mostly takes care of platform differences.

/***********************************************************************
 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB,
 (c) 2004-2009 by Educational Technology Resources, Inc., and
 (c) 2009 by Warren Young.  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
................................................................................

	// Make DLL stuff a no-op on this platform.
	#define MYSQLPP_EXPORT

	// Assume POSIX path separator
	#define MYSQLPP_PATH_SEPARATOR '/'
#endif






















namespace mysqlpp {

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








|
|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/// \file common.h
/// \brief This file includes top-level definitions for use both
/// internal to the library, and outside it.  Contrast mysql++.h
///
/// This file mostly takes care of platform differences.

/***********************************************************************
 Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB,
 © 2004-2009, 2018  by Educational Technology Resources, Inc., and
 © 2009 by Warren Young.  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
................................................................................

	// Make DLL stuff a no-op on this platform.
	#define MYSQLPP_EXPORT

	// Assume POSIX path separator
	#define MYSQLPP_PATH_SEPARATOR '/'
#endif

// Workarounds for deprecations in C++11 and newer.  We must still
// support systems whose contemporaneous C++ compiler only understands
// C++98.  Because of the large gap between C++98 and C++11, it will
// likely be years yet until we can start using C++11 unconditionally
// within MySQL++, then years more until we can use C++14, etc.
//
// Our test here currently only works for g++ and clang++: it's testing
// for C++17.
//
// That release finally did away with throwspecs, a feature of C++ that
// is only used by the oldest parts of MySQL++.  We can't drop the
// throwspecs until MySQL++ 4, if we ever get around to that, since
// 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;

Changes to lib/exceptions.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// \file exceptions.h
/// \brief Declares the MySQL++-specific exception classes.
///
/// When exceptions are enabled for a given mysqlpp::OptionalExceptions
/// derivative, any of these exceptions can be thrown on error.

/***********************************************************************
 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
 (c) 2004-2010 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
................................................................................

/// \brief Base class for all MySQL++ custom exceptions

class MYSQLPP_EXPORT Exception : public std::exception
{
public:
	/// \brief Create exception object as copy of another
	Exception(const Exception& e) throw() :
	std::exception(e),
	what_(e.what_)
	{
	}

	/// \brief Assign another exception object's contents to this one
	Exception& operator=(const Exception& rhs) throw()







|
|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// \file exceptions.h
/// \brief Declares the MySQL++-specific exception classes.
///
/// When exceptions are enabled for a given mysqlpp::OptionalExceptions
/// derivative, any of these exceptions can be thrown on error.

/***********************************************************************
 Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
 © 2004-2010, 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
................................................................................

/// \brief Base class for all MySQL++ custom exceptions

class MYSQLPP_EXPORT Exception : public std::exception
{
public:
	/// \brief Create exception object as copy of another
	Exception(const Exception& e) MAY_THROW() :
	std::exception(e),
	what_(e.what_)
	{
	}

	/// \brief Assign another exception object's contents to this one
	Exception& operator=(const Exception& rhs) throw()

Changes to lib/stadapter.cpp.

1
2
3
4
5
6
7
8
9
10
11
12
...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/***********************************************************************
 stadapter.cpp - Implements the SQLTypeAdapter class.

 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
 (c) 2004-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
................................................................................
{
	buffer_ = new SQLBuffer(null_str, typeid(void), true);
	is_processed_ = false;
	return *this;
}

char
SQLTypeAdapter::at(size_type i) const throw(std::out_of_range)
{
	if (buffer_) {
		if (i <= length()) {
			return *(buffer_->data() + i);
		}
		else {
			throw BadIndex("Not enough chars in SQLTypeAdapter", int(i),



|
|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/***********************************************************************
 stadapter.cpp - Implements the SQLTypeAdapter class.

 Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
 © 2004-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
................................................................................
{
	buffer_ = new SQLBuffer(null_str, typeid(void), true);
	is_processed_ = false;
	return *this;
}

char
SQLTypeAdapter::at(size_type i) const MAY_THROW(std::out_of_range)
{
	if (buffer_) {
		if (i <= length()) {
			return *(buffer_->data() + i);
		}
		else {
			throw BadIndex("Not enough chars in SQLTypeAdapter", int(i),

Changes to lib/stadapter.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/// \file stadapter.h
/// \brief Declares the SQLTypeAdapter class

/***********************************************************************
 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
 (c) 2004-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
................................................................................
	/// \throw mysqlpp::BadIndex if the internal buffer is not
	/// initialized (default ctor called, and no subsequent assignment)
	/// or if there are not at least i + 1 characters in the buffer.
	///
	/// WARNING: The throw-spec is incorrect, but it can't be changed
	/// until v4, where we can break the ABI.  Throw-specs shouldn't be
	/// relied on anyway.
	char at(size_type i) const throw(std::out_of_range);

	/// \brief Compare the internal buffer to the given string
	///
	/// Works just like string::compare(const std::string&).
	int compare(const SQLTypeAdapter& other) const;

	/// \brief Compare the internal buffer to the given string




|
|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/// \file stadapter.h
/// \brief Declares the SQLTypeAdapter class

/***********************************************************************
 Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
 © 2004-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
................................................................................
	/// \throw mysqlpp::BadIndex if the internal buffer is not
	/// initialized (default ctor called, and no subsequent assignment)
	/// or if there are not at least i + 1 characters in the buffer.
	///
	/// WARNING: The throw-spec is incorrect, but it can't be changed
	/// until v4, where we can break the ABI.  Throw-specs shouldn't be
	/// relied on anyway.
	char at(size_type i) const MAY_THROW(std::out_of_range);

	/// \brief Compare the internal buffer to the given string
	///
	/// Works just like string::compare(const std::string&).
	int compare(const SQLTypeAdapter& other) const;

	/// \brief Compare the internal buffer to the given string