diff options
-rw-r--r-- | include/Exceptions.h | 13 | ||||
-rw-r--r-- | lib/Exceptions.cc | 5 | ||||
-rw-r--r-- | lib/Handle.cc | 6 | ||||
-rw-r--r-- | lib/Input.cc | 5 | ||||
-rw-r--r-- | lib/String.cc | 25 | ||||
-rw-r--r-- | lib/generic.cc | 3 |
6 files changed, 46 insertions, 11 deletions
diff --git a/include/Exceptions.h b/include/Exceptions.h index 9f0c3a6..c1fb303 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Exceptions.h,v 1.35 2004-07-22 23:38:31 pixel Exp $ */ +/* $Id: Exceptions.h,v 1.36 2004-07-23 16:56:03 pixel Exp $ */ #ifndef __EXCEPTIONS_H__ #define __EXCEPTIONS_H__ @@ -144,6 +144,17 @@ class printer_t : public Base { extern printer_t * printer; +class locker_t : public Base { + public: + virtual void lock() = 0; + virtual void unlock() = 0; +}; + +extern locker_t * locker; + +#define LOCK if (locker) locker->lock() +#define UNLOCK if (locker) locker->unlock(); + #include <BString.h> #endif diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index 2ecafef..06d283d 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Exceptions.cc,v 1.32 2004-03-01 07:41:48 pixel Exp $ */ +/* $Id: Exceptions.cc,v 1.33 2004-07-23 16:56:03 pixel Exp $ */ #include <string.h> #include <errno.h> @@ -48,16 +48,19 @@ char GeneralException::t[BUFSIZ]; std::vector<String> Base::context; GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { + UNLOCK; #ifdef DEBUG printm(M_BARE, String(_("Generating a General Exception error: '")) + msg + "'.\n"); #endif } GeneralException::GeneralException() : msg(0) { + UNLOCK; #ifdef DEBUG printm(M_BARE, String(_("Generating a General Exception error: '")) + msg + "'.\n"); #endif } GeneralException::GeneralException(const GeneralException & e) : msg(strdup(e.msg)) { + UNLOCK; #ifdef DEBUG printm(M_BARE, String(_("Generating a General Exception error: '")) + msg + "'.\n"); #endif diff --git a/lib/Handle.cc b/lib/Handle.cc index 9f369ce..c38f47e 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Handle.cc,v 1.70 2004-05-01 11:48:57 pixel Exp $ */ +/* $Id: Handle.cc,v 1.71 2004-07-23 16:56:03 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -547,6 +547,8 @@ void copy(Handle * s, Handle * d, ssize_t size) { if (size < 0) size = s->GetSize(); + + LOCK; while (size) { if ((size > BSIZE) || (size < 0)) { @@ -563,6 +565,8 @@ void copy(Handle * s, Handle * d, ssize_t size) { if (size > 0) size -= r; } + + UNLOCK; } void Handle::Flush() { diff --git a/lib/Input.cc b/lib/Input.cc index 88f9343..d6d9ebf 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Input.cc,v 1.46 2004-07-23 09:54:25 pixel Exp $ */ +/* $Id: Input.cc,v 1.47 2004-07-23 16:56:03 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -103,6 +103,8 @@ Input::Input(const String & no) throw (GeneralException) : results = gresults; + UNLOCK + fromarchive = false; if (results.name == "") { struct stat s; @@ -188,6 +190,7 @@ off_t Input::seek(off_t offset, int whence) throw (GeneralException) { } int Input::wrapopen(const String & fname, openresults_t * results) { + LOCK; #ifdef DEBUG printm(M_INFO, _("Wrap-opening ") + fname + "\n"); #endif diff --git a/lib/String.cc b/lib/String.cc index ff6a45f..b2c3dbe 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: String.cc,v 1.33 2003-12-04 04:09:02 pixel Exp $ */ +/* $Id: String.cc,v 1.34 2004-07-23 16:56:03 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -157,20 +157,26 @@ const char * String::set(const char * s, va_list ap) { r = str; #else // !HAVE_VASPRINTF #ifdef HAVE_VSNPRINTF + LOCK; vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); + UNLOCK; #else // !HAVE_VSNPRINTF #ifdef _WIN32 #ifdef _MSC_VER r = str = (char *) malloc(_vscprintf(s, ap) + 1); vsprintf(str, s, ap); #else + LOCK; _vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); + UNLOCK; #endif #else + LOCK; vsprintf(t, s, ap); str = Base::strdup(r = t); + UNLOCK; #endif #endif // HAVE_VSNPRINTF #endif // HAVE_VASPRINTF @@ -229,7 +235,10 @@ int String::scanf(const ugly_string & s, ...) const { const char * String::to_charp(size_t from, ssize_t to) const { if (to < 0) { - strncpy(t, &(str[from]), BUFSIZ); + if (from) + strncpy(t, &(str[from]), BUFSIZ); + else + return str; } else { if (((size_t) to) >= siz) { to = siz - 1; @@ -257,7 +266,13 @@ String String::extract(size_t from, ssize_t to) const { } char * String::strdup(size_t from, ssize_t to) const { - return Base::strdup(extract(from, to).str); + char * r; + + LOCK; + r = Base::strdup(to_charp(from, to)); + UNLOCK; + + return r; } int String::to_int(void) const { @@ -361,9 +376,7 @@ char String::operator[](size_t i) const { } char & String::operator[](size_t i) { - static char zero; - - zero = 0; + static char zero = 0; if (i >= siz) { return zero; diff --git a/lib/generic.cc b/lib/generic.cc index f69aba3..933f158 100644 --- a/lib/generic.cc +++ b/lib/generic.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: generic.cc,v 1.9 2004-07-22 23:38:32 pixel Exp $ */ +/* $Id: generic.cc,v 1.10 2004-07-23 16:56:03 pixel Exp $ */ #include <stdio.h> #include <stdarg.h> @@ -32,6 +32,7 @@ char verbosity = 0; static char * heads[] = {"EE", "--", "WW", "II"}; printer_t * printer = 0; +locker_t * locker = 0; void Base::printm(int level, const ugly_string & m, ...) { va_list ap; |