1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

Import BDB 4.3.28

This commit is contained in:
jimw@mysql.com
2005-07-20 15:48:22 -07:00
parent c2c0cb18c3
commit d8c0749279
765 changed files with 98154 additions and 36929 deletions

View File

@@ -1,68 +1,20 @@
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997-2002
* Copyright (c) 1997-2004
* Sleepycat Software. All rights reserved.
*
* $Id: cxx_except.cpp,v 11.28 2004/09/22 03:34:48 bostic Exp $
*/
#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: cxx_except.cpp,v 11.17 2002/08/23 01:07:27 mjc Exp $";
#endif /* not lint */
#include <string.h>
#include <errno.h>
#include "db_cxx.h"
#include "dbinc/cxx_int.h"
// tmpString is used to create strings on the stack
//
class tmpString
{
public:
tmpString(const char *str1,
const char *str2 = 0,
const char *str3 = 0,
const char *str4 = 0,
const char *str5 = 0);
~tmpString() { delete [] s_; }
operator const char *() { return (s_); }
private:
char *s_;
};
tmpString::tmpString(const char *str1,
const char *str2,
const char *str3,
const char *str4,
const char *str5)
{
size_t len = strlen(str1);
if (str2)
len += strlen(str2);
if (str3)
len += strlen(str3);
if (str4)
len += strlen(str4);
if (str5)
len += strlen(str5);
s_ = new char[len+1];
strcpy(s_, str1);
if (str2)
strcat(s_, str2);
if (str3)
strcat(s_, str3);
if (str4)
strcat(s_, str4);
if (str5)
strcat(s_, str5);
}
// Note: would not be needed if we can inherit from exception
// It does not appear to be possible to inherit from exception
// with the current Microsoft library (VC5.0).
@@ -80,65 +32,113 @@ static char *dupString(const char *s)
// //
////////////////////////////////////////////////////////////////////////
DbException::~DbException()
DbException::~DbException() throw()
{
if (what_)
delete [] what_;
delete [] what_;
}
DbException::DbException(int err)
: err_(err)
, env_(0)
{
what_ = dupString(db_strerror(err));
describe(0, 0);
}
DbException::DbException(const char *description)
: err_(0)
, env_(0)
{
what_ = dupString(tmpString(description));
describe(0, description);
}
DbException::DbException(const char *prefix, int err)
DbException::DbException(const char *description, int err)
: err_(err)
, env_(0)
{
what_ = dupString(tmpString(prefix, ": ", db_strerror(err)));
describe(0, description);
}
DbException::DbException(const char *prefix1, const char *prefix2, int err)
DbException::DbException(const char *prefix, const char *description, int err)
: err_(err)
, env_(0)
{
what_ = dupString(tmpString(prefix1, ": ", prefix2, ": ",
db_strerror(err)));
describe(prefix, description);
}
DbException::DbException(const DbException &that)
: err_(that.err_)
: __DB_STD(exception)()
, what_(dupString(that.what_))
, err_(that.err_)
, env_(0)
{
what_ = dupString(that.what_);
}
DbException &DbException::operator = (const DbException &that)
{
if (this != &that) {
err_ = that.err_;
if (what_)
delete [] what_;
what_ = 0; // in case new throws exception
delete [] what_;
what_ = dupString(that.what_);
}
return (*this);
}
void DbException::describe(const char *prefix, const char *description)
{
char msgbuf[1024], *p, *end;
p = msgbuf;
end = msgbuf + sizeof(msgbuf) - 1;
if (prefix != NULL) {
strncpy(p, prefix, (p < end) ? end - p: 0);
p += strlen(prefix);
strncpy(p, ": ", (p < end) ? end - p: 0);
p += 2;
}
if (description != NULL) {
strncpy(p, description, (p < end) ? end - p: 0);
p += strlen(description);
if (err_ != 0) {
strncpy(p, ": ", (p < end) ? end - p: 0);
p += 2;
}
}
if (err_ != 0) {
strncpy(p, db_strerror(err_), (p < end) ? end - p: 0);
p += strlen(db_strerror(err_));
}
/*
* If the result was too long, the buffer will not be null-terminated,
* so we need to fix that here before duplicating it.
*/
if (p >= end)
*end = '\0';
what_ = dupString(msgbuf);
}
int DbException::get_errno() const
{
return (err_);
}
const char *DbException::what() const
const char *DbException::what() const throw()
{
return (what_);
}
DbEnv *DbException::get_env() const
{
return env_;
}
void DbException::set_env(DbEnv *env)
{
env_= env;
}
////////////////////////////////////////////////////////////////////////
// //
// DbMemoryException //
@@ -146,7 +146,7 @@ const char *DbException::what() const
////////////////////////////////////////////////////////////////////////
static const char *memory_err_desc = "Dbt not large enough for available data";
DbMemoryException::~DbMemoryException()
DbMemoryException::~DbMemoryException() throw()
{
}
@@ -156,25 +156,12 @@ DbMemoryException::DbMemoryException(Dbt *dbt)
{
}
DbMemoryException::DbMemoryException(const char *description)
: DbException(description, ENOMEM)
, dbt_(0)
{
}
DbMemoryException::DbMemoryException(const char *prefix, Dbt *dbt)
: DbException(prefix, memory_err_desc, ENOMEM)
, dbt_(dbt)
{
}
DbMemoryException::DbMemoryException(const char *prefix1, const char *prefix2,
Dbt *dbt)
: DbException(prefix1, prefix2, ENOMEM)
, dbt_(dbt)
{
}
DbMemoryException::DbMemoryException(const DbMemoryException &that)
: DbException(that)
, dbt_(that.dbt_)
@@ -202,7 +189,7 @@ Dbt *DbMemoryException::get_dbt() const
// //
////////////////////////////////////////////////////////////////////////
DbDeadlockException::~DbDeadlockException()
DbDeadlockException::~DbDeadlockException() throw()
{
}
@@ -230,7 +217,7 @@ DbDeadlockException
// //
////////////////////////////////////////////////////////////////////////
DbLockNotGrantedException::~DbLockNotGrantedException()
DbLockNotGrantedException::~DbLockNotGrantedException() throw()
{
delete lock_;
}
@@ -243,9 +230,19 @@ DbLockNotGrantedException::DbLockNotGrantedException(const char *prefix,
, op_(op)
, mode_(mode)
, obj_(obj)
, lock_(new DbLock(lock))
, index_(index)
{
lock_ = new DbLock(lock);
}
DbLockNotGrantedException::DbLockNotGrantedException(const char *description)
: DbException(description, DB_LOCK_NOTGRANTED)
, op_(DB_LOCK_GET)
, mode_(DB_LOCK_NG)
, obj_(NULL)
, lock_(NULL)
, index_(0)
{
}
DbLockNotGrantedException::DbLockNotGrantedException
@@ -255,7 +252,7 @@ DbLockNotGrantedException::DbLockNotGrantedException
op_ = that.op_;
mode_ = that.mode_;
obj_ = that.obj_;
lock_ = new DbLock(*that.lock_);
lock_ = (that.lock_ != NULL) ? new DbLock(*that.lock_) : NULL;
index_ = that.index_;
}
@@ -267,7 +264,7 @@ DbLockNotGrantedException
op_ = that.op_;
mode_ = that.mode_;
obj_ = that.obj_;
lock_ = new DbLock(*that.lock_);
lock_ = (that.lock_ != NULL) ? new DbLock(*that.lock_) : NULL;
index_ = that.index_;
}
return (*this);
@@ -298,15 +295,13 @@ int DbLockNotGrantedException::get_index() const
return index_;
}
////////////////////////////////////////////////////////////////////////
// //
// DbRunRecoveryException //
// //
////////////////////////////////////////////////////////////////////////
DbRunRecoveryException::~DbRunRecoveryException()
DbRunRecoveryException::~DbRunRecoveryException() throw()
{
}