From ea9e900ab3323afa405b599adff70a1e35ba18a3 Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Sun, 14 Nov 2004 18:05:13 +0000 Subject: [PATCH] cleanup of methods, storing data in plain char* --- src/common/classes/fb_string.cpp | 12 ------------ src/include/fb_string.h | 10 +++++++--- src/jrd/dfw.epp | 2 +- src/jrd/dyn_def.epp | 2 +- src/jrd/gds.cpp | 2 +- src/jrd/isc_f_proto.h | 3 +-- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/common/classes/fb_string.cpp b/src/common/classes/fb_string.cpp index 20946053de..27ae1d01e8 100644 --- a/src/common/classes/fb_string.cpp +++ b/src/common/classes/fb_string.cpp @@ -107,18 +107,6 @@ namespace Firebird { memset(stringBuffer, c, sizeL); } - AbstractString::size_type AbstractString::copy_to(pointer destination, - size_type bufsize) const - { - if (!destination || !bufsize) - return 0; - - const size_type copy_len = length() < bufsize ? length() : bufsize - 1; - memcpy(destination, stringBuffer, copy_len); - destination[copy_len] = 0; - return copy_len; - } - void AbstractString::AdjustRange(size_type length, size_type& pos, size_type& n) { if (pos == npos) { pos = length > n ? length - n : 0; diff --git a/src/include/fb_string.h b/src/include/fb_string.h index ba8e00c672..a93cf08e32 100644 --- a/src/include/fb_string.h +++ b/src/include/fb_string.h @@ -209,15 +209,15 @@ namespace Firebird void reserve(size_type n = 0); void resize(size_type n, char_type c = ' '); +/* deprecated STL-compliant method - unsafe! inline size_type copy_from(pointer s, size_type n, size_type pos = 0) const { AdjustRange(length(), pos, n); memcpy(s, c_str() + pos, n); return n; } + */ - size_type copy_to(pointer destination, size_type bufsize) const; - /* inline void swap(AbstractString& str) { Storage *tmp = StringData; StringData = str.StringData; @@ -346,11 +346,15 @@ namespace Firebird inline void alltrim(const_pointer ToTrim = " ") { baseTrim(TrimBoth, ToTrim); } + bool LoadFromFile(FILE *file); void vprintf(const char* Format, va_list params); void printf(const char* Format, ...); - inline int saveTo(char* to, size_type toSize) const + + inline int copyTo(pointer to, size_type toSize) const { + fb_assert(to); + fb_assert(toSize); if (--toSize > length()) { toSize = length(); diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index 7a79f9a607..7eb0826406 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -907,7 +907,7 @@ static bool add_shadow( thread_db* tdbb, SSHORT phase, DeferredWork* work, expanded_fname = F.RDB$FILE_NAME; ISC_expand_filename(expanded_fname, false); MODIFY F USING - expanded_fname.saveTo(F.RDB$FILE_NAME, sizeof(F.RDB$FILE_NAME)); + expanded_fname.copyTo(F.RDB$FILE_NAME, sizeof(F.RDB$FILE_NAME)); END_MODIFY; for (shadow = dbb->dbb_shadow; shadow; shadow = shadow->sdw_next) diff --git a/src/jrd/dyn_def.epp b/src/jrd/dyn_def.epp index 5cd7997b43..f4494290a9 100644 --- a/src/jrd/dyn_def.epp +++ b/src/jrd/dyn_def.epp @@ -818,7 +818,7 @@ void DYN_define_file(Global* gbl, STORE(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction) X IN RDB$FILES - temp_f.saveTo(X.RDB$FILE_NAME, sizeof(X.RDB$FILE_NAME)); + temp_f.copyTo(X.RDB$FILE_NAME, sizeof(X.RDB$FILE_NAME)); X.RDB$SHADOW_NUMBER = (SSHORT)shadow_number; X.RDB$FILE_FLAGS = 0; X.RDB$FILE_FLAGS.NULL = FALSE; diff --git a/src/jrd/gds.cpp b/src/jrd/gds.cpp index 1fbc8ad538..17ddf0c007 100644 --- a/src/jrd/gds.cpp +++ b/src/jrd/gds.cpp @@ -1385,7 +1385,7 @@ SSHORT API_ROUTINE gds__msg_format(void* handle, fb_utils::snprintf(formatted, size, "message system code %d", n); s += formatted; } - s.copy_to(formatted, size); + s.copyTo(formatted, size); } const USHORT l = strlen(formatted); diff --git a/src/jrd/isc_f_proto.h b/src/jrd/isc_f_proto.h index 0ab61ac2b8..92e8471bcb 100644 --- a/src/jrd/isc_f_proto.h +++ b/src/jrd/isc_f_proto.h @@ -39,7 +39,6 @@ bool ISC_check_if_remote(const Firebird::PathName&, bool); void ISC_expand_filename(Firebird::PathName&, bool); // This form of ISC_expand_filename makes epp files happy -// It's explicit that expanded amy be equal to unexpanded inline int ISC_expand_filename(const TEXT* unexpanded, USHORT len_unexpanded, TEXT* expanded, @@ -49,7 +48,7 @@ inline int ISC_expand_filename(const TEXT* unexpanded, Firebird::PathName pn(unexpanded, len_unexpanded ? len_unexpanded : strlen(unexpanded)); ISC_expand_filename(pn, expand_share); - return pn.saveTo(expanded, len_expanded); + return pn.copyTo(expanded, len_expanded); } #ifdef VMS