diff --git a/cint/cint/inc/FastAllocString.h b/cint/cint/inc/FastAllocString.h index 942cd095e6ed567eafbcd371b1460d2b8b40aaf0..1ad5da2495c6a677902db728aa8e4b073e64f9aa 100644 --- a/cint/cint/inc/FastAllocString.h +++ b/cint/cint/inc/FastAllocString.h @@ -17,6 +17,7 @@ #define G__FASTALLOGSTRING_H #include <stdarg.h> +#include <stddef.h> namespace Cint { namespace Internal { @@ -44,12 +45,15 @@ namespace Cint { // class G__FastAllocString { public: - G__FastAllocString(int reqsize): fBuf(0), fBucket(reqsize) { + G__FastAllocString(int reqsize = 1024): fBuf(0), fCapacity(reqsize) { // GetBuf takes as parameter the size in bytes // and modify the parameter (fBucket) to hold the // bucket number. - fBuf = GetBuf(fBucket); + fBuf = GetBuf(fCapacity); } + G__FastAllocString(const char* s); + G__FastAllocString(const G__FastAllocString&); + ~G__FastAllocString(); // plenty of char* conversion fuctions: @@ -67,16 +71,43 @@ public: int FormatArgList(const char *fmt, va_list args); int Format(const char *fmt, ...); - + + size_t Capacity() const { return fCapacity; } + + G__FastAllocString& operator=(const G__FastAllocString& s) { + // Copy s into *this. + // Cannot rely on operator=(const char*) overload - compiler-generated one wins resolution! + return operator=(s.data()); + } + G__FastAllocString& operator=(const char*); + G__FastAllocString& operator+=(const char*); + G__FastAllocString& Swap(G__FastAllocString&); + void Resize(size_t cap); + + void Set(size_t pos, char c) { + // Set character at position pos to c; resize if needed. + Resize(pos + 1); + fBuf[pos] = c; + } + /* + size_t Set(size_t& pos, const char* s) { + // Overwrite string at position pos with s; resize if needed. + // Return pos incremented by strlen(s) + size_t len = strlen(s); + Resize(pos + len + 1); + memcpy(fBuf + pos, s, len + 1); + return pos + len; + }*/ + protected: - static char* GetBuf(int &size_then_bucket_index); - static Cint::Internal::G__BufferReservoir& GetReservoir(); + static char* GetBuf(size_t &size); - void ResizeNoCopy(int newsize); + void ResizeToBucketNoCopy(int newbucket); + void ResizeNoCopy(size_t cap); private: - char* fBuf; // the buffer - int fBucket; // measure representing the buffer's size, used by the internal reservoir + char* fBuf; // the buffer + size_t fCapacity; // measure representing the buffer's size, used by the internal reservoir }; #endif // G__FASTALLOGSTRING_H diff --git a/cint/cint/src/Api.cxx b/cint/cint/src/Api.cxx index 92cb3b85dd69c2c18fef3bccda92af8f87e11cc0..239e695c7aa62b55a2beeae82340270863c3ea65 100644 --- a/cint/cint/src/Api.cxx +++ b/cint/cint/src/Api.cxx @@ -391,21 +391,21 @@ int Cint::G__ExceptionWrapper(G__InterfaceMethod funcp } #ifdef G__STD_EXCEPTION catch(std::exception& x) { - char buf[G__LONGLINE]; + G__FastAllocString buf(G__LONGLINE); #ifdef G__VISUAL // VC++ has problem in typeid(x).name(), so every thrown exception is // translated to G__exception. - sprintf(buf,"new G__exception(\"%s\")",x.what()); + buf.Format("new G__exception(\"%s\")",x.what()); G__fprinterr(G__serr,"Exception: %s\n",x.what()); #else - char buf2[G__ONELINE]; + G__FastAllocString buf2(G__ONELINE); if(G__DemangleClassname(buf2,typeid(x).name())) { - sprintf(buf,"new %s(*(%s*)%ld)",buf2,buf2,(long)(&x)); - G__fprinterr(G__serr,"Exception %s: %s\n", buf2, x.what()); + buf.Format("new %s(*(%s*)%ld)",buf2(),buf2(),(long)(&x)); + G__fprinterr(G__serr,"Exception %s: %s\n", buf2(), x.what()); } else { G__getexpr("#include <exception>"); - sprintf(buf,"new G__exception(\"%s\",\"CINT forwarded std::exception\")",x.what()); + buf.Format("new G__exception(\"%s\",\"CINT forwarded std::exception\")",x.what()); } #endif G__exceptionbuffer = G__getexpr(buf); @@ -530,29 +530,29 @@ extern "C" const char* G__saveconststring(const char* s) extern "C" void G__initcxx() { #if defined(__HP_aCC)||defined(__SUNPRO_CC)||defined(__BCPLUSPLUS__)||defined(__KCC)||defined(__INTEL_COMPILER) - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); #endif #ifdef __HP_aCC /* HP aCC C++ compiler */ - sprintf(temp,"G__HP_aCC=%ld",(long)__HP_aCC); G__add_macro(temp); + temp.Format("G__HP_aCC=%ld",(long)__HP_aCC); G__add_macro(temp); #if __HP_aCC > 15000 - sprintf(temp,"G__ANSIISOLIB=1"); G__add_macro(temp); + temp.Format("G__ANSIISOLIB=1"); G__add_macro(temp); #endif #endif #ifdef __SUNPRO_CC /* Sun C++ compiler */ - sprintf(temp,"G__SUNPRO_CC=%ld",(long)__SUNPRO_CC); G__add_macro(temp); + temp.Format("G__SUNPRO_CC=%ld",(long)__SUNPRO_CC); G__add_macro(temp); #endif #ifdef __BCPLUSPLUS__ /* Borland C++ compiler */ - sprintf(temp,"G__BCPLUSPLUS=%ld",(long)__BCPLUSPLUS__); G__add_macro(temp); + temp.Format("G__BCPLUSPLUS=%ld",(long)__BCPLUSPLUS__); G__add_macro(temp); #endif #ifdef __KCC /* KCC C++ compiler */ - sprintf(temp,"G__KCC=%ld",(long)__KCC); G__add_macro(temp); + temp.Format("G__KCC=%ld",(long)__KCC); G__add_macro(temp); #endif #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER<810) /* icc and ecc C++ compilers */ - sprintf(temp,"G__INTEL_COMPILER=%ld",(long)__INTEL_COMPILER); G__add_macro(temp); + temp.Format("G__INTEL_COMPILER=%ld",(long)__INTEL_COMPILER); G__add_macro(temp); #endif /* #ifdef __cplusplus - sprintf(temp,"G__CPLUSPLUS=%ld",(long)__cplusplus); G__add_macro(temp); + temp.Format("G__CPLUSPLUS=%ld",(long)__cplusplus); G__add_macro(temp); #endif */ } @@ -622,10 +622,10 @@ extern "C" const char* G__replacesymbol(const char* s) { ******************************************************************/ int G__display_replacesymbol_body(FILE *fout,const char* name) { map<string,string>::iterator i; - char msg[G__LONGLINE]; + G__FastAllocString msg(G__LONGLINE); for(i=G__get_symbolmacro().begin();i!=G__get_symbolmacro().end();++i) { if(!name || !name[0] || strcmp(name,(*i).first.c_str())==0) { - sprintf(msg,"#define %s %s\n",(*i).first.c_str(),(*i).second.c_str()); + msg.Format("#define %s %s\n",(*i).first.c_str(),(*i).second.c_str()); G__more(fout,msg); if(name && name[0]) return(1); } diff --git a/cint/cint/src/CallFunc.cxx b/cint/cint/src/CallFunc.cxx index 0ea5fa5d56d6042f65ce4f4bf717e7ae6df01829..07a6c638a335f4a787d867848f46410ee1647e77 100644 --- a/cint/cint/src/CallFunc.cxx +++ b/cint/cint/src/CallFunc.cxx @@ -362,7 +362,7 @@ void Cint::G__CallFunc::SetFunc(G__ClassInfo* cls // G__getstream(), G__type2string() int isrc=0; char *endmark=(char*)","; - char argtype[G__ONELINE]; + G__FastAllocString argtype(G__ONELINE); int pos=0; G__value *buf; @@ -377,14 +377,13 @@ void Cint::G__CallFunc::SetFunc(G__ClassInfo* cls para.para[para.paran] = G__calc(para.parameter[para.paran]); buf = ¶.para[para.paran]; // set type string - if(pos) argtype[pos++]=','; + if(pos) argtype.Set(pos++, ','); + argtype.Set(pos, 0); if(islower(buf->type)) - strcpy(argtype+pos - ,G__type2string(buf->type,buf->tagnum,buf->typenum,0,0)); + argtype += G__type2string(buf->type,buf->tagnum,buf->typenum,0,0); else - strcpy(argtype+pos - ,G__type2string(buf->type,buf->tagnum,buf->typenum - ,buf->obj.reftype.reftype,0)); + argtype += G__type2string(buf->type,buf->tagnum,buf->typenum + ,buf->obj.reftype.reftype,0); pos = strlen(argtype); ++para.paran; // increment argument count } diff --git a/cint/cint/src/Class.cxx b/cint/cint/src/Class.cxx index c74acb03c6b09569b278b31f516c956de0d46cf6..744d4551c4591209e5fc1d527c73436e012c17c0 100644 --- a/cint/cint/src/Class.cxx +++ b/cint/cint/src/Class.cxx @@ -847,14 +847,14 @@ void* Cint::G__ClassInfo::New() // Interpreted class,struct long store_struct_offset; long store_tagnum; - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); int known=0; p = new char[G__struct.size[tagnum]]; store_tagnum = G__tagnum; store_struct_offset = G__store_struct_offset; G__tagnum = tagnum; G__store_struct_offset = (long)p; - sprintf(temp,"%s()",G__struct.name[tagnum]); + temp.Format("%s()",G__struct.name[tagnum]); G__getfunction(temp,&known,G__CALLCONSTRUCTOR); G__store_struct_offset = store_struct_offset; G__tagnum = (int)store_tagnum; @@ -918,7 +918,6 @@ void* Cint::G__ClassInfo::New(int n) int i; long store_struct_offset; long store_tagnum; - char temp[G__ONELINE]; int known=0; p = new char[G__struct.size[tagnum]*n]; // Record that we have allocated an array, and how many @@ -936,7 +935,8 @@ void* Cint::G__ClassInfo::New(int n) ////G__store_struct_offset = (long)(((char*)p) + (2*sizeof(int))); ////... at end adjust returned pointer address ... ////p = ((char*) p) + (2 * sizeof(int)); - sprintf(temp,"%s()",G__struct.name[tagnum]); + G__FastAllocString temp(G__struct.name[tagnum]); + temp += "()"; for(i=0;i<n;i++) { G__getfunction(temp,&known,G__CALLCONSTRUCTOR); if(!known) break; @@ -1005,14 +1005,14 @@ void* Cint::G__ClassInfo::New(void *arena) // Interpreted class,struct long store_struct_offset; long store_tagnum; - char temp[G__ONELINE]; int known=0; p = arena; store_tagnum = G__tagnum; store_struct_offset = G__store_struct_offset; G__tagnum = tagnum; G__store_struct_offset = (long)p; - sprintf(temp,"%s()",G__struct.name[tagnum]); + G__FastAllocString temp(G__struct.name[tagnum]); + temp += "()"; G__getfunction(temp,&known,G__CALLCONSTRUCTOR); G__store_struct_offset = store_struct_offset; G__tagnum = (int)store_tagnum; @@ -1086,7 +1086,6 @@ void* Cint::G__ClassInfo::New(int n, void *arena) // Interpreted class,struct long store_struct_offset; long store_tagnum; - char temp[G__ONELINE]; int known=0; p = arena; // Record that we have allocated an array, and how many @@ -1104,7 +1103,8 @@ void* Cint::G__ClassInfo::New(int n, void *arena) ////G__store_struct_offset = (long)(((char*)p) + (2*sizeof(int))); ////... at end adjust returned pointer address ... ////p = ((char*) p) + (2 * sizeof(int)); - sprintf(temp,"%s()",G__struct.name[tagnum]); + G__FastAllocString temp(G__struct.name[tagnum]); + temp += "()"; for (int i = 0; i < n; ++i) { G__getfunction(temp,&known,G__CALLCONSTRUCTOR); if (!known) break; diff --git a/cint/cint/src/FastAllocString.cxx b/cint/cint/src/FastAllocString.cxx index 897245846c402e64528aaf4a961baff7293e99d9..da090924481494400b02b5d936a68162f2ee12ca 100644 --- a/cint/cint/src/FastAllocString.cxx +++ b/cint/cint/src/FastAllocString.cxx @@ -17,11 +17,9 @@ #include "FastAllocString.h" #include "math.h" #include "stdio.h" +#include "string.h" #include <map> -#define G__STRBUF_RESERVOIR_CHUNKSIZE 1024 -#define G__STRBUF_RESERVOIR_NUMBUFFERS 32 -#define G__STRBUF_RESERVOIR_NUMBUCKETS 1024*10 namespace Cint { namespace Internal { //___________________________________________________________________ @@ -31,166 +29,234 @@ namespace Cint { // a buffer >= that size is returned (or 0 if // there is no available buffer). The buffers // are kept in a fixed-size array (size-dimension, - // G__STRBUF_RESERVOIR_NUMBUFFERS) of a fixed + // fNumBuffers) of a fixed // size array (available buffers dimension, - // G__STRBUF_RESERVOIR_NUMBUCKETS) of char*. + // fgNumBuckets) of char*. // The size-to-index mapping is done logarithmically, // which increases the probability of re-using buffers, - // and allows the size-dimenion array to span a large - // amount of possible buffer sizes (up to - // (1<<32)*1024bytes for - // G__STRBUF_RESERVOIR_CHUNKSIZE == 1024, - // G__STRBUF_RESERVOIR_NUMBUFFERS == 32. + // and allows the size-dimension array to span a large + // amount of possible buffer sizes (up to + // (1<<7)*1024bytes for + // fgChunksize == 1024, + // fgNumBuffers == 7-1. + // Buffer fill stands after stress.cxx(30): + // bucket: maxfill + "maxReallocBecausePoolTooSmall" (maxAllocBecausePoolTooSmall) + // 0: 32 + 200 (250) + // 1: 24 + 0 (0) + // 2: 2 ... + // 3: 1 + // 4: 6 + // 5: 6 + // 6: 0 + // 7: 0 + // 8: 0 class G__BufferReservoir { public: class Bucket { public: Bucket(): - fWatermark(fBuffers + G__STRBUF_RESERVOIR_NUMBUFFERS) {} + fBuffers(0), fWatermark(0), fNumBuffers(0) + {} ~Bucket() { // delete all buffers char* buf; while ((buf = pop())) delete [] buf; + delete [] fBuffers; + } + + void init(size_t numBuffers) { + fNumBuffers = numBuffers; + fBuffers = new Buffer_t[numBuffers]; + fWatermark = fBuffers + numBuffers; } bool push(char* buf) { - if (fWatermark == fBuffers) return false; + if (fWatermark == fBuffers) { + return false; + } *(--fWatermark) = buf; return true; } char* pop() { - if (fWatermark < fBuffers + G__STRBUF_RESERVOIR_NUMBUFFERS) + if (fWatermark < fBuffers + fNumBuffers) { return *(fWatermark++); + } return 0; } private: - char* fBuffers[G__STRBUF_RESERVOIR_NUMBUFFERS]; // array of buffers, - char** fWatermark; // most recently filled slot + typedef char* Buffer_t; + + Buffer_t* fBuffers; // array of buffers, + Buffer_t* fWatermark; // most recently filled slot + size_t fNumBuffers; // size of fBuffers }; - static int logtwo(int i) { - // Return the index of the highest set bit. - // A fast imprecise version of log(i). - int j = 0; - while ( i > 255 ) { - i = i >> 8; - j += 8; + G__BufferReservoir() { + static size_t numBuffers[fgNumBuckets] = {256, 64, 16, 8, 4, 2, 1}; + for (size_t i = 0; i < fgNumBuckets; ++i) { + fMap[i].init(numBuffers[i]); } - if (i & 0xf0) { - i = i >> 4; - j += 4; - } - if (i & 12) { - i = i >> 2; - j += 2; - } - if (i & 2) { - i = i / 2; - j += 1; - } - return j + i; } - static int bucket(int size) { - // get the bucket index for a given buffer size - int b = (size - 1) / G__STRBUF_RESERVOIR_CHUNKSIZE; - b = logtwo(b); - if (b >= G__STRBUF_RESERVOIR_NUMBUCKETS) - return -1; - return b; + static char logtwo(unsigned char i) { + // Return the index of the highest set bit. + // A fast imprecise version of log(i) working up to 8 bit i. + // i must be > 0 + const static char msb[256] = { +#define G__FASTALLOC_MSBx16(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n + -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + G__FASTALLOC_MSBx16(4), + G__FASTALLOC_MSBx16(5), G__FASTALLOC_MSBx16(5), + G__FASTALLOC_MSBx16(6), G__FASTALLOC_MSBx16(6), G__FASTALLOC_MSBx16(6), + G__FASTALLOC_MSBx16(6), + G__FASTALLOC_MSBx16(7), G__FASTALLOC_MSBx16(7), G__FASTALLOC_MSBx16(7), + G__FASTALLOC_MSBx16(7), G__FASTALLOC_MSBx16(7), G__FASTALLOC_MSBx16(7), + G__FASTALLOC_MSBx16(7), G__FASTALLOC_MSBx16(7) + }; +#undef G__FASTALLOC_MSBx16 + return msb[i]; } - bool push(int buck, char* buf) { - // add buf into buck; return false if there is no space - if (buck < 0) return false; - return fMap[buck].push(buf); + static int bucket(size_t size) { + // Get the bucket index for a given buffer size. + // 0: 1 .. fgChunkSize + // 1: fgChunkSize+1 .. 2*fgChunkSize + // 2: 2*fgChunkSize+1 .. 4*fgChunkSize + // 3: 4*fgChunkSize+1 .. 8*fgChunkSize + // ... + if (!size) return -1; + const size_t b = (size - 1) / fgChunkSize; + if (b > (1L << (fgNumBuckets + 1))) + return -1; + int buck = b ? logtwo((unsigned char)b) + 1 : 0; + if (buck >= (int)fgNumBuckets) + return -1; + // 16 bits is enough, and this expression can be optimized + // away at compile time. + if (fgNumBuckets > 8 && buck == -1) { + buck = 8 + logtwo((unsigned char)(b / 256)); + } + return buck; } - char* pop(int &size) { - // retrieve a buffer of given size; - // when returning, size will be the bucket index. - size = bucket(size); - if (size < 0) return 0; - return fMap[size].pop(); + bool push(size_t cap, char* buf) { + // add buf into capacity cap's bucket; return false if there is no space + const int buck = bucket(cap); + if (buck == -1) return false; + return fMap[buck].push(buf); } - static int allocsize(int size) { - // Determine the allocation size that should be used for - // a buffer of size. - int asize = bucket(size) + 1; - asize = (1 << asize) / 2 * G__STRBUF_RESERVOIR_CHUNKSIZE; - return asize; + char* pop(size_t& size) { + // retrieve a buffer of given size, adjusting it to the bucket allocation size. + const int buck = bucket(size); + //printf("size=%d, buck=%d\n", size, buck); + if (buck < 0) { + return 0; + } + size = bucketallocsize(buck); + return fMap[buck].pop(); } - static int bucketallocsize(int bucket_index) { + static size_t bucketallocsize(int bucket) { // Determine the allocation size that is used for - // the specified bucket index. - int asize = bucket_index + 1; - asize = (1 << asize) / 2 * G__STRBUF_RESERVOIR_CHUNKSIZE; - return asize; + // the specified bucket index; see bucket(). + return (1 << bucket) * fgChunkSize; } - + private: - Bucket fMap[G__STRBUF_RESERVOIR_NUMBUCKETS]; // the buckets + static const size_t fgChunkSize = 1024; + static const size_t fgNumBuckets = 7; + Bucket fMap[fgNumBuckets]; // the buckets }; } // Internal } // Cint using namespace Cint::Internal; +namespace { +static Cint::Internal::G__BufferReservoir& +GetReservoir() +{ + // Return the static BufferReservoir + static G__BufferReservoir sReservoir; + return sReservoir; +} +} + +G__FastAllocString::G__FastAllocString(const char* s) +{ + // Construct from a character array, using the character array's + // length plus 32 as the initial buffer capacity. + int len = s ? strlen(s) + 1 : 1024; + fCapacity = len + 32; + fBuf = GetBuf(fCapacity); + if (s) + memcpy(fBuf, s, len); + else + fBuf[0] = 0; +} + +G__FastAllocString::G__FastAllocString(const G__FastAllocString& other) +{ + // Construct from another G__FastAllocString, using the + // other string's length plus 32 as the initial buffer capacity. + int len = strlen(other) + 1; + fCapacity = len + 32; + fBuf = GetBuf(fCapacity); + memcpy(fBuf, other, len); +} + G__FastAllocString::~G__FastAllocString() { // Give our buffer back to the BufMap, i.e. make it available again. - if (fBucket < 0 || !GetReservoir().push(fBucket, fBuf)) { + if (!GetReservoir().push(Capacity(), fBuf)) { delete [] fBuf; } } -char* G__FastAllocString::GetBuf(int &size_then_bucket_index) +char* G__FastAllocString::GetBuf(size_t &size) { // Return a buffer of given size (or larger). // If there is one in the map, return that one, otherwise allocatea new one. - // When entering GetBuf 'size_then_bucket_index' is the requested size in bytes - // it is then updated to return the corresponding bucket number. + // When entering GetBuf 'size' is the requested size in bytes + // it is then updated to return the size corresponding to the bucket number, + // or -1 if no suitable buffer could be extracted from the pool. - int origsize = size_then_bucket_index; // Look for an existing bucket and update with the bucket index. - char* buf = GetReservoir().pop(size_then_bucket_index); + char* buf = GetReservoir().pop(size); if (!buf) { - buf = new char[G__BufferReservoir::allocsize(origsize)]; + buf = new char[size]; } return buf; } -Cint::Internal::G__BufferReservoir& G__FastAllocString::GetReservoir() -{ - // Return the static BufferReservoir - static G__BufferReservoir sReservoir; - return sReservoir; -} - int G__FastAllocString::FormatArgList(const char *fmt, va_list args) { + // sprintf into this string, resizing until it fits. if (!fmt) { fBuf[0] = 0; return 0; } int result = -1; - int bucket_req = fBucket; - - while (result == -1) + int bucket_req = -2; + + while (result == -1 && bucket_req != -1) { - int length = G__BufferReservoir::bucketallocsize(bucket_req); #ifdef _MSC_VER - result = _vsnprintf(fBuf, length, fmt, args); + result = _vsnprintf(fBuf, fCapacity, fmt, args); #else - result = vsnprintf(fBuf, length, fmt, args); -#endif + result = vsnprintf(fBuf, fCapacity, fmt, args); +#endif if (result == -1) { - ++bucket_req; - ResizeNoCopy( bucket_req ); + if (bucket_req == -2) + bucket_req = G__BufferReservoir::bucket(fCapacity); + if (bucket_req != -1) { + // we had a valid bucket, increase it + ++bucket_req; + ResizeNoCopy( bucket_req ); + } } } return result; @@ -198,6 +264,7 @@ int G__FastAllocString::FormatArgList(const char *fmt, va_list args) int G__FastAllocString::Format(const char *fmt, ...) { + // sprintf into this string, resizing until it fits. va_list args; va_start(args, fmt); int res = FormatArgList(fmt, args); @@ -205,21 +272,82 @@ int G__FastAllocString::Format(const char *fmt, ...) return res; } -void G__FastAllocString::ResizeNoCopy(int newbucket) +void G__FastAllocString::ResizeToBucketNoCopy(int newbucket) { // Extend the size used by this buffer to at least newsize. // This does NOT copy the content. - if (newbucket > fBucket) { - - int newsize_then_index = G__BufferReservoir::bucketallocsize(newbucket); - char *newbuf = GetBuf(newsize_then_index); - - if (fBucket < 0 || !GetReservoir().push(fBucket, fBuf)) - delete [] fBuf; - - fBuf = newbuf; - fBucket = newsize_then_index; + size_t cap = G__BufferReservoir::bucketallocsize(newbucket); + if (cap > Capacity()) { + ResizeNoCopy(cap); + } +} + +G__FastAllocString& G__FastAllocString::operator=(const char* s) { + // Assign a string. If necessary, resize the buffer. + if (!s) { + fBuf[0] = 0; + return *this; + } + size_t len = strlen(s) + 1; + if (len > Capacity()) { + ResizeNoCopy(len); + } + memcpy(fBuf, s, len); + return *this; +} + +G__FastAllocString& G__FastAllocString::operator+=(const char* s) { + // Assign a string. If necessary, resize the buffer. + if (!s) { + return *this; } + size_t len = strlen(s); + size_t mylen = strlen(fBuf); + Resize(len + 1 + mylen); + memcpy(fBuf + mylen, s, len + 1); + return *this; } +G__FastAllocString& G__FastAllocString::Swap(G__FastAllocString& other) { + // Swap this and other string. + char* tmpBuf = fBuf; + fBuf = other.fBuf; + other.fBuf = tmpBuf; + size_t tmpCap = fCapacity; + fCapacity = other.fCapacity; + other.fCapacity = tmpCap; + return *this; +} + +void G__FastAllocString::ResizeNoCopy(size_t cap) +{ + // Adjust the capacity so at least cap characters could be + // stored. Capacity() will be >= cap after this call. + // This does NOT copy the content. + + if (cap < Capacity()) + return; + + char *newbuf = GetBuf(cap); + + if (!GetReservoir().push(fCapacity, fBuf)) + delete [] fBuf; + + fBuf = newbuf; + fCapacity = cap; +} + +void G__FastAllocString::Resize(size_t cap) +{ + // Adjust the capacity so at least cap characters could be + // stored. Capacity() will be >= cap after this call. + + if (cap < Capacity()) + return; + + G__FastAllocString tmp(cap); + // we cannot rely on data() being 0-terminated. + memcpy(tmp.fBuf, data(), Capacity()); + Swap(tmp); +} diff --git a/cint/cint/src/Method.cxx b/cint/cint/src/Method.cxx index 1bc1e182d7c668c0930138b2750be008177524a4..43bcaf068803910a34f745ef43021a9780228372 100644 --- a/cint/cint/src/Method.cxx +++ b/cint/cint/src/Method.cxx @@ -651,11 +651,10 @@ int Cint::G__SetGlobalcomp(char *funcname,char *param,int globalcomp) G__ClassInfo globalscope; G__MethodInfo method; long dummy=0; - char classname[G__LONGLINE]; + G__FastAllocString classname(funcname); // Actually find the last :: to get the full classname, including // namespace and/or containing classes. - strcpy(classname,funcname); char *fname = 0; char * tmp = classname; while ( (tmp = strstr(tmp,"::")) ) { @@ -701,11 +700,10 @@ int Cint::G__SetForceStub(char *funcname,char *param) G__ClassInfo globalscope; G__MethodInfo method; long dummy=0; - char classname[G__LONGLINE]; + G__FastAllocString classname(funcname); // Actually find the last :: to get the full classname, including // namespace and/or containing classes. - strcpy(classname,funcname); char *fname = 0; char * tmp = classname; while ( (tmp = strstr(tmp,"::")) ) { @@ -751,11 +749,10 @@ int Cint::G__ForceBytecodecompilation(char *funcname,char *param) G__ClassInfo globalscope; G__MethodInfo method; long dummy=0; - char classname[G__LONGLINE]; + G__FastAllocString classname(funcname); // Actually find the last :: to get the full classname, including // namespace and/or containing classes. - strcpy(classname,funcname); char *fname = 0; char * tmp = classname; while ( (tmp = strstr(tmp,"::")) ) { diff --git a/cint/cint/src/auxu.cxx b/cint/cint/src/auxu.cxx index ca471e4e12841343ebc21b5fbd9ec22312688424..3ac9f8d7b9b4d93516489bf531dc22c735420be0 100644 --- a/cint/cint/src/auxu.cxx +++ b/cint/cint/src/auxu.cxx @@ -15,6 +15,28 @@ #include "common.h" +//______________________________________________________________________________ +int G__readline_FastAlloc(FILE* fp, G__FastAllocString& line, G__FastAllocString& argbuf, + int* argn, char* arg[]) +{ + // -- FIXME: Describe this function! + char* null_fgets = fgets(line, line.Capacity() - 1, fp); + if (null_fgets) { + argbuf = line; + G__split(line, argbuf, argn, arg); + } + else { + line = ""; + argbuf = ""; + *argn = 0; + arg[0] = line; + } + if (!null_fgets) { + return 0; + } + return 1; +} + extern "C" { // Static functions. @@ -347,7 +369,8 @@ int G__scanobject(G__value* buf) if (var->p_typetable[i] > -1) { type_name = G__newtype.name[var->p_typetable[i]]; } - char ifunc[G__ONELINE]; + G__FastAllocString ifunc_sb(G__ONELINE); + char* ifunc = ifunc_sb; sprintf(ifunc, "G__do_scanobject((%s *)%ld,%ld,%d,%ld,%ld)", tagname, pointer, (long) name, type, (long) tagname, (long) type_name); G__getexpr(ifunc); } diff --git a/cint/cint/src/bc_debug.cxx b/cint/cint/src/bc_debug.cxx index bfffff10c91ef4849ee785fc5a7609e40c3ac78e..2fb089ead2328df57833653020ea08dc5b9d88b0 100644 --- a/cint/cint/src/bc_debug.cxx +++ b/cint/cint/src/bc_debug.cxx @@ -69,7 +69,7 @@ int G__bc_funccall::setstackenv(struct G__view* pview) const { int G__bc_funccall::disp(FILE* fout) const { // todo, need some review if(!m_bytecode) return(0); - char msg[G__LONGLINE]; + G__FastAllocString msg(G__LONGLINE); struct G__ifunc_table_internal *ifunc = m_bytecode->ifunc; int ifn = m_bytecode->ifn; int tagnum=ifunc->tagnum; @@ -78,28 +78,28 @@ int G__bc_funccall::disp(FILE* fout) const { // class name if member function if(-1!=tagnum) { - sprintf(msg,"%s::",G__struct.name[tagnum]); - if(G__more(fout,msg)) return(1); + msg.Format("%s::",G__struct.name[tagnum]); + if(G__more(fout,msg())) return(1); } // function name - sprintf(msg,"%s(",ifunc->funcname[ifn]); - if(G__more(fout,msg)) return(1); + msg.Format("%s(",ifunc->funcname[ifn]); + if(G__more(fout,msg())) return(1); // function parameter for(int temp1=0;temp1<libp->paran;temp1++) { if(temp1) { - sprintf(msg,","); - if(G__more(fout,msg)) return(1); + msg = ","; + if(G__more(fout,msg())) return(1); } G__valuemonitor(libp->para[temp1],msg); - if(G__more(fout,msg)) return(1); + if(G__more(fout,msg())) return(1); } if(-1!=filenum) { - sprintf(msg,") [%s:%d]\n" + msg.Format(") [%s:%d]\n" ,G__stripfilename(G__srcfile[filenum].filename) ,m_line_number); - if(G__more(fout,msg)) return(1); + if(G__more(fout,msg())) return(1); } else { if(G__more(fout,") [entry]\n")) return(1); @@ -141,11 +141,11 @@ int G__bc_funccallstack::setstackenv(int i,struct G__view* pview) { //////////////////////////////////////////////////////////////// int G__bc_funccallstack::disp(FILE* fout) const { //deque<G__bc_funccall>::iterator i; - char msg[100]; + G__FastAllocString msg(100); for(int i=0;i<(int)m_funccallstack.size();++i) { - sprintf(msg,"%d ",i); - if(G__more(fout,msg)) return(1); - if(m_funccallstack[i].disp(fout)) return(1); + msg.Format("%d ",i); + if(G__more(fout,msg())) return(1); + if(m_funccallstack[i].disp(fout)) return(1); } return(0); } diff --git a/cint/cint/src/bc_exec.cxx b/cint/cint/src/bc_exec.cxx index c0c45a2fa4e68c893cea42626e212c0abfb832e4..c3c1686d3f20d1823a0b9e87835b05c6087f21a4 100644 --- a/cint/cint/src/bc_exec.cxx +++ b/cint/cint/src/bc_exec.cxx @@ -544,13 +544,13 @@ extern "C" int G__exec_bytecode(G__value *result7,G__CONST char *funcname,struct #ifdef G__DUMPFILE if(G__dumpfile!=NULL) { int ipara; - char resultx[G__ONELINE]; + G__FastAllocString resultx(G__ONELINE); for(ipara=0;ipara<G__dumpspace;ipara++) fprintf(G__dumpfile," "); fprintf(G__dumpfile,"%s(",bytecode->ifunc->funcname[bytecode->ifn]); for(ipara=1;ipara<= libp->paran;ipara++) { if(ipara!=1) fprintf(G__dumpfile,","); G__valuemonitor(libp->para[ipara-1],resultx); - fprintf(G__dumpfile,"%s",resultx); + fprintf(G__dumpfile,"%s",resultx()); } fprintf(G__dumpfile,");/*%s %d (bc)*/\n" ,G__ifile.name,G__ifile.line_number); G__dumpspace += 3; @@ -571,7 +571,7 @@ extern "C" int G__exec_bytecode(G__value *result7,G__CONST char *funcname,struct #endif #ifdef G__ASM_DBG if(G__asm_dbg) { - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); G__fprinterr(G__serr,"returns %s\n",G__valuemonitor(*result7,temp)); } #endif @@ -596,12 +596,12 @@ extern "C" int G__exec_bytecode(G__value *result7,G__CONST char *funcname,struct #ifdef G__DUMPFILE if(G__dumpfile!=NULL) { int ipara; - char resultx[G__ONELINE]; + G__FastAllocString resultx(G__ONELINE); G__dumpspace -= 3; for(ipara=0;ipara<G__dumpspace;ipara++) fprintf(G__dumpfile," "); G__valuemonitor(*result7,resultx); fprintf(G__dumpfile ,"/* return(bc) %s()=%s*/\n" - ,bytecode->ifunc->funcname[bytecode->ifn],resultx); + ,bytecode->ifunc->funcname[bytecode->ifn],resultx()); } #endif diff --git a/cint/cint/src/bc_exec_asm.h b/cint/cint/src/bc_exec_asm.h index f0f596199c8fd74b5e461778dc5daad42b3b2d4a..e8604c8e312a3f9cc38cdb1aadcae5795700459d 100644 --- a/cint/cint/src/bc_exec_asm.h +++ b/cint/cint/src/bc_exec_asm.h @@ -12,7 +12,7 @@ extern "C" void G__exec_alloc_unlock(); int G__exec_asm(int start, int stack, G__value* presult, long localmem) { // -- Execute the bytecode which was compiled on-the-fly by the interpreter. - char clnull[1]; clnull[0] = 0; + static char clnull[1] = {0}; int pc; /* instruction program counter */ int sp; /* data stack pointer */ int strosp = 0; /* struct offset stack pointer */ @@ -28,7 +28,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) int store_return = 0; struct G__tempobject_list* store_p_tempbuf = 0; #ifdef G__ASM_IFUNC - char funcnamebuf[G__MAXNAME]; + G__FastAllocString funcnamebuf(G__MAXNAME); int store_memberfunc_tagnum; long store_memberfunc_struct_offset; int store_exec_memberfunc; @@ -609,7 +609,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) } #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -942,7 +942,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -993,7 +993,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -1040,7 +1040,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -1091,7 +1091,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -1139,7 +1139,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -1193,7 +1193,7 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG @@ -1483,14 +1483,14 @@ int G__exec_asm(int start, int stack, G__value* presult, long localmem) goto ld_func; } #endif - strcpy(funcnamebuf, (char*) G__asm_inst[pc+1]); + funcnamebuf = (char*) G__asm_inst[pc+1]; fpara.paran = G__asm_inst[pc+3]; pfunc = (G__InterfaceMethod) G__asm_inst[pc+4]; for (int i = 0; i < fpara.paran; ++i) { fpara.para[i] = G__asm_stack[sp-fpara.paran+i]; #ifdef G__ASM_DBG if (G__asm_dbg) { - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__fprinterr(G__serr, " : para[%d]: %s %s:%d\n", i, G__valuemonitor(fpara.para[i], tmp), __FILE__, __LINE__); } #endif // G__ASM_DBG diff --git a/cint/cint/src/bc_parse.cxx b/cint/cint/src/bc_parse.cxx index cd2cea071f2ddea0e09ef6e8e6e00ced0d4f5c32..eee19212590a8070a8d9d3103b2cef1ef1dacc33 100644 --- a/cint/cint/src/bc_parse.cxx +++ b/cint/cint/src/bc_parse.cxx @@ -1827,10 +1827,10 @@ int G__blockscope::initstruct(G__TypeReader& type, struct G__var_array* var, int int mparen = 1; int linear_index = -1; buf.obj.i = var->p[varid] + memvar->p[memindex]; - char expr[G__ONELINE]; + G__FastAllocString expr(G__ONELINE); while (mparen) { // -- Read the next initializer value. - int c = G__fgetstream(expr, ",{}"); + int c = G__fgetstream(expr, 0, ",{}"); if (expr[0]) { // -- We have an initializer expression. // FIXME: Do we handle a string literal correctly here? @@ -1878,7 +1878,7 @@ int G__blockscope::initstruct(G__TypeReader& type, struct G__var_array* var, int break; } // Get next initializer expression. - c = G__fgetstream(expr, ",{}"); + c = G__fgetstream(expr, 0, ",{}"); } while (memvar); // Reset back to the beginning of the data member list. memvar = G__initmemvar(var->p_tagtable[varid], &memindex, &buf); @@ -1924,7 +1924,7 @@ int G__blockscope::initscalarary(G__TypeReader& /*type*/, struct G__var_array* v // int ary[] = { 1,2,3 }; // int ary[n] = { 1,2,3 }; // ^ - char expr[G__ONELINE]; + G__FastAllocString expr(G__ONELINE); int& num_of_elements = var->varlabel[ig15][1]; const int& stride = var->varlabel[ig15][0]; // Check for an unspecified length array declaration. @@ -1972,7 +1972,7 @@ int G__blockscope::initscalarary(G__TypeReader& /*type*/, struct G__var_array* v // // Read initialization list. // - c = G__fgetstream(expr, ",;{}"); + c = G__fgetstream(expr, 0, ",;{}"); if (c == ';') { // -- Should be a one-dimensional character array. // char ary[] = "abc"; @@ -2002,7 +2002,7 @@ int G__blockscope::initscalarary(G__TypeReader& /*type*/, struct G__var_array* v int stringflag = 0; while (mparen) { // -- Get next initializer expression. - c = G__fgetstream(expr, ",{}"); + c = G__fgetstream(expr, 0, ",{}"); if (expr[0]) { // -- We got an initializer expression. if ((var->type[ig15] == 'c') && (expr[0] == '"')) { @@ -2579,14 +2579,14 @@ long G__blockscope::getstaticobject(const string& varname ,int noerror) { // todo, This implementation is not exactly correct in a sense that // static objects do not have block scope. - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); int hash,i; struct G__var_array *var; if(-1!=ifunc->tagnum) - sprintf(temp,"%s\\%x\\%x\\%x",varname.c_str(),ifunc->page,ifn,ifunc->tagnum); + temp.Format("%s\\%x\\%x\\%x",varname.c_str(),ifunc->page,ifn,ifunc->tagnum); else - sprintf(temp,"%s\\%x\\%x" ,varname.c_str(),ifunc->page,ifn); + temp.Format("%s\\%x\\%x" ,varname.c_str(),ifunc->page,ifn); G__hash(temp,hash,i) var = &G__global; @@ -2602,7 +2602,7 @@ long G__blockscope::getstaticobject(const string& varname } while(var); if(!noerror) { - G__fprinterr(G__serr,"Error: No memory for static object %s ",temp); + G__fprinterr(G__serr,"Error: No memory for static object %s ",temp()); G__genericerror((char*)NULL); //legacy } return(0); diff --git a/cint/cint/src/bc_reader.h b/cint/cint/src/bc_reader.h index 7e3b67fe11a97f7288696b23d121503c317bb963..9cf0bb05708df68fba8f2893f3eba108bcccc299 100644 --- a/cint/cint/src/bc_reader.h +++ b/cint/cint/src/bc_reader.h @@ -309,9 +309,9 @@ int G__srcreader<T>::fgetc_separator() { ////////////////////////////////////////////////////////////////////// template<class T> int G__srcreader<T>::fpp_command(int c) { - char buf[G__ONELINE]; - c=G__fgetname(buf,"\n\r"); // legacy - string condition=buf; + G__FastAllocString buf(G__ONELINE); + c=G__fgetname(buf, 0, "\n\r"); // legacy + string condition=buf.data(); if(condition.size() && isdigit(condition.c_str()[0])) { if('\n'!=c && '\r'!=c) fignoreline(); G__ifile.line_number=atoi(condition.c_str()); diff --git a/cint/cint/src/cast.cxx b/cint/cint/src/cast.cxx index 2a497781ca6dc87efc0c02e560bd318af4e2784d..35aefca1053e2ddacef1885065689e55de81957e 100644 --- a/cint/cint/src/cast.cxx +++ b/cint/cint/src/cast.cxx @@ -91,12 +91,13 @@ static void G__castclass(G__value* result3, int tagnum, int castflag, int* ptype , "G__ulonglong") == 0 || strcmp(G__struct.name[G__newtype.tagnum[result3->typenum]] , "G__longdouble") == 0)))) { - char com[G__ONELINE], buf2[G__ONELINE]; + G__FastAllocString com(G__ONELINE); + G__FastAllocString buf2(G__ONELINE); int known = 0; int store_typenum = result3->typenum; result3->typenum = -1; G__valuemonitor(*result3, buf2); - sprintf(com, "%s(%s)", G__fulltagname(tagnum, 1), buf2); + com.Format("%s(%s)", G__fulltagname(tagnum, 1), buf2()); *result3 = G__getfunction(com, &known, G__TRYNORMAL); result3->typenum = store_typenum; return; @@ -490,13 +491,13 @@ G__value G__castvalue_bc(char* casttype, G__value result3, int bc) --type; } if (type && 'u' == store_result.type) { - char ttt[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); G__fundamental_conversion_operator(type , -1 , -1 , reftype, isconst , &store_result, ttt); return(store_result); } else if ('u' == store_result.type && strcmp(casttype, "bool") == 0) { - char ttt[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); G__fundamental_conversion_operator(type , G__defined_tagname("bool", 2) , -1 , reftype, isconst , &store_result, ttt); @@ -572,7 +573,7 @@ G__value G__castvalue_bc(char* casttype, G__value result3, int bc) } } else if ('u' == store_result.type) { - char ttt[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); G__fundamental_conversion_operator(type, -1, result3.typenum , reftype, isconst , &store_result, ttt); diff --git a/cint/cint/src/debug.cxx b/cint/cint/src/debug.cxx index b4881b0ffd213cc14a8d0190a843e35e7bffb898..5983a5aa7385809aed22a723f1ac3c1b40e3e38b 100644 --- a/cint/cint/src/debug.cxx +++ b/cint/cint/src/debug.cxx @@ -61,24 +61,23 @@ int G__setbreakpoint(const char* breakline, const char* breakfile); static int G__findfuncposition(const char* func, int* pline, int* pfnum) { // -- FIXME: Describe this function! - char funcname[G__ONELINE]; - char scope[G__ONELINE]; - char temp[G__ONELINE]; + size_t lenfunc = strlen(func) + 1; + G__FastAllocString funcname(func); + G__FastAllocString scope(lenfunc); + G__FastAllocString temp(lenfunc); char *pc; int temp1; int tagnum; struct G__ifunc_table_internal *ifunc; - strcpy(funcname, func); - pc = strstr(funcname, "::"); /* get appropreate scope */ if (pc) { *pc = '\0'; - strcpy(scope, funcname); - strcpy(temp, pc + 2); - strcpy(funcname, temp); + scope = funcname; + temp = pc + 2; + funcname.Swap(temp); tagnum = G__defined_tagname(scope, 0); if ('\0' == funcname[0] && -1 != tagnum) { /* display class declaration */ @@ -375,9 +374,10 @@ int G__display_proto(FILE* fp, const char* func) int G__display_proto_pretty(FILE* fp, const char* func, const char friendlyStyle) { // -- FIXME: Describe this function! - char funcname[G__LONGLINE]; - char scope[G__LONGLINE]; - char temp[G__LONGLINE]; + size_t lenfunc = strlen(func) + 1; + G__FastAllocString funcname(lenfunc); + G__FastAllocString scope(lenfunc); + G__FastAllocString temp(lenfunc); char *pc; /* int temp1; */ int tagnum; @@ -385,16 +385,16 @@ int G__display_proto_pretty(FILE* fp, const char* func, const char friendlyStyle int i = 0; while (isspace(func[i])) ++i; - strcpy(funcname, func + i); + funcname = func + i; pc = strstr(funcname, "::"); /* get appropreate scope */ if (pc) { *pc = '\0'; - strcpy(scope, funcname); - strcpy(temp, pc + 2); - strcpy(funcname, temp); + scope = funcname; + temp = pc + 2; + funcname.Swap(temp); if (0 == scope[0]) tagnum = -1; else tagnum = G__defined_tagname(scope, 0); /* class scope A::func , global scope ::func */ @@ -803,10 +803,14 @@ G__value G__exec_text(const char* unnamedmacro) { // -- FIXME: Describe this function! #ifndef G__TMPFILE - char tname[L_tmpnam+10], sname[L_tmpnam+10]; + G__FastAllocString tname_sb(L_tmpnam+10); + G__FastAllocString sname_sb(L_tmpnam+10); #else - char tname[G__MAXFILENAME], sname[G__MAXFILENAME]; + G__FastAllocString tname_sb(G__MAXFILENAME); + G__FastAllocString sname_sb(G__MAXFILENAME); #endif + char* tname = tname_sb; + char* sname = sname_sb; int nest = 0, single_quote = 0, double_quote = 0; int ccomment = 0, cppcomment = 0; G__value buf; @@ -921,9 +925,11 @@ G__value G__exec_text(const char* unnamedmacro) char* G__exec_text_str(const char* unnamedmacro, char* result) { // -- FIXME: Describe this function! + G__FastAllocString resbuf; G__value buf = G__exec_text(unnamedmacro); - G__valuemonitor(buf, result); - return(result); + G__valuemonitor(buf, resbuf); + strcpy(result, resbuf); + return result; } #endif diff --git a/cint/cint/src/decl.cxx b/cint/cint/src/decl.cxx index 5f792769a3397b07c2efefae13c2317a76f70b9f..b9dd184f4538405916d06ca17ac1a54e605b9a8e 100644 --- a/cint/cint/src/decl.cxx +++ b/cint/cint/src/decl.cxx @@ -31,18 +31,22 @@ extern "C" { int G__initval_eval = 0; int G__dynconst = 0; +} + // Static functions. -static int G__get_newname(char* new_name); -static void G__removespacetemplate(char* name); -static int G__initstruct(char* new_name); -static int G__initary(char* new_name); -static void G__initstructary(char* new_name, int tagnum); -static int G__readpointer2function(char* new_name, char* pvar_type); +static int G__get_newname(G__FastAllocString& new_name); +static void G__removespacetemplate(G__FastAllocString& name, size_t offset = 0); +static int G__initstruct(G__FastAllocString& new_name); +static int G__initary(G__FastAllocString& new_name); +static void G__initstructary(G__FastAllocString& new_name, int tagnum); +static int G__readpointer2function(G__FastAllocString& new_name, char* pvar_type); +extern "C" { // External functions. void G__define_var(int tagnum, int typenum); struct G__var_array* G__initmemvar(int tagnum, int* pindex, G__value* pbuf); G__var_array* G__incmemvar(G__var_array* memvar, int* pindex, G__value* pbuf); +} // Funtions in the C interface. // None. @@ -53,7 +57,7 @@ G__var_array* G__incmemvar(G__var_array* memvar, int* pindex, G__value* pbuf); // //______________________________________________________________________________ -static int G__get_newname(char* new_name) +static int G__get_newname(G__FastAllocString& new_name) { // -- Parse a variable name from the input file. // @@ -68,33 +72,33 @@ static int G__get_newname(char* new_name) // int store_def_struct_member = 0; int store_tagdefining = 0; - char temp[G__ONELINE]; - char temp1[G__ONELINE]; - int cin = G__fgetvarname(new_name, "*&,;=():}"); + G__FastAllocString temp1(G__ONELINE); + + int cin = G__fgetvarname(new_name, 0, "*&,;=():}"); if (cin == '&') { if (!strcmp(new_name, "operator")) { new_name[8] = cin; - cin = G__fgetvarname(new_name + 9, ",;=():}"); + cin = G__fgetvarname(new_name, 9, ",;=():}"); } else { - strcat(new_name, "&"); + new_name += "&"; cin = ' '; } } else if (cin == '*') { if (!strcmp(new_name, "operator")) { new_name[8] = cin; - cin = G__fgetvarname(new_name + 9, ",;=():}"); + cin = G__fgetvarname(new_name, 9, ",;=():}"); } else { - strcat(new_name, "*"); + new_name += "*"; cin = ' '; } } if (isspace(cin)) { if (!strcmp(new_name, "const*")) { new_name[0] = '*'; - cin = G__fgetvarname(new_name + 1, ",;=():}"); + cin = G__fgetvarname(new_name, 1, ",;=():}"); G__constvar |= G__CONSTVAR; } if (!strcmp(new_name, "friend")) { @@ -109,17 +113,17 @@ static int G__get_newname(char* new_name) return(';'); } else if (!strcmp(new_name, "&") || !strcmp(new_name, "*")) { - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } if (!strcmp(new_name, "&*") || !strcmp(new_name, "*&")) { - cin = G__fgetvarname(new_name + 2, ",;=():"); + cin = G__fgetvarname(new_name, 2, ",;=():"); } if (!strcmp(new_name, "double") && (G__var_type != 'l')) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__var_type = 'd'; } else if (!strcmp(new_name, "int")) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } else if ( !strcmp(new_name, "long") || @@ -205,40 +209,40 @@ static int G__get_newname(char* new_name) return 0; } else if (strcmp(new_name, "unsigned") == 0 || strcmp(new_name, "signed") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); --G__var_type; /* make it unsigned */ if (strcmp(new_name, "int*") == 0) { G__var_type = toupper(G__var_type); - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } else if (strcmp(new_name, "int&") == 0) { G__var_type = toupper(G__var_type); - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__reftype = G__PARAREFERENCE; } else if (strcmp(new_name, "int") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } } else if (strcmp(new_name, "int*") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__var_type = toupper(G__var_type); } else if (strcmp(new_name, "double*") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__var_type = 'D'; } else if (strcmp(new_name, "int&") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__reftype = G__PARAREFERENCE; } else if (strcmp(new_name, "double&") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__reftype = G__PARAREFERENCE; } if (isspace(cin)) { if (strcmp(new_name, "static") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__static_alloc = 1; } } @@ -246,81 +250,81 @@ static int G__get_newname(char* new_name) if (strcmp(new_name, "*const") == 0 || strcmp(new_name, "const") == 0) { if (new_name[0]=='*') { G__constvar |= G__PCONSTVAR; - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } else { if (isupper(G__var_type)) G__constvar |= G__PCONSTVAR; else G__constvar |= G__CONSTVAR; - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } if (strcmp(new_name, "&*") == 0 || strcmp(new_name, "*&") == 0) { G__reftype = G__PARAREFERENCE; new_name[0] = '*'; - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } else if (strcmp(new_name, "&") == 0) { G__reftype = G__PARAREFERENCE; - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } if (strcmp(new_name, "*") == 0) { - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); if (strcmp(new_name, "*const") == 0) { G__constvar |= G__PCONSTVAR; - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } } } else if (strcmp(new_name, "const&") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); G__reftype = G__PARAREFERENCE; G__constvar |= G__PCONSTVAR; } else if (strcmp(new_name, "*const&") == 0) { - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); G__constvar |= G__PCONSTVAR; G__reftype = G__PARAREFERENCE; } #ifndef G__OLDIMPLEMENTATION1857 else if (strcmp(new_name, "const*&") == 0) { new_name[0] = '*'; - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); G__constvar |= G__CONSTVAR; G__reftype = G__PARAREFERENCE; } else if (strcmp(new_name, "const**") == 0) { new_name[0] = '*'; - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); G__constvar |= G__CONSTVAR; G__var_type = 'U'; G__reftype = G__PARAP2P; } #endif // G__OLDIMPLEMENTATION1857 else if (strcmp(new_name, "volatile") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } else if (strcmp(new_name, "*volatile") == 0) { - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } else if (strcmp(new_name, "**volatile") == 0) { - cin = G__fgetvarname(new_name + 2, ",;=():"); + cin = G__fgetvarname(new_name, 2, ",;=():"); } else if (strcmp(new_name, "***volatile") == 0) { - cin = G__fgetvarname(new_name + 3, ",;=():"); + cin = G__fgetvarname(new_name, 3, ",;=():"); } else if (strcmp(new_name, "inline") == 0) { - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } else if (strcmp(new_name, "*inline") == 0) { - cin = G__fgetvarname(new_name + 1, ",;=():"); + cin = G__fgetvarname(new_name, 1, ",;=():"); } else if (strcmp(new_name, "**inline") == 0) { - cin = G__fgetvarname(new_name + 2, ",;=():"); + cin = G__fgetvarname(new_name, 2, ",;=():"); } else if (strcmp(new_name, "***inline") == 0) { - cin = G__fgetvarname(new_name + 3, ",;=():"); + cin = G__fgetvarname(new_name, 3, ",;=():"); } else if (strcmp(new_name, "virtual") == 0) { G__virtual = 1; - cin = G__fgetvarname(new_name, ",;=():"); + cin = G__fgetvarname(new_name, 0, ",;=():"); } } if (isspace(cin)) { @@ -332,7 +336,7 @@ static int G__get_newname(char* new_name) !strcmp(new_name, "&operator") ) { /* read real name */ - cin = G__fgetstream(temp1, "("); + cin = G__fgetstream(temp1, 0, "("); /* came to * type operator +(var1 , var2); * ^ @@ -355,28 +359,26 @@ static int G__get_newname(char* new_name) case '!': case '[': case ',': - sprintf(temp, "%s%s", new_name, temp1); - strcpy(new_name, temp); + new_name += temp1; break; case '\0': - cin = G__fgetstream(temp1, ")"); + cin = G__fgetstream(temp1, 0, ")"); if (strcmp(temp1, "") != 0 || cin != ')') { G__fprinterr(G__serr, "Error: Syntax error '%s(%s%c' " - , new_name, temp1, cin); + , new_name(), temp1(), cin); G__genericerror((char*)NULL); } - cin = G__fgetstream(temp1, "("); + cin = G__fgetstream(temp1, 0, "("); if (strcmp(temp1, "") != 0 || cin != '(') { G__fprinterr(G__serr, "Error: Syntax error '%s()%s%c' " - , new_name, temp1, cin); + , new_name(), temp1(), cin); G__genericerror((char*)NULL); } - sprintf(temp, "%s()", new_name); - strcpy(new_name, temp); + new_name += "()"; break; default: - sprintf(temp, "%s %s", new_name, temp1); - strcpy(new_name, temp); + new_name += " "; + new_name += temp1; /* G__genericerror( "Warning: name 'operator' will be a keyword for C++" @@ -388,16 +390,16 @@ static int G__get_newname(char* new_name) } store_len = strlen(new_name); do { - cin = G__fgetstream(new_name + strlen(new_name), ",;=():"); + cin = G__fgetstream(new_name, strlen(new_name), ",;=():"); if (cin == ']') { - strcpy(new_name + strlen(new_name), "]"); + new_name += "]"; } } while (cin == ']'); if (store_len > 1 && isalnum(new_name[store_len]) && isalnum(new_name[store_len-1])) { if (G__dispmsg >= G__DISPWARN) { - G__fprinterr(G__serr, "Warning: %s Syntax error??", new_name); + G__fprinterr(G__serr, "Warning: %s Syntax error??", new_name()); G__printlinenum(); } } @@ -412,18 +414,19 @@ static int G__get_newname(char* new_name) int tmpline = G__ifile.line_number; fgetpos(G__ifile.fp, &tmppos); if (G__dispsource) G__disp_mask = 1000; - cin = G__fgetvarname(new_name, ")"); + cin = G__fgetvarname(new_name, 0, ")"); + G__FastAllocString temp(strlen(new_name)); if ('*' != new_name[0] || 0 == new_name[1]) goto escapehere; - strcpy(temp, new_name + 1); - cin = G__fgetvarname(new_name, ",;=():}"); + temp = new_name() + 1; + cin = G__fgetvarname(new_name, 0, ",;=():}"); if ('[' != new_name[0]) goto escapehere; if (G__dispsource) { G__disp_mask = 0; - G__fprinterr(G__serr, "*%s)%s", temp, new_name); + G__fprinterr(G__serr, "*%s)%s", temp(), new_name()); } - strcat(temp, "[]"); - strcat(temp, new_name); - strcpy(new_name, temp); + temp += "[]"; + temp += new_name; + new_name.Swap(temp); return cin; escapehere: if (G__dispsource) G__disp_mask = 0; @@ -436,15 +439,15 @@ static int G__get_newname(char* new_name) if (cin == '=') { fseek(G__ifile.fp, -1, SEEK_CUR); if (G__dispsource) G__disp_mask = 1; - cin = G__fgetstream(new_name + strlen(new_name), "("); + cin = G__fgetstream(new_name, strlen(new_name), "("); } else if ((cin == '(') && !new_name[8]) { - cin = G__fgetstream(new_name, ")"); - cin = G__fgetstream(new_name, "("); + cin = G__fgetstream(new_name, 0, ")"); + cin = G__fgetstream(new_name, 0, "("); sprintf(new_name, "operator()"); } else if ((cin == ',') && !new_name[8]) { - cin = G__fgetstream(new_name, "("); + cin = G__fgetstream(new_name, 0, "("); sprintf(new_name, "operator,"); } return cin; @@ -456,11 +459,12 @@ static int G__get_newname(char* new_name) if (cin == '=') { fseek(G__ifile.fp, -1, SEEK_CUR); if (G__dispsource) G__disp_mask = 1; - cin = G__fgetstream(new_name + strlen(new_name), "("); + cin = G__fgetstream(new_name, strlen(new_name), "("); } else if ((cin == '(') && !new_name[9]) { cin = G__fignorestream(")"); cin = G__fignorestream("("); + new_name.Resize(12); strcpy(new_name + 9, "()"); } return cin; @@ -472,11 +476,12 @@ static int G__get_newname(char* new_name) if ('=' == cin) { fseek(G__ifile.fp, -1, SEEK_CUR); if (G__dispsource) G__disp_mask = 1; - cin = G__fgetstream(new_name + strlen(new_name), "("); + cin = G__fgetstream(new_name, strlen(new_name), "("); } else if ('(' == cin && '\0' == new_name[10]) { cin = G__fignorestream(")"); cin = G__fignorestream("("); + new_name.Resize(13); strcpy(new_name + 10, "()"); } return(cin); @@ -484,8 +489,6 @@ static int G__get_newname(char* new_name) return cin; } -} // Extern "C" - //______________________________________________________________________________ static int G__setvariablecomment(char* new_name, Cint::G__DataMemberHandle &member) { @@ -507,17 +510,17 @@ static int G__setvariablecomment(char* new_name, Cint::G__DataMemberHandle &memb return 0; } -extern "C" { - //______________________________________________________________________________ -static void G__removespacetemplate(char* name) +static void G__removespacetemplate(G__FastAllocString& name, size_t offset /* = 0 */) { - char buf[G__LONGLINE]; + size_t len = strlen(name.data()) + 1; + G__FastAllocString buf(len); + memcpy(buf, name, len); int c = 0; - int i = 0; - int j = 0; + size_t i = offset; + int j = len; while ((c = name[i])) { - if (isspace(c) && i > 0) { + if (isspace(c) && i > offset) { switch (name[i-1]) { case ':': case '<': @@ -548,22 +551,21 @@ static void G__removespacetemplate(char* name) ++i; } buf[j] = 0; - strcpy(name, buf); + name.Swap(buf); } //______________________________________________________________________________ -static int G__initstruct(char* new_name) +static int G__initstruct(G__FastAllocString& new_name) { // FIXME: We do not handle brace nesting properly, // we need to default initialize members // whose initializers were omitted. - char expr[G__ONELINE]; + G__FastAllocString expr(G__ONELINE); #ifdef G__ASM G__abortbytecode(); #endif // G__ASM // Separate the variable name from any index specification. - char name[G__MAXNAME]; - std::strcpy(name, new_name); + G__FastAllocString name(new_name); { char* p = std::strchr(name, '['); if (p) { @@ -579,12 +581,12 @@ static int G__initstruct(char* new_name) if ((G__static_alloc == 1) && (G__func_now != -1)) { // -- Function-local static structure initialization at prerun, use a special global variable name. if (G__memberfunc_tagnum != -1) { // questionable - std::sprintf(expr, "%s\\%x\\%x\\%x", name, G__func_page, G__func_now, G__memberfunc_tagnum); + expr.Format("%s\\%x\\%x\\%x", name(), G__func_page, G__func_now, G__memberfunc_tagnum); } else { - std::sprintf(expr, "%s\\%x\\%x", name, G__func_page, G__func_now); + expr.Format("%s\\%x\\%x", name(), G__func_page, G__func_now); } - std::strcpy(name, expr); + name = expr; } // // Lookup the variable. @@ -627,7 +629,7 @@ static int G__initstruct(char* new_name) } } if (!var) { - G__fprinterr(G__serr, "Limitation: %s initialization ignored", name); + G__fprinterr(G__serr, "Limitation: %s initialization ignored", name()); G__printlinenum(); int c = G__fignorestream("},;"); if (c == '}') { @@ -640,7 +642,7 @@ static int G__initstruct(char* new_name) // -- We have base classes, i.e., we are not an aggregate. // FIXME: This test should be stronger, the accessibility // of the data members should be tested for example. - G__fprinterr(G__serr, "Error: %s must be initialized by a constructor", name); + G__fprinterr(G__serr, "Error: %s must be initialized by a constructor", name()); G__genericerror(0); int c = G__fignorestream("}"); // type var1[N] = { 0, 1, 2.. } , ... ; @@ -695,7 +697,7 @@ static int G__initstruct(char* new_name) int linear_index = -1; while (mparen) { // -- Read the next initializer value. - int c = G__fgetstream(expr, ",{}"); + int c = G__fgetstream(expr, 0, ",{}"); if (expr[0]) { // -- We have an initializer expression. // FIXME: Do we handle a string literal correctly here? See similar code in G__initary(). @@ -727,7 +729,7 @@ static int G__initstruct(char* new_name) // -- Fixed-size array, error, array index out of range. if (G__asm_wholefunction == G__ASM_FUNC_NOP) { if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: %s: %d: Array initialization out of range *(%s+%d), upto %d ", __FILE__, __LINE__, name, linear_index, num_of_elements); + G__fprinterr(G__serr, "Error: %s: %d: Array initialization out of range *(%s+%d), upto %d ", __FILE__, __LINE__, name(), linear_index, num_of_elements); } } G__genericerror(0); @@ -774,7 +776,7 @@ static int G__initstruct(char* new_name) break; } // Get next initializer expression. - c = G__fgetstream(expr, ",{}"); + c = G__fgetstream(expr, 0, ",{}"); } while (memvar); // Reset back to the beginning of the data member list. memvar = G__initmemvar(var->p_tagtable[varid], &memindex, &buf); @@ -804,15 +806,14 @@ static int G__initstruct(char* new_name) } //______________________________________________________________________________ -static int G__initary(char* new_name) +static int G__initary(G__FastAllocString& new_name) { // -- Parse and execute an array initialization. // //printf("Begin G__initary for '%s'...\n", new_name); - static char expr[G__ONELINE]; + static G__FastAllocString expr(G__ONELINE); // Separate the array name from the index specification. - char name[G__MAXNAME]; - std::strcpy(name, new_name); + G__FastAllocString name(new_name); { char* p = std::strchr(name, '['); if (p) { @@ -832,12 +833,12 @@ static int G__initary(char* new_name) if (var && (var->varlabel[varid][1] /* number of elements */ == INT_MAX /* unspecified length flag */)) { // -- Variable exists and is an unspecified length array. // Look for a corresponding special name, both locally and globally. - char namestatic[G__ONELINE]; + G__FastAllocString namestatic(G__ONELINE); if (G__memberfunc_tagnum != -1) { // questionable - sprintf(namestatic, "%s\\%x\\%x\\%x", name, G__func_page, G__func_now, G__memberfunc_tagnum); + namestatic.Format("%s\\%x\\%x\\%x", name(), G__func_page, G__func_now, G__memberfunc_tagnum); } else { - sprintf(namestatic, "%s\\%x\\%x", name, G__func_page, G__func_now); + namestatic.Format("%s\\%x\\%x", name(), G__func_page, G__func_now); } int hashstatic = 0; G__hash(namestatic, hashstatic, i) @@ -861,12 +862,12 @@ static int G__initary(char* new_name) if ((G__static_alloc == 1) && (G__func_now != -1)) { // -- Function-local static array initialization, use a special global variable name. if (G__memberfunc_tagnum != -1) { // questionable - std::sprintf(expr, "%s\\%x\\%x\\%x", name, G__func_page, G__func_now, G__memberfunc_tagnum); + expr.Format("%s\\%x\\%x\\%x", name(), G__func_page, G__func_now, G__memberfunc_tagnum); } else { - std::sprintf(expr, "%s\\%x\\%x", name, G__func_page, G__func_now); + expr.Format("%s\\%x\\%x", name(), G__func_page, G__func_now); } - std::strcpy(name, expr); + name.Swap(expr); } #ifdef G__ASM G__abortbytecode(); @@ -922,12 +923,12 @@ static int G__initary(char* new_name) *px = 0; } // Use the special name for a class/enum/namespace/struct/union/func local. - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); if (G__tagdefining != -1) { - sprintf(temp, "%s\\%x\\%x\\%x", name, G__func_page, G__func_now, G__tagdefining); + temp.Format("%s\\%x\\%x\\%x", name(), G__func_page, G__func_now, G__tagdefining); } else { - sprintf(temp, "%s\\%x\\%x", name, G__func_page, G__func_now); + temp.Format("%s\\%x\\%x", name(), G__func_page, G__func_now); } // Calculate the hash value of the special name. int varhash = 0; @@ -938,7 +939,7 @@ static int G__initary(char* new_name) // If not found, try again using a member variable lookup. if (!var && (G__tagdefining != -1)) { // -- Not found, use the normal name, but do a member variable lookup. - std::sprintf(temp, "%s", name); + temp = name; G__hash(temp, varhash, itmpx); var = G__getvarentry(temp, varhash, &varid, G__struct.memvar[G__tagdefining], G__struct.memvar[G__tagdefining]); } @@ -1021,7 +1022,7 @@ static int G__initary(char* new_name) int linear_index = 0; while (brace_level) { // -- Read the next initializer value. - int c = G__fgetstream(expr, ",{}"); + int c = G__fgetstream(expr, 0, ",{}"); if (expr[0]) { // -- Found one. //printf("%d: '%s', ", linear_index, expr); @@ -1030,7 +1031,7 @@ static int G__initary(char* new_name) // -- Semantic error, gone past the end of the array. if (G__asm_wholefunction == G__ASM_FUNC_NOP) { if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: Too many initializers, exceeded length of array for '%s'", name); + G__fprinterr(G__serr, "Error: Too many initializers, exceeded length of array for '%s'", name()); } } G__genericerror(0); @@ -1049,7 +1050,7 @@ static int G__initary(char* new_name) // -- Semantic error, too many initializers. if (G__asm_wholefunction == G__ASM_FUNC_NOP) { if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: Too many initializers for '%s'", name); + G__fprinterr(G__serr, "Error: Too many initializers for '%s'", name()); } } G__genericerror(0); @@ -1129,7 +1130,7 @@ static int G__initary(char* new_name) // -- Semantic error, attempt to initialize a char with a string array constant. if (G__asm_wholefunction == G__ASM_FUNC_NOP) { if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: Attempt to initialize a char with a string constant for '%s'", name); + G__fprinterr(G__serr, "Error: Attempt to initialize a char with a string constant for '%s'", name()); } } G__genericerror(0); @@ -1154,7 +1155,7 @@ static int G__initary(char* new_name) // -- Semantic error, attempt to initialize a char array with a string array constant of the wrong size. if (G__asm_wholefunction == G__ASM_FUNC_NOP) { if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: Initializer for a char array is too big while intializing '%s'", name); + G__fprinterr(G__serr, "Error: Initializer for a char array is too big while intializing '%s'", name()); } } G__genericerror(0); @@ -1348,7 +1349,7 @@ static int G__initary(char* new_name) } //______________________________________________________________________________ -static void G__initstructary(char* new_name, int tagnum) +static void G__initstructary(G__FastAllocString& new_name, int tagnum) { // -- Initialize an array of structures. // @@ -1358,7 +1359,7 @@ static void G__initstructary(char* new_name, int tagnum) int cin = 0; long store_struct_offset = G__store_struct_offset; long store_globalvarpointer = G__globalvarpointer; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); G__DataMemberHandle member; #ifdef G__ASM G__abortbytecode(); @@ -1376,14 +1377,16 @@ static void G__initstructary(char* new_name, int tagnum) // FIXME: This does not allow nested curly braces. p_inc = 0; do { - cin = G__fgetstream(buf, ",}"); + cin = G__fgetstream(buf, 0, ",}"); ++p_inc; } while (cin != '}'); // Now modify the name by adding the calculated dimensionality. - // FIXME: We modify new_name, which may not be big enough! - std::strcpy(buf, index + 1); - std::sprintf(index + 1, "%d", p_inc); - std::strcat(new_name, buf); + buf = index + 1; + G__FastAllocString idx(16); + idx.Format("%d", p_inc); + *(++index) = 0; + new_name += idx; + new_name += buf; // Rewind the file back to the beginning of the initializer spec. G__ifile.line_number = store_line; std::fsetpos(G__ifile.fp, &store_pos); @@ -1402,7 +1405,7 @@ static void G__initstructary(char* new_name, int tagnum) long len = strlen(buf); int i = 0; do { - cin = G__fgetstream(buf + len, ",}"); + cin = G__fgetstream(buf, len, ",}"); std::strcat(buf, ")"); if (G__struct.iscpplink[tagnum] != G__CPPLINK) { G__store_struct_offset = adr + (i * G__struct.size[tagnum]); @@ -1419,7 +1422,7 @@ static void G__initstructary(char* new_name, int tagnum) } //______________________________________________________________________________ -static int G__readpointer2function(char* new_name, char* pvar_type) +static int G__readpointer2function(G__FastAllocString& new_name, char* pvar_type) { // -- FIXME: Describe this function! // @@ -1449,7 +1452,7 @@ static int G__readpointer2function(char* new_name, char* pvar_type) fpos_t pos2; fgetpos(G__ifile.fp, &pos2); int line2 = G__ifile.line_number; - int c = G__fgetstream(new_name, "()"); + int c = G__fgetstream(new_name, 0, "()"); if ((new_name[0] != '*') && !strstr(new_name, "::*")) { fsetpos(G__ifile.fp, &pos2); G__ifile.line_number = line2; @@ -1465,14 +1468,14 @@ static int G__readpointer2function(char* new_name, char* pvar_type) else { line2 = 0; } - char tagname[G__ONELINE]; + G__FastAllocString tagname(G__ONELINE); tagname[0] = '\0'; { char* p = strstr(new_name, "::*"); if (p) { isp2memfunc = G__POINTER2MEMFUNC; // (A::*p)(...) => new_name="p" , tagname="A::" - strcpy(tagname, new_name); + tagname = new_name; p = strstr(tagname, "::*"); strcpy(new_name, p + 3); *(p + 2) = '\0'; @@ -1488,12 +1491,12 @@ static int G__readpointer2function(char* new_name, char* pvar_type) if (c == '[') { // -- type (*pary)[n]; pointer to array // ^ - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); int n = 0; while (c == '[') { - c = G__fgetstream(temp, "]"); + c = G__fgetstream(temp, 0, "]"); G__p2arylabel[n++] = G__int(G__getexpr(temp)); - c = G__fgetstream(temp, "[;,)="); + c = G__fgetstream(temp, 0, "[;,)="); } G__p2arylabel[n] = 0; fseek(G__ifile.fp, -1, SEEK_CUR); @@ -1505,7 +1508,7 @@ static int G__readpointer2function(char* new_name, char* pvar_type) // -- type (*pfunc)(...); pointer to function // ^ // Set newtype for pointer to function. - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); fpos_t pos; fgetpos(G__ifile.fp, &pos); int line = G__ifile.line_number; @@ -1513,18 +1516,19 @@ static int G__readpointer2function(char* new_name, char* pvar_type) G__disp_mask = 1000; // FIXME: Gross hack! } if (ispointer) { - sprintf(temp, "%s *(%s*)(", G__type2string(G__var_type, G__tagnum, G__typenum, G__reftype, G__constvar), tagname); + temp.Format("%s *(%s*)(", G__type2string(G__var_type, G__tagnum, G__typenum, G__reftype, G__constvar), tagname()); } else { - sprintf(temp, "%s (%s*)(", G__type2string(G__var_type, G__tagnum, G__typenum, G__reftype, G__constvar), tagname); + temp.Format("%s (%s*)(", G__type2string(G__var_type, G__tagnum, G__typenum, G__reftype, G__constvar), tagname()); } - c = G__fdumpstream(temp + strlen(temp), ")"); - temp[strlen(temp)+1] = '\0'; - temp[strlen(temp)] = c; + c = G__fdumpstream(temp, strlen(temp), ")"); + size_t lentemp = strlen(temp); + temp.Set(lentemp++, c); + temp.Set(lentemp, 0); G__tagnum = -1; if (isp2memfunc == G__POINTER2MEMFUNC) { G__typenum = G__search_typename(temp, 'a', -1, 0); - sprintf(temp, "G__p2mf%d", G__typenum); + temp.Format("G__p2mf%d", G__typenum); G__typenum = G__search_typename(temp, 'a', -1, 0); G__var_type = 'a'; *pvar_type = 'a'; @@ -1618,9 +1622,9 @@ void G__define_var(int tagnum, int typenum) static int bitfieldwarn = 0; fpos_t store_fpos; G__value reg = G__null; - char temp1[G__LONGLINE]; - char new_name[G__LONGLINE]; - char temp[G__LONGLINE]; + G__FastAllocString temp1(G__LONGLINE); + G__FastAllocString new_name(G__LONGLINE); + G__FastAllocString temp(G__LONGLINE); store_static_alloc2 = G__static_alloc; new_name[0] = '\0'; store_tagnum = G__tagnum; @@ -1662,13 +1666,13 @@ void G__define_var(int tagnum, int typenum) var_type = G__var_type; if (new_name[0] == '&') { G__reftype = G__PARAREFERENCE; - strcpy(temp, new_name + 1); - strcpy(new_name, temp); + temp = new_name + 1; + new_name = temp; } else if ((new_name[0] == '*') && (new_name[1] == '&')) { G__reftype = G__PARAREFERENCE; - sprintf(temp, "*%s", new_name + 2); - strcpy(new_name, temp); + temp.Format("*%s", new_name + 2); + new_name = temp; } // // Now we have: @@ -1753,7 +1757,7 @@ void G__define_var(int tagnum, int typenum) temp[0] = '\0'; } else { - cin = G__fgetstream(temp, ",)"); + cin = G__fgetstream(temp, 0, ",)"); store_var_type = G__var_type; G__var_type = 'p'; if (G__def_tagnum != -1) { @@ -1857,9 +1861,9 @@ void G__define_var(int tagnum, int typenum) G__ansiheader = 0; if (G__struct.iscpplink[tagnum] == G__CPPLINK) { // -- The struct is compiled code. - char tttt[G__ONELINE]; + G__FastAllocString tttt(G__ONELINE); G__valuemonitor(reg, tttt); - sprintf(temp1, "%s(%s)", G__struct.name[tagnum], tttt); + temp1.Format("%s(%s)", G__struct.name[tagnum], tttt()); if (G__struct.parent_tagnum[tagnum] != -1) { int store_exec_memberfunc = G__exec_memberfunc; int store_memberfunc_tagnum = G__memberfunc_tagnum; @@ -1952,7 +1956,7 @@ void G__define_var(int tagnum, int typenum) case G__CONSTRUCTORFUNC: if (G__tagnum != -1) { cin = '('; - strcpy(new_name, G__struct.name[G__tagnum]); + new_name = G__struct.name[G__tagnum]; G__var_type = 'i'; goto define_function; } @@ -2018,14 +2022,14 @@ void G__define_var(int tagnum, int typenum) if (G__dispsource) { G__disp_mask = 1000; } - cin = G__fgetname(temp, ",)!\"%&'*+-./<=>?[]^|~"); // FIXME: No '(' here because then given "B f(A(3, 5), 12)" the "A" passes the typename test and we parse it as a function declaration. + cin = G__fgetname(temp, 0, ",)!\"%&'*+-./<=>?[]^|~"); // FIXME: No '(' here because then given "B f(A(3, 5), 12)" the "A" passes the typename test and we parse it as a function declaration. if (strlen(temp) && isspace(cin)) { // -- There was an argument and the parsing was stopped by a white // space rather than on of ",)*&<=", it is possible that // we have a namespace followed by '::' in which case we have // to grab more before stopping! int namespace_tagnum; - char more[G__LONGLINE]; + G__FastAllocString more(G__LONGLINE); namespace_tagnum = G__defined_tagname(temp, 2); while ( isspace(cin) && @@ -2035,8 +2039,8 @@ void G__define_var(int tagnum, int typenum) (temp[strlen(temp)-1] == ':') ) ) { - cin = G__fgetname(temp, ",)!\"%&'(*+-./<=>?[]^|~"); - strcat(temp, more); + cin = G__fgetname(more, 0, ",)!\"%&'(*+-./<=>?[]^|~"); + temp += more; namespace_tagnum = G__defined_tagname(temp, 2); } } @@ -2059,7 +2063,8 @@ void G__define_var(int tagnum, int typenum) // function definition // type funcname( type var1,.....) // ^ - sprintf(temp, "%s(", new_name); + temp = new_name; + temp += "("; G__make_ifunctable(temp); G__isfuncreturnp2f = 0; // this is set above in this function // body of the function is skipped all @@ -2082,7 +2087,7 @@ void G__define_var(int tagnum, int typenum) // type varname(const, const); // ^ // Read parameter list and build command string. - cin = G__fgetstream_newtemplate(temp, ")"); + cin = G__fgetstream_newtemplate(temp, 0, ")"); if ((new_name[0] == '*') && (var_type != 'c') && (temp[0] == '"')) { G__genericerror("Error: illegal pointer initialization"); } @@ -2119,14 +2124,14 @@ void G__define_var(int tagnum, int typenum) cin = G__fignorestream(",;"); if (G__PARAREFERENCE == G__reftype && 0 == G__asm_wholefunction) { if (0 == reg.ref) { - G__fprinterr(G__serr, "Error: reference type %s with no initialization ", new_name); + G__fprinterr(G__serr, "Error: reference type %s with no initialization ", new_name()); G__genericerror(0); } G__globalvarpointer = reg.ref; } goto create_body; } - sprintf(temp1, "%s(%s)", G__struct.name[G__tagnum], temp); + temp1.Format("%s(%s)", G__struct.name[G__tagnum], temp()); // Store flags. store_prerun = G__prerun; G__prerun = 0; @@ -2202,7 +2207,7 @@ void G__define_var(int tagnum, int typenum) G__store_struct_offset = G__PVOID; } if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration of %s %s:%d", G__store_struct_offset, temp1, new_name, __FILE__, __LINE__); + G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration of %s %s:%d", G__store_struct_offset, temp1(), new_name(), __FILE__, __LINE__); } // call constructor, error if no constructor. G__decl = 0; @@ -2272,7 +2277,7 @@ void G__define_var(int tagnum, int typenum) // -- Temporary solution, later this must be deleted. if ((G__asm_wholefunction == G__ASM_FUNC_NOP) || G__asm_noverflow) { if (!G__xrefflag) { - G__fprinterr(G__serr, "Error: %s not allocated(1), maybe duplicate declaration ", new_name); + G__fprinterr(G__serr, "Error: %s not allocated(1), maybe duplicate declaration ", new_name()); } G__genericerror(0); } @@ -2336,7 +2341,7 @@ void G__define_var(int tagnum, int typenum) /* if(i>1) G__reftype = i+1; not needed */ } if (strchr(new_name + i, '<')) { - G__removespacetemplate(new_name + i); + G__removespacetemplate(new_name, i); } do { G__def_tagnum = G__defined_tagname(new_name + i, 0) ; @@ -2355,14 +2360,15 @@ void G__define_var(int tagnum, int typenum) return; } G__tagdefining = G__def_tagnum; - cin = G__fgetstream(new_name + i, "(=;:"); + cin = G__fgetstream(new_name, i, "(=;:"); } while (':' == cin && EOF != (cin = G__fgetc())) ; temp[0] = '\0'; switch (cin) { case '=': if (strncmp(new_name + i, "operator", 8) == 0) { - cin = G__fgetstream(new_name + strlen(new_name) + 1, "("); + cin = G__fgetstream(new_name, strlen(new_name) + 1, "("); + new_name.Resize(strlen(new_name) + 1); new_name[strlen(new_name)] = '='; break; } @@ -2370,8 +2376,8 @@ void G__define_var(int tagnum, int typenum) /* PHILIPPE17: the following is fixed in 1306! */ /* static class object member must call constructor * TO BE IMPLEMENTED */ - sprintf(temp, "%s::%s", G__fulltagname(G__def_tagnum, 1), new_name + i); - strcpy(new_name, temp); + temp.Format("%s::%s", G__fulltagname(G__def_tagnum, 1), new_name + i); + new_name = temp; if ('u' != var_type || G__reftype) var_type = 'p'; else staticclassobject = 1; G__def_struct_member = store_def_struct_member; @@ -2385,12 +2391,12 @@ void G__define_var(int tagnum, int typenum) * handled correctly. */ } if (strcmp(new_name + i, "operator") == 0) { - sprintf(temp, "%s()(", new_name); + temp.Format("%s()(", new_name()); cin = G__fignorestream(")"); cin = G__fignorestream("("); } else { - sprintf(temp, "%s(", new_name); + temp.Format("%s(", new_name()); } G__make_ifunctable(temp); G__def_struct_member = store_def_struct_member; @@ -2423,12 +2429,13 @@ void G__define_var(int tagnum, int typenum) } bitfieldwarn = 1; } - cin = G__fgetstream(temp, ",;=}"); - sprintf(new_name, "%s : %s", new_name, temp); + cin = G__fgetstream(temp, 0, ",;=}"); + new_name += " : "; + new_name += temp; G__bitfield = 1; } else { - cin = G__fgetstream(temp, ",;=}"); + cin = G__fgetstream(temp, 0, ",;=}"); G__bitfield = atoi(temp); if (!G__bitfield) { G__bitfield = -1; @@ -2450,10 +2457,10 @@ void G__define_var(int tagnum, int typenum) G__tagnum = G__get_envtagnum(); // Scan the initializer into temp. if ((var_type == 'u')) { - cin = G__fgetstream_newtemplate(temp, ",;{}"); + cin = G__fgetstream_newtemplate(temp, 0, ",;{}"); } else { - cin = G__fgetstream_new(temp, ",;{"); + cin = G__fgetstream_new(temp, 0, ",;{"); } if ( G__def_struct_member && @@ -2608,7 +2615,7 @@ void G__define_var(int tagnum, int typenum) (G__reftype == G__PARAREFERENCE) && !G__def_struct_member ) { - G__fprinterr(G__serr, "Error: reference type %s with no initialization ", new_name); + G__fprinterr(G__serr, "Error: reference type %s with no initialization ", new_name()); G__genericerror(0); } reg = G__null; @@ -2741,9 +2748,9 @@ void G__define_var(int tagnum, int typenum) // // type a; // - sprintf(temp, "%s()", G__struct.name[G__tagnum]); + temp.Format("%s()", G__struct.name[G__tagnum]); if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling default constructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp, new_name); + G__fprinterr(G__serr, "\n!!!Calling default constructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp(), new_name()); } G__decl = 0; if ((index = strchr(new_name, '['))) { @@ -2887,7 +2894,7 @@ void G__define_var(int tagnum, int typenum) if (G__asm_wholefunction == G__ASM_FUNC_NOP) { // -- We are not generating bytecode for a whole function, // so we are allowed to print this error message. - G__fprinterr(G__serr, "Error: %s no default constructor", temp); + G__fprinterr(G__serr, "Error: %s no default constructor", temp()); } // Print a generic error message, and keep going. G__genericerror(0); @@ -2950,7 +2957,7 @@ void G__define_var(int tagnum, int typenum) // struct class initialization = { x, y, z } if (initary) { if (known && (G__struct.funcs[tagnum]& G__HAS_XCONSTRUCTOR)) { - G__fprinterr(G__serr, "Error: Illegal initialization of %s. Constructor exists ", new_name); + G__fprinterr(G__serr, "Error: Illegal initialization of %s. Constructor exists ", new_name()); G__genericerror(0); cin = G__fignorestream("}"); cin = G__fignorestream(",;"); @@ -2977,16 +2984,16 @@ void G__define_var(int tagnum, int typenum) // to pass G__getfunction() G__tagnum = store_tagnum; } - sprintf(temp1, "%s(", G__struct.name[G__tagnum]); + temp1.Format("%s(", G__struct.name[G__tagnum]); // FIXME: ifdef G__TEMPLATECLASS: Need to evaluate template argument list here. if (temp == strstr(temp, temp1)) { int c; int isrc = 0; - char buf[G__LONGLINE]; + G__FastAllocString buf(G__LONGLINE); flag = 1; - c = G__getstream_template(temp, &isrc, buf, "("); + c = G__getstream_template(temp, &isrc, buf, 0, "("); if (c == '(') { - c = G__getstream_template(temp, &isrc, buf, ")"); + c = G__getstream_template(temp, &isrc, buf, 0, ")"); if (c == ')') { if (temp[isrc]) { flag = 0; @@ -3000,8 +3007,8 @@ void G__define_var(int tagnum, int typenum) *index = '\0'; flag = G__defined_typename(temp); if ((flag != -1) && (G__newtype.tagnum[flag] == G__tagnum)) { - sprintf(temp1, "%s(%s", G__struct.name[G__tagnum], index + 1); - strcpy(temp, temp1); + temp1.Format("%s(%s", G__struct.name[G__tagnum], index + 1); + temp = temp1; flag = 1; } else { @@ -3021,7 +3028,7 @@ void G__define_var(int tagnum, int typenum) if (flag) { // -- Call explicit constructor, error if no constructor. if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp, new_name); + G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp(), new_name()); } G__decl = 0; if (G__struct.iscpplink[tagnum] == G__CPPLINK) { @@ -3106,17 +3113,17 @@ void G__define_var(int tagnum, int typenum) if (G__struct.iscpplink[tagnum] == G__CPPLINK) { if ((reg.tagnum == tagnum) && (reg.type == 'u')) { if (reg.obj.i < 0) { - sprintf(temp, "%s((%s)(%ld))", G__struct.name[tagnum], G__struct.name[tagnum], G__int(reg)); + temp.Format("%s((%s)(%ld))", G__struct.name[tagnum], G__struct.name[tagnum], G__int(reg)); } else { - sprintf(temp, "%s((%s)%ld)", G__struct.name[tagnum], G__struct.name[tagnum], G__int(reg)); + temp.Format("%s((%s)%ld)", G__struct.name[tagnum], G__struct.name[tagnum], G__int(reg)); } } else { - char tttt[G__ONELINE]; + G__FastAllocString tttt(G__ONELINE); #define G__OLDIMPLEMENTATION1780 // FIXME: Should this be removed? G__valuemonitor(reg, tttt); - sprintf(temp, "%s(%s)", G__struct.name[tagnum], tttt); + temp.Format("%s(%s)", G__struct.name[tagnum], tttt()); } #ifndef G__OLDIMPLEMENTATION1073 if (G__asm_wholefunction) { @@ -3195,7 +3202,7 @@ void G__define_var(int tagnum, int typenum) } else { if (G__var_type == 'u') { - G__fprinterr(G__serr, "Error: %s not allocated(2), maybe duplicate declaration ", new_name); + G__fprinterr(G__serr, "Error: %s not allocated(2), maybe duplicate declaration ", new_name()); G__genericerror(0); } // else OK because this is type name[]; @@ -3328,7 +3335,7 @@ void G__define_var(int tagnum, int typenum) // // type var1, var2, var3; // ^ - cin = G__fgetstream(new_name, ",;=():"); + cin = G__fgetstream(new_name, 0, ",;=():"); if (cin == EOF) { // -- Reached end of input file, syntax error, missing semicolon, return. G__decl = store_decl; @@ -3359,13 +3366,13 @@ void G__define_var(int tagnum, int typenum) // if (new_name[0] == '&') { G__reftype = G__PARAREFERENCE; - strcpy(temp, new_name + 1); - strcpy(new_name, temp); + temp = new_name + 1; + new_name = temp; } else if ((new_name[0] == '*') && (new_name[1] == '&')) { G__reftype = G__PARAREFERENCE; - sprintf(temp, "*%s", new_name + 2); - strcpy(new_name, temp); + temp.Format("*%s", new_name + 2); + new_name = temp; } } } @@ -3421,8 +3428,6 @@ G__var_array* G__incmemvar(G__var_array* memvar, int* pindex, G__value* pbuf) // None. -} // extern "C" - /* * Local Variables: * c-tab-always-indent:nil diff --git a/cint/cint/src/disp.cxx b/cint/cint/src/disp.cxx index 3b879831b4efd3a3a76c095c07e34f9cec187311..5f5cade201e2d6fcb272dfd24dcd4fef08a84ee7 100644 --- a/cint/cint/src/disp.cxx +++ b/cint/cint/src/disp.cxx @@ -259,9 +259,8 @@ int G__more_pause(FILE *fp,int len) * judgement for pause *************************************************/ if(shownline>=dispsize || onemore) { - char buf[G__MAXNAME]; shownline=0; - strcpy(buf,G__input("-- Press return for more -- (input [number] of lines, Cont,Step,More) ")); + G__FastAllocString buf(G__input("-- Press return for more -- (input [number] of lines, Cont,Step,More) ")); if(isdigit(buf[0])) { /* change display size */ dispsize = G__int(G__calc_internal(buf)); if(dispsize>0) store_dispsize = dispsize; @@ -321,11 +320,11 @@ void G__display_purevirtualfunc(int /* tagnum */) ***********************************************************************/ int G__display_friend(FILE *fp,G__friendtag*friendtag) { - char msg[G__LONGLINE]; - sprintf(msg," friend "); + G__FastAllocString msg(" friend "); if(G__more(fp,msg)) return(1); while(friendtag) { - sprintf(msg,"%s,",G__fulltagname(friendtag->tagnum,1)); + msg = G__fulltagname(friendtag->tagnum,1); + msg += ","; if(G__more(fp,msg)) return(1); friendtag = friendtag->next; } @@ -346,8 +345,8 @@ int G__listfunc(FILE *fp,int access,const char *fname,G__ifunc_table *ifunc) int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *iref, char friendlyStyle) { int i,n; - char temp[G__ONELINE]; - char msg[G__LONGLINE]; + G__FastAllocString temp(G__ONELINE); + G__FastAllocString msg(G__LONGLINE); G__browsing=1; @@ -359,11 +358,11 @@ int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *ire if (showHeader) { if (!friendlyStyle || -1==ifunc->tagnum) { - sprintf(msg,"%-15sline:size busy function type and name ","filename"); + msg.Format("%-15sline:size busy function type and name ","filename"); if(G__more(fp,msg)) return(1); } if(-1!=ifunc->tagnum) { - sprintf(msg,"(in %s)\n",G__struct.name[ifunc->tagnum]); + msg.Format("(in %s)\n",G__struct.name[ifunc->tagnum]); if(G__more(fp,msg)) return(1); } else { @@ -389,7 +388,7 @@ int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *ire /* print out file name and line number */ if(ifunc->pentry[i]->filenum>=0) { - sprintf(msg,"%-15s%4d:%-3d%c%2d " + msg.Format("%-15s%4d:%-3d%c%2d " ,G__stripfilename(G__srcfile[ifunc->pentry[i]->filenum].filename) ,ifunc->pentry[i]->line_number #ifdef G__ASM_FUNC @@ -430,39 +429,34 @@ int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *ire } else { if (!friendlyStyle) { - sprintf(msg,"%-15s%4d:%-3d%3d " ,"(compiled)" ,0,0 ,ifunc->busy[i]); + msg.Format("%-15s%4d:%-3d%3d " ,"(compiled)" ,0,0 ,ifunc->busy[i]); if(G__more(fp,msg)) return(1); } } if(ifunc->hash[i]) - sprintf(msg,"%s ",G__access2string(ifunc->access[i])); + msg.Format("%s ",G__access2string(ifunc->access[i])); else - sprintf(msg,"------- "); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"------- ")) return(1); if(ifunc->isexplicit[i]) { - sprintf(msg,"explicit "); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"explicit ")) return(1); } #ifndef G__NEWINHERIT if(ifunc->isinherit[i]) { - sprintf(msg,"inherited "); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"inherited ")) return(1); } #endif if(ifunc->isvirtual[i]) { - sprintf(msg,"virtual "); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"virtual ")) return(1); } if(ifunc->staticalloc[i]) { - sprintf(msg,"static "); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"static ")) return(1); } /* print out type of return value */ - sprintf(msg,"%s ",G__type2string(ifunc->type[i] + msg.Format("%s ",G__type2string(ifunc->type[i] ,ifunc->p_tagtable[i] ,ifunc->p_typetable[i] ,ifunc->reftype[i] @@ -476,41 +470,41 @@ int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *ire * print out type and name of function and parameters **********************************************************/ /* print out function name */ - if(strlen(ifunc->funcname[i])>=sizeof(msg)-6) { - strncpy(msg,ifunc->funcname[i],sizeof(msg)-3); - msg[sizeof(msg)-6]=0; - strcat(msg,"...("); + if(strlen(ifunc->funcname[i])>=msg.Capacity()-6) { + strncpy(msg,ifunc->funcname[i],msg.Capacity()-3); + msg[msg.Capacity()-6]=0; + msg += "...("; } else { if (friendlyStyle) { - sprintf(msg,"%s::",parentname); + msg = parentname; + msg += "::"; if(G__more(fp,msg)) return(1); } - sprintf(msg,"%s(",ifunc->funcname[i]); + msg = ifunc->funcname[i]; + msg += "("; } if(G__more(fp,msg)) return(1); if(ifunc->ansi[i] && 0==ifunc->para_nu[i]) { - sprintf(msg,"void"); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"void")) return(1); } /* print out parameter types */ for(n=0;n<ifunc->para_nu[i];n++) { if(n!=0) { - sprintf(msg,","); - if(G__more(fp,msg)) return(1); + if(G__more(fp,",")) return(1); } /* print out type of return value */ #ifndef G__OLDIMPLEMENATTION401 - sprintf(msg,"%s",G__type2string(ifunc->param[i][n]->type + msg = G__type2string(ifunc->param[i][n]->type ,ifunc->param[i][n]->p_tagtable ,ifunc->param[i][n]->p_typetable ,ifunc->param[i][n]->reftype - ,ifunc->param[i][n]->isconst)); + ,ifunc->param[i][n]->isconst); #else - sprintf(msg,"%s",G__type2string(ifunc->param[i][n]->type + msg = G__type2string(ifunc->param[i][n]->type ,ifunc->param[i][n]->p_tagtable ,ifunc->param[i][n]->p_typetable ,ifunc->param[i][n]->reftype)); @@ -518,34 +512,30 @@ int G__listfunc_pretty(FILE *fp,int access,const char *fname,G__ifunc_table *ire if(G__more(fp,msg)) return(1); if(ifunc->param[i][n]->name) { - sprintf(msg," %s",ifunc->param[i][n]->name); + msg.Format(" %s",ifunc->param[i][n]->name); if(G__more(fp,msg)) return(1); } if(ifunc->param[i][n]->def) { - sprintf(msg,"=%s",ifunc->param[i][n]->def); + msg.Format("=%s",ifunc->param[i][n]->def); if(G__more(fp,msg)) return(1); } } if(2==ifunc->ansi[i]) { - sprintf(msg," ..."); - if(G__more(fp,msg)) return(1); + ; + if(G__more(fp," ...")) return(1); } - sprintf(msg,")"); - if(G__more(fp,msg)) return(1); + if(G__more(fp,")")) return(1); if(ifunc->isconst[i]&G__CONSTFUNC) { - sprintf(msg," const"); - if(G__more(fp,msg)) return(1); + if(G__more(fp," const")) return(1); } if(ifunc->ispurevirtual[i]) { - sprintf(msg,"=0"); - if(G__more(fp,msg)) return(1); + if(G__more(fp,"=0")) return(1); } - sprintf(msg,";"); - if(G__more(fp,msg)) return(1); + if(G__more(fp,";")) return(1); temp[0] = '\0'; G__getcomment(temp,&ifunc->comment[i],ifunc->tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fp,msg)) return(1); } if(ifunc->friendtag[i]) @@ -574,31 +564,31 @@ int G__showstack(FILE *fout) { int temp,temp1; struct G__var_array *local; - char syscom[G__MAXNAME]; - char msg[G__LONGLINE]; + G__FastAllocString syscom(G__MAXNAME); + G__FastAllocString msg(G__LONGLINE); local=G__p_local; temp=0; while(local) { #ifdef G__VAARG - sprintf(msg,"%d ",temp); + msg.Format("%d ",temp); if(G__more(fout,msg)) return(1); if(local->exec_memberfunc && -1!=local->tagnum) { - sprintf(msg,"%s::",G__struct.name[local->tagnum]); + msg.Format("%s::",G__struct.name[local->tagnum]); if(G__more(fout,msg)) return(1); } - sprintf(msg,"%s(",G__get_ifunc_internal(local->ifunc)->funcname[local->ifn]); + msg.Format("%s(",G__get_ifunc_internal(local->ifunc)->funcname[local->ifn]); if(G__more(fout,msg)) return(1); for(temp1=0;temp1<local->libp->paran;temp1++) { if(temp1) { - sprintf(msg,","); + msg.Format(","); if(G__more(fout,msg)) return(1); } G__valuemonitor(local->libp->para[temp1],syscom); if(G__more(fout,syscom)) return(1); } if(-1!=local->prev_filenum) { - sprintf(msg,") [%s: %d]\n" + msg.Format(") [%s: %d]\n" ,G__stripfilename(G__srcfile[local->prev_filenum].filename) ,local->prev_line_number); if(G__more(fout,msg)) return(1); @@ -607,7 +597,7 @@ int G__showstack(FILE *fout) if(G__more(fout,") [entry]\n")) return(1); } #else - sprintf(msg,"%d %s() [%s: %d]\n" ,temp ,local->ifunc->funcname[local->ifn] + msg.Format("%d %s() [%s: %d]\n" ,temp ,local->ifunc->funcname[local->ifn] ,G__filenameary[local->prev_filenum] ,local->prev_line_number); if(G__more(fout,msg)) return(1) ; #endif @@ -673,24 +663,24 @@ int G__display_string(FILE *fout) int len; unsigned long totalsize=0; struct G__ConstStringList *pconststring; - char msg[G__ONELINE]; + G__FastAllocString msg(G__ONELINE); pconststring = G__plastconststring; while(pconststring->prev) { len=strlen(pconststring->string); totalsize+=len+1; - if(totalsize>=sizeof(msg)-5) { - sprintf(msg,"%3d ",len); - strncpy(msg+4,pconststring->string,sizeof(msg)-5); - msg[sizeof(msg)-1]=0; + if(totalsize>=msg.Capacity()-5) { + msg.Format("%3d ",len); + strncpy(msg+4,pconststring->string,msg.Capacity()-5); + msg[msg.Capacity()-1]=0; } else { - sprintf(msg,"%3d %s\n",len,pconststring->string); + msg.Format("%3d %s\n",len,pconststring->string); } if(G__more(fout,msg)) return(1); pconststring=pconststring->prev; } - sprintf(msg,"Total string constant size = %ld\n",totalsize); + msg.Format("Total string constant size = %ld\n",totalsize); if(G__more(fout,msg)) return(1); return(0); } @@ -703,27 +693,25 @@ static int G__display_classinheritance(FILE *fout,int tagnum,const char *space) { int i; struct G__inheritance *baseclass; - char addspace[50]; - char temp[G__ONELINE]; - char msg[G__LONGLINE]; + G__FastAllocString addspace(50); + G__FastAllocString temp(G__ONELINE); + G__FastAllocString msg(G__LONGLINE); baseclass = G__struct.baseclass[tagnum]; if(NULL==baseclass) return(0); - sprintf(addspace,"%s ",space); + addspace.Format("%s ",space); for(i=0;i<baseclass->basen;i++) { if(baseclass->herit[i]->property&G__ISDIRECTINHERIT) { - sprintf(msg,"%s0x%-8lx ",space ,baseclass->herit[i]->baseoffset); + msg.Format("%s0x%-8lx ",space ,baseclass->herit[i]->baseoffset); if(G__more(fout,msg)) return(1); if(baseclass->herit[i]->property&G__ISVIRTUALBASE) { - sprintf(msg,"virtual "); - if(G__more(fout,msg)) return(1); + if(G__more(fout,"virtual ")) return(1); } if(baseclass->herit[i]->property&G__ISINDIRECTVIRTUALBASE) { - sprintf(msg,"(virtual) "); - if(G__more(fout,msg)) return(1); + if(G__more(fout,"(virtual) ")) return(1); } sprintf(msg,"%s %s" ,G__access2string(baseclass->herit[i]->baseaccess) @@ -733,7 +721,7 @@ static int G__display_classinheritance(FILE *fout,int tagnum,const char *space) G__getcomment(temp,&G__struct.comment[baseclass->herit[i]->basetagnum] ,baseclass->herit[i]->basetagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + sprintf(msg," //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -824,8 +812,8 @@ int G__display_class(FILE *fout, char *name,int base,int start) int tagnum; int i,j; struct G__inheritance *baseclass; - char temp[G__ONELINE]; - char msg[G__LONGLINE]; + G__FastAllocString temp(G__ONELINE); + G__FastAllocString msg(G__LONGLINE); char *p; int store_globalcomp; int store_iscpp; @@ -842,51 +830,51 @@ int G__display_class(FILE *fout, char *name,int base,int start) if(base) { /* In case of 'Class' command */ for(i=0;i<G__struct.alltag;i++) { - sprintf(temp,"%d",i); + temp.Format("%d",i); G__display_class(fout,temp,0,0); } return(0); } /* no class name specified, list up all tagnames */ if(G__more(fout,"List of classes\n")) return(1); - sprintf(msg,"%-15s%5s\n","file","line"); + msg.Format("%-15s%5s\n","file","line"); if(G__more(fout,msg)) return(1); for(i=start;i<G__struct.alltag;i++) { if(!G__browsing) return(0); switch(G__struct.iscpplink[i]) { case G__CLINK: - if (G__struct.filenum[i] == -1) sprintf(msg,"%-20s " ,"(C compiled)"); + if (G__struct.filenum[i] == -1) msg.Format("%-20s " ,"(C compiled)"); else - sprintf(msg,"%-15s%5d " + msg.Format("%-15s%5d " ,G__stripfilename(G__srcfile[G__struct.filenum[i]].filename) ,G__struct.line_number[i]); if(G__more(fout,msg)) return(1); break; case G__CPPLINK: - if (G__struct.filenum[i] == -1) sprintf(msg,"%-20s " ,"(C++ compiled)"); + if (G__struct.filenum[i] == -1) msg.Format("%-20s " ,"(C++ compiled)"); else - sprintf(msg,"%-15s%5d " + msg.Format("%-15s%5d " ,G__stripfilename(G__srcfile[G__struct.filenum[i]].filename) ,G__struct.line_number[i]); if(G__more(fout,msg)) return(1); break; case 1: - sprintf(msg,"%-20s " ,"(C compiled old 1)"); + msg.Format("%-20s " ,"(C compiled old 1)"); if(G__more(fout,msg)) return(1); break; case 2: - sprintf(msg,"%-20s " ,"(C compiled old 2)"); + msg.Format("%-20s " ,"(C compiled old 2)"); if(G__more(fout,msg)) return(1); break; case 3: - sprintf(msg,"%-20s " ,"(C compiled old 3)"); + msg.Format("%-20s " ,"(C compiled old 3)"); if(G__more(fout,msg)) return(1); break; default: if (G__struct.filenum[i] == -1) - sprintf(msg,"%-20s " ," "); + msg.Format("%-20s " ," "); else - sprintf(msg,"%-15s%5d " + msg.Format("%-15s%5d " ,G__stripfilename(G__srcfile[G__struct.filenum[i]].filename) ,G__struct.line_number[i]); if(G__more(fout,msg)) return(1); @@ -901,7 +889,7 @@ int G__display_class(FILE *fout, char *name,int base,int start) G__iscpp=0; /* 'struct','union' or 'namespace' in msg */ store_globalcomp=G__globalcomp; G__globalcomp=G__NOLINK; - sprintf(msg," %s ",G__type2string('u',i,-1,0,0)); + msg.Format(" %s ",G__type2string('u',i,-1,0,0)); G__iscpp=store_iscpp; /* dirty trick reset */ G__globalcomp=store_globalcomp; if(G__more(fout,msg)) return(1); @@ -910,10 +898,9 @@ int G__display_class(FILE *fout, char *name,int base,int start) for(j=0;j<baseclass->basen;j++) { if(baseclass->herit[j]->property&G__ISDIRECTINHERIT) { if(baseclass->herit[j]->property&G__ISVIRTUALBASE) { - sprintf(msg,"virtual "); - if(G__more(fout,msg)) return(1); + if(G__more(fout,"virtual ")) return(1); } - sprintf(msg,"%s%s " + msg.Format("%s%s " ,G__access2string(baseclass->herit[j]->baseaccess) ,G__fulltagname(baseclass->herit[j]->basetagnum,0)); if(G__more(fout,msg)) return(1); @@ -921,13 +908,13 @@ int G__display_class(FILE *fout, char *name,int base,int start) } } if('$'==G__struct.name[i][0]) { - sprintf(msg," (typedef %s)",G__struct.name[i]+1); + msg.Format(" (typedef %s)",G__struct.name[i]+1); if(G__more(fout,msg)) return(1); } temp[0]='\0'; G__getcomment(temp,&G__struct.comment[i],i); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -948,10 +935,9 @@ int G__display_class(FILE *fout, char *name,int base,int start) if((char*)NULL!=strstr(name+i,">>")) { /* dealing with A<A<int>> -> A<A<int> > */ char *pt1; - char tmpbuf[G__ONELINE]; pt1 = strstr(name+i,">>"); ++pt1; - strcpy(tmpbuf,pt1); + G__FastAllocString tmpbuf(pt1); *pt1=' '; ++pt1; strcpy(pt1,tmpbuf); @@ -966,21 +952,21 @@ int G__display_class(FILE *fout, char *name,int base,int start) G__class_autoloading(&tagnum); G__more(fout,"===========================================================================\n"); - sprintf(msg,"%s ",G__tagtype2string(G__struct.type[tagnum])); + msg.Format("%s ",G__tagtype2string(G__struct.type[tagnum])); if(G__more(fout,msg)) return(1); - sprintf(msg,"%s",G__fulltagname(tagnum,0)); + msg.Format("%s",G__fulltagname(tagnum,0)); if(G__more(fout,msg)) return(1); temp[0]='\0'; G__getcomment(temp,&G__struct.comment[tagnum],tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); if (G__struct.filenum[tagnum] == -1) - sprintf(msg," size=0x%x\n" ,G__struct.size[tagnum]); + msg.Format(" size=0x%x\n" ,G__struct.size[tagnum]); else { - sprintf(msg," size=0x%x FILE:%s LINE:%d\n" ,G__struct.size[tagnum] + msg.Format(" size=0x%x FILE:%s LINE:%d\n" ,G__struct.size[tagnum] ,G__stripfilename(G__srcfile[G__struct.filenum[tagnum]].filename) ,G__struct.line_number[tagnum]); } @@ -998,7 +984,7 @@ int G__display_class(FILE *fout, char *name,int base,int start) ); if(G__more(fout,msg)) return(1); if('$'==G__struct.name[tagnum][0]) { - sprintf(msg," (typedef %s)",G__struct.name[tagnum]+1); + msg.Format(" (typedef %s)",G__struct.name[tagnum]+1); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -1035,8 +1021,8 @@ int G__display_typedef(FILE *fout,const char *name,int startin) { int i,j; int start,stop; - char temp[G__ONELINE]; - char msg[G__LONGLINE]; + G__FastAllocString temp(G__ONELINE); + G__FastAllocString msg(G__LONGLINE); i=0; while(name[i]&&isspace(name[i])) i++; @@ -1061,11 +1047,11 @@ int G__display_typedef(FILE *fout,const char *name,int startin) if(!G__browsing) return(0); #ifdef G__TYPEDEFFPOS if(G__newtype.filenum[i]>=0) - sprintf(msg,"%-15s%4d " + msg.Format("%-15s%4d " ,G__stripfilename(G__srcfile[G__newtype.filenum[i]].filename) ,G__newtype.linenum[i]); else - sprintf(msg,"%-15s " ,"(compiled)"); + msg.Format("%-15s " ,"(compiled)"); if(G__more(fout,msg)) return(1); #endif if( @@ -1076,17 +1062,17 @@ int G__display_typedef(FILE *fout,const char *name,int startin) #endif ) { /* pointer to statuc function */ - sprintf(msg,"typedef void* %s",G__newtype.name[i]); + msg.Format("typedef void* %s",G__newtype.name[i]); if(G__more(fout,msg)) return(1); } else if('a'==G__newtype.type[i]) { /* pointer to member */ - sprintf(msg,"typedef G__p2memfunc %s",G__newtype.name[i]); + msg.Format("typedef G__p2memfunc %s",G__newtype.name[i]); if(G__more(fout,msg)) return(1); } else { /* G__typedef may need to be changed to add isconst member */ - sprintf(msg,"typedef %s" ,G__type2string(tolower(G__newtype.type[i]) + msg.Format("typedef %s" ,G__type2string(tolower(G__newtype.type[i]) ,G__newtype.tagnum[i],-1 ,G__newtype.reftype[i] ,G__newtype.isconst[i])); @@ -1094,35 +1080,35 @@ int G__display_typedef(FILE *fout,const char *name,int startin) if(G__more(fout," ")) return(1); if(isupper(G__newtype.type[i])&&G__newtype.nindex[i]) { if(0<=G__newtype.parent_tagnum[i]) - sprintf(msg,"(*%s::%s)" + msg.Format("(*%s::%s)" ,G__fulltagname(G__newtype.parent_tagnum[i],1) ,G__newtype.name[i]); else - sprintf(msg,"(*%s)",G__newtype.name[i]); + msg.Format("(*%s)",G__newtype.name[i]); if(G__more(fout,msg)) return(1); } else { if(isupper(G__newtype.type[i])) { - if(G__newtype.isconst[i]&G__PCONSTVAR) sprintf(msg,"*const "); - else sprintf(msg,"*"); + if(G__newtype.isconst[i]&G__PCONSTVAR) msg.Format("*const "); + else msg.Format("*"); if(G__more(fout,msg)) return(1); } if(0<=G__newtype.parent_tagnum[i]) { - sprintf(msg,"%s::",G__fulltagname(G__newtype.parent_tagnum[i],1)); + msg.Format("%s::",G__fulltagname(G__newtype.parent_tagnum[i],1)); if(G__more(fout,msg)) return(1); } - sprintf(msg,"%s",G__newtype.name[i]); + msg.Format("%s",G__newtype.name[i]); if(G__more(fout,msg)) return(1); } for(j=0;j<G__newtype.nindex[i];j++) { - sprintf(msg,"[%d]",G__newtype.index[i][j]); + msg.Format("[%d]",G__newtype.index[i][j]); if(G__more(fout,msg)) return(1); } } temp[0]='\0'; G__getcommenttypedef(temp,&G__newtype.comment[i],i); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -1140,57 +1126,57 @@ int G__display_eachtemplate(FILE *fout,G__Definedtemplateclass *deftmplt,int det struct G__Definedtemplatememfunc *memfunctmplt; fpos_t store_pos; /* char buf[G__LONGLINE]; */ - char msg[G__LONGLINE]; + G__FastAllocString msg(G__LONGLINE); int c; if(!deftmplt->def_fp) return(0); - sprintf(msg,"%-20s%5d " + msg.Format("%-20s%5d " ,G__stripfilename(G__srcfile[deftmplt->filenum].filename) ,deftmplt->line); if(G__more(fout,msg)) return(1); - sprintf(msg,"template<"); + msg.Format("template<"); if(G__more(fout,msg)) return(1); def_para=deftmplt->def_para; while(def_para) { switch(def_para->type) { case G__TMPLT_CLASSARG: - sprintf(msg,"class "); + msg.Format("class "); if(G__more(fout,msg)) return(1); break; case G__TMPLT_TMPLTARG: - sprintf(msg,"template<class U> class "); + msg.Format("template<class U> class "); if(G__more(fout,msg)) return(1); break; case G__TMPLT_SIZEARG: - sprintf(msg,"size_t "); + msg.Format("size_t "); if(G__more(fout,msg)) return(1); break; default: - sprintf(msg,"%s ",G__type2string(def_para->type,-1,-1,0,0)); + msg.Format("%s ",G__type2string(def_para->type,-1,-1,0,0)); if(G__more(fout,msg)) return(1); break; } - sprintf(msg,"%s",def_para->string); + msg.Format("%s",def_para->string); if(G__more(fout,msg)) return(1); def_para=def_para->next; if(def_para) fprintf(fout,","); else fprintf(fout,">"); G__more_col(1); } - sprintf(msg," class "); + msg.Format(" class "); if(G__more(fout,msg)) return(1); if(-1!=deftmplt->parent_tagnum) { - sprintf(msg,"%s::",G__fulltagname(deftmplt->parent_tagnum,1)); + msg.Format("%s::",G__fulltagname(deftmplt->parent_tagnum,1)); if(G__more(fout,msg)) return(1); } - sprintf(msg,"%s\n",deftmplt->name); + msg.Format("%s\n",deftmplt->name); if(G__more(fout,msg)) return(1); if(detail) { memfunctmplt = &deftmplt->memfunctmplt; while(memfunctmplt->next) { - sprintf(msg,"%-20s%5d " + msg.Format("%-20s%5d " ,G__stripfilename(G__srcfile[memfunctmplt->filenum].filename) ,memfunctmplt->line); if(G__more(fout,msg)) return(1); @@ -1211,7 +1197,7 @@ int G__display_eachtemplate(FILE *fout,G__Definedtemplateclass *deftmplt,int det if(detail) { struct G__IntList *ilist = deftmplt->instantiatedtagnum; while(ilist) { - sprintf(msg," %s\n",G__fulltagname(ilist->i,1)); + msg.Format(" %s\n",G__fulltagname(ilist->i,1)); if(G__more(fout,msg)) return(1); ilist=ilist->next; } @@ -1225,15 +1211,15 @@ int G__display_eachtemplate(FILE *fout,G__Definedtemplateclass *deftmplt,int det ****************************************************************/ int G__display_eachtemplatefunc(FILE *fout, G__Definetemplatefunc *deftmpfunc) { - char msg[G__LONGLINE]; + G__FastAllocString msg(G__LONGLINE); struct G__Templatearg *def_para; struct G__Templatefuncarg *pfuncpara; int i; - sprintf(msg,"%-20s%5d " + msg.Format("%-20s%5d " ,G__stripfilename(G__srcfile[deftmpfunc->filenum].filename) ,deftmpfunc->line); if(G__more(fout,msg)) return(1); - sprintf(msg,"template<"); + msg.Format("template<"); if(G__more(fout,msg)) return(1); def_para=deftmpfunc->def_para; while(def_para) { @@ -1242,23 +1228,23 @@ int G__display_eachtemplatefunc(FILE *fout, G__Definetemplatefunc *deftmpfunc) case G__TMPLT_POINTERARG1: case G__TMPLT_POINTERARG2: case G__TMPLT_POINTERARG3: - sprintf(msg,"class "); + msg.Format("class "); if(G__more(fout,msg)) return(1); break; case G__TMPLT_TMPLTARG: - sprintf(msg,"template<class U> class "); + msg.Format("template<class U> class "); if(G__more(fout,msg)) return(1); break; case G__TMPLT_SIZEARG: - sprintf(msg,"size_t "); + msg.Format("size_t "); if(G__more(fout,msg)) return(1); break; default: - sprintf(msg,"%s ",G__type2string(def_para->type,-1,-1,0,0)); + msg.Format("%s ",G__type2string(def_para->type,-1,-1,0,0)); if(G__more(fout,msg)) return(1); break; } - sprintf(msg,"%s",def_para->string); + msg.Format("%s",def_para->string); if(G__more(fout,msg)) return(1); switch(def_para->type) { case G__TMPLT_POINTERARG3: fprintf(fout,"*"); G__more_col(1); @@ -1270,23 +1256,23 @@ int G__display_eachtemplatefunc(FILE *fout, G__Definetemplatefunc *deftmpfunc) else fprintf(fout,">"); G__more_col(1); } - sprintf(msg," func "); + msg.Format(" func "); if(G__more(fout,msg)) return(1); if(-1!=deftmpfunc->parent_tagnum) { - sprintf(msg,"%s::",G__fulltagname(deftmpfunc->parent_tagnum,1)); + msg.Format("%s::",G__fulltagname(deftmpfunc->parent_tagnum,1)); if(G__more(fout,msg)) return(1); } - sprintf(msg,"%s(",deftmpfunc->name); + msg.Format("%s(",deftmpfunc->name); if(G__more(fout,msg)) return(1); def_para=deftmpfunc->def_para; pfuncpara = &deftmpfunc->func_para; for(i=0;i<pfuncpara->paran;i++) { if(i) { - sprintf(msg,","); + msg.Format(","); if(G__more(fout,msg)) return(1); } if(pfuncpara->argtmplt[i]>0) { - sprintf(msg,"%s",G__gettemplatearg(pfuncpara->argtmplt[i],def_para)); + msg.Format("%s",G__gettemplatearg(pfuncpara->argtmplt[i],def_para)); if(G__more(fout,msg)) return(1); if(isupper(pfuncpara->type[i])) { fprintf(fout,"*"); @@ -1295,18 +1281,18 @@ int G__display_eachtemplatefunc(FILE *fout, G__Definetemplatefunc *deftmpfunc) } else if(pfuncpara->argtmplt[i]<-1) { if(pfuncpara->typenum[i]) - sprintf(msg,"%s<",G__gettemplatearg(pfuncpara->typenum[i],def_para)); + msg.Format("%s<",G__gettemplatearg(pfuncpara->typenum[i],def_para)); else - sprintf(msg,"X<"); + msg.Format("X<"); if(G__more(fout,msg)) return(1); if(pfuncpara->tagnum[i]) - sprintf(msg,"%s>",G__gettemplatearg(pfuncpara->tagnum[i],def_para)); + msg.Format("%s>",G__gettemplatearg(pfuncpara->tagnum[i],def_para)); else - sprintf(msg,"Y>"); + msg.Format("Y>"); if(G__more(fout,msg)) return(1); } else { - sprintf(msg,"%s",G__type2string(pfuncpara->type[i] + msg.Format("%s",G__type2string(pfuncpara->type[i] ,pfuncpara->tagnum[i] ,pfuncpara->typenum[i] ,pfuncpara->reftype[i] @@ -1389,19 +1375,19 @@ int G__display_macro(FILE *fout,const char *name) struct G__var_array *var = &G__global; int ig15; - char msg[G__LONGLINE]; + G__FastAllocString msg(G__LONGLINE); while(name[i]&&isspace(name[i])) i++; while(var) { for(ig15=0;ig15<var->allvar;ig15++) { if(name && name[i] && strcmp(name+i,var->varnamebuf[ig15])!=0) continue; if('p'==var->type[ig15]) { - sprintf(msg,"#define %s %d\n",var->varnamebuf[ig15] + msg.Format("#define %s %d\n",var->varnamebuf[ig15] ,*(int*)var->p[ig15]); G__more(fout,msg); } else if('T'==var->type[ig15]) { - sprintf(msg,"#define %s \"%s\"\n",var->varnamebuf[ig15] + msg.Format("#define %s \"%s\"\n",var->varnamebuf[ig15] ,*(char**)var->p[ig15]); G__more(fout,msg); } @@ -1462,30 +1448,30 @@ int G__display_macro(FILE *fout,const char *name) ****************************************************************/ int G__display_files(FILE *fout) { - char msg[G__ONELINE]; + G__FastAllocString msg(G__ONELINE); int i; for(i=0;i<G__nfile;i++) { if (G__srcfile[i].ispermanentsl==2) { - sprintf(msg,"%3d fp=%14s lines=%-4d*file=\"%s\" " + msg.Format("%3d fp=%14s lines=%-4d*file=\"%s\" " ,i,"via hard link",G__srcfile[i].maxline ,G__srcfile[i].filename); } else if(G__srcfile[i].hasonlyfunc) { - sprintf(msg,"%3d fp=0x%012lx lines=%-4d*file=\"%s\" " + msg.Format("%3d fp=0x%012lx lines=%-4d*file=\"%s\" " ,i,(long)G__srcfile[i].fp,G__srcfile[i].maxline ,G__srcfile[i].filename); } else { - sprintf(msg,"%3d fp=0x%012lx lines=%-4d file=\"%s\" " + msg.Format("%3d fp=0x%012lx lines=%-4d file=\"%s\" " ,i,(long)G__srcfile[i].fp,G__srcfile[i].maxline ,G__srcfile[i].filename); } if(G__more(fout,msg)) return(1); if(G__srcfile[i].prepname) { - sprintf(msg,"cppfile=\"%s\"",G__srcfile[i].prepname); + msg.Format("cppfile=\"%s\"",G__srcfile[i].prepname); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); } - sprintf(msg,"G__MAXFILE = %d\n",G__MAXFILE); + msg.Format("G__MAXFILE = %d\n",G__MAXFILE); if(G__more(fout,"\n")) return(1); return(0); } @@ -1499,7 +1485,7 @@ int G__display_files(FILE *fout) int G__pr(FILE *fout,G__input_file view) { int center,thisline,filenum; - char G__oneline[G__LONGLINE*2]; + G__FastAllocString G__oneline(G__LONGLINE*2); int top,bottom,screen,line=0; fpos_t store_fpos; /* char original[G__MAXFILENAME]; */ @@ -1602,7 +1588,7 @@ int G__pr(FILE *fout,G__input_file view) if(line==thisline) fprintf(fout,">"); else fprintf(fout," "); - fprintf(fout,"\t%s\n",G__oneline); + fprintf(fout,"\t%s\n",G__oneline()); } } @@ -1659,33 +1645,33 @@ int G__dump_tracecoverage(FILE *fout) int G__objectmonitor(FILE *fout,long pobject,int tagnum,const char *addspace) { struct G__inheritance *baseclass; - char space[G__ONELINE]; - char msg[G__LONGLINE]; + G__FastAllocString space(G__ONELINE); + G__FastAllocString msg(G__LONGLINE); int i; - sprintf(space,"%s ",addspace); + space.Format("%s ",addspace); baseclass = G__struct.baseclass[tagnum]; for(i=0;i<baseclass->basen;i++) { if(baseclass->herit[i]->property&G__ISDIRECTINHERIT) { if(baseclass->herit[i]->property&G__ISVIRTUALBASE) { if(0>G__getvirtualbaseoffset(pobject,tagnum,baseclass,i)) { - sprintf(msg,"%s-0x%-7lx virtual ",space + msg.Format("%s-0x%-7lx virtual ",space() ,-1*G__getvirtualbaseoffset(pobject,tagnum,baseclass,i)); } else { - sprintf(msg,"%s0x%-8lx virtual ",space + msg.Format("%s0x%-8lx virtual ",space() ,G__getvirtualbaseoffset(pobject,tagnum,baseclass,i)); } if(G__more(fout,msg)) return(1); msg[0] = 0; switch(baseclass->herit[i]->baseaccess) { - case G__PRIVATE: sprintf(msg,"private: "); break; - case G__PROTECTED: sprintf(msg,"protected: "); break; - case G__PUBLIC: sprintf(msg,"public: "); break; + case G__PRIVATE: msg.Format("private: "); break; + case G__PROTECTED: msg.Format("protected: "); break; + case G__PUBLIC: msg.Format("public: "); break; } if(G__more(fout,msg)) return(1); - sprintf(msg,"%s\n",G__fulltagname(baseclass->herit[i]->basetagnum,1)); + msg.Format("%s\n",G__fulltagname(baseclass->herit[i]->basetagnum,1)); if(G__more(fout,msg)) return(1); #ifdef G__NEVER_BUT_KEEP if(G__objectmonitor(fout @@ -1695,16 +1681,16 @@ int G__objectmonitor(FILE *fout,long pobject,int tagnum,const char *addspace) #endif } else { - sprintf(msg,"%s0x%-8lx ",space ,baseclass->herit[i]->baseoffset); + msg.Format("%s0x%-8lx ",space(),baseclass->herit[i]->baseoffset); if(G__more(fout,msg)) return(1); msg[0] = 0; switch(baseclass->herit[i]->baseaccess) { - case G__PRIVATE: sprintf(msg,"private: "); break; - case G__PROTECTED: sprintf(msg,"protected: "); break; - case G__PUBLIC: sprintf(msg,"public: "); break; + case G__PRIVATE: msg.Format("private: "); break; + case G__PROTECTED: msg.Format("protected: "); break; + case G__PUBLIC: msg.Format("public: "); break; } if(G__more(fout,msg)) return(1); - sprintf(msg,"%s\n",G__fulltagname(baseclass->herit[i]->basetagnum,1)); + msg.Format("%s\n",G__fulltagname(baseclass->herit[i]->basetagnum,1)); if(G__more(fout,msg)) return(1); if(G__objectmonitor(fout ,pobject+baseclass->herit[i]->baseoffset @@ -1726,9 +1712,9 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add { int imon1; long addr; - char space[50]; - char temp[G__ONELINE]; - char msg[G__ONELINE]; + G__FastAllocString space(50); + G__FastAllocString temp(G__ONELINE); + G__FastAllocString msg(G__ONELINE); int startindex,stopindex; int precompiled_private; @@ -1766,7 +1752,7 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add stopindex=startindex+1; } - sprintf(space,"%s ",addspace); + space.Format("%s ",addspace); G__browsing=1; @@ -1781,21 +1767,21 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add #ifdef G__VARIABLEFPOS if(var->filenum[imon1]>=0) - sprintf(msg,"%-15s%4d " + msg.Format("%-15s%4d " , G__stripfilename(G__srcfile[var->filenum[imon1]].filename) ,var->linenum[imon1]); else - sprintf(msg,"%-15s " ,"(compiled)"); + msg.Format("%-15s " ,"(compiled)"); if(G__more(fout,msg)) return(1); #endif - sprintf(msg,"%s",addspace); + msg.Format("%s",addspace); if(G__more(fout,msg)) return(1); - sprintf(msg,"0x%-8lx ",addr); + msg.Format("0x%-8lx ",addr); if(G__more(fout,msg)) return(1); #ifndef G__NEWINHERIT if(var->isinherit[imon1]) { - sprintf(msg,"inherited "); + msg.Format("inherited "); if(G__more(fout,msg)) return(1); } #endif @@ -1807,14 +1793,14 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add /* fprintf(fout,"public: "); */ break; case G__PROTECTED: - sprintf(msg,"protected: "); + msg.Format("protected: "); if(G__more(fout,msg)) return(1); if(-1!=var->tagnum && G__CPPLINK==G__struct.iscpplink[var->tagnum]) { precompiled_private=1; } break; case G__PRIVATE: - sprintf(msg,"private: "); + msg.Format("private: "); if(G__more(fout,msg)) return(1); if(-1!=var->tagnum && G__CPPLINK==G__struct.iscpplink[var->tagnum]) { precompiled_private=1; @@ -1826,40 +1812,40 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add case G__AUTO : /* auto */ break; case G__LOCALSTATIC : /* static for function */ - sprintf(msg,"static "); + msg.Format("static "); if(G__more(fout,msg)) return(1); break; case G__LOCALSTATICBODY : /* body for function static */ - sprintf(msg,"body of static "); + msg.Format("body of static "); if(G__more(fout,msg)) return(1); break; default : /* static for file 0,1,2,... */ if(var->statictype[imon1]>=0) { /* bug fix */ - sprintf(msg,"file=%s static " + msg.Format("file=%s static " ,G__srcfile[var->statictype[imon1]].filename); if(G__more(fout,msg)) return(1); } else { - sprintf(msg,"static "); + msg.Format("static "); if(G__more(fout,msg)) return(1); } break; } - sprintf(msg,"%s" + msg.Format("%s" ,G__type2string((int)var->type[imon1],var->p_tagtable[imon1] ,var->p_typetable[imon1],var->reftype[imon1] ,var->constvar[imon1])); if(G__more(fout,msg)) return(1); - sprintf(msg," "); + msg.Format(" "); if(G__more(fout,msg)) return(1); - sprintf(msg,"%s",var->varnamebuf[imon1]); + msg.Format("%s",var->varnamebuf[imon1]); if(G__more(fout,msg)) return(1); if (var->varlabel[imon1][1] /* num of elements */ || var->paran[imon1]) { for (int ixxx = 0; ixxx < var->paran[imon1]; ++ixxx) { if (ixxx) { // -- Not a special case dimension, just print it. - sprintf(msg, "[%d]", var->varlabel[imon1][ixxx+1]); + msg.Format( "[%d]", var->varlabel[imon1][ixxx+1]); if (G__more(fout, msg)) { return 1; } @@ -1873,7 +1859,7 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add } else { // -- Special case dimension, first dimension must be calculated. - sprintf(msg, "[%d]", var->varlabel[imon1][1] /* num of elements */ / var->varlabel[imon1][0] /* stride */); + msg.Format( "[%d]", var->varlabel[imon1][1] /* num of elements */ / var->varlabel[imon1][0] /* stride */); if (G__more(fout, msg)) { return 1; } @@ -1882,7 +1868,7 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add } if (var->bitfield[imon1]) { - sprintf(msg, " : %d (%d)", var->bitfield[imon1], var->varlabel[imon1][G__MAXVARDIM-1]); + msg.Format( " : %d (%d)", var->bitfield[imon1], var->varlabel[imon1][G__MAXVARDIM-1]); if (G__more(fout, msg)) { return 1; } @@ -1892,7 +1878,7 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add if (!var->varlabel[imon1][1] && !var->paran[imon1]) { switch (var->type[imon1]) { case 'T': - sprintf(msg,"=\"%s\"",*(char**)addr); + msg.Format("=\"%s\"",*(char**)addr); if(G__more(fout,msg)) return(1); break; #ifndef G__OLDIMPLEMENTATION2191 @@ -1902,21 +1888,21 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add #endif case 'p': case 'o': - sprintf(msg,"=%d",*(int*)addr); + msg.Format("=%d",*(int*)addr); if(G__more(fout,msg)) return(1); break; case 'P': case 'O': - sprintf(msg,"=%g",*(double*)addr); + msg.Format("=%g",*(double*)addr); if(G__more(fout,msg)) return(1); break; case 'u': - sprintf(msg," , size=%d",G__struct.size[var->p_tagtable[imon1]]); + msg.Format(" , size=%d",G__struct.size[var->p_tagtable[imon1]]); if(G__more(fout,msg)) return(1); temp[0]='\0'; G__getcomment(temp,&var->comment[imon1],var->tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -1925,67 +1911,67 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add ,"",space,addr)) return(1); break; case 'b': - sprintf(msg,"=%d",*(unsigned char*)addr); + msg.Format("=%d",*(unsigned char*)addr); if(G__more(fout,msg)) return(1); break; case 'c': - sprintf(msg,"=%d ('%c')",*(char*)addr,*(char*)addr); + msg.Format("=%d ('%c')",*(char*)addr,*(char*)addr); if(G__more(fout,msg)) return(1); break; case 's': - sprintf(msg,"=%d",*(short*)addr); + msg.Format("=%d",*(short*)addr); if(G__more(fout,msg)) return(1); break; case 'r': - sprintf(msg,"=%d",*(unsigned short*)addr); + msg.Format("=%d",*(unsigned short*)addr); if(G__more(fout,msg)) return(1); break; case 'i': - sprintf(msg,"=%d",*(int*)addr); + msg.Format("=%d",*(int*)addr); if(G__more(fout,msg)) return(1); break; case 'h': - sprintf(msg,"=%d",*(unsigned int*)addr); + msg.Format("=%d",*(unsigned int*)addr); if(G__more(fout,msg)) return(1); break; case 'l': - sprintf(msg,"=%ld",*(long*)addr); + msg.Format("=%ld",*(long*)addr); if(G__more(fout,msg)) return(1); break; case 'k': - sprintf(msg,"=0x%lx",*(unsigned long*)addr); + msg.Format("=0x%lx",*(unsigned long*)addr); if(G__more(fout,msg)) return(1); break; case 'f': - sprintf(msg,"=%g",*(float*)addr); + msg.Format("=%g",*(float*)addr); if(G__more(fout,msg)) return(1); break; case 'd': - sprintf(msg,"=%g",*(double*)addr); + msg.Format("=%g",*(double*)addr); if(G__more(fout,msg)) return(1); break; case 'g': #ifdef G__BOOL4BYTE - sprintf(msg,"=%d",(*(int*)addr)?1:0); + msg.Format("=%d",(*(int*)addr)?1:0); #else - sprintf(msg,"=%d",(*(unsigned char*)addr)?1:0); + msg.Format("=%d",(*(unsigned char*)addr)?1:0); #endif if(G__more(fout,msg)) return(1); break; case 'n': /* long long */ - sprintf(msg,"=%lld",(*(G__int64*)addr)); + msg.Format("=%lld",(*(G__int64*)addr)); if(G__more(fout,msg)) return(1); break; case 'm': /* unsigned long long */ - sprintf(msg,"=%llu",(*(G__uint64*)addr)); + msg.Format("=%llu",(*(G__uint64*)addr)); if(G__more(fout,msg)) return(1); break; case 'q': /* long double */ - sprintf(msg,"=%Lg",(*(long double*)addr)); + msg.Format("=%Lg",(*(long double*)addr)); if(G__more(fout,msg)) return(1); break; default: - sprintf(msg,"=0x%lx",*(long*)addr); + msg.Format("=0x%lx",*(long*)addr); if(G__more(fout,msg)) return(1); break; } @@ -1995,20 +1981,20 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add switch(var->type[imon1]) { case 'c': if(isprint(*(char*)addr)) - sprintf(msg,"=0x%lx=\"%s\"",addr,(char*)addr); + msg.Format("=0x%lx=\"%s\"",addr,(char*)addr); else - sprintf(msg,"=0x%lx",addr); + msg.Format("=0x%lx",addr); if(G__more(fout,msg)) return(1); break; default: - sprintf(msg,"=0x%lx",addr); + msg.Format("=0x%lx",addr); if(G__more(fout,msg)) return(1); break; } temp[0]='\0'; G__getcomment(temp,&var->comment[imon1],var->tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -2016,12 +2002,12 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add } else { if('u'==var->type[imon1]) { - sprintf(msg," , size=%d",G__struct.size[var->p_tagtable[imon1]]); + msg.Format(" , size=%d",G__struct.size[var->p_tagtable[imon1]]); if(G__more(fout,msg)) return(1); temp[0]='\0'; G__getcomment(temp,&var->comment[imon1],var->tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -2033,7 +2019,7 @@ int G__varmonitor(FILE *fout,G__var_array *var,const char *index,const char *add temp[0]='\0'; G__getcomment(temp,&var->comment[imon1],var->tagnum); if(temp[0]) { - sprintf(msg," //%s",temp); + msg.Format(" //%s",temp()); if(G__more(fout,msg)) return(1); } if(G__more(fout,"\n")) return(1); @@ -2413,7 +2399,7 @@ int G__system(char *com) * G__tmpfile() **************************************************************************/ const char* G__tmpfilenam() { - char dirname[MAX_PATH]; + G__FastAllocString dirname(MAX_PATH); static char filename[MAX_PATH]; if (!::GetTempPath(MAX_PATH, dirname)) return 0; if (!::GetTempFileName(dirname, "cint_", 0, filename)) return 0; diff --git a/cint/cint/src/end.cxx b/cint/cint/src/end.cxx index ce91a538487316b1395a9e90f2c67024264a4ded..192e80ab0a0f61d5c767ff0d8cae7a1d494d37db 100644 --- a/cint/cint/src/end.cxx +++ b/cint/cint/src/end.cxx @@ -46,12 +46,13 @@ int G__call_atexit() { // -- Execute atexit function. // Note: atexit is reset before calling the function to avoid recursive atexit call. - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); if (G__breaksignal) { G__fprinterr(G__serr, "!!! atexit() call\n"); } G__ASSERT(G__atexit); - sprintf(temp, "%s()", G__atexit); + temp = G__atexit; + temp += "()"; G__atexit = 0; G__getexpr(temp); return 0; diff --git a/cint/cint/src/error.cxx b/cint/cint/src/error.cxx index b90360647de1b0b075a034097e615d131c58892d..f8e6cf88425bc1b28971d8de3046f74aa2a40412 100644 --- a/cint/cint/src/error.cxx +++ b/cint/cint/src/error.cxx @@ -267,14 +267,13 @@ int G__warnundefined(const char* item) ) { char *p = (char*)strchr(item, '('); if (p) { - char tmp[G__ONELINE]; - strcpy(tmp, item); + G__FastAllocString tmp(item); p = (char*)G__strrstr(tmp, "::"); if (p) { *p = 0; p += 2; G__fprinterr(G__serr, - "Error: Function %s is not defined in %s ", p, tmp); + "Error: Function %s is not defined in %s ", p, tmp()); } else { G__fprinterr(G__serr, @@ -283,13 +282,12 @@ int G__warnundefined(const char* item) } } else { - char tmp[G__ONELINE]; - strcpy(tmp, item); + G__FastAllocString tmp(item); if (p) { *p = 0; p += 2; G__fprinterr(G__serr, - "Error: Symbol %s is not defined in %s ", p, tmp); + "Error: Symbol %s is not defined in %s ", p, tmp()); } else { G__fprinterr(G__serr, @@ -411,14 +409,14 @@ int G__changeconsterror(const char* item, const char* categ) int G__pounderror() { // -- #error xxx - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); char *p; fgets(buf, G__ONELINE, G__ifile.fp); p = strchr(buf, '\n'); if (p) *p = '\0'; p = strchr(buf, '\r'); if (p) *p = '\0'; - G__fprinterr(G__serr, "#error %s\n", buf); + G__fprinterr(G__serr, "#error %s\n", buf()); G__CHECK(G__SECURE_EXIT_AT_ERROR, 1, G__return = G__RETURN_EXIT1); #ifdef G__SECURITY G__security_error = G__RECOVERABLE; diff --git a/cint/cint/src/expr.cxx b/cint/cint/src/expr.cxx index 2f81dbc7d40584509bbb782baea7557ca0052d34..cc542f345cf23f2e97ad34789534330a0f16b910 100644 --- a/cint/cint/src/expr.cxx +++ b/cint/cint/src/expr.cxx @@ -16,8 +16,6 @@ #include "common.h" #include "value.h" -extern "C" { - // Static functions. static void G__getiparseobject(G__value* result, char* item); static G__value G__conditionaloperator(G__value defined, const char* expression, int ig1, char* ebuf); @@ -27,6 +25,8 @@ static int G__getpointer2memberfunc(const char* item, G__value* presult); #endif // G__PTR2MEMFUNC static int G__getoperator(int newoperator, int oldoperator); +extern "C" { + // External functions. char* G__setiparseobject(G__value* result, char* str); G__value G__calc_internal(const char* exprwithspace); @@ -43,6 +43,8 @@ int G__lasterror(); void G__reset_lasterror(); G__value G__calc(const char* exprwithspace); +} // extern "C" + #ifndef G__ROOT #define G__NOPOWEROPR #endif // G__ROOT @@ -933,6 +935,7 @@ static int G__getoperator(int newoperator, int oldoperator) // //______________________________________________________________________________ +extern "C" char* G__setiparseobject(G__value* result, char* str) { // -- @@ -948,6 +951,7 @@ char* G__setiparseobject(G__value* result, char* str) } //______________________________________________________________________________ +extern "C" G__value G__calc_internal(const char* exprwithspace) { // -- Grand entry for C/C++ expression evaluator. @@ -1085,6 +1089,7 @@ G__value G__calc_internal(const char* exprwithspace) } //______________________________________________________________________________ +extern "C" G__value G__getexpr(const char* expression) { // -- Grand entry for C/C++ expression evaluator. Space chars must be removed. @@ -1096,12 +1101,8 @@ G__value G__getexpr(const char* expression) int op = 0; /* operator stack pointer */ int unaopr[G__STACKDEPTH]; /* unary operator stack */ int up = 0; /* unary operator stack pointer */ - char vv[G__BUFLEN]; - char *ebuf = vv; - int lenbuf = 0; /* ebuf pointer */ int c; /* temp char */ int ig1 = 0; /* input expression pointer */ - int length; /* length of input expression */ int nest = 0; /* parenthesis nesting state variable */ int single_quote = 0, double_quote = 0; /* quotation flags */ int iscastexpr = 0; /* whether this expression start with a cast */ @@ -1114,20 +1115,18 @@ G__value G__getexpr(const char* expression) int store_no_exec_compile_and[G__STACKDEPTH]; int store_no_exec_compile_or[G__STACKDEPTH]; G__value vtmp_and, vtmp_or; + // // Return null for no expression. // - length = strlen(expression); + int length = strlen(expression); if (!length) { return G__null; } - if (strlen(expression) > (G__BUFLEN - 2)) { - ebuf = (char*) malloc(strlen(expression) + 6); - } - if (!ebuf) { - G__genericerror("Internal error: malloc, G__getexpr(), ebuf"); - return G__null; - } + + G__FastAllocString ebuf(length); + int lenbuf = 0; + // // Operator expression. // @@ -1153,7 +1152,6 @@ G__value G__getexpr(const char* expression) case '(': /* new(arena) type(), (type)val, (expr) */ if ((nest == 0) && (single_quote == 0) && (double_quote == 0) && lenbuf == 3 && strncmp(expression + inew, "new", 3) == 0) { /* ON994 */ - if (vv != ebuf) free((void*) ebuf); return(G__new_operator(expression + ig1)); } /* no break here */ @@ -1188,7 +1186,6 @@ G__value G__getexpr(const char* expression) case ' ': /* new type, new (arena) type */ if ((nest == 0) && (single_quote == 0) && (double_quote == 0)) { if (lenbuf - inew == 3 && strncmp(expression + inew, "new", 3) == 0) { /* ON994 */ - if (vv != ebuf) free((void*)ebuf); return(G__new_operator(expression + ig1 + 1)); } /* else ignore c, shoud not happen, but not sure */ @@ -1244,7 +1241,7 @@ G__value G__getexpr(const char* expression) if (G__defined_templateclass(ebuf)) { ++ig1; ebuf[lenbuf++] = c; - c = G__getstream_template(expression, &ig1, ebuf + lenbuf, ">"); + c = G__getstream_template(expression, &ig1, ebuf, lenbuf, ">"); lenbuf = strlen(ebuf); ebuf[lenbuf++] = c; ebuf[lenbuf] = '\0'; @@ -1260,14 +1257,14 @@ G__value G__getexpr(const char* expression) )) { ++ig1; ebuf[lenbuf++] = c; - c = G__getstream_template(expression, &ig1, ebuf + lenbuf, ">"); - if ('>' == c) strcat(ebuf, ">"); + c = G__getstream_template(expression, &ig1, ebuf, lenbuf, ">"); + if ('>' == c) ebuf += ">"; lenbuf = strlen(ebuf); - c = G__getstream_template(expression, &ig1, ebuf + lenbuf, "("); - if ('(' == c) strcat(ebuf, "("); + c = G__getstream_template(expression, &ig1, ebuf, lenbuf, "("); + if ('(' == c) ebuf += "("; lenbuf = strlen(ebuf); - c = G__getstream_template(expression, &ig1, ebuf + lenbuf, ")"); - if (')' == c) strcat(ebuf, ")"); + c = G__getstream_template(expression, &ig1, ebuf, lenbuf, ")"); + if (')' == c) ebuf += ")"; lenbuf = strlen(ebuf); --ig1; break; @@ -1279,10 +1276,9 @@ G__value G__getexpr(const char* expression) /* TODO, implement casts, may need to introduce new instruction */ ++ig1; ebuf[0] = '('; - c = G__getstream_template(expression, &ig1, ebuf + 1, ">"); + c = G__getstream_template(expression, &ig1, ebuf, 1, ">"); lenbuf = strlen(ebuf); - ebuf[lenbuf++] = ')'; - ebuf[lenbuf] = '\0'; + ebuf += ")"; --ig1; break; } @@ -1427,7 +1423,6 @@ G__value G__getexpr(const char* expression) ebuf[ig1] = '\0'; G__var_type = store_var_type; vstack[0] = G__letvariable(ebuf, defined, &G__global, G__p_local); - if (vv != ebuf) free((void*)ebuf); return(vstack[0]); } inew = ig1 + 1; @@ -1442,9 +1437,6 @@ G__value G__getexpr(const char* expression) G__RESTORE_ANDOPR G__RESTORE_OROPR vstack[1] = G__conditionaloperator(vstack[0], expression, ig1, ebuf); - if (vv != ebuf) { - free(ebuf); - } return vstack[1]; } else { @@ -1473,18 +1465,16 @@ G__value G__getexpr(const char* expression) G__RESTORE_NOEXEC_OROPR G__RESTORE_ANDOPR G__RESTORE_OROPR - if (vv != ebuf) { - free((void*) ebuf); - } return vstack[0]; } //______________________________________________________________________________ +extern "C" G__value G__getprod(char* expression1) { // -- G__value defined1, reg; - char ebuf1[G__ONELINE]; + G__FastAllocString ebuf1(G__ONELINE); int operator1, prodpower = 0; int lenbuf1 = 0; int ig11, ig2; @@ -1518,17 +1508,17 @@ G__value G__getprod(char* expression1) if (single_quote == 0) { double_quote ^= 1; } - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); break; case '\'' : /* single quote */ if (double_quote == 0) { single_quote ^= 1; } - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); break; case '*': if (strncmp(expression1, "new ", 4) == 0) { - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); break; } case '/': @@ -1540,17 +1530,17 @@ G__value G__getprod(char* expression1) break; default: if (operator1 == '\0') operator1 = '*'; - ebuf1[lenbuf1] = '\0'; + ebuf1.Set(lenbuf1, 0); reg = G__getpower(ebuf1); G__bstore(operator1, reg, &defined1); lenbuf1 = 0; - ebuf1[0] = '\0'; + ebuf1[0] = 0; operator1 = expression1[ig11]; break; } } else { - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); } break; case '(': @@ -1558,21 +1548,21 @@ G__value G__getprod(char* expression1) case '{': if ((double_quote == 0) && (single_quote == 0)) { nest1++; - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); } else { - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); } break; case ')': case ']': case '}': if ((double_quote == 0) && (single_quote == 0)) { - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); nest1--; } else { - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); } break; case '@': @@ -1581,21 +1571,21 @@ G__value G__getprod(char* expression1) if ((nest1 == 0) && (single_quote == 0) && (double_quote == 0)) { prodpower = 1; } - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); break; case '\\' : - ebuf1[lenbuf1++] = expression1[ig11++]; - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11++]); + ebuf1.Set(lenbuf1++, expression1[ig11]); break; default: - ebuf1[lenbuf1++] = expression1[ig11]; + ebuf1.Set(lenbuf1++, expression1[ig11]); break; } } - ebuf1[lenbuf1] = '\0'; + ebuf1.Set(lenbuf1, 0); if ((nest1 != 0) || (single_quote != 0) || (double_quote != 0)) { G__parenthesiserror(expression1, "G__getprod"); return(G__null); @@ -1611,11 +1601,12 @@ G__value G__getprod(char* expression1) } //______________________________________________________________________________ +extern "C" G__value G__getpower(const char* expression2) { // -- G__value defined2, reg; - char ebuf2[G__ONELINE]; + G__FastAllocString ebuf2(G__ONELINE); int operator2; int lenbuf2 = 0; int ig12; @@ -1634,13 +1625,13 @@ G__value G__getpower(const char* expression2) if (single_quote == 0) { double_quote ^= 1; } - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); break; case '\'' : /* single quote */ if (double_quote == 0) { single_quote ^= 1; } - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); break; case '~': /* 1's complement */ /* explicit destructor handled in G__getexpr(), just go through here */ @@ -1651,17 +1642,17 @@ G__value G__getpower(const char* expression2) operator2 = G__getoperator(operator2, expression2[ig12]); break; default: - ebuf2[lenbuf2] = '\0'; + ebuf2.Set(lenbuf2, 0); reg = G__getitem(ebuf2); G__bstore(operator2, reg, &defined2); lenbuf2 = 0; - ebuf2[0] = '\0'; + ebuf2[0] = 0; operator2 = expression2[ig12]; break; } } else { - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); } break; case ' ': @@ -1680,36 +1671,36 @@ G__value G__getpower(const char* expression2) case '{': if ((double_quote == 0) && (single_quote == 0)) { nest2++; - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); } else { - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); } break; case ')': case ']': case '}': if ((double_quote == 0) && (single_quote == 0)) { - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); nest2--; } else { - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); } break; case '\\' : - ebuf2[lenbuf2++] = expression2[ig12++]; - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12++]); + ebuf2.Set(lenbuf2++, expression2[ig12]); break; default : - ebuf2[lenbuf2++] = expression2[ig12]; + ebuf2.Set(lenbuf2++, expression2[ig12]); break; } ig12++; } - ebuf2[lenbuf2] = '\0'; + ebuf2.Set(lenbuf2, 0); if ((nest2 != 0) || (single_quote != 0) || (double_quote != 0)) { G__parenthesiserror(expression2, "G__getpower"); return(G__null); @@ -1720,6 +1711,7 @@ G__value G__getpower(const char* expression2) } //______________________________________________________________________________ +extern "C" G__value G__getitem(const char* item) { // -- @@ -1975,6 +1967,7 @@ G__value G__getitem(const char* item) } //______________________________________________________________________________ +extern "C" int G__test(const char* expr) { G__value result = G__getexpr(expr); @@ -1985,6 +1978,7 @@ int G__test(const char* expr) } //______________________________________________________________________________ +extern "C" int G__btest(int operator2, G__value lresult, G__value rresult) { // -- @@ -2047,6 +2041,7 @@ int G__btest(int operator2, G__value lresult, G__value rresult) // //______________________________________________________________________________ +extern "C" int G__lasterror() { // -- @@ -2054,6 +2049,7 @@ int G__lasterror() } //______________________________________________________________________________ +extern "C" void G__reset_lasterror() { // -- @@ -2061,6 +2057,7 @@ void G__reset_lasterror() } //______________________________________________________________________________ +extern "C" G__value G__calc(const char* exprwithspace) { // -- Grand entry for C/C++ expression evaluator. @@ -2088,8 +2085,6 @@ G__value G__calc(const char* exprwithspace) return(result); } -} // extern "C" - /* * Local Variables: * c-tab-always-indent:nil diff --git a/cint/cint/src/fproto.h b/cint/cint/src/fproto.h index 948e6bdd6b4a5a8eb1045f714de1b3826297579c..843a072ee8943d87c5999e8fd8b5dee1b70c3b69 100644 --- a/cint/cint/src/fproto.h +++ b/cint/cint/src/fproto.h @@ -23,6 +23,7 @@ namespace Cint { class G__DataMemberHandle; } +class G__FastAllocString; extern "C" { #endif @@ -149,15 +150,20 @@ int G__test(const char *expression2); int G__btest(int operator2,G__value lresult,G__value rresult); int G__fgetspace(void); int G__fgetspace_peek(void); -int G__fgetvarname(char *string,const char *endmark); -int G__fgetname(char *string,const char *endmark); -int G__getname(const char* source,int* isrc,char *string,const char *endmark); -int G__fdumpstream(char *string,const char *endmark); -int G__fgetstream(char *string,const char *endmark); -void G__fgetstream_peek(char* string, int nchars); -int G__fignorestream(const char *endmark); +#ifdef __cplusplus +} // extern "C" +int G__fgetvarname(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetname(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getname(const char* source,int* isrc,G__FastAllocString& string,const char *endmark); +int G__fgetstream(G__FastAllocString& string, size_t offset, const char *endmark); +void G__fgetstream_peek(G__FastAllocString& string, int nchars); +int G__fgetstream_new(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fdumpstream(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getcommentstring(G__FastAllocString& buf,int tagnum,struct G__comment_info *pcomment); +extern "C" { +#endif int G__ignorestream(const char *string,int* isrc,const char *endmark); -int G__fgetstream_new(char *string,const char *endmark); +int G__fignorestream(const char *endmark); void G__fignoreline(void); void G__fignoreline_peek(void); void G__fsetcomment(struct G__comment_info *pcomment); @@ -296,7 +302,6 @@ void G__cppif_genconstructor(FILE *fp,FILE *hfp,int tagnum,int ifn,struct G__ifu int G__isprivateconstructor(int tagnum,int iscopy); void G__cppif_gendefault(FILE *fp,FILE *hfp,int tagnum,int ifn,struct G__ifunc_table_internal *ifunc,int isconstructor,int iscopyconstructor,int isdestructor,int isassignmentoperator,int isnonpublicnew); void G__cppif_genfunc(FILE *fp,FILE *hfp,int tagnum,int ifn,struct G__ifunc_table_internal *ifunc); -int G__cppif_returntype(FILE *fp,int ifn,struct G__ifunc_table_internal *ifunc,char *endoffunc); void G__cppif_paratype(FILE *fp,int ifn,struct G__ifunc_table_internal *ifunc,int k); void G__cpplink_tagtable(FILE *pfp,FILE *hfp); #ifdef G__VIRTUALBASE @@ -336,11 +341,9 @@ struct G__ifunc_table_internal *G__get_methodhandle4(char *funcname #endif //G__NOSTUBS void G__setnewtype_settypeum(int typenum); -int G__separate_parameter(char *original,int *pos,char *param); int G__parse_parameter_link(char *paras); int G__cppif_p2memfunc(FILE *fp); int G__set_sizep2memfunc(FILE *fp); -int G__getcommentstring(char *buf,int tagnum,struct G__comment_info *pcomment); void G__bstore(int operatorin,G__value expressionin,G__value *defined); void G__doubleassignbyref(G__value *defined,double val); void G__intassignbyref(G__value *defined,G__int64 val); @@ -404,9 +407,7 @@ void G__asm_get_strip_quotation(G__value *pval); G__value G__strip_quotation(const char *string); char *G__charaddquote(char *string,char c); G__value G__strip_singlequotation(char *string); -char *G__add_quotation(char *string,char *temp); char *G__tocharexpr(char *result7); -char *G__string(G__value buf,char *temp); char *G__quotedstring(char *buf,char *result); char *G__logicstring(G__value buf,int dig,char *result); int G__revprint(FILE *fp); @@ -433,13 +434,26 @@ int G__checkset_charlist(char *tname,struct G__Charlist *pcall_para,int narg,int int G__class_autoloading(int* tagnum); void G__define_struct(char type); G__value G__classassign(long pdest,int tagnum,G__value result); -int G__cattemplatearg(char *tagname,struct G__Charlist *charlist); char *G__catparam(struct G__param *libp,int catn,const char *connect); -int G__fgetname_template(char *string,const char *endmark); -int G__fgetstream_newtemplate(char *string,const char *endmark); -int G__fgetstream_template(char *string,const char *endmark); -int G__fgetstream_spaces(char *string,const char *endmark); -int G__getstream_template(const char *source,int *isrc,char *string,const char *endmark); +#ifdef __cplusplus +} // extern "C" +int G__readline_FastAlloc(FILE* fp, G__FastAllocString& line, G__FastAllocString& argbuf, + int* argn, char* arg[]); +int G__separate_parameter(const char *original,int *pos,G__FastAllocString& param); +int G__cppif_returntype(FILE *fp,int ifn,struct G__ifunc_table_internal *ifunc,G__FastAllocString& endoffunc); +char *G__string(G__value buf, G__FastAllocString& temp); +char *G__add_quotation(const char* string,G__FastAllocString& temp); +int G__cattemplatearg(G__FastAllocString& tagname,struct G__Charlist *charlist); +int G__fgetname_template(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_newtemplate(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_template(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_spaces(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getstream_template(const char *source,int *isrc,G__FastAllocString& string, size_t offset, const char *endmark); +char* G__rename_templatefunc(G__FastAllocString& funcname); +int G__templatesubstitute(G__FastAllocString& symbol,struct G__Charlist *callpara,struct G__Templatearg *defpara,const char *templatename,const char *tagname,int c,int npara,int isnew); +char *G__valuemonitor(G__value buf,G__FastAllocString& temp); +extern "C" { +#endif void G__IntList_init(struct G__IntList *body,long iin,struct G__IntList *prev); struct G__IntList* G__IntList_new(long iin,struct G__IntList *prev); void G__IntList_add(struct G__IntList *body,long iin); @@ -455,8 +469,7 @@ struct G__Definetemplatefunc *G__defined_templatememfunc(const char *name); void G__declare_template(void); int G__gettemplatearglist(const char *paralist,struct G__Charlist *charlist,struct G__Templatearg *def_para,int *pnpara,int parent_tagnum); int G__instantiate_templateclass(const char *tagname,int noerror); -void G__replacetemplate(char *templatename,const char *tagname,struct G__Charlist *callpara,FILE *def_fp,int line,int filenum,fpos_t *pdef_pos,struct G__Templatearg *def_para,int isclasstemplate,int npara,int parent_tagnum); -int G__templatesubstitute(char *symbol,struct G__Charlist *callpara,struct G__Templatearg *defpara,const char *templatename,const char *tagname,int c,int npara,int isnew); +void G__replacetemplate(const char* templatename,const char *tagname,struct G__Charlist *callpara,FILE *def_fp,int line,int filenum,fpos_t *pdef_pos,struct G__Templatearg *def_para,int isclasstemplate,int npara,int parent_tagnum); void G__freedeftemplateclass(struct G__Definedtemplateclass *deftmpclass); void G__freetemplatememfunc(struct G__Definedtemplatememfunc *memfunctmplt); char *G__gettemplatearg(int n,struct G__Templatearg *def_para); @@ -469,10 +482,8 @@ int G__templatefunc(G__value *result,const char *funcname,struct G__param *libp, int G__matchtemplatefunc(struct G__Definetemplatefunc *deftmpfunc,struct G__param *libp,struct G__Charlist *pcall_para,int funcmatch); int G__createtemplatefunc(char *funcname,struct G__Templatearg *targ,int line_number,fpos_t *ppos); void G__define_type(void); -char *G__valuemonitor(G__value buf,char *temp); const char *G__access2string(int caccess); const char *G__tagtype2string(int tagtype); -char* G__rename_templatefunc(char* funcname,int isrealloc); char *G__fulltypename(int typenum); int G__val2pointer(G__value *result7); char *G__getbase(unsigned int expression,int base,int digit,char *result1); @@ -523,8 +534,14 @@ int G__appendautocc(FILE *fp); int G__isautoccupdate(void); int G__free_exceptionbuffer(void); -int G__exec_catch(char* statement); +#ifdef __cplusplus +} // extern "C" + +int G__exec_catch(G__FastAllocString& statement); + +extern "C" { +#endif void G__cppstub_memfunc(FILE* fp); void G__cppstub_func(FILE* fp); diff --git a/cint/cint/src/fread.cxx b/cint/cint/src/fread.cxx index c9e70c2b545137743838022a6bc2a98cb0a64de6..72b9c589107dcf1639872ea14f7d1c6a506b96ea 100644 --- a/cint/cint/src/fread.cxx +++ b/cint/cint/src/fread.cxx @@ -15,29 +15,30 @@ #include "common.h" +int G__fgetvarname(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetname_template(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_newtemplate(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_template(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getstream_template(const char* source, int* isrc,G__FastAllocString& string, size_t offset, const char* endmark); +int G__fgetname(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getname(const char* source, int* isrc, char* string, const char* endmark); +int G__getfullpath(char* string, char* pbegin, int i); +int G__fdumpstream(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream(G__FastAllocString& string, size_t offset, const char *endmark); +void G__fgetstream_peek(char* string, int nchars); +int G__fgetstream_new(G__FastAllocString& string, size_t offset, const char *endmark); +int G__fgetstream_spaces(G__FastAllocString& string, size_t offset, const char *endmark); +int G__getstream(const char* source, int* isrc, char* string, const char* endmark); +static int G__isstoragekeyword(const char* buf); + extern "C" { #ifdef G__MULTIBYTE int G__CodingSystem(int c); #endif // G__MULTIBYTE -static int G__isstoragekeyword(char* buf); -int G__fgetname_template(char* string, const char* endmark); -int G__fgetstream_newtemplate(char* string, const char* endmark); -int G__fgetstream_template(char* string, const char* endmark); -int G__getstream_template(const char* source, int* isrc, char* string, const char* endmark); int G__fgetspace(); int G__fgetspace_peek(); -int G__fgetvarname(char* string, const char* endmark); -int G__fgetname(char* string, const char* endmark); -int G__getname(const char* source, int* isrc, char* string, const char* endmark); -int G__getfullpath(char* string, char* pbegin, int i); -int G__fdumpstream(char* string, const char* endmark); -int G__fgetstream(char* string, const char* endmark); -void G__fgetstream_peek(char* string, int nchars); -int G__fgetstream_new(char* string, const char* endmark); -int G__fgetstream_spaces(char* string, const char* endmark); -int G__getstream(const char* source, int* isrc, char* string, const char* endmark); int G__fignorestream(const char* endmark); int G__ignorestream(const char* source, int* isrc, const char* endmark); void G__fignoreline(); @@ -46,9 +47,11 @@ int G__fgetline(char* string); void G__fsetcomment(G__comment_info* pcomment); void G__set_eolcallback(void* eolcallback); int G__fgetc(); +} // extern "C" #ifdef G__MULTIBYTE //______________________________________________________________________________ +extern "C" int G__CodingSystem(int c) { c &= 0x7f; @@ -74,7 +77,7 @@ int G__CodingSystem(int c) #endif // G__MULTIBYTE //______________________________________________________________________________ -static int G__isstoragekeyword(char* buf) +static int G__isstoragekeyword(const char* buf) { if (!buf) return(0); if (strcmp(buf, "const") == 0 || @@ -102,7 +105,7 @@ static int G__isstoragekeyword(char* buf) } //______________________________________________________________________________ -int G__fgetname_template(char* string, const char* endmark) +int G__fgetname_template(G__FastAllocString& string, size_t offset, const char *endmark) { // char *string : string until the endmark appears // char *endmark : specify endmark characters @@ -124,12 +127,12 @@ int G__fgetname_template(char* string, const char* endmark) // ' azAZ09*&^%/; ' // ----------------^ return(';'); // - short i = 0, l; + size_t i = offset, l; int c, prev; short single_quote = 0, double_quote = 0, flag = 0, spaceflag, ignoreflag; int nest = 0; int tmpltnest = 0; - char *pp = string; + char *pp = string + offset; int pflag = 0; int start_line = G__ifile.line_number; @@ -156,7 +159,7 @@ backtoreadtemplate: case '\r': case '\f': if ((single_quote == 0) && (double_quote == 0)) { - string[i] = '\0'; /* temporarily close the string */ + string.Set(i, 0); /* temporarily close the string */ if (tmpltnest) { if (G__isstoragekeyword(pp)) { if (G__iscpp && strcmp("typename", pp) == 0) { @@ -174,7 +177,7 @@ backtoreadtemplate: pflag = 1; } } - if (strlen(pp) < 8 && strncmp(pp, "typename", 8) == 0 && pp != string) { + if (strlen(pp) < 8 && strncmp(pp, "typename", 8) == 0 && pp != string + offset) { i -= 8; } ignoreflag = 1; @@ -200,7 +203,7 @@ backtoreadtemplate: ) { int lnest = 0; ++nest; - string[i] = '\0'; + string.Set(i, 0); pp = string + i; while (pp > string && (pp[-1] != '<' || lnest) && pp[-1] != ',' && pp[-1] != ' ') { @@ -230,16 +233,16 @@ backtoreadtemplate: case '>': if ((single_quote == 0) && (double_quote == 0) && - strncmp(string, "operator", 8) != 0) { + strncmp(string + offset, "operator", 8) != 0) { --nest; if (tmpltnest) --tmpltnest; if (nest < 0) { - string[i] = '\0'; + string.Set(i, 0); return(c); } else if (i && '>' == string[i-1]) { /* A<A<int> > */ - string[i++] = ' '; + string.Set(i++, ' '); } else if (i > 2 && isspace(string[i-1]) && '>' != string[i-2]) { --i; @@ -251,7 +254,7 @@ backtoreadtemplate: if ((single_quote == 0) && (double_quote == 0)) { --nest; if (nest < 0) { - string[i] = '\0'; + string.Set(i, 0); return(c); } } @@ -260,7 +263,7 @@ backtoreadtemplate: case '/': if ((single_quote == 0) && (double_quote == 0)) { /* comment */ - string[i++] = c ; + string.Set(i++, c); c = G__fgetc(); switch (c) { @@ -286,7 +289,7 @@ backtoreadtemplate: break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -298,12 +301,12 @@ backtoreadtemplate: case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetname():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); case '*': case '&': - if (i > 0 && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) + if (i > offset && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) --i; break; @@ -314,7 +317,7 @@ backtoreadtemplate: spaceflag = 1; #ifdef G__MULTIBYTE if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -324,10 +327,10 @@ backtoreadtemplate: if (ignoreflag == 0) { if (pflag && (isalpha(c) || '_' == c)) { - string[i++] = ' ' ; + string.Set(i++, ' '); } pflag = 0; - string[i++] = c ; + string.Set(i++, c); G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); } @@ -345,7 +348,7 @@ backtoreadtemplate: } if (!flag) { if ('<' == c) { - if (strncmp(string, "operator", 8) == 0) string[i++] = c; + if (strncmp(string + offset, "operator", 8) == 0) string.Set(i++, c); flag = ignoreflag = 0; goto backtoreadtemplate; } @@ -355,13 +358,13 @@ backtoreadtemplate: } } - string[i] = '\0'; + string.Set(i, 0); return(c); } //______________________________________________________________________________ -int G__fgetstream_newtemplate(char* string, const char* endmark) +int G__fgetstream_newtemplate(G__FastAllocString& string, size_t offset, const char *endmark) { // char *string : string until the endmark appears // char *endmark : specify endmark characters @@ -386,12 +389,12 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) // 'abc=new xxx;' // 'func(new xxx);' // - short i = 0, l; + size_t i = offset, l; int c, prev; int nest = 0, single_quote = 0, double_quote = 0, flag = 0, ignoreflag; int commentflag = 0; - char *pp = string; - short inew = 0; + char *pp = string + offset; + size_t inew = offset; int start_line = G__ifile.line_number; do { @@ -414,7 +417,7 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) case '\n': case '\r': case '\t': - string[i] = '\0'; + string.Set(i, 0); if (G__isstoragekeyword(pp)) { pp = string + i + 1; commentflag = 0; @@ -448,7 +451,7 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) break; case '<': if ((single_quote == 0) && (double_quote == 0)) { - string[i] = 0; + string.Set(i, 0); if (G__defined_templateclass(pp)) ++nest; inew = i + 1; pp = string + i + 1; @@ -469,7 +472,8 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) if (0 == nest || (i && '-' == string[i-1])) break; else if (nest && i && '>' == string[i-1] && 0 == double_quote && 0 == single_quote - ) string[i++] = ' '; + ) + string.Set(i++, ' '); case '}': case ')': case ']': @@ -493,13 +497,13 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) case '\\': if (ignoreflag == 0) { - string[i++] = c ; + string.Set(i++, c); c = G__fgetc() ; } break; case '/': - if (0 == double_quote && 0 == single_quote && i > 0 && string[i-1] == '/' && + if (0 == double_quote && 0 == single_quote && i > offset && string[i-1] == '/' && commentflag) { i--; G__fignoreline(); @@ -511,14 +515,14 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) break; case '&': - if (i > 0 && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) + if (i > offset && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) --i; break; case '*': /* comment */ if (0 == double_quote && 0 == single_quote) { - if (i > 0 && string[i-1] == '/' && commentflag) { + if (i > offset && string[i-1] == '/' && commentflag) { G__skip_comment(); --i; ignoreflag = 1; @@ -532,7 +536,7 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -544,13 +548,13 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetstream_newtemplate():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -559,20 +563,19 @@ int G__fgetstream_newtemplate(char* string, const char* endmark) } if (ignoreflag == 0) { - string[i++] = c ; - G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); + string.Set(i++, c); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } //______________________________________________________________________________ -int G__fgetstream_template(char* string, const char* endmark) +int G__fgetstream_template(G__FastAllocString& string, size_t offset, const char *endmark) { // char *string : string until the endmark appears // char *endmark : specify endmark characters @@ -594,11 +597,11 @@ int G__fgetstream_template(char* string, const char* endmark) // ' abc );' // -----^ *string="abc"; return(')'); // - short i = 0, l; + size_t i = offset, l; int c, prev; short nest = 0, single_quote = 0, double_quote = 0, flag = 0, ignoreflag; int commentflag = 0; - char *pp = string; + char *pp = string + offset; int pflag = 0; int start_line = G__ifile.line_number; @@ -624,7 +627,7 @@ int G__fgetstream_template(char* string, const char* endmark) case '\t': commentflag = 0; if ((single_quote == 0) && (double_quote == 0)) { - string[i] = '\0'; + string.Set(i, 0); if (G__isstoragekeyword(pp)) { if (G__iscpp && strcmp("typename", pp) == 0) { i -= 8; @@ -647,7 +650,7 @@ int G__fgetstream_template(char* string, const char* endmark) case '<': if ((single_quote == 0) && (double_quote == 0)) { #ifdef G__OLDIMPLEMENTATION1721_YET - string[i] = 0; + string.Set(i, 0); if (G__defined_templateclass(pp)) ++nest; #endif pp = string + i + 1; @@ -677,7 +680,7 @@ int G__fgetstream_template(char* string, const char* endmark) } else if ('>' == c && i && '>' == string[i-1]) { /* A<A<int> > */ - string[i++] = ' '; + string.Set(i++, ' '); } } break; @@ -690,13 +693,13 @@ int G__fgetstream_template(char* string, const char* endmark) case '\\': if (ignoreflag == 0) { - string[i++] = c ; + string.Set(i++, c); c = G__fgetc() ; } break; case '/': - if (0 == double_quote && 0 == single_quote && i > 0 && string[i-1] == '/' && + if (0 == double_quote && 0 == single_quote && i > offset && string[i-1] == '/' && commentflag) { G__fignoreline(); --i; @@ -708,14 +711,14 @@ int G__fgetstream_template(char* string, const char* endmark) break; case '&': - if (i > 0 && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) + if (i > offset && ' ' == string[i-1] && nest && single_quote == 0 && double_quote == 0) --i; break; case '*': /* comment */ #ifndef G__OLDIMPLEMENTATION1864 - if (0 == double_quote && 0 == single_quote && i > 0) { + if (0 == double_quote && 0 == single_quote && i > offset) { if (string[i-1] == '/' && commentflag) { G__skip_comment(); --i; @@ -731,7 +734,7 @@ int G__fgetstream_template(char* string, const char* endmark) } #else - if (0 == double_quote && 0 == single_quote && i > 0 && string[i-1] == '/' && + if (0 == double_quote && 0 == single_quote && i > offset && string[i-1] == '/' && commentflag) { G__skip_comment(); --i; @@ -741,7 +744,7 @@ int G__fgetstream_template(char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -753,7 +756,7 @@ int G__fgetstream_template(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetstream_template():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); /* break; */ @@ -765,7 +768,7 @@ int G__fgetstream_template(char* string, const char* endmark) #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -775,23 +778,23 @@ int G__fgetstream_template(char* string, const char* endmark) if (ignoreflag == 0) { if (pflag && (isalpha(c) || '_' == c)) { - string[i++] = ' ' ; + string.Set(i++, ' '); } pflag = 0; - string[i++] = c ; + string.Set(i++, c); G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } //______________________________________________________________________________ -int G__getstream_template(const char* source, int* isrc, char* string, const char* endmark) +int G__getstream_template(const char* source, int* isrc,G__FastAllocString& string, size_t offset, const char* endmark) { // char *source; : source string. If NULL, read from input file // int *isrc; : char position of the *source if source!=NULL @@ -810,10 +813,10 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha // char *source="abcdefg * hijklmn) ; " // -----------------^ *string="abcdefg*hijklmn" // - short i = 0, l; + size_t i = offset, l; int c, prev; short nest = 0, single_quote = 0, double_quote = 0, flag = 0, ignoreflag; - char *pp = string; + char *pp = string + offset; int pflag = 0; int start_line = G__ifile.line_number; @@ -864,7 +867,7 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha } else if ('>' == c && i && '>' == string[i-1]) { /* A<A<int> > */ - string[i++] = ' '; + string.Set(i++, ' '); } } break; @@ -874,7 +877,7 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha case '\r': case '\t': if ((single_quote == 0) && (double_quote == 0)) { - string[i] = '\0'; + string.Set(i, 0); if (G__isstoragekeyword(pp)) { if (G__iscpp && strcmp("typename", pp) == 0) { i -= 8; @@ -887,7 +890,7 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha } break; } - else if (i>0 && '*' == string[i-1]) { + else if (i>offset && '*' == string[i-1]) { pflag = 1; } ignoreflag = 1; @@ -902,7 +905,7 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__getstream()"); - string[i] = '\0'; + string.Set(i, 0); break; @@ -913,7 +916,7 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -923,17 +926,16 @@ int G__getstream_template(const char* source, int* isrc, char* string, const cha if (ignoreflag == 0) { if (pflag && (isalpha(c) || '_' == c)) { - string[i++] = ' ' ; + string.Set(i++, ' '); } pflag = 0; - string[i++] = c ; - G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); + string.Set(i++, c); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } @@ -1075,16 +1077,17 @@ int G__fgetspace_peek() } //______________________________________________________________________________ -int G__fgetvarname(char* string, const char* endmark) +int G__fgetvarname(G__FastAllocString& string, size_t offset, const char *endmark) { - short i = 0, l; + size_t i = offset; + int l; int c, prev; short nest = 0, single_quote = 0, double_quote = 0, flag = 0, spaceflag = 0, ignoreflag; #ifdef G__TEMPLATEMEMFUNC int tmpltflag = 0; int notmpltflag = 0; #endif - char* pp = string; + char* pp = (char*)string + offset; int start_line = G__ifile.line_number; do { @@ -1108,7 +1111,7 @@ int G__fgetvarname(char* string, const char* endmark) case '\r': case '\f': if ((single_quote == 0) && (double_quote == 0)) { - string[i] = '\0'; + string.Set(i, 0); if (tmpltflag && G__isstoragekeyword(pp)) { c = ' '; pp = string + i + 1; @@ -1137,9 +1140,9 @@ int G__fgetvarname(char* string, const char* endmark) if ((single_quote == 0) && (double_quote == 0)) { pp = string + i + 1; } - if (notmpltflag || (8 == i && strncmp("operator", string, 8) == 0) - || (9 == i && (strncmp("&operator", string, 9) == 0 || - strncmp("*operator", string, 9) == 0)) + if (notmpltflag || (8 == i - offset && strncmp("operator", string() + offset, 8) == 0) + || (9 == i - offset && (strncmp("&operator", string() + offset, 9) == 0 || + strncmp("*operator", string() + offset, 9) == 0)) ) { notmpltflag = 1; break; @@ -1158,7 +1161,8 @@ int G__fgetvarname(char* string, const char* endmark) #ifdef G__TEMPLATEMEMFUNC case '>': if (!tmpltflag) break; - else if (nest && i && '>' == string[i-1]) string[i++] = ' '; + else if (nest && i && '>' == string[i-1]) + string.Set(i++, ' '); #endif case '}': case ')': @@ -1174,7 +1178,7 @@ int G__fgetvarname(char* string, const char* endmark) case '/': if ((single_quote == 0) && (double_quote == 0)) { /* comment */ - string[i++] = c ; + string.Set(i++, c); c = G__fgetc(); switch (c) { @@ -1203,7 +1207,7 @@ int G__fgetvarname(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetvarname():1"); - string[i] = '\0'; + string.Set(i, 0); return(c); default: fseek(G__ifile.fp, -1, SEEK_CUR); @@ -1216,7 +1220,7 @@ int G__fgetvarname(char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -1228,7 +1232,7 @@ int G__fgetvarname(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetvarname():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); case ',': @@ -1239,7 +1243,7 @@ int G__fgetvarname(char* string, const char* endmark) spaceflag = 1; #ifdef G__MULTIBYTE if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -1248,20 +1252,20 @@ int G__fgetvarname(char* string, const char* endmark) } if (ignoreflag == 0) { - string[i++] = c ; + string.Set(i++, c); G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } //______________________________________________________________________________ -int G__fgetname(char* string, const char* endmark) +int G__fgetname(G__FastAllocString& string, size_t offset, const char *endmark) { // char *string : string until the endmark appears // char *endmark : specify endmark characters @@ -1283,7 +1287,7 @@ int G__fgetname(char* string, const char* endmark) // ' azAZ09*&^%/; ' // ----------------^ return(';'); // - short i = 0, l; + size_t i = offset, l; int c, prev; short single_quote = 0, double_quote = 0, flag = 0, spaceflag, ignoreflag; int start_line = G__ifile.line_number; @@ -1336,7 +1340,7 @@ int G__fgetname(char* string, const char* endmark) case '/': if ((single_quote == 0) && (double_quote == 0)) { /* comment */ - string[i++] = c ; + string.Set(i++, c); c = G__fgetc(); switch (c) { @@ -1362,7 +1366,7 @@ int G__fgetname(char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -1374,13 +1378,13 @@ int G__fgetname(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetname():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); default: spaceflag = 1; #ifdef G__MULTIBYTE if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -1389,14 +1393,13 @@ int G__fgetname(char* string, const char* endmark) } if (ignoreflag == 0) { - string[i++] = c ; - G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); + string.Set(i++, c); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } @@ -1504,7 +1507,7 @@ int G__getname(const char* source, int* isrc, char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -1561,7 +1564,7 @@ int G__getfullpath(char* string, char* pbegin, int i) } //______________________________________________________________________________ -int G__fdumpstream(char* string, const char* endmark) +int G__fdumpstream(G__FastAllocString& string, size_t offset, const char *endmark) { // char *string : string until the endmark appears // char *endmark : specify endmark characters @@ -1569,11 +1572,11 @@ int G__fdumpstream(char* string, const char* endmark) // This function is used only for reading pointer to function arguments. // type (*)(....) type(*p2f)(....) // - short i = 0, l; + size_t i = offset, l; int c, prev; short nest = 0, single_quote = 0, double_quote = 0, flag = 0, ignoreflag; int commentflag = 0; - char *pbegin = string; + char *pbegin = string + offset; int tmpltnest = 0; int start_line = G__ifile.line_number; @@ -1600,7 +1603,7 @@ int G__fdumpstream(char* string, const char* endmark) commentflag = 0; if ((single_quote == 0) && (double_quote == 0)) { c = ' '; - if (i > 0 && isspace(string[i-1])) { + if (i > offset && isspace(string[i-1])) { ignoreflag = 1; } else { @@ -1612,7 +1615,7 @@ int G__fdumpstream(char* string, const char* endmark) case '<': if ((single_quote == 0) && (double_quote == 0)) { - string[i] = 0; + string.Set(i, 0); if (G__defined_templateclass(pbegin)) ++tmpltnest; } break; @@ -1656,7 +1659,7 @@ int G__fdumpstream(char* string, const char* endmark) case '\\': if (ignoreflag == 0) { - string[i++] = c ; + string.Set(i++, c); c = G__fgetc() ; } break; @@ -1670,7 +1673,7 @@ int G__fdumpstream(char* string, const char* endmark) case '/': - if (0 == double_quote && 0 == single_quote && i > 0 && string[i-1] == '/' && + if (0 == double_quote && 0 == single_quote && i > offset && string[i-1] == '/' && commentflag) { G__fignoreline(); --i; @@ -1683,7 +1686,7 @@ int G__fdumpstream(char* string, const char* endmark) case '*': /* comment */ - if (0 == double_quote && 0 == single_quote && i > 0 && string[i-1] == '/' && + if (0 == double_quote && 0 == single_quote && i > offset && string[i-1] == '/' && commentflag) { G__skip_comment(); --i; @@ -1700,7 +1703,7 @@ int G__fdumpstream(char* string, const char* endmark) break; case '#': - if (single_quote == 0 && double_quote == 0 && (i == 0 || string[i-1] != '$')) { + if (single_quote == 0 && double_quote == 0 && (i == offset || string[i-1] != '$')) { G__pp_command(); ignoreflag = 1; #ifdef G__TEMPLATECLASS @@ -1712,13 +1715,13 @@ int G__fdumpstream(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fdumpstream():2"); - string[i] = '\0'; + string.Set(i, 0); return(c); #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -1727,20 +1730,19 @@ int G__fdumpstream(char* string, const char* endmark) } if (ignoreflag == 0) { - string[i++] = c ; - G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return(EOF)); + string.Set(i++, c); } } while (flag == 0) ; - string[i] = '\0'; + string.Set(i, 0); return(c); } //______________________________________________________________________________ -int G__fgetstream(char* string, const char* endmark) +int G__fgetstream(G__FastAllocString& string, size_t offset, const char *endmark) { // -- Read source file until specified endmark char appears. // @@ -1762,7 +1764,7 @@ int G__fgetstream(char* string, const char* endmark) // ' abc );' // -----^ *string="abc"; return(')'); // - short i = 0; + size_t i = offset; short l = 0; int c = 0; int prev = 0; @@ -1827,12 +1829,12 @@ int G__fgetstream(char* string, const char* endmark) break; case '\\': if (!ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc(); } break; case '/': - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { G__fignoreline(); --i; ignoreflag = 1; @@ -1847,7 +1849,7 @@ int G__fgetstream(char* string, const char* endmark) break; case '*': // comment - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { G__skip_comment(); --i; ignoreflag = 1; @@ -1865,13 +1867,13 @@ int G__fgetstream(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetstream():2"); - string[i] = '\0'; + string.Set(i, 0); return c; // -- #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -1879,12 +1881,11 @@ int G__fgetstream(char* string, const char* endmark) #endif // G__MULTIBYTE } if (!ignoreflag) { - string[i++] = c; - G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return EOF); + string.Set(i++, c); } } while (!flag); - string[i] = '\0'; + string.Set(i, 0); return c; } @@ -1928,7 +1929,7 @@ void G__fgetstream_peek(char* string, int nchars) } //______________________________________________________________________________ -int G__fgetstream_new(char* string, const char* endmark) +int G__fgetstream_new(G__FastAllocString& string, size_t offset, const char *endmark) { // -- Read source file until specified endmark char appears, keep space after 'new' and 'const' keywords. // @@ -1954,7 +1955,7 @@ int G__fgetstream_new(char* string, const char* endmark) // 'func(new xxx);' // 'func(const int xxx);' // - short i = 0; + size_t i = offset; short l = 0; int c = 0; int prev = 0; @@ -1964,7 +1965,7 @@ int G__fgetstream_new(char* string, const char* endmark) int flag = 0; int ignoreflag = 0; int commentflag = 0; - short inew = 0; + size_t inew = offset; int start_line = G__ifile.line_number; do { ignoreflag = 0; @@ -2045,12 +2046,12 @@ int G__fgetstream_new(char* string, const char* endmark) break; case '\\': if (!ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc(); } break; case '/': - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { --i; G__fignoreline(); ignoreflag = 1; @@ -2061,7 +2062,7 @@ int G__fgetstream_new(char* string, const char* endmark) break; case '*': // comment - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { G__skip_comment(); --i; ignoreflag = 1; @@ -2080,13 +2081,13 @@ int G__fgetstream_new(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetstream_new():2"); - string[i] = '\0'; + string.Set(i, 0); return c; // -- #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc() ; G__CheckDBCS2ndByte(c); } @@ -2095,17 +2096,17 @@ int G__fgetstream_new(char* string, const char* endmark) // -- } if (!ignoreflag) { - string[i++] = c; + string.Set(i++, c); G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return EOF); } } while (!flag); - string[i] = '\0'; + string.Set(i, 0); return c; } //______________________________________________________________________________ -int G__fgetstream_spaces(char* string, const char* endmark) +int G__fgetstream_spaces(G__FastAllocString& string, size_t offset, const char *endmark) { // -- Read source file until specified endmark char appears, retain whitespace (trimmed and collapsed). // @@ -2124,7 +2125,7 @@ int G__fgetstream_spaces(char* string, const char* endmark) // ' abc );' // -----^ *string="abc"; return(')'); // - short i = 0; + size_t i = offset; short l = 0; int c = 0; int prev = 0; @@ -2187,12 +2188,12 @@ int G__fgetstream_spaces(char* string, const char* endmark) break; case '\\': if (!ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc(); } break; case '/': - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { --i; G__fignoreline(); ignoreflag = 1; @@ -2203,7 +2204,7 @@ int G__fgetstream_spaces(char* string, const char* endmark) break; case '*': // comment - if (!double_quote && !single_quote && (i > 0) && (string[i-1] == '/') && commentflag) { + if (!double_quote && !single_quote && (i > offset) && (string[i-1] == '/') && commentflag) { G__skip_comment(); --i; ignoreflag = 1; @@ -2222,13 +2223,13 @@ int G__fgetstream_spaces(char* string, const char* endmark) case EOF: G__fprinterr(G__serr, "Error: Missing one of '%s' expected at or after line %d.\n", endmark, start_line); G__unexpectedEOF("G__fgetstream_new():2"); - string[i] = '\0'; + string.Set(i, 0); return c; // -- #ifdef G__MULTIBYTE default: if (G__IsDBCSLeadByte(c) && !ignoreflag) { - string[i++] = c; + string.Set(i++, c); c = G__fgetc(); G__CheckDBCS2ndByte(c); } @@ -2237,16 +2238,16 @@ int G__fgetstream_spaces(char* string, const char* endmark) // -- } if (!ignoreflag) { - string[i++] = c; + string.Set(i++, c); G__CHECK(G__SECURE_BUFFER_SIZE, i >= G__LONGLINE, return EOF); } last_was_space = (c == ' '); } while (!flag); - while ((i > 0) && (string[i-1] == ' ')) { + while ((i > offset) && (string[i-1] == ' ')) { --i; } - string[i] = '\0'; + string.Set(i, 0); return c; } @@ -2801,8 +2802,6 @@ int G__fgetc_for_peek() return c; } -} // extern "C" - /* * Local Variables: * c-tab-always-indent:nil diff --git a/cint/cint/src/func.cxx b/cint/cint/src/func.cxx index 3b442b359b85b8c2b8619a5852e82e3d22ec8154..b200b2a04fdfa34bd9930c011762fc080ad3216a 100644 --- a/cint/cint/src/func.cxx +++ b/cint/cint/src/func.cxx @@ -187,11 +187,11 @@ void G__p2f_void_void(void *p2f) { switch (G__isinterpretedp2f(p2f)) { case G__INTERPRETEDFUNC: { - char buf[G__ONELINE]; char *fname; fname = G__p2f2funcname(p2f); - sprintf(buf, "%s()", fname); - if (G__asm_dbg) G__fprinterr(G__serr, "(*p2f)() %s interpreted\n", buf); + G__FastAllocString buf(fname); + buf += "()"; + if (G__asm_dbg) G__fprinterr(G__serr, "(*p2f)() %s interpreted\n", buf()); G__calc_internal(buf); } break; @@ -268,15 +268,14 @@ static void G__getindexedvalue(G__value *result3, char *cindex) int size; int index; int len; - char sindex[G__ONELINE]; + G__FastAllocString sindex(cindex); char *p; - strcpy(sindex, cindex); p = strstr(sindex, "]["); if (p) { *(p + 1) = 0; G__getindexedvalue(result3, sindex); p = strstr(cindex, "]["); - strcpy(sindex, p + 1); + sindex = p + 1; } len = strlen(sindex); #ifdef G__OLDIMPLEMENTATION424 @@ -618,13 +617,12 @@ int G__explicit_fundamental_typeconv(char *funcname, int hash, G__param *libp, G } #ifndef G_OLDIMPLEMENTATION1128 if (flag && 'u' == libp->para[0].type) { - char ttt[G__ONELINE]; int xtype = presult3->type; int xreftype = 0; int xisconst = 0; *presult3 = libp->para[0]; G__fundamental_conversion_operator(xtype, -1 , -1 , xreftype, xisconst - , presult3, ttt); + , presult3, 0); } #endif return(flag); @@ -656,15 +654,11 @@ void G__gen_addstros(int addstros) ******************************************************************/ G__value G__pointer2memberfunction(char *parameter0, char *parameter1, int *known3) { - char buf[G__LONGLINE]; - char buf2[G__ONELINE]; - char expr[G__LONGLINE]; + G__FastAllocString buf(parameter0); char* mem; G__value res; const char* opx; - strcpy(buf, parameter0); - if ((mem = strstr(buf, ".*"))) { *mem = 0; mem += 2; @@ -695,9 +689,13 @@ G__value G__pointer2memberfunction(char *parameter0, char *parameter1, int *know /* For the time being, pointer to member function can only be handed as * function name */ - strcpy(buf2, *(char**)res.obj.i); + G__FastAllocString buf2(*(char**)res.obj.i); - sprintf(expr, "%s%s%s%s", buf, opx, buf2, parameter1); + G__FastAllocString expr(G__LONGLINE); + expr = buf; + expr += opx; + expr += buf2; + expr += parameter1; G__abortbytecode(); return(G__getvariable(expr, known3, &G__global, G__p_local)); @@ -721,13 +719,11 @@ G__value G__pointerReference(char *item, G__param *libp, int *known3) *known3 = 1; if (2 == libp->paran && strstr(libp->parameter[1], "][")) { - char arg[G__ONELINE]; + G__FastAllocString arg(libp->parameter[1]); char *p = arg; - int k; - strcpy(p, libp->parameter[1]); i = 1; while (*p) { - k = 0; + int k = 0; if (*p == '[') ++p; while (*p && *p != ']') libp->parameter[i][k++] = *p++; libp->parameter[i][k++] = 0; @@ -738,9 +734,7 @@ G__value G__pointerReference(char *item, G__param *libp, int *known3) } for (i = 1;i < libp->paran;i++) { - char arg[G__ONELINE]; - - strcpy(arg, libp->parameter[i]); + G__FastAllocString arg(libp->parameter[i]); if ('[' == arg[0]) { j = 0; while (arg[++j] && ']' != arg[j]) arg[j-1] = arg[j]; @@ -748,7 +742,7 @@ G__value G__pointerReference(char *item, G__param *libp, int *known3) } if ('u' == result3.type) { /* operator[] overloading */ - char expr[G__ONELINE]; + G__FastAllocString expr(G__ONELINE); /* Set member function environment */ G__tagnum = result3.tagnum; G__typenum = result3.typenum; @@ -769,7 +763,7 @@ G__value G__pointerReference(char *item, G__param *libp, int *known3) #endif /* call operator[] */ *known3 = 0; - sprintf(expr, "operator[](%s)", arg); + expr.Format("operator[](%s)", arg()); result3 = G__getfunction(expr, known3, G__CALLMEMFUNC); /* Restore environment */ G__tagnum = store_tagnum; @@ -810,7 +804,7 @@ int G__additional_paranthesis G__P((G__value* presult, struct G__param* libp)); ******************************************************************/ int G__additional_parenthesis(G__value *presult, G__param *libp) { - char buf[G__LONGLINE]; + G__FastAllocString buf(G__LONGLINE); int known; int store_tagnum = G__tagnum; long store_struct_offset = G__store_struct_offset; @@ -821,7 +815,7 @@ int G__additional_parenthesis(G__value *presult, G__param *libp) G__tagnum = presult->tagnum; G__store_struct_offset = presult->obj.i; - sprintf(buf, "operator()%s", libp->parameter[1]); + buf.Format("operator()%s", libp->parameter[1]); *presult = G__getfunction(buf, &known, G__CALLMEMFUNC); G__tagnum = store_tagnum; @@ -830,10 +824,12 @@ int G__additional_parenthesis(G__value *presult, G__param *libp) return(known); } +} // extern "C" + /****************************************************************** * G__rename_templatefunc() ******************************************************************/ -char* G__rename_templatefunc(char *funcname, int isrealloc) +char* G__rename_templatefunc(G__FastAllocString& funcname) { char *ptmplt ; ptmplt = strchr(funcname, '<'); @@ -848,34 +844,33 @@ char* G__rename_templatefunc(char *funcname, int isrealloc) } } if (ptmplt) { - char funcname2[G__LONGLINE]; - char buf[G__ONELINE]; - char buf2[20]; + G__FastAllocString funcname2(funcname); + G__FastAllocString buf(G__ONELINE); + G__FastAllocString buf2(20); int typenum, tagnum, len; int ip = 1; int c; - strcpy(funcname2, funcname); - strcat(funcname2, "<"); + funcname2 += "<"; do { - c = G__getstream_template(ptmplt, &ip, buf, ",>"); + c = G__getstream_template(ptmplt, &ip, buf, 0, ",>"); len = strlen(buf) - 1; while ('*' == buf[len] || '&' == buf[len]) --len; ++len; if (buf[len]) { - strcpy(buf2, buf + len); + buf2 = buf + len; buf[len] = 0; } else buf2[0] = 0; typenum = G__defined_typename(buf); if (-1 != typenum) { - strcpy(buf, G__fulltypename(typenum)); + buf = G__fulltypename(typenum); } else { tagnum = G__defined_tagname(buf, 1); if (-1 != tagnum) strcpy(buf, G__fulltagname(tagnum, 1)); } - strcat(buf, buf2); - strcat(funcname2, buf); + buf += buf2; + funcname2 += buf; if (funcname2[strlen(funcname2)-1] == '>' && c == '>') { buf2[0] = ' '; buf2[1] = c; @@ -885,24 +880,21 @@ char* G__rename_templatefunc(char *funcname, int isrealloc) buf2[0] = c; buf2[1] = 0; } - strcat(funcname2, buf2); - } - while (c != '>'); - if (isrealloc) { - free((void*)funcname); - funcname = (char*)malloc(strlen(funcname2) + 1); - } - strcpy(funcname, funcname2); + funcname2 += buf2; + } while (c != '>'); + funcname = funcname2; } - return(funcname); + return funcname; } +extern "C" { + /****************************************************************** * G__operatorfunction() * * ******************************************************************/ -G__value G__operatorfunction(G__value *presult, const char *item, int *known3, char *result7, const char *funcname) +G__value G__operatorfunction(G__value *presult, const char *item, int *known3, G__FastAllocString& result7, const char *funcname) { G__value result3 = G__null; struct G__param fpara; @@ -911,7 +903,6 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c int nest = 0; int double_quote = 0, single_quote = 0; int lenitem = strlen(item); - int overflowflag = 0; int castflag = 0; int base1 = 0; int nindex = 0; @@ -964,11 +955,11 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c if ((double_quote == 0) && (single_quote == 0)) nest--; break; case '\\': - result7[ig35++] = item[ig15++]; + result7.Set(ig35++, item[ig15++]); break; case '<': if (double_quote == 0 && single_quote == 0) { - result7[ig35] = 0; + result7.Set(ig35, 0); if (0 == strcmp(result7, "operator") || tmpltnest || G__defined_templateclass(result7)) ++tmpltnest; @@ -980,61 +971,7 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c } break; } - result7[ig35++] = item[ig15++]; - if (ig35 >= G__ONELINE - 1) { - if (result7[0] == '"') { - G__value bufv; - char bufx[G__LONGLINE]; - strncpy(bufx, result7, G__ONELINE - 1); - while ((((item[ig15] != ',') && (item[ig15] != ')')) || - (nest > 0) || (single_quote > 0) || - (double_quote > 0)) && (ig15 < lenitem)) { - switch (item[ig15]) { - case '"' : /* double quote */ - if (single_quote == 0) double_quote ^= 1; - break; - case '\'' : /* single quote */ - if (double_quote == 0) single_quote ^= 1; - break; - case '(': - case '[': - case '{': - if ((double_quote == 0) && (single_quote == 0)) nest++; - break; - case ')': - case ']': - case '}': - if ((double_quote == 0) && (single_quote == 0)) nest--; - break; - case '\\': - bufx[ig35++] = item[ig15++]; - break; - } - bufx[ig35++] = item[ig15++]; - if (ig35 >= G__LONGLINE - 1) { - G__genericerror("Limitation: Too long function argument"); - return(G__null); - } - } - bufx[ig35] = 0; - bufv = G__strip_quotation(bufx); - sprintf(result7, "(char*)(%ld)", bufv.obj.i); - ig35 = strlen(result7) + 1; - break; - } - else if (ig35 > G__LONGLINE - 1) { - G__fprinterr(G__serr, - "Limitation: length of one function argument be less than %d" - , G__LONGLINE); - G__genericerror((char*)NULL); - G__fprinterr(G__serr, "Use temp variable as workaround.\n"); - *known3 = 1; - return(G__null); - } - else { - overflowflag = 1; - } - } + result7.Set(ig35++, item[ig15++]); } /************************************************* * if ')' is found at the middle of expression, @@ -1065,7 +1002,7 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c } else { ++ig15; - result7[ig35] = '\0'; + result7.Set(ig35, 0); strcpy(fpara.parameter[fpara.paran], result7); if (ig35) fpara.parameter[++fpara.paran][0] = '\0'; for (itmp = 0;itmp < fpara.paran;itmp++) { @@ -1084,7 +1021,7 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c * set null char to parameter list buffer. *************************************************/ ig15++; - result7[ig35] = '\0'; + result7.Set(ig35, 0); if (ig35 < G__ONELINE) { strcpy(fpara.parameter[fpara.paran], result7); } @@ -1114,7 +1051,7 @@ G__value G__operatorfunction(G__value *presult, const char *item, int *known3, c G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, int* known3, int memfunc_flag) { G__value result3; - char result7[G__LONGLINE]; + G__FastAllocString result7(G__LONGLINE); int ig15, ipara; static struct G__param *p2ffpara = (struct G__param*)NULL; int hash; @@ -1181,7 +1118,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i for (ipara = 1;ipara <= libp->paran;ipara++) { if (ipara != 1) fprintf(G__dumpfile, ","); G__valuemonitor(libp->para[ipara-1], result7); - fprintf(G__dumpfile, "%s", result7); + fprintf(G__dumpfile, "%s", result7()); } fprintf(G__dumpfile, ");/*%s %d,%lx %lx*/\n" , G__ifile.name, G__ifile.line_number @@ -1215,7 +1152,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); fprintf(G__dumpfile, "/* return(inp) %s.%s()=%s*/\n" - , G__struct.name[G__tagnum], funcname, result7); + , G__struct.name[G__tagnum], funcname, result7()); } #endif if (G__store_struct_offset != store_struct_offset) @@ -1337,7 +1274,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" - , funcname, result7); + , funcname, result7()); } #endif G__exec_memberfunc = store_exec_memberfunc; @@ -1366,8 +1303,8 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i ) { G__fprinterr(G__serr, "Possible candidates are...\n"); { - char itemtmp[G__LONGLINE]; - sprintf(itemtmp, "%s::%s", G__struct.name[G__tagnum], funcname); + G__FastAllocString itemtmp(G__LONGLINE); + itemtmp.Format("%s::%s", G__struct.name[G__tagnum], funcname); G__display_proto_pretty(G__serr, itemtmp, 1); } } @@ -1414,7 +1351,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(inp) %s()=%s*/\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(inp) %s()=%s*/\n" , funcname, result7()); } #endif @@ -1491,7 +1428,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(cmp) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(cmp) %s()=%s */\n" , funcname, result7()); } #endif G__exec_memberfunc = store_exec_memberfunc; @@ -1554,7 +1491,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7()); } #endif @@ -1583,7 +1520,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7()); } #endif G__exec_memberfunc = store_exec_memberfunc; @@ -1614,11 +1551,10 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i strcpy(funcname, G__struct.name[G__newtype.tagnum[i]]); } else { - char ttt[G__ONELINE]; result3 = libp->para[0]; if (G__fundamental_conversion_operator(G__newtype.type[i], -1 , i , G__newtype.reftype[i], 0 - , &result3, ttt)) { + , &result3, 0)) { *known3 = 1; if (oprp) *known3 = G__additional_parenthesis(&result3, libp); return(result3); @@ -1851,7 +1787,7 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i ********************************************************************/ var = G__getvarentry(funcname, hash, &ig15, &G__global, G__p_local); if (var && var->type[ig15] == '1') { - sprintf(result7, "*%s", funcname); + result7.Format("*%s", funcname); *known3 = 0; pfparam = (char*)strchr(item, '('); p2ffpara = libp; @@ -1903,9 +1839,6 @@ G__value G__getfunction_libp(const char* item, char* funcname, G__param* libp, i G__value G__getfunction(const char* item, int* known3, int memfunc_flag) { G__value result3 = G__null; - char funcname[G__LONGLINE]; - int overflowflag = 0; - char result7[G__LONGLINE]; int ig15, ig35, ipara; int lenitem, nest = 0; int single_quote = 0, double_quote = 0; @@ -1964,6 +1897,9 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ******************************************************/ lenitem = strlen(item); + G__FastAllocString result7(lenitem); + G__FastAllocString funcname(lenitem + 24); + /****************************************************** * Scan item[] until '(' to get function name and hash ******************************************************/ @@ -2017,7 +1953,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) /****************************************************** * conv<B>(x) -> conv<ns::B>(x) ******************************************************/ - G__rename_templatefunc(funcname, 0); + G__rename_templatefunc(funcname); // @@ -2068,11 +2004,11 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) if ((double_quote == 0) && (single_quote == 0)) nest--; break; case '\\': - result7[ig35++] = item[ig15++]; + result7.Set(ig35++, item[ig15++]); break; case '<': if (double_quote == 0 && single_quote == 0) { - result7[ig35] = 0; + result7.Set(ig35, 0); char* checkForTemplate = result7; if (checkForTemplate && !strncmp(checkForTemplate, "const ", 6)) checkForTemplate += 6; @@ -2087,62 +2023,8 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) } break; } - result7[ig35++] = item[ig15++]; - if (ig35 >= (G__ONELINE - 1)) { - if (result7[0] == '"') { - G__value bufv; - char bufx[G__LONGLINE]; - strncpy(bufx, result7, G__ONELINE - 1); - while ((((item[ig15] != ',') && (item[ig15] != ')')) || - (nest > 0) || (single_quote > 0) || - (double_quote > 0)) && (ig15 < lenitem)) { - switch (item[ig15]) { - case '"' : /* double quote */ - if (single_quote == 0) double_quote ^= 1; - break; - case '\'' : /* single quote */ - if (double_quote == 0) single_quote ^= 1; - break; - case '(': - case '[': - case '{': - if ((double_quote == 0) && (single_quote == 0)) nest++; - break; - case ')': - case ']': - case '}': - if ((double_quote == 0) && (single_quote == 0)) nest--; - break; - case '\\': - bufx[ig35++] = item[ig15++]; - break; - } - bufx[ig35++] = item[ig15++]; - if (ig35 >= G__LONGLINE - 1) { - G__genericerror("Limitation: Too long function argument"); - return(G__null); - } - } - bufx[ig35] = 0; - bufv = G__strip_quotation(bufx); - sprintf(result7, "(char*)(%ld)", bufv.obj.i); - ig35 = strlen(result7) + 1; - break; - } - else if (ig35 > G__LONGLINE - 1) { - G__fprinterr(G__serr, - "Limitation: length of one function argument be less than %d" - , G__LONGLINE); - G__genericerror((char*)NULL); - G__fprinterr(G__serr, "Use temp variable as workaround.\n"); - *known3 = 1; - return(G__null); - } - else { - overflowflag = 1; - } - } - } + result7.Set(ig35++, item[ig15++]); + } // // If a right parenthesis is found in the middle of an expression, // this should either be casting or a pointer to a function. @@ -2494,11 +2376,11 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ***************************************************************/ if (G__dumpfile != NULL && 0 == G__no_exec_compile) { for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); - fprintf(G__dumpfile, "%s(", funcname); + fprintf(G__dumpfile, "%s(", funcname()); for (ipara = 1;ipara <= fpara.paran;ipara++) { if (ipara != 1) fprintf(G__dumpfile, ","); G__valuemonitor(fpara.para[ipara-1], result7); - fprintf(G__dumpfile, "%s", result7); + fprintf(G__dumpfile, "%s", result7()); } fprintf(G__dumpfile, ");/*%s %d,%lx %lx*/\n" , G__ifile.name, G__ifile.line_number @@ -2541,7 +2423,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) fprintf(G__dumpfile, " "); } G__valuemonitor(result3, result7); - fprintf(G__dumpfile, "/* return(inp) %s.%s()=%s*/\n", G__struct.name[G__tagnum], funcname, result7); + fprintf(G__dumpfile, "/* return(inp) %s.%s()=%s*/\n", G__struct.name[G__tagnum], funcname(), result7()); } #endif // G__DUMPFILE if (G__store_struct_offset != store_struct_offset) { @@ -2671,7 +2553,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" - , funcname, result7); + , funcname(), result7()); } #endif G__exec_memberfunc = store_exec_memberfunc; @@ -2699,8 +2581,8 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ) { G__fprinterr(G__serr, "Possible candidates are...\n"); { - char itemtmp[G__LONGLINE]; - sprintf(itemtmp, "%s::%s", G__struct.name[G__tagnum], funcname); + G__FastAllocString itemtmp(G__LONGLINE); + itemtmp.Format("%s::%s", G__struct.name[G__tagnum], funcname()); G__display_proto_pretty(G__serr, itemtmp, 1); } } @@ -2755,7 +2637,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) fprintf(G__dumpfile, " "); } G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(inp) %s()=%s*/\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(inp) %s()=%s*/\n" , funcname(), result7()); } #endif G__exec_memberfunc = store_exec_memberfunc; @@ -2793,7 +2675,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ****************************************/ #ifdef G__ASM_DBG if (G__asm_dbg) { - G__fprinterr(G__serr, "%3x,%3x: LD_FUNC compiled '%s' paran: %d %s:%d\n", G__asm_cp, G__asm_dt, funcname, fpara.paran, __FILE__, __LINE__); + G__fprinterr(G__serr, "%3x,%3x: LD_FUNC compiled '%s' paran: %d %s:%d\n", G__asm_cp, G__asm_dt, funcname(), fpara.paran, __FILE__, __LINE__); } #endif // G__ASM_DBG G__asm_inst[G__asm_cp] = G__LD_FUNC; @@ -2828,7 +2710,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(cmp) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(cmp) %s()=%s */\n" , funcname(), result7()); } #endif @@ -2856,7 +2738,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ****************************************/ #ifdef G__ASM_DBG if (G__asm_dbg) { - G__fprinterr(G__serr, "%3x,%3x: LD_FUNC library '%s' paran: %d %s:%d\n", G__asm_cp, G__asm_dt, funcname, fpara.paran, __FILE__, __LINE__); + G__fprinterr(G__serr, "%3x,%3x: LD_FUNC library '%s' paran: %d %s:%d\n", G__asm_cp, G__asm_dt, funcname(), fpara.paran, __FILE__, __LINE__); } #endif // G__ASM_DBG G__asm_inst[G__asm_cp] = G__LD_FUNC; @@ -2891,7 +2773,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname(), result7()); } #endif @@ -2918,7 +2800,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) G__dumpspace -= 3; for (ipara = 0;ipara < G__dumpspace;ipara++) fprintf(G__dumpfile, " "); G__valuemonitor(result3, result7); - fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname, result7); + fprintf(G__dumpfile , "/* return(lib) %s()=%s */\n" , funcname(), result7()); } #endif @@ -2949,21 +2831,20 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) G__var_type = store_var_typeX; if (-1 != i) { if (-1 != G__newtype.tagnum[i]) { - strcpy(funcname, G__struct.name[G__newtype.tagnum[i]]); + funcname = G__struct.name[G__newtype.tagnum[i]]; } else { - char ttt[G__ONELINE]; result3 = fpara.para[0]; if (G__fundamental_conversion_operator(G__newtype.type[i], -1 , i , G__newtype.reftype[i], 0 - , &result3, ttt)) { + , &result3, 0)) { *known3 = 1; if (oprp) *known3 = G__additional_parenthesis(&result3, &fpara); return(result3); } - strcpy(funcname, G__type2string(G__newtype.type[i] + funcname = G__type2string(G__newtype.type[i] , G__newtype.tagnum[i] , -1 - , G__newtype.reftype[i] , 0)); + , G__newtype.reftype[i] , 0); } G__hash(funcname, hash, i); } @@ -3038,7 +2919,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) G__fprinterr(G__serr, "!!!Create temp object (%s)0x%lx,%d for %s()\n" , G__struct.name[G__tagnum] , G__p_tempbuf->obj.obj.i - , G__templevel , funcname); + , G__templevel , funcname()); } #ifdef G__ASM if (G__asm_noverflow) { @@ -3106,7 +2987,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) #endif } #endif - sprintf(funcname, "operator %s", G__fulltagname(i, 1)); + funcname.Format("operator %s", G__fulltagname(i, 1)); G__hash(funcname, hash, i); G__incsetup_memfunc(G__tagnum); fpara.paran = 0; @@ -3191,7 +3072,7 @@ G__value G__getfunction(const char* item, int* known3, int memfunc_flag) ********************************************************************/ var = G__getvarentry(funcname, hash, &ig15, &G__global, G__p_local); if (var && var->type[ig15] == '1') { - sprintf(result7, "*%s", funcname); + sprintf(result7, "*%s", funcname()); *known3 = 0; pfparam = (char*)strchr(item, '('); p2ffpara = &fpara; @@ -4923,22 +4804,22 @@ void G__printf_error() return result; \ } -void G__sprintformatll(char* result, const char* fmt, void *p, char* buf) +void G__sprintformatll(char* result, const char* fmt, void *p, G__FastAllocString& buf) { G__int64 *pll = (G__int64*)p; - sprintf(buf, fmt, result, *pll); + buf.Format(fmt, result, *pll); strcpy(result, buf); } -void G__sprintformatull(char* result, const char* fmt, void *p, char* buf) +void G__sprintformatull(char* result, const char* fmt, void *p, G__FastAllocString& buf) { G__uint64 *pll = (G__uint64*)p; - sprintf(buf, fmt, result, *pll); + buf.Format(fmt, result, *pll); strcpy(result, buf); } -void G__sprintformatld(char* result, const char* fmt, void *p, char* buf) +void G__sprintformatld(char* result, const char* fmt, void *p, G__FastAllocString& buf) { long double *pld = (long double*)p; - sprintf(buf, fmt, result, *pld); + buf.Format(fmt, result, *pld); strcpy(result, buf); } @@ -4949,8 +4830,9 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) { int ipara, ichar, lenfmt; int ionefmt = 0, fmtflag = 0; - char onefmt[G__LONGLINE], fmt[G__LONGLINE]; - char pformat[G__LONGLINE]; + G__FastAllocString onefmt(G__LONGLINE); + G__FastAllocString fmt(G__LONGLINE); + G__FastAllocString pformat(G__LONGLINE); short dig = 0; int usedpara = 0; @@ -4961,21 +4843,24 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) for (ichar = 0;ichar <= lenfmt;ichar++) { switch (pformat[ichar]) { case '\0': /* end of the format */ - onefmt[ionefmt] = '\0'; - sprintf(fmt, "%%s%s", onefmt); - sprintf(onefmt, fmt, result); + onefmt.Set(ionefmt, 0); + fmt = "%s"; + fmt += onefmt; + onefmt.Format(fmt(), result); strcpy(result, onefmt); ionefmt = 0; break; case 's': /* string */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); if (fmtflag == 1) { - onefmt[ionefmt] = '\0'; + onefmt.Set(ionefmt, 0); if (libp->para[ipara].obj.i) { G__PRINTF_ERROR(strlen(onefmt) + strlen(result) + - strlen((char*)G__int(libp->para[usedpara])) >= G__LONGLINE) - sprintf(fmt, "%%s%s", onefmt); - sprintf(onefmt, fmt, result , (char *)G__int(libp->para[usedpara])); + strlen((char*)G__int(libp->para[usedpara])) >= G__LONGLINE) { + fmt = "%s"; + fmt += onefmt; + } + onefmt.Format(fmt(), result , (char *)G__int(libp->para[usedpara])); strcpy(result, onefmt); } ipara++; @@ -4984,11 +4869,12 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) } break; case 'c': /* char */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); if (fmtflag == 1) { - onefmt[ionefmt] = '\0'; - sprintf(fmt, "%%s%s", onefmt); - sprintf(onefmt, fmt, result , (char)G__int(libp->para[usedpara])); + onefmt.Set(ionefmt, 0); + fmt= "%s"; + fmt += onefmt; + onefmt.Format(fmt(), result , (char)G__int(libp->para[usedpara])); strcpy(result, onefmt); ipara++; ionefmt = 0; @@ -4996,14 +4882,17 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) } break; case 'b': /* int */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); if (fmtflag == 1) { - onefmt[ionefmt-1] = 's'; - onefmt[ionefmt] = '\0'; - sprintf(fmt, "%%s%s", onefmt); + onefmt.Set(ionefmt-1, 's'); + onefmt.Set(ionefmt, 0); + fmt = "%s"; + fmt += onefmt; G__logicstring(libp->para[usedpara], dig, onefmt); ipara++; - sprintf(result, fmt, result, onefmt); + G__FastAllocString resBuf; + resBuf.Format(fmt(), result, onefmt()); + strcpy(result, resBuf); ionefmt = 0; } break; @@ -5014,10 +4903,11 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) case 'x': /* hex */ case 'X': /* HEX */ case 'p': /* pointer */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); if (fmtflag == 1) { - onefmt[ionefmt] = '\0'; - sprintf(fmt, "%%s%s", onefmt); + onefmt.Set(ionefmt, 0); + fmt = "%s"; + fmt += onefmt; if ('n' == libp->para[usedpara].type) { G__value *pval = &libp->para[usedpara]; ipara++; @@ -5032,32 +4922,31 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) if ( 'u' == libp->para[usedpara].type ) { - char llbuf[100]; + G__FastAllocString llbuf(100); G__value *pval = &libp->para[usedpara]; ipara++; if (strcmp(G__struct.name[pval->tagnum], "G__longlong") == 0) { - sprintf(llbuf - , "G__printformatll((char*)(%ld),(const char*)(%ld),(void*)(%ld))" - , (long)fmt, (long)onefmt, pval->obj.i); + llbuf.Format("G__printformatll((char*)(%ld),(const char*)(%ld),(void*)(%ld))" + , (long)fmt(), (long)onefmt(), pval->obj.i); G__getitem(llbuf); strcat(result, fmt); } else if (strcmp(G__struct.name[pval->tagnum], "G__ulonglong") == 0) { sprintf(llbuf , "G__printformatull((char*)(%ld),(const char*)(%ld),(void*)(%ld))" - , (long)fmt, (long)onefmt, pval->obj.i); + , (long)fmt(), (long)onefmt(), pval->obj.i); G__getitem(llbuf); strcat(result, fmt); } else { ++usedpara; - sprintf(onefmt, fmt , result, G__int(libp->para[usedpara])); + onefmt.Format(fmt(), result, G__int(libp->para[usedpara])); ipara++; strcpy(result, onefmt); } } else { - sprintf(onefmt, fmt , result, G__int(libp->para[usedpara])); + onefmt.Format(fmt(), result, G__int(libp->para[usedpara])); ipara++; strcpy(result, onefmt); } @@ -5070,10 +4959,11 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) case 'f': /* floating */ case 'g': /* floating or exponential */ case 'G': /* floating or exponential */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); if (fmtflag == 1) { - onefmt[ionefmt] = '\0'; - sprintf(fmt, "%%s%s", onefmt); + onefmt.Set(ionefmt, 0); + fmt = "%s"; + fmt += onefmt; if ('q' == libp->para[usedpara].type) { G__value *pval = &libp->para[usedpara]; ipara++; @@ -5083,25 +4973,24 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) if ( 'u' == libp->para[usedpara].type ) { - char llbuf[100]; + G__FastAllocString llbuf(100); G__value *pval = &libp->para[usedpara]; ipara++; if (strcmp(G__struct.name[pval->tagnum], "G__longdouble") == 0) { - sprintf(llbuf - , "G__printformatld((char*)(%ld),(const char*)(%ld),(void*)(%ld))" - , (long)fmt, (long)onefmt, pval->obj.i); + llbuf.Format("G__printformatld((char*)(%ld),(const char*)(%ld),(void*)(%ld))" + , (long)fmt(), (long)onefmt(), pval->obj.i); G__getitem(llbuf); strcat(result, fmt); } else { ++usedpara; - sprintf(onefmt, fmt, result, G__double(libp->para[usedpara])); + onefmt.Format(fmt(), result, G__double(libp->para[usedpara])); ipara++; strcpy(result, onefmt); } } else { - sprintf(onefmt, fmt , result, G__double(libp->para[usedpara])); + onefmt.Format(fmt(), result, G__double(libp->para[usedpara])); ipara++; strcpy(result, onefmt); } @@ -5114,7 +5003,7 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) if ('q' == libp->para[usedpara].type) { G__value *pval = &libp->para[usedpara]; ipara++; - G__sprintformatld(fmt, onefmt, result, &pval->obj.ld); + G__sprintformatld(result, fmt(), &pval->obj.ld, result, onefmt); } break; #endif @@ -5135,7 +5024,7 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) case '+': case 'l': /* long int */ case 'h': /* short int unsinged int */ - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); break; case '%': if (fmtflag == 0) { @@ -5145,18 +5034,19 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) else { fmtflag = 0; } - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); dig = 0; break; case '*': /* printf("%*s",4,"*"); */ if (fmtflag == 1) { + onefmt.Resize(ionefmt + 100); // 100 digits for %ld should suffice sprintf(onefmt + ionefmt, "%ld", G__int(libp->para[usedpara])); ipara++; usedpara++; ionefmt = strlen(onefmt); } else { - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); } break; case '$': @@ -5171,7 +5061,7 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) dig = 0; } else { - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); } break; case ' ': @@ -5181,12 +5071,12 @@ char *G__charformatter(int ifmt, G__param *libp, char *result) case '\f': /* end of line */ if (fmtflag) { if ('%' != onefmt[ionefmt-1] && !isspace(onefmt[ionefmt-1])) fmtflag = 0; - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); break; } default: fmtflag = 0; - onefmt[ionefmt++] = pformat[ichar]; + onefmt.Set(ionefmt++, pformat[ichar]); break; } } diff --git a/cint/cint/src/gcoll.cxx b/cint/cint/src/gcoll.cxx index 76397b0b7c794ea07cebd2f3634ce7302971c109..6830d7ffa5c03f2e446b84fca7e86d9db32a5acc 100644 --- a/cint/cint/src/gcoll.cxx +++ b/cint/cint/src/gcoll.cxx @@ -175,11 +175,11 @@ void G__destroy_garbageobject(G__alloclist *alloc) long store_struct_offset; long store_globalvarpointer; int done=0; - char dtor[G__ONELINE]; + G__FastAllocString dtor(G__ONELINE); if(-1!=alloc->tagnum) { /* Call destructor if class object */ - sprintf(dtor,"~%s()",G__struct.name[alloc->tagnum]); + dtor.Format("~%s()",G__struct.name[alloc->tagnum]); store_globalvarpointer = G__globalvarpointer; store_tagnum = G__tagnum; store_struct_offset = G__store_struct_offset; diff --git a/cint/cint/src/global.h b/cint/cint/src/global.h index 151dbebd8791a1183bb595f657ee97752a0198a4..bfc85d46f3d1457f072df85e348955dcd10f571f 100644 --- a/cint/cint/src/global.h +++ b/cint/cint/src/global.h @@ -163,8 +163,8 @@ extern fpos_t G__nextmacro; extern int G__mline; extern const char *G__macro; extern struct G__Deffuncmacro G__deffuncmacro; -extern char G__macros[G__LONGLINE]; -extern char G__ppopt[G__ONELINE]; +extern char G__macros[16*G__LONGLINE]; +extern char G__ppopt[16*G__ONELINE]; extern char *G__allincludepath; extern const char *G__undeflist; struct G__funcmacro_stackelt; diff --git a/cint/cint/src/global1.cxx b/cint/cint/src/global1.cxx index 8a629c26390819b464ae8b883066f147831215a7..f8bcee700992abe81315d97399a8566e5e6871c6 100644 --- a/cint/cint/src/global1.cxx +++ b/cint/cint/src/global1.cxx @@ -165,8 +165,8 @@ fpos_t G__nextmacro; int G__mline; const char *G__macro="tmpfile"; struct G__Deffuncmacro G__deffuncmacro; -char G__macros[G__LONGLINE]; -char G__ppopt[G__ONELINE]; +char G__macros[16 * G__LONGLINE]; +char G__ppopt[16 * G__ONELINE]; char *G__allincludepath=(char*)NULL; const char *G__undeflist=""; diff --git a/cint/cint/src/ifunc.cxx b/cint/cint/src/ifunc.cxx index d5c385738306d35fe187e8f64615b353ca4014e2..67c0efa4cad3e9d043717a53b26ded0d04cab95e 100644 --- a/cint/cint/src/ifunc.cxx +++ b/cint/cint/src/ifunc.cxx @@ -27,19 +27,6 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now); static int G__calldepth = 0; -//______________________________________________________________________________ -char* G__savestring(char** pbuf, char* name) -{ - // -- FIXME: Describe this function! - G__ASSERT(pbuf); - if (*pbuf) { - free((void*)(*pbuf)); - *pbuf = 0; - } - *pbuf = (char*) malloc(strlen(name) + 1); - return strcpy(*pbuf, name); -} - #ifndef G__OLDIMPLEMENTATION1167 //______________________________________________________________________________ void G__reftypeparam(G__ifunc_table_internal* p_ifunc, int ifn, G__param* libp) @@ -494,8 +481,6 @@ void G__make_ifunctable(char* funcheader) // int iin = 0; int cin = '\0'; - G__FastAllocString paraname_sb(G__LONGLINE); - char *paraname = paraname_sb; int func_now; int iexist; struct G__ifunc_table_internal* ifunc; @@ -557,6 +542,7 @@ void G__make_ifunctable(char* funcheader) G__func_now = G__p_ifunc->allifunc; G__func_page = G__p_ifunc->page; func_now = G__func_now; + G__FastAllocString funcname(G__LONGLINE); if ('~' == funcheader[0] && 0 == ifunc->hash[0]) { G__p_ifunc = ifunc; G__func_now = 0; @@ -569,12 +555,7 @@ void G__make_ifunctable(char* funcheader) while ('*' == funcheader[numstar]) { ++numstar; } - if (strlen(funcheader + 2) > G__LONGLINE - 1) { - G__fprinterr(G__serr, "Limitation: Function name length overflow strlen(%s)>%d", funcheader + 2, G__LONGLINE - 1); - G__genericerror((char*)NULL); - funcheader[G__MAXNAME+1] = 0; - } - G__savestring(&G__p_ifunc->funcname[func_now], funcheader + numstar); + funcname = funcheader + numstar; if (isupper(G__var_type)) { switch (G__reftype) { case G__PARANORMAL: @@ -601,12 +582,7 @@ void G__make_ifunctable(char* funcheader) G__reftype += numstar - 2; } else { - if (strlen(funcheader + 1) > G__LONGLINE - 1) { - G__fprinterr(G__serr, "Limitation: Function name length overflow strlen(%s)>%d", funcheader + 1, G__LONGLINE - 1); - G__genericerror((char*)NULL); - funcheader[G__MAXNAME] = 0; - } - G__savestring(&G__p_ifunc->funcname[func_now], funcheader + 1); + funcname = funcheader + 1; if (isupper(G__var_type)) { switch (G__reftype) { case G__PARANORMAL: @@ -624,13 +600,6 @@ void G__make_ifunctable(char* funcheader) G__var_type = toupper(G__var_type); } else { - char* pt1; - if (strlen(funcheader) > G__LONGLINE - 1) { - funcheader[G__MAXNAME-1] = 0; - G__fprinterr(G__serr, "Limitation: Function name length overflow strlen(%s)>%d", funcheader, G__LONGLINE - 1); - G__genericerror((char*)NULL); - funcheader[G__MAXNAME-1] = 0; - } if (strncmp(funcheader, "operator ", 9) == 0) { char* oprtype = funcheader + 9; if ( @@ -708,23 +677,20 @@ void G__make_ifunctable(char* funcheader) strcat(oprtype, "("); } } - G__savestring(&G__p_ifunc->funcname[func_now], funcheader); + funcname = funcheader; if ( (strstr(funcheader, ">>") != NULL && strchr(funcheader, '<') != NULL) || (strstr(funcheader, "<<") != NULL && strchr(funcheader, '>') != NULL) ) { - int maxpt2 = strlen(G__p_ifunc->funcname[func_now]) + 20; /* allow 20 extra spaces */ - char *pt2 = (char*)malloc(maxpt2); - strcpy(pt2, G__p_ifunc->funcname[func_now]); - free((void*)(G__p_ifunc->funcname[func_now])); - G__p_ifunc->funcname[func_now] = pt2; + char* pt1 = funcheader; + char* pt2 = funcname; if ((char*)NULL != strstr(funcheader, "operator<<") && (char*)NULL != strchr(funcheader, '>')) { /* we might have operator< <> or operator< <double> or operator<< <> or operator<< <double> with the space missing */ - pt2 = pt2 + strlen("operator<"); - pt1 = funcheader + strlen("operator<"); + pt2 += strlen("operator<"); + pt1 += strlen("operator<"); /*char *pt2 = G__p_ifunc->funcname[func_now] + strlen( "operator<" );*/ if (*(pt2 + 1) == '<') { /* we have operator<< <...> */ @@ -740,15 +706,11 @@ void G__make_ifunctable(char* funcheader) /* we might have operator>><> */ /* we have nothing to do ... yet (we may have to do something for nested templates */ - pt2 = pt2 + strlen("operator>>"); - pt1 = funcheader + strlen("operator>>"); - } - else { - pt1 = funcheader; + pt2 += strlen("operator>>"); + pt1 += strlen("operator>>"); } while ((char*)NULL != (pt1 = strstr(pt1, ">>"))) { - char *pt3; - pt3 = strstr(pt2, ">>"); + char *pt3 = strstr(pt2, ">>"); ++pt3; *pt3 = ' '; ++pt3; @@ -758,12 +720,14 @@ void G__make_ifunctable(char* funcheader) } } } - G__p_ifunc->funcname[func_now][strlen(G__p_ifunc->funcname[func_now]) - 1] = '\0'; + + funcname[strlen(funcname) - 1] = 0; // remove trailing '(' /****************************************************** * conv<B>(x) -> conv<ns::B>(x) ******************************************************/ - G__p_ifunc->funcname[func_now] = G__rename_templatefunc(G__p_ifunc->funcname[func_now], 1); - G__hash(G__p_ifunc->funcname[func_now], G__p_ifunc->hash[func_now], iin2); + G__rename_templatefunc(funcname); + + G__hash(funcname, G__p_ifunc->hash[func_now], iin2); G__paramfunc* param = ifunc->param[func_now][0]; param->name = 0; /************************************************************* @@ -772,12 +736,15 @@ void G__make_ifunctable(char* funcheader) *************************************************************/ if ( (G__p_ifunc->hash[func_now] == G__HASH_OPERATOR) && - !strcmp(G__p_ifunc->funcname[func_now], "operator") + !strcmp(funcname, "operator") ) { - char* tmpp = (char*) "operator()"; - G__savestring(&G__p_ifunc->funcname[func_now], tmpp); - G__p_ifunc->hash[func_now] += ('(' + ')'); + funcname = "operator()"; + G__p_ifunc->hash[func_now] += '(' + ')'; } + size_t funcnamelen = strlen(funcname) + 1; + G__p_ifunc->funcname[func_now] = (char*)malloc(funcnamelen); + memcpy(G__p_ifunc->funcname[func_now], funcname(), funcnamelen); + fgetpos(G__ifile.fp, &G__p_ifunc->entry[func_now].pos); G__p_ifunc->entry[func_now].p = (void*)G__ifile.fp; G__p_ifunc->entry[func_now].line_number = G__ifile.line_number; @@ -887,7 +854,8 @@ void G__make_ifunctable(char* funcheader) #else G__access = G__PRIVATE; #endif - char vinfo[20]; + G__FastAllocString vinfo_sb(20); + char* vinfo = vinfo_sb; strcpy(vinfo,"G__virtualinfo"); G__letvariable(vinfo, G__null, &G__global, G__p_local); G__access = store_access; @@ -935,15 +903,15 @@ void G__make_ifunctable(char* funcheader) * - - - - - - */ isparam = 0; - cin = G__fgetname_template(paraname, "<*&,()="); + G__FastAllocString paraname(G__LONGLINE); + cin = G__fgetname_template(paraname, 0, "<*&,()="); if (strlen(paraname) && isspace(cin)) { /* There was an argument and the parsing was stopped by a white * space rather than on of ",)*&<=", it is possible that * we have a namespace followed by '::' in which case we have * to grab more before stopping! */ int namespace_tagnum; - G__FastAllocString more_sb(G__LONGLINE); - char *more = more_sb; + G__FastAllocString more(G__LONGLINE); namespace_tagnum = G__defined_tagname(paraname, 2); while ((((namespace_tagnum != -1) @@ -951,8 +919,8 @@ void G__make_ifunctable(char* funcheader) || (strcmp("std", paraname) == 0) || (paraname[strlen(paraname)-1] == ':')) && isspace(cin)) { - cin = G__fgetname(more, "<*&,)="); - strcat(paraname, more); + cin = G__fgetname(more, 0, "<*&,)="); + paraname += more; namespace_tagnum = G__defined_tagname(paraname, 2); } } @@ -996,7 +964,7 @@ void G__make_ifunctable(char* funcheader) ) { if (G__dispmsg >= G__DISPWARN) { G__fprinterr(G__serr, "Warning: Unknown type %s in function argument" - , paraname); + , paraname()); G__printlinenum(); } } @@ -1110,14 +1078,16 @@ void G__make_ifunctable(char* funcheader) cin = G__fignorestream("("); cin = G__fignorestream(")"); } - cin = G__fgetstream_template(paraname, ",;{("); + cin = G__fgetstream_template(paraname, 0, ",;{("); if ('(' == cin) { int len = strlen(paraname); + paraname.Resize(len + 10); paraname[len++] = cin; - cin = G__fgetstream(paraname + len, ")"); + cin = G__fgetstream(paraname, len, ")"); len = strlen(paraname); + paraname.Resize(len + 10); paraname[len++] = cin; - cin = G__fgetstream_template(paraname + len, ",;{"); + cin = G__fgetstream_template(paraname, len, ",;{"); } // If header ignore following headers, else read function body. if ((paraname[0] == '\0' @@ -1273,11 +1243,10 @@ void G__make_ifunctable(char* funcheader) G__ifile.line_number = store_line_number; if (G__dispsource) G__disp_mask = 1000; - strcpy(paraname, funcheader); - cin = G__fgetstream(paraname + strlen(paraname), ")"); + paraname = funcheader; + cin = G__fgetstream(paraname, strlen(paraname), ")"); iin = strlen(paraname); - paraname[iin] = ')'; - paraname[iin+1] = '\0'; + paraname += ")"; if (G__dispsource) G__disp_mask = 0; G__no_exec = 0; /* must be set to 1 again after return */ @@ -1716,11 +1685,10 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) } G__paramfunc* param = ifunc->param[func_now][iin]; param->isconst = G__VARIABLE; - G__FastAllocString buf_sb(G__LONGLINE); - char *buf = buf_sb; // Parsing I/O buffer. + G__FastAllocString buf(G__LONGLINE); buf[0] = '\0'; // Get first keyword, id, or separator of the type specification. - c = G__fgetname_template(buf, "&*[(=,)"); + c = G__fgetname_template(buf, 0, "&*[(=,)"); if (strlen(buf) && isspace(c)) { // -- There was an argument and the parsing stopped at white space. // It is possible that we have a qualified name, check. @@ -1734,10 +1702,9 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) !strcmp("std", buf) ) ) { - G__FastAllocString more_sb(G__LONGLINE); - char *more = more_sb; - c = G__fgetname(more, "&*[(=,)"); - strcat(buf, more); + G__FastAllocString more(G__LONGLINE); + c = G__fgetname(more, 0, "&*[(=,)"); + buf += more; namespace_tagnum = G__defined_tagname(buf, 2); } } @@ -1758,7 +1725,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) if (!strcmp(buf, "const")) { ifunc->param[func_now][iin]->isconst |= G__CONSTVAR; } - c = G__fgetname_template(buf, "&*[(=,)"); + c = G__fgetname_template(buf, 0, "&*[(=,)"); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); } // @@ -1790,19 +1757,19 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) case '(': case '=': case '*': - strcpy(buf, "int"); + buf = "int"; //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); break; default: if (isspace(c)) { - c = G__fgetname(buf, ",)&*[(="); // FIXME: Change to G__getname_template??? + c = G__fgetname(buf, 0, ",)&*[(="); // FIXME: Change to G__getname_template??? //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); } else { fpos_t pos; fgetpos(G__ifile.fp, &pos); int store_line = G__ifile.line_number; - c = G__fgetname(buf, ",)&*[(="); + c = G__fgetname(buf, 0, ",)&*[(="); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); if (strcmp(buf, "short") && strcmp(buf, "int") && strcmp(buf, "long")) { G__ifile.line_number = store_line; @@ -1816,25 +1783,25 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) } } if (!strcmp(buf, "class")) { - c = G__fgetname_template(buf, ",)&*[(="); + c = G__fgetname_template(buf, 0, ",)&*[(="); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); tagnum = G__search_tagname(buf, 'c'); type = 'u'; } else if (!strcmp(buf, "struct")) { - c = G__fgetname_template(buf, ",)&*[(="); + c = G__fgetname_template(buf, 0, ",)&*[(="); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); tagnum = G__search_tagname(buf, 's'); type = 'u'; } else if (!strcmp(buf, "union")) { - c = G__fgetname_template(buf, ",)&*[(="); + c = G__fgetname_template(buf, 0, ",)&*[(="); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); tagnum = G__search_tagname(buf, 'u'); type = 'u'; } else if (!strcmp(buf, "enum")) { - c = G__fgetname_template(buf, ",)&*[(="); + c = G__fgetname_template(buf, 0, ",)&*[(="); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); tagnum = G__search_tagname(buf, 'e'); type = 'i'; @@ -1854,7 +1821,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) fgetpos(G__ifile.fp, &pos); int store_line = G__ifile.line_number; int store_c = c; - c = G__fgetname(buf, ",)&*[(="); // FIXME: Change to G__fgetname_template??? + c = G__fgetname(buf, 0, ",)&*[(="); // FIXME: Change to G__fgetname_template??? //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); if (!strcmp(buf, "long") || !strcmp(buf, "double")) { if (!strcmp(buf, "long")) { @@ -1930,8 +1897,8 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) //fprintf(stderr, "G__readansiproto: failed to find tagname: '%s' ... \n", buf); if (G__fpundeftype) { tagnum = G__search_tagname(buf, 'c'); - fprintf(G__fpundeftype, "class %s; /* %s %d */\n", buf, G__ifile.name, G__ifile.line_number); - fprintf(G__fpundeftype, "#pragma link off class %s;\n\n", buf); + fprintf(G__fpundeftype, "class %s; /* %s %d */\n", buf(), G__ifile.name, G__ifile.line_number); + fprintf(G__fpundeftype, "#pragma link off class %s;\n\n", buf()); G__struct.globalcomp[tagnum] = G__NOLINK; type = 'u'; } @@ -1940,7 +1907,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) type = 'i' + isunsigned; if (!isdigit(buf[0]) && !isunsigned) { if (G__dispmsg >= G__DISPWARN) { - G__fprinterr(G__serr, "Warning: Unknown type '%s' in function argument handled as int", buf); + G__fprinterr(G__serr, "Warning: Unknown type '%s' in function argument handled as int", buf()); G__printlinenum(); } } @@ -1956,8 +1923,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) // int is_a_reference = 0; int has_a_default = 0; - G__FastAllocString param_name_sb(G__LONGLINE); - char *param_name = param_name_sb; // Parameter name. + G__FastAllocString param_name(G__LONGLINE); param_name[0] = '\0'; { int arydim = 0; // Track which array bound we are processing, so we can handle an unspecified length array. @@ -2000,6 +1966,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) ) { // read 'MyFunc(int [][30])' or 'MyFunc(int [])' int len = strlen(param_name); + param_name.Resize(len + 2); param_name[len++] = c; param_name[len++] = ']'; // Ignore the given array bound value. @@ -2012,14 +1979,14 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) fpos_t tmp_pos; fgetpos(G__ifile.fp, &tmp_pos); int tmp_line = G__ifile.line_number; - c = G__fgetstream(param_name + len, "[=,)"); + c = G__fgetstream(param_name, len, "[=,)"); fsetpos(G__ifile.fp, &tmp_pos); G__ifile.line_number = tmp_line; G__disp_mask = 0; } if (c == '[') { // Collect all the rest of the array bounds. - c = G__fgetstream(param_name + len, "=,)"); + c = G__fgetstream(param_name, len, "=,)"); ptrcnt = 0; // FIXME: This erases all pointers (int* ary[d][d] is broken!) break; } @@ -2038,7 +2005,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) // -- Parameter has a default value, collect it, and we are done. // Collect the rest of the parameter specification as the default text. has_a_default = 1; - c = G__fgetstream_template(buf, ",)"); + c = G__fgetstream_template(buf, 0, ",)"); // Note: The enclosing loop will terminate after we break. break; case '(': // Assume a function pointer type, e.g., MyFunc(int, int (*fp)(int, ...), int, ...) @@ -2058,7 +2025,8 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) else { p = buf; } - strcpy(p, G__type2string(0, tagnum, typenum, 0, 0)); + *p = 0; + buf += G__type2string(0, tagnum, typenum, 0, 0); } // // Normalize the rest of the parameter specification, @@ -2068,6 +2036,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) // Handle any ref part of the return type. // FIXME: This is wrong, cannot have a pointer to a reference! int i = strlen(buf); + buf.Resize(i + ptrcnt * 2 + 10); // CINT cannot handle that many anyway if (is_a_reference) { buf[i++] = '&'; } @@ -2081,12 +2050,14 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) ptrcnt = 0; // Start constructing the parameter name part. buf[i++] = '('; - c = G__fgetstream(buf + i, "*)"); + c = G__fgetstream(buf, i, "*)"); if (c == '*') { + buf.Resize(i + 1); buf[i++] = c; - c = G__fgetstream(param_name, ")"); + c = G__fgetstream(param_name, 0, ")"); int j = 0; for (; param_name[j] == '*'; ++j) { + buf.Resize(i + 1); buf[i++] = '*'; } if (j) { @@ -2098,12 +2069,12 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) } } if (c == ')') { + buf.Resize(i + 1); buf[i++] = ')'; } // Copy out the rest of the parameter specification (up to a default value, if any). - c = G__fdumpstream(buf + i, ",)="); + c = G__fdumpstream(buf, i, ",)="); } - buf[strlen(buf)] = '\0'; //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); #ifndef G__OLDIMPLEMENTATION2191 typenum = G__search_typename(buf, '1', -1, 0); @@ -2123,7 +2094,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) } // Collect next keyword or id into param_name. param_name[0] = c; - c = G__fgetstream(param_name + 1, "[=,)& \t"); + c = G__fgetstream(param_name, 1, "[=,)& \t"); if (!strcmp(param_name, "const")) { // handle const keyword ifunc->param[func_now][iin]->isconst |= G__PCONSTVAR; // FIXME: This is intentionally wrong! Fix the code that depends on this! param_name[0] = 0; @@ -2151,7 +2122,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) if (G__dispsource) { G__disp_mask = 1; } - c = G__fgetstream(param_name + len, "=,)"); + c = G__fgetstream(param_name, len, "=,)"); // Note: Either we next process a default value, or enclosing loop terminates. break; } @@ -2161,7 +2132,7 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) } if (c == '=') { // We have a default value. has_a_default = 1; - c = G__fgetstream_template(buf, ",)"); + c = G__fgetstream_template(buf, 0, ",)"); //fprintf(stderr, "G__readansiproto: buf: '%s'\n", buf); // Note: Enclosing loop will terminate after we break. } @@ -2230,9 +2201,8 @@ static int G__readansiproto(G__ifunc_table_internal* ifunc, int func_now) G__value* val = ifunc->param[func_now][iin]->pdefault; if (is_a_reference && !ptrcnt && ((toupper(val->type) != toupper(type)) || (val->tagnum != tagnum))) { // -- If binding a reference to default rvalue and the types do not match, do a cast. - G__FastAllocString tmp_sb(G__ONELINE); - char *tmp = tmp_sb; - sprintf(tmp, "%s(%s)", G__type2string(type, tagnum, -1, 0, 0), buf); + G__FastAllocString tmp(G__ONELINE); + tmp.Format("%s(%s)", G__type2string(type, tagnum, -1, 0, 0), buf()); *val = G__getexpr(tmp); if (val->type == 'u') { val->ref = val->obj.i; @@ -2325,10 +2295,8 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame int match = 0; int rewindflag = 0; G__value reg; - G__FastAllocString conv_sb(G__ONELINE); - char *conv = conv_sb; - G__FastAllocString arg1_sb(G__ONELINE); - char *arg1 = arg1_sb; + G__FastAllocString conv(G__ONELINE); + G__FastAllocString arg1(G__ONELINE); if (default_parameter && (param_type == '\0')) { return 2; @@ -2711,19 +2679,19 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame /* try finding constructor */ if ('u' == param_type) { if (param->obj.i < 0) - sprintf(arg1, "(%s)(%ld)" + arg1.Format("(%s)(%ld)" , G__fulltagname(param_tagnum, 1), param->obj.i); else - sprintf(arg1, "(%s)%ld", G__fulltagname(param_tagnum, 1), param->obj.i); + arg1.Format("(%s)%ld", G__fulltagname(param_tagnum, 1), param->obj.i); } else { G__valuemonitor(*param, arg1); } - sprintf(conv, "%s(%s)", G__struct.name[formal_tagnum], arg1); + conv.Format("%s(%s)", G__struct.name[formal_tagnum], arg1()); if (G__dispsource) { G__fprinterr(G__serr, "!!!Trying implicit conversion %s,%d\n" - , conv, G__templevel); + , conv(), G__templevel); } long store_struct_offset = G__store_struct_offset; @@ -2767,7 +2735,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame #endif } else { - sprintf(conv, "operator %s()", G__fulltagname(formal_tagnum, 1)); + conv.Format("operator %s()", G__fulltagname(formal_tagnum, 1)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; if (-1 != G__tagnum) reg = G__getfunction(conv, &match, G__TRYMEMFUNC); @@ -2790,7 +2758,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame } else { if (G__asm_noverflow) G__inc_cp_asm(-3, 0); - sprintf(conv, "operator %s()", G__fulltagname(formal_tagnum, 1)); + conv.Format("operator %s()", G__fulltagname(formal_tagnum, 1)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; reg = G__getfunction(conv, &match, G__TRYMEMFUNC); @@ -2869,7 +2837,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame } else { // All conversions failed. if (G__dispsource) { - G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n", conv, G__templevel); + G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n", conv(), G__templevel); } G__pop_tempobject(); #ifdef G__ASM @@ -2886,7 +2854,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame #else // ON181 // All conversions failed. if (G__dispsource) { - G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n", conv, G__templevel); + G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n", conv(), G__templevel); } G__pop_tempobject(); #ifdef G__ASM @@ -2906,10 +2874,10 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame else { /* match==1, conversion successful */ if (G__dispsource) { if (G__p_tempbuf->obj.obj.i < 0) { - G__fprinterr(G__serr, "!!!Create temp object (%s)(%ld),%d for implicit conversion\n", conv, G__p_tempbuf->obj.obj.i, G__templevel); + G__fprinterr(G__serr, "!!!Create temp object (%s)(%ld),%d for implicit conversion\n", conv(), G__p_tempbuf->obj.obj.i, G__templevel); } else { - G__fprinterr(G__serr, "!!!Create temp object (%s)%ld,%d for implicit conversion\n", conv, G__p_tempbuf->obj.obj.i, G__templevel); + G__fprinterr(G__serr, "!!!Create temp object (%s)%ld,%d for implicit conversion\n", conv(), G__p_tempbuf->obj.obj.i, G__templevel); } } #ifdef G__ASM @@ -2932,7 +2900,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame else if (-1 != param->tagnum) { long store_struct_offset = G__store_struct_offset; int store_tagnum = G__tagnum; - sprintf(conv, "operator %s()", G__type2string(formal_type, formal_tagnum, -1, 0, 0)); + conv.Format("operator %s()", G__type2string(formal_type, formal_tagnum, -1, 0, 0)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; #ifdef G__ASM @@ -2962,7 +2930,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame #endif // G__ASM reg = G__getfunction(conv, &match, G__TRYMEMFUNC); if (!match && formal_isconst) { - sprintf(conv, "operator const %s()", G__type2string(formal_type, formal_tagnum, -1, 0, 0)); + conv.Format("operator const %s()", G__type2string(formal_type, formal_tagnum, -1, 0, 0)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; reg = G__getfunction(conv, &match, G__TRYMEMFUNC); @@ -3018,7 +2986,7 @@ int G__param_match(char formal_type, int formal_tagnum, G__value* default_parame match = 0; if (recursive && G__dispsource) { G__valuemonitor(*param, arg1); - G__fprinterr(G__serr, "!!!Recursive implicit conversion %s(%s) rejected\n", G__struct.name[formal_tagnum], arg1); + G__fprinterr(G__serr, "!!!Recursive implicit conversion %s(%s) rejected\n", G__struct.name[formal_tagnum], arg1()); } } } @@ -3585,10 +3553,8 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, int formal_reftype; int formal_isconst; G__value* param; - G__FastAllocString conv_sb(G__ONELINE); - char *conv = conv_sb; - G__FastAllocString arg1_sb(G__ONELINE); - char *arg1 = arg1_sb; + G__FastAllocString conv(G__ONELINE); + G__FastAllocString arg1(G__ONELINE); G__FastAllocString parameter_sb(G__ONELINE); char *parameter = parameter_sb; long store_struct_offset; @@ -3646,19 +3612,19 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, /* try finding constructor */ if ('u' == param_type) { if (param->obj.i < 0) - sprintf(arg1, "(%s)(%ld)" + arg1.Format("(%s)(%ld)" , G__fulltagname(param_tagnum, 1), param->obj.i); else - sprintf(arg1, "(%s)%ld", G__fulltagname(param_tagnum, 1), param->obj.i); + arg1.Format("(%s)%ld", G__fulltagname(param_tagnum, 1), param->obj.i); } else { G__valuemonitor(*param, arg1); } - sprintf(conv, "%s(%s)", G__struct.name[formal_tagnum], arg1); + conv.Format("%s(%s)", G__struct.name[formal_tagnum], arg1()); if (G__dispsource) { G__fprinterr(G__serr, "!!!Trying implicit conversion %s,%d\n" - , conv, G__templevel); + , conv(), G__templevel); } store_struct_offset = G__store_struct_offset; @@ -3704,7 +3670,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, } else { G__pop_tempobject(); - sprintf(conv, "operator %s()", G__fulltagname(formal_tagnum, 1)); + conv.Format("operator %s()", G__fulltagname(formal_tagnum, 1)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; if (-1 != G__tagnum) reg = G__getfunction(conv, &match, G__TRYMEMFUNC); @@ -3728,7 +3694,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, else { G__pop_tempobject(); if (G__asm_noverflow) G__inc_cp_asm(-3, 0); - sprintf(conv, "operator %s()", G__fulltagname(formal_tagnum, 1)); + conv.Format("operator %s()", G__fulltagname(formal_tagnum, 1)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; #ifdef G__ASM @@ -3833,7 +3799,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, if (G__dispsource) { G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n" - , conv, G__templevel); + , conv(), G__templevel); } G__pop_tempobject(); #ifdef G__ASM @@ -3851,7 +3817,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, if (G__dispsource) { G__fprinterr(G__serr, "!!!Implicit conversion %s,%d tried, but failed\n" - , conv, G__templevel); + , conv(), G__templevel); } G__pop_tempobject(); #ifdef G__ASM @@ -3870,11 +3836,11 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, if (G__p_tempbuf->obj.obj.i < 0) G__fprinterr(G__serr, "!!!Create temp object (%s)(%ld),%d for implicit conversion\n" - , conv , G__p_tempbuf->obj.obj.i , G__templevel); + , conv(), G__p_tempbuf->obj.obj.i , G__templevel); else G__fprinterr(G__serr, "!!!Create temp object (%s)%ld,%d for implicit conversion\n" - , conv , G__p_tempbuf->obj.obj.i , G__templevel); + , conv(), G__p_tempbuf->obj.obj.i , G__templevel); } #ifdef G__ASM if (G__asm_noverflow && rewind_arg) { @@ -3898,7 +3864,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, long store_struct_offset = G__store_struct_offset; int store_tagnum = G__tagnum; int store_isconst = G__isconst; - sprintf(conv, "operator %s()" + conv.Format("operator %s()" , G__type2string(formal_type, formal_tagnum, -1, 0, 0)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; @@ -3929,7 +3895,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, if (!match && 0 != formal_isconst ) { - sprintf(conv, "operator const %s()" + conv.Format("operator const %s()" , G__type2string(formal_type, formal_tagnum, -1, 0, 0)); G__store_struct_offset = param->obj.i; G__tagnum = param->tagnum; @@ -3979,7 +3945,7 @@ int G__convert_param(G__param* libp, G__ifunc_table_internal* p_ifunc, int ifn, if (recursive && G__dispsource) { G__valuemonitor(*param, arg1); G__fprinterr(G__serr, "!!!Recursive implicit conversion %s(%s) rejected\n" - , G__struct.name[formal_tagnum], arg1); + , G__struct.name[formal_tagnum], arg1()); } /* #endif */ } @@ -4427,12 +4393,10 @@ struct G__funclist* G__add_templatefunc(const char* funcnamein, G__param* libp, int store_friendtagnum = G__friendtagnum; struct G__ifunc_table_internal *ifunc; int ifn; - char *funcname; char *ptmplt; char *pexplicitarg = 0; - funcname = (char*)malloc(strlen(funcnamein) + 1); - strcpy(funcname, funcnamein); + G__FastAllocString funcname(funcnamein); if (-1 != env_tagnum) baseclass = G__struct.baseclass[env_tagnum]; else baseclass = &G__globalusingnamespace; @@ -4489,10 +4453,9 @@ struct G__funclist* G__add_templatefunc(const char* funcnamein, G__param* libp, int itmp = 0; int ip = 1; int c; - G__FastAllocString buf_sb(G__ONELINE); - char *buf = buf_sb; + G__FastAllocString buf(G__ONELINE); do { - c = G__getstream_template(ptmplt, &ip, buf, ",>"); + c = G__getstream_template(ptmplt, &ip, buf, 0, ",>"); G__checkset_charlist(buf, &call_para, ++itmp, 'u'); } while (c != '>'); @@ -4594,8 +4557,6 @@ match_found: } G__freecharlist(&call_para); - if (funcname) free((void*)funcname); - return funclist; } @@ -4886,9 +4847,7 @@ int G__interpret_func(G__value* result7, const char* funcname, G__param* libp, i FILE *prev_fp; fpos_t prev_pos; // paraname[][] is used only for K&R func param. length should be OK. - G__FastAllocString paraname_buf(G__MAXFUNCPARA * G__MAXNAME); - typedef char namearray_t[G__MAXNAME]; - namearray_t *paraname = (namearray_t*) paraname_buf.data(); + G__FastAllocString paraname[G__MAXFUNCPARA]; int ipara = 0; int cin = '\0'; int itemp = 0; @@ -5874,9 +5833,8 @@ int G__interpret_func(G__value* result7, const char* funcname, G__param* libp, i // -- K&R C. ipara = 0; while (cin != ')') { - G__FastAllocString temp_sb(G__ONELINE); - char *temp = temp_sb; - cin = G__fgetstream(temp, ",)"); + G__FastAllocString temp(G__ONELINE); + cin = G__fgetstream(temp, 0, ",)"); if (temp[0] != '\0') { strcpy(paraname[ipara], temp); ++ipara; @@ -6252,11 +6210,10 @@ int G__interpret_func(G__value* result7, const char* funcname, G__param* libp, i , G__fulltagname(result7->tagnum, 1) , result7->obj.i); } else { - G__FastAllocString buf2_sb(G__ONELINE); - char *buf2 = buf2_sb; + G__FastAllocString buf2(G__ONELINE); G__valuemonitor(*result7, buf2); sprintf(temp, "%s(%s)", G__struct.name[p_ifunc->p_tagtable[ifn]] - , buf2); + , buf2()); } store_tagnum = G__tagnum; @@ -6955,8 +6912,7 @@ struct G__ifunc_table_internal* G__get_ifunchandle_base(const char* funcname, G_ void G__argtype2param(const char* argtype, G__param* libp, int noerror, int* error) { // -- FIXME: Describe this function! - G__FastAllocString typenam_sb(G__MAXNAME*2); - char *typenam = typenam_sb; + G__FastAllocString typenam(G__MAXNAME*2); int p = 0; int c; const char *endmark = ",);"; @@ -6965,7 +6921,7 @@ void G__argtype2param(const char* argtype, G__param* libp, int noerror, int* err libp->para[0] = G__null; do { - c = G__getstream_template(argtype, &p, typenam, endmark); + c = G__getstream_template(argtype, &p, typenam, 0, endmark); if (typenam[0]) { char* start = typenam; while (isspace(*start)) ++start; diff --git a/cint/cint/src/inherit.cxx b/cint/cint/src/inherit.cxx index ed2b12148723ff9345630f1698beabe35235b669..c6df04daf14460126266b89e3da5b6419c986a71 100644 --- a/cint/cint/src/inherit.cxx +++ b/cint/cint/src/inherit.cxx @@ -121,7 +121,7 @@ void G__inheritclass(int to_tagnum,int from_tagnum,char baseaccess) int G__baseconstructorwp() { int c; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); int n=0; struct G__baseparam *pbaseparamin = (struct G__baseparam*)NULL; struct G__baseparam *pbaseparam = pbaseparamin; @@ -133,7 +133,7 @@ int G__baseconstructorwp() if(':'==c) c=','; while(','==c) { - c=G__fgetstream_newtemplate(buf,"({,"); /* case 3) */ + c=G__fgetstream_newtemplate(buf, 0, "({,"); /* case 3) */ if('('==c) { if(pbaseparamin) { pbaseparam->next @@ -150,11 +150,11 @@ int G__baseconstructorwp() pbaseparam->param = (char*)NULL; pbaseparam->name=(char*)malloc(strlen(buf)+1); strcpy(pbaseparam->name,buf); - c=G__fgetstream_newtemplate(buf,")"); + c=G__fgetstream_newtemplate(buf, 0, ")"); pbaseparam->param=(char*)malloc(strlen(buf)+1); strcpy(pbaseparam->param,buf); ++n; - c=G__fgetstream(buf,",{"); + c=G__fgetstream(buf, 0, ",{"); } } @@ -282,7 +282,7 @@ int G__baseconstructor(int n, G__baseparam *pbaseparamin) struct G__baseparam *pbaseparam = pbaseparamin; char *tagname,*memname; int flag; - char construct[G__ONELINE]; + G__FastAllocString construct(G__ONELINE); int size; long store_globalvarpointer; int donen=0; @@ -363,10 +363,10 @@ int G__baseconstructor(int n, G__baseparam *pbaseparamin) pbaseparam=pbaseparam->next; } } - if(flag) sprintf(construct,"%s(%s)" ,tagname,pbaseparam->param); - else sprintf(construct,"%s()",tagname); + if(flag) construct.Format("%s(%s)" ,tagname,pbaseparam->param); + else construct.Format("%s()",tagname); if(G__dispsource) { - G__fprinterr(G__serr,"\n!!!Calling base class constructor %s",construct); + G__fprinterr(G__serr,"\n!!!Calling base class constructor %s",construct()); } if(G__CPPLINK==G__struct.iscpplink[G__tagnum]) { /* C++ compiled class */ G__globalvarpointer=G__store_struct_offset; @@ -453,11 +453,11 @@ int G__baseconstructor(int n, G__baseparam *pbaseparamin) } continue; } - sprintf(construct,"%s(%s)" ,G__struct.name[G__tagnum] + construct.Format("%s(%s)" ,G__struct.name[G__tagnum] ,pbaseparam->param); } else { - sprintf(construct,"%s()" ,G__struct.name[G__tagnum]); + construct.Format("%s()" ,G__struct.name[G__tagnum]); if(G__PARAREFERENCE==mem->reftype[i]) { #ifndef G__OLDIMPLEMENTATION945 if(G__NOLINK!=G__globalcomp) @@ -471,7 +471,7 @@ int G__baseconstructor(int n, G__baseparam *pbaseparamin) } } if(G__dispsource) { - G__fprinterr(G__serr,"\n!!!Calling class member constructor %s",construct); + G__fprinterr(G__serr,"\n!!!Calling class member constructor %s",construct()); } int linear_index = mem->varlabel[i][1] /* number of elements */; if (linear_index) { @@ -630,7 +630,7 @@ int G__basedestructor() int store_tagnum; long store_struct_offset; int i,j; - char destruct[G__ONELINE]; + G__FastAllocString destruct(G__ONELINE); long store_globalvarpointer; int store_addstros=0; @@ -687,9 +687,9 @@ int G__basedestructor() if(-1!=G__struct.virtual_offset[G__tagnum]) *(long*)(G__store_struct_offset+G__struct.virtual_offset[G__tagnum]) = G__tagnum; - sprintf(destruct,"~%s()",G__struct.name[G__tagnum]); + destruct.Format("~%s()",G__struct.name[G__tagnum]); if(G__dispsource) - G__fprinterr(G__serr,"\n!!!Calling base class destructor %s",destruct); + G__fprinterr(G__serr,"\n!!!Calling base class destructor %s",destruct()); j=0; if(G__CPPLINK==G__struct.iscpplink[G__tagnum]) { G__globalvarpointer = G__store_struct_offset; @@ -714,7 +714,7 @@ int G__basedestructor() **************************************************************************/ int G__basedestructrc(G__var_array *mem) { - char destruct[G__ONELINE]; + G__FastAllocString destruct(G__ONELINE); if (!mem) { return 1; } @@ -736,7 +736,7 @@ int G__basedestructrc(G__var_array *mem) ) { G__tagnum = mem->p_tagtable[i]; G__store_struct_offset = store_struct_offset + mem->p[i]; - sprintf(destruct, "~%s()", G__struct.name[G__tagnum]); + destruct.Format("~%s()", G__struct.name[G__tagnum]); int linear_index = mem->varlabel[i][1] /* number of elements */; if (linear_index) { --linear_index; @@ -758,7 +758,7 @@ int G__basedestructrc(G__var_array *mem) if (G__struct.virtual_offset[G__tagnum] != -1) *((long*) (G__store_struct_offset + G__struct.virtual_offset[G__tagnum])) = G__tagnum; if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling class member destructor %s", destruct); + G__fprinterr(G__serr, "\n!!!Calling class member destructor %s", destruct()); } G__getfunction(destruct, &known, G__TRYDESTRUCTOR); G__store_struct_offset -= size; diff --git a/cint/cint/src/init.cxx b/cint/cint/src/init.cxx index bdd3f93ec46007a1c9132f47cfbea7b5f6f4b179..837385bb0cb31bd07a10dd3f34a778950e239896 100644 --- a/cint/cint/src/init.cxx +++ b/cint/cint/src/init.cxx @@ -533,13 +533,13 @@ int G__main(int argc, char** argv) int ii; char* forceassignment = 0; int xfileflag = 0; - char sourcefile[G__MAXFILENAME]; + G__FastAllocString sourcefile(G__MAXFILENAME); /************************************************************* * C/C++ interpreter option related variables *************************************************************/ extern int optind; extern char *optarg; - static char usage[] = "Usage: %s [options] [sourcefiles|suboptions] [arguments]\n"; + static const char usage[] = "Usage: %s [options] [sourcefiles|suboptions] [arguments]\n"; static char *progname; char *ppc; /************************************************************* @@ -1205,12 +1205,12 @@ int G__main(int argc, char** argv) xfileflag = 0; } #else - sprintf(sourcefile, G__xfile); + sourcefile = G__xfile; xfileflag = 0; #endif } else { - strcpy(sourcefile, argv[optind]); + sourcefile = argv[optind]; ++optind; } if (strcmp(sourcefile, "+P") == 0) { @@ -1269,7 +1269,7 @@ int G__main(int argc, char** argv) FILE *fp = fopen(linkfilename_h.c_str(),"a"); if(fp) { fprintf(fp,"#ifndef G__includes_dict_%s\n", headerb.c_str()); - fprintf(fp,"#define G__includes_dict_%s\n", headerb.c_str(), sourcefile); + fprintf(fp,"#define G__includes_dict_%s\n", headerb.c_str(), sourcefile()); fclose(fp); } includes_printed = 1; @@ -2238,6 +2238,12 @@ void G__platformMacro() #ifdef __i386__ /* Intel 386,486,586 */ G__DEFINE_MACRO_S(__i386__); #endif +#ifdef __x86_64__ /* Intel / AMD 64 */ + G__DEFINE_MACRO_S(__x86_64__); +#endif +#ifdef __amd64 /* Intel / AMD 64 */ + G__DEFINE_MACRO_S(__amd64); +#endif #ifdef __i860__ /* Intel 860 */ G__DEFINE_MACRO_S(__i860__); #endif diff --git a/cint/cint/src/input.cxx b/cint/cint/src/input.cxx index 37a6578dfd0bf10ed1cf1bc756f13835d9ac75f3..3a969d311d55e4369094cdbcf3a1eff70d739f66 100644 --- a/cint/cint/src/input.cxx +++ b/cint/cint/src/input.cxx @@ -46,16 +46,17 @@ extern int add_history(const char* str); *************************************************************/ void G__input_history(int *state,const char *string) { - char G__oneline[G__LONGLINE*2]; - char G__argbuf[G__LONGLINE*2]; + G__FastAllocString G__oneline(G__LONGLINE*2); + G__FastAllocString G__argbuf(G__LONGLINE*2); /* int G__null_fgets=1; */ char *arg[G__LONGLINE]; int argn; #ifdef G__TMPFILE - char tname[G__MAXFILENAME]; + G__FastAllocString tname_sb(G__MAXFILENAME); #else - char tname[L_tmpnam+10]; + G__FastAllocString tname_sb(L_tmpnam+10); #endif + char* tname = tname_sb; int istmpnam=0; static char prevstring[G__LONGLINE]; @@ -77,7 +78,7 @@ void G__input_history(int *state,const char *string) sprintf(histfile,"./%s",homehist); fp=fopen(histfile,"r"); if(fp) { - while(G__readline(fp,G__oneline,G__argbuf,&argn,arg)!=0){ + while(G__readline_FastAlloc(fp,G__oneline,G__argbuf,&argn,arg)!=0){ add_history(arg[0]); strcpy(prevstring,arg[0]); *state = (*state)+1; @@ -121,7 +122,7 @@ void G__input_history(int *state,const char *string) } } while((FILE*)NULL==tmp && G__setTMPDIR(tname)); if(tmp&&fp) { - while(G__readline(fp,G__oneline,G__argbuf,&argn,arg)!=0){ + while(G__readline_FastAlloc(fp,G__oneline,G__argbuf,&argn,arg)!=0){ ++line; if(line>G__history_size_max-G__history_size_min) fprintf(tmp,"%s\n",arg[0]); } @@ -138,7 +139,7 @@ void G__input_history(int *state,const char *string) fp=fopen(histfile,"w"); if(istmpnam) tmp=fopen(tname,"r"); if(tmp&&fp) { - while(G__readline(tmp,G__oneline,G__argbuf,&argn,arg)!=0){ + while(G__readline_FastAlloc(tmp,G__oneline,G__argbuf,&argn,arg)!=0){ fprintf(fp,"%s\n",arg[0]); } } diff --git a/cint/cint/src/intrpt.cxx b/cint/cint/src/intrpt.cxx index 8096c5a4f721f58af17752314a64e758680e07ec..e976a60308129680c59a4d73164a465c8eba44a3 100644 --- a/cint/cint/src/intrpt.cxx +++ b/cint/cint/src/intrpt.cxx @@ -277,217 +277,111 @@ int G__call_interruptfunc(char *func) return(0); } +#define G__OLDIMPLEMENTATION1945 + +#ifdef _MVC_VER +# define G__PASTE0(A) A +# define G__PASTE(A,B) G__PASTE0(A)B +#else +# define G__PASTE(A,B) A##B +#endif + +#define G__DEF_FSIG(FUNC, SIG, CINTSIG, ARG) \ + void FUNC(int) { \ + G__FastAllocString temp(G__ONELINE); \ + signal(SIG, ARG); \ + if (CINTSIG) { \ + temp.Format("%s()", CINTSIG); \ + CINTSIG = NULL; \ + G__call_interruptfunc(temp); \ + } \ +} + + /****************************************************************** * G__fsigabrt() ******************************************************************/ -void G__fsigabrt(int) -{ - char temp[G__ONELINE]; - signal(SIGABRT, SIG_DFL); - if (G__SIGABRT) { -#define G__OLDIMPLEMENTATION1945 - sprintf(temp, "%s()", G__SIGABRT); - G__SIGABRT = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigabrt, SIGABRT, G__SIGABRT, SIG_DFL) /****************************************************************** * G__fsigfpe() ******************************************************************/ -void G__fsigfpe(int) -{ - char temp[G__ONELINE]; - signal(SIGFPE, G__floatexception); - if (G__SIGFPE) { - sprintf(temp, "%s()", G__SIGFPE); - G__SIGFPE = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigfpe, SIGFPE, G__SIGFPE, G__floatexception) /****************************************************************** * G__fsigill() ******************************************************************/ -void G__fsigill(int) -{ - char temp[G__ONELINE]; - signal(SIGILL, SIG_DFL); - if (G__SIGILL) { - sprintf(temp, "%s()", G__SIGILL); - G__SIGILL = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigill, SIGILL, G__SIGILL, SIG_DFL) /****************************************************************** * G__fsigint() ******************************************************************/ -void G__fsigint(int) -{ - char temp[G__ONELINE]; - signal(SIGINT, G__breakkey); - if (G__SIGINT) { - sprintf(temp, "%s()", G__SIGINT); - G__SIGINT = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigint, SIGINT, G__SIGINT, G__breakkey) /****************************************************************** * G__fsigsegv() ******************************************************************/ -void G__fsigsegv(int) -{ - char temp[G__ONELINE]; - signal(SIGSEGV, G__segmentviolation); - if (G__SIGSEGV) { - sprintf(temp, "%s()", G__SIGSEGV); - G__SIGSEGV = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigsegv, SIGSEGV, G__SIGSEGV, G__segmentviolation) /****************************************************************** * G__fsigterm() ******************************************************************/ -void G__fsigterm(int) -{ - char temp[G__ONELINE]; - signal(SIGTERM, SIG_DFL); - if (G__SIGTERM) { - sprintf(temp, "%s()", G__SIGTERM); - G__SIGTERM = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigterm, SIGTERM, G__SIGTERM, SIG_DFL) #ifdef SIGHUP /****************************************************************** * G__fsighup() ******************************************************************/ -void G__fsighup(int) -{ - char temp[G__ONELINE]; - signal(SIGHUP, SIG_DFL); - if (G__SIGHUP) { - sprintf(temp, "%s()", G__SIGHUP); - G__SIGHUP = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsighup, SIGHUP, G__SIGHUP, SIG_DFL) #endif #ifdef SIGQUIT /****************************************************************** * G__fsigquit() ******************************************************************/ -void G__fsigquit(int) -{ - char temp[G__ONELINE]; - signal(SIGQUIT, SIG_DFL); - if (G__SIGQUIT) { - sprintf(temp, "%s()", G__SIGQUIT); - G__SIGQUIT = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigquit, SIGQUIT, G__SIGQUIT, SIG_DFL) #endif #ifdef SIGTSTP /****************************************************************** * G__fsigtstp() ******************************************************************/ -void G__fsigtstp(int) -{ - char temp[G__ONELINE]; - signal(SIGTSTP, SIG_DFL); - if (G__SIGTSTP) { - sprintf(temp, "%s()", G__SIGTSTP); - G__SIGTSTP = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigtstp, SIGTSTP, G__SIGTSTP, SIG_DFL) #endif #ifdef SIGTTIN /****************************************************************** * G__fsigttin() ******************************************************************/ -void G__fsigttin(int) -{ - char temp[G__ONELINE]; - signal(SIGTTIN, SIG_DFL); - if (G__SIGTTIN) { - sprintf(temp, "%s()", G__SIGTTIN); - G__SIGTTIN = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigttin, SIGTTIN, G__SIGTTIN, SIG_DFL) #endif #ifdef SIGTTOU /****************************************************************** * G__fsigttou() ******************************************************************/ -void G__fsigttou(int) -{ - char temp[G__ONELINE]; - signal(SIGTTOU, SIG_DFL); - if (G__SIGTTOU) { - sprintf(temp, "%s()", G__SIGTTOU); - G__SIGTTOU = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigttou, SIGTTOU, G__SIGTTOU, SIG_DFL) #endif #ifdef SIGALRM /****************************************************************** * G__fsigalrm() ******************************************************************/ -void G__fsigalrm(int) -{ - char temp[G__ONELINE]; - signal(SIGALRM, SIG_DFL); - if (G__SIGALRM) { - sprintf(temp, "%s()", G__SIGALRM); - G__SIGALRM = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigalrm, SIGALRM, G__SIGALRM, SIG_DFL) #endif #ifdef SIGUSR1 /****************************************************************** * G__fsigusr1() ******************************************************************/ -void G__fsigusr1(int) -{ - char temp[G__ONELINE]; - signal(SIGUSR1, SIG_DFL); - if (G__SIGUSR1) { - sprintf(temp, "%s()", G__SIGUSR1); - G__SIGUSR1 = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigusr1, SIGUSR1, G__SIGUSR1, SIG_DFL); #endif #ifdef SIGUSR2 /****************************************************************** * G__fsigusr2() ******************************************************************/ -void G__fsigusr2(int) -{ - char temp[G__ONELINE]; - signal(SIGUSR2, SIG_DFL); - if (G__SIGUSR2) { - sprintf(temp, "%s()", G__SIGUSR2); - G__SIGUSR2 = NULL; - G__call_interruptfunc(temp); - } -} +G__DEF_FSIG(G__fsigusr2, SIGUSR2, G__SIGUSR2, SIG_DFL); #endif #endif /* G__SIGNAL */ diff --git a/cint/cint/src/loadfile.cxx b/cint/cint/src/loadfile.cxx index d01adaeb1b55900ae1cd66e54835c5f4d040e14f..8377d01d3bc3426fcb7026655ab25b41112306fb 100644 --- a/cint/cint/src/loadfile.cxx +++ b/cint/cint/src/loadfile.cxx @@ -180,7 +180,7 @@ int G__include_file() { int result; int c; - char filename[G__MAXFILENAME]; + G__FastAllocString filename(G__MAXFILENAME); int i=0; int storeit=0; /* char sysinclude[G__MAXFILENAME]; */ @@ -214,14 +214,14 @@ int G__include_file() default: if(!isspace(c)) { if(1==storeit) { - filename[i++]=c; - filename[i]='\0'; + filename.Set(i++, c); + filename.Set(i, 0); } else if(-1!=storeit) { storeit=1; expandflag=1; - filename[i++]=c; - filename[i]='\0'; + filename.Set(i++, c); + filename.Set(i, 0); } } else if(expandflag) { @@ -239,11 +239,11 @@ int G__include_file() G__hash(filename,hash,ig15); var = G__getvarentry(filename,hash,&ig15,&G__global,G__p_local); if(var) { - strcpy(filename,*(char**)var->p[ig15]); + filename = *(char**)var->p[ig15]; G__kindofheader=G__USERHEADER; } else { - G__fprinterr(G__serr,"Error: cannot expand #include %s",filename); + G__fprinterr(G__serr,"Error: cannot expand #include %s",filename()); G__genericerror(NULL); if('#'==c) G__fignoreline(); return(G__LOADFILE_FAILURE); @@ -276,7 +276,7 @@ int G__include_file() if('#'==c) { if(G__LOADFILE_FAILURE==result && G__ispragmainclude) { G__ispragmainclude=0; - c = G__fgetname(filename,"\n\r"); + c = G__fgetname(filename, 0, "\n\r"); store_globalcomp = G__globalcomp; if(++G__gcomplevel>=G__gcomplevellimit) G__globalcomp=G__NOLINK; if('\n'!=c && '\r'!=c) result = G__include_file(); @@ -297,14 +297,14 @@ int G__include_file() ******************************************************************/ const char *G__getmakeinfo(const char *item) { - char makeinfo[G__MAXFILENAME]; + G__FastAllocString makeinfo(G__MAXFILENAME); FILE *fp; - char line[G__LARGEBUF]; - char argbuf[G__LARGEBUF]; + G__FastAllocString line(G__LARGEBUF); + G__FastAllocString argbuf(G__LARGEBUF); char *arg[G__MAXARG]; int argn; char *p; - static char buf[G__ONELINE]; + static G__FastAllocString buf(G__ONELINE); buf[0]='\0'; @@ -333,7 +333,7 @@ const char *G__getmakeinfo(const char *item) * Environment variable overrides MAKEINFO file if exists. ****************************************************************/ if((p=getenv(item)) && p[0] && !isspace(p[0])) { - strcpy(buf,p); + buf = p; return(buf); } @@ -343,15 +343,15 @@ const char *G__getmakeinfo(const char *item) /* Get $CINTSYSDIR/MAKEINFO file name */ if(G__getcintsysdir()) return(buf); #ifdef G__VMS - sprintf(makeinfo,"%s%s/MAKEINFO.txt",G__cintsysdir); + makeinfo.Format("%s%s/MAKEINFO.txt",G__cintsysdir); #else - sprintf(makeinfo,"%s/%s/MAKEINFO",G__cintsysdir, G__CFG_COREVERSION); + makeinfo.Format("%s/%s/MAKEINFO",G__cintsysdir, G__CFG_COREVERSION); #endif /* Open MAKEINFO file */ fp = fopen(makeinfo,"r"); if(!fp) { - G__fprinterr(G__serr,"Error: cannot open %s\n",makeinfo); + G__fprinterr(G__serr,"Error: cannot open %s\n",makeinfo()); G__fprinterr(G__serr, "!!! There are examples of MAKEINFO files under %s/platform/ !!!\n" ,G__cintsysdir); @@ -361,14 +361,14 @@ const char *G__getmakeinfo(const char *item) } /* Read the MAKEINFO file */ - while(G__readline(fp,line,argbuf,&argn,arg)) { + while(G__readline_FastAlloc(fp,line,argbuf,&argn,arg)) { if(argn>2 && strcmp(arg[1],item)==0) { p = strchr(arg[0],'='); if(p) { do { ++p; } while(isspace(*p)); - strcpy(buf,p); + buf = p; fclose(fp); return(buf); } @@ -564,13 +564,6 @@ int G__matchfilename(int i1,const char *filename) { #if !defined(__CINT__) -#ifdef G__WIN32 - char i1name[_MAX_PATH],fullfile[_MAX_PATH]; -#else - struct stat statBufItem; - struct stat statBuf; -#endif - if (G__srcfile[i1].filename==0) { return 0; } @@ -579,10 +572,14 @@ int G__matchfilename(int i1,const char *filename) } #ifdef G__WIN32 - _fullpath( i1name, G__srcfile[i1].filename, _MAX_PATH ); + G__FastAllocString i1name(_MAX_PATH); + G__FastAllocString fullfile(_MAX_PATH); + _fullpath( iname, G__srcfile[i1].filename, _MAX_PATH ); _fullpath( fullfile, filename, _MAX_PATH ); if((stricmp(i1name, fullfile)==0)) return 1; #else + struct stat statBufItem; + struct stat statBuf; if ( ( 0 == stat( filename, & statBufItem ) ) && ( 0 == stat( G__srcfile[i1].filename, & statBuf ) ) && ( statBufItem.st_dev == statBuf.st_dev ) // Files on same device @@ -603,7 +600,7 @@ int G__matchfilename(int i1,const char *filename) if(filenamebase) { char *parentdir = (char*)G__strrstr(G__srcfile[i1].filename,"../"); if(!parentdir && strcmp(filename,filenamebase+2)==0) { - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); #if defined(G__WIN32) char *p; #endif @@ -613,9 +610,8 @@ int G__matchfilename(int i1,const char *filename) p=buf; while((p=strchr(p,'\\'))) *p='/'; if(strlen(buf)>1 && ':'==buf[1]) { - char buf2[G__ONELINE]; - strcpy(buf2,buf+2); - strcpy(buf,buf2); + G__FastAllocString buf2(buf+2); + buf.Swap(buf2); } #elif defined(G__POSIX) || defined(G__ROOT) getcwd(buf,G__ONELINE); @@ -640,7 +636,7 @@ const char* G__stripfilename(const char *filename) filenamebase = G__strrstr(filename,"./"); if(filenamebase) { const char *parentdir = G__strrstr(filename,"../"); - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); #if defined(G__WIN32) char *p; #endif @@ -651,9 +647,8 @@ const char* G__stripfilename(const char *filename) p=buf; while((p=strchr(p,'\\'))) *p='/'; if(strlen(buf)>1 && ':'==buf[1]) { - char buf2[G__ONELINE]; - strcpy(buf2,buf+2); - strcpy(buf,buf2); + G__FastAllocString buf2(buf+2); + buf.Swap(buf2); } #elif defined(G__POSIX) || defined(G__ROOT) getcwd(buf,G__ONELINE); @@ -730,14 +725,13 @@ int G__unloadfile(const char *filename) int hash; /* int from = -1 ,to = -1, next; */ int flag; - char buf[G__MAXFILENAME]; + G__FastAllocString buf(filename); char *fname; char *scope; int envtagnum; G__LockCriticalSection(); - strcpy(buf,filename); fname = (char*)G__strrstr(buf,"::"); if(fname) { scope = buf; @@ -1188,14 +1182,12 @@ int G__loadfile_tmpfile(FILE *fp) int G__statfilename(const char *filenamein, struct stat *statBuf) { - char filename[G__ONELINE]; - char workname[G__ONELINE]; + G__FastAllocString filename(filenamein); + G__FastAllocString workname(G__ONELINE); int hash,temp; char addpost[3][8]; int res = -1; - strcpy(filename,filenamein); - /************************************************* * delete space chars at the end of filename *************************************************/ @@ -1247,7 +1239,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) #endif G__ifile.name[0] != '\0') { char* p; - strcpy(workname,G__ifile.name); + workname = G__ifile.name; #ifdef G__WIN32 p = strrchr (workname, '/'); { @@ -1271,7 +1263,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try ./filename **********************************************/ if(G__USERHEADER==G__kindofheader) { - sprintf(workname,"%s%s",filename,addpost[i2]); + workname.Format("%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } else { @@ -1283,8 +1275,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) **********************************************/ struct G__includepath *ipath = &G__ipathentry; while(res!=0 && ipath->pathname) { - sprintf(workname,"%s%s%s%s" - ,ipath->pathname,G__psep,filename,addpost[i2]); + workname.Format("%s%s%s%s" + ,ipath->pathname,G__psep,filename(),addpost[i2]); res = stat( workname, statBuf ); ipath = ipath->next; } @@ -1296,8 +1288,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try $CINTSYSDIR/stl **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"%s%s%s%sstl%s%s%s",G__cintsysdir,G__psep,G__CFG_COREVERSION - ,G__psep,G__psep,filename,addpost[i2]); + workname.Format("%s%s%s%sstl%s%s%s",G__cintsysdir,G__psep,G__CFG_COREVERSION + ,G__psep,G__psep,filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1307,8 +1299,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) **********************************************/ /* G__getcintsysdir(); */ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"%s%s%s%slib%s%s%s",G__cintsysdir,G__psep,G__CFG_COREVERSION - ,G__psep,G__psep,filename,addpost[i2]); + workname.Format("%s%s%s%slib%s%s%s",G__cintsysdir,G__psep,G__CFG_COREVERSION + ,G__psep,G__psep,filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1318,8 +1310,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try include/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"include%s%s%s" - ,G__psep,filename,addpost[i2]); + workname.Format("include%s%s%s" + ,G__psep,filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1328,8 +1320,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) **********************************************/ G__getcintsysdir(); if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"stl%s%s%s" - ,G__psep,filename,addpost[i2]); + workname.Format("stl%s%s%s" + ,G__psep,filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1340,7 +1332,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /msdev/include **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/msdev/include/%s%s",filename,addpost[i2]); + workname.Format("/msdev/include/%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1351,7 +1343,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /sc/include **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/sc/include/%s%s",filename,addpost[i2]); + workname.Format("/sc/include/%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1362,7 +1354,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /usr/include/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/usr/include/%s%s",filename,addpost[i2]); + workname.Format("/usr/include/%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1373,7 +1365,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /usr/include/g++/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/usr/include/g++/%s%s",filename,addpost[i2]); + workname.Format("/usr/include/g++/%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1385,7 +1377,7 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /usr/include/CC/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/usr/include/CC/%s%s",filename,addpost[i2]); + workname.Format("/usr/include/CC/%s%s",filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1396,8 +1388,8 @@ int G__statfilename(const char *filenamein, struct stat *statBuf) * try /usr/include/codelibs/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(workname,"/usr/include/codelibs/%s%s" - ,filename,addpost[i2]); + workname.Format("/usr/include/codelibs/%s%s" + ,filename(),addpost[i2]); res = stat( workname, statBuf ); if (res==0) return res; } @@ -1435,9 +1427,9 @@ int G__loadfile(const char *filenamein) struct G__includepath *ipath; int store_nobreak; #ifdef G__TMPFILE - char prepname[G__MAXFILENAME]; + G__FastAllocString prepname(G__MAXFILENAME); #else - char prepname[L_tmpnam+10]; + G__FastAllocString prepname(L_tmpnam+10); #endif int store_step; int null_entry = -1; @@ -1464,8 +1456,7 @@ int G__loadfile(const char *filenamein) char soext[]=SOEXT; #endif char hdrprop = G__NONCINTHDR; - char filename[G__ONELINE]; - strcpy(filename,filenamein); + G__FastAllocString filename(filenamein); /************************************************* @@ -1601,7 +1592,7 @@ int G__loadfile(const char *filenamein) cintdlls = (!strncmp(filename+len-excludelen[i], excludelist[i], excludelen[i])); } } - if (!cintdlls) G__fprinterr(G__serr,"Note: File \"%s\" already loaded\n",filename); + if (!cintdlls) G__fprinterr(G__serr,"Note: File \"%s\" already loaded\n",filename()); } /****************************************************** * restore input file information to G__ifile @@ -1650,7 +1641,7 @@ int G__loadfile(const char *filenamein) /********************************************** * -p option. open preprocessed tmpfile **********************************************/ - sprintf(G__ifile.name,"%s",filename); + strcpy(G__ifile.name, filename); #ifndef G__OLDIMPLEMENTATION1922 if(G__fons_comment && G__cpp && G__NOLINK!=G__globalcomp) { #ifndef G__WIN32 @@ -1663,7 +1654,7 @@ int G__loadfile(const char *filenamein) G__ifile.fp = G__copytotmpfile(prepname); if(G__ifile.fp) { remove(prepname); - strcpy(prepname,"(tmpfile)"); + prepname = "(tmpfile)"; } else { #ifndef G__WIN32 @@ -1676,7 +1667,7 @@ int G__loadfile(const char *filenamein) #else /* 1922 */ G__ifile.fp = G__copytotmpfile(prepname); remove(prepname); - strcpy(prepname,"(tmpfile)"); + prepname = "(tmpfile)"; #endif /* 1922 */ G__kindofheader = G__USERHEADER; } @@ -1690,20 +1681,24 @@ int G__loadfile(const char *filenamein) if((len>3&& (strcmp(filename+len-3,".sl")==0 || strcmp(filename+len-3,".dl")==0 || strcmp(filename+len-3,".so")==0))) { - strcpy(filename+len-3,G__getmakeinfo1("DLLPOST")); + filename[len - 3] = 0; + filename += G__getmakeinfo1("DLLPOST"); } else if((len>4&& (strcmp(filename+len-4,".dll")==0 || strcmp(filename+len-4,".DLL")==0))) { - strcpy(filename+len-4,G__getmakeinfo1("DLLPOST")); + filename[len - 4] = 0; + filename += G__getmakeinfo1("DLLPOST"); } else if((len>2&& (strcmp(filename+len-2,".a")==0 || strcmp(filename+len-2,".A")==0))) { - strcpy(filename+len-2,G__getmakeinfo1("DLLPOST")); + filename[len - 2] = 0; + filename += G__getmakeinfo1("DLLPOST"); } #if defined(R__FBSD) || defined(R__OBSD) else if (len>strlen(soext) && strcmp(filename+len-strlen(soext),soext)==0) { - strcpy(filename+len-strlen(soext),G__getmakeinfo1("DLLPOST")); + filename[len - strlen(soext)] = 0; + filename += G__getmakeinfo1("DLLPOST"); } #endif } @@ -1750,9 +1745,9 @@ int G__loadfile(const char *filenamein) **********************************************/ if(G__USERHEADER==G__kindofheader) { #ifdef G__VMS - sprintf(G__ifile.name,"%s",filename); + sprintf(G__ifile.name,"%s",filename()); #else - sprintf(G__ifile.name,"%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"%s%s",filename(),addpost[i2]); #endif #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); @@ -1772,7 +1767,7 @@ int G__loadfile(const char *filenamein) ipath = &G__ipathentry; while(G__ifile.fp==NULL && ipath->pathname) { sprintf(G__ifile.name,"%s%s%s%s" - ,ipath->pathname,G__psep,filename,addpost[i2]); + ,ipath->pathname,G__psep,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1798,7 +1793,7 @@ int G__loadfile(const char *filenamein) G__getcintsysdir(); if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"%s%s%s%sinclude%s%s%s",G__cintsysdir,G__psep,G__CFG_COREVERSION - ,G__psep,G__psep,filename,addpost[i2]); + ,G__psep,G__psep,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1819,7 +1814,7 @@ int G__loadfile(const char *filenamein) G__getcintsysdir(); if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"%s%s%s%sstl%s%s%s",G__cintsysdir, G__psep, G__CFG_COREVERSION, - G__psep, G__psep, filename,addpost[i2]); + G__psep, G__psep, filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1840,7 +1835,7 @@ int G__loadfile(const char *filenamein) /* G__getcintsysdir(); */ if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"%s%s%s%slib%s%s%s",G__cintsysdir, G__psep, G__CFG_COREVERSION, - G__psep, G__psep,filename,addpost[i2]); + G__psep, G__psep,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1857,7 +1852,7 @@ int G__loadfile(const char *filenamein) G__getcintsysdir(); if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"include%s%s%s" - ,G__psep,filename,addpost[i2]); + ,G__psep,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1878,7 +1873,7 @@ int G__loadfile(const char *filenamein) G__getcintsysdir(); if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"stl%s%s%s" - ,G__psep,filename,addpost[i2]); + ,G__psep,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1899,7 +1894,7 @@ int G__loadfile(const char *filenamein) * try /msdev/include **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(G__ifile.name,"/msdev/include/%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"/msdev/include/%s%s",filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1915,7 +1910,7 @@ int G__loadfile(const char *filenamein) * try /sc/include **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(G__ifile.name,"/sc/include/%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"/sc/include/%s%s",filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1933,7 +1928,7 @@ int G__loadfile(const char *filenamein) if('\0'!=G__cintsysdir[0]) { /* sprintf(G__ifile.name,getenv("ROOTSYS")); sprintf(&G__ifile.name[strlen(G__ifile.name)-1],".include]%s",filename);*/ - sprintf(G__ifile.name,"%s[include]%s",getenv("ROOTSYS"),filename); + sprintf(G__ifile.name,"%s[include]%s",getenv("ROOTSYS"),filename()); G__ifile.fp = fopen(G__ifile.name,"r"); /*G__globalcomp=G__store_globalcomp;*/ @@ -1946,7 +1941,7 @@ int G__loadfile(const char *filenamein) if('\0'!=G__cintsysdir[0]) { /* sprintf(G__ifile.name,"%s",G__cintsysdir); sprintf(&G__ifile.name[strlen(G__ifile.name)-1],".include]%s",filename);*/ - sprintf(G__ifile.name,"%s[include]%s",G__cintsysdir,filename); + sprintf(G__ifile.name,"%s[include]%s",G__cintsysdir,filename()); G__ifile.fp = fopen(G__ifile.name,"r"); hdrprop = G__CINTHDR; @@ -1958,7 +1953,7 @@ int G__loadfile(const char *filenamein) * try sys$common:[decc$lib.reference.decc$rtldef..] **********************************************/ - sprintf(G__ifile.name,"sys$common:decc$lib.reference.decc$rtdef]%s",filename); + sprintf(G__ifile.name,"sys$common:decc$lib.reference.decc$rtdef]%s",filename()); G__ifile.fp = fopen(G__ifile.name,"r"); G__globalcomp=G__store_globalcomp; @@ -1972,7 +1967,7 @@ int G__loadfile(const char *filenamein) * try /usr/include/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(G__ifile.name,"/usr/include/%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"/usr/include/%s%s",filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -1988,7 +1983,7 @@ int G__loadfile(const char *filenamein) * try /usr/include/g++/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(G__ifile.name,"/usr/include/g++/%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"/usr/include/g++/%s%s",filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -2005,7 +2000,7 @@ int G__loadfile(const char *filenamein) * try /usr/include/CC/filename **********************************************/ if('\0'!=G__cintsysdir[0]) { - sprintf(G__ifile.name,"/usr/include/CC/%s%s",filename,addpost[i2]); + sprintf(G__ifile.name,"/usr/include/CC/%s%s",filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -2024,7 +2019,7 @@ int G__loadfile(const char *filenamein) **********************************************/ if('\0'!=G__cintsysdir[0]) { sprintf(G__ifile.name,"/usr/include/codelibs/%s%s" - ,filename,addpost[i2]); + ,filename(),addpost[i2]); #ifndef G__WIN32 G__ifile.fp = fopen(G__ifile.name,"r"); #else @@ -2089,7 +2084,7 @@ int G__loadfile(const char *filenamein) G__step=store_step; G__globalcomp=G__store_globalcomp; if(0==G__ispragmainclude) { - G__fprinterr(G__serr,"Error: cannot open file \"%s\" ", filename); + G__fprinterr(G__serr,"Error: cannot open file \"%s\" ", filename()); G__genericerror((char*)NULL); } G__iscpp=store_iscpp; @@ -2181,7 +2176,7 @@ int G__loadfile(const char *filenamein) } if(G__debugtrace) { - G__fprinterr(G__serr,"LOADING file=%s:%s:%s\n",filename,G__ifile.name,prepname); + G__fprinterr(G__serr,"LOADING file=%s:%s:%s\n",filename(),G__ifile.name,prepname()); } if(G__debug) { G__fprinterr(G__serr,"%-5d",G__ifile.line_number); @@ -2479,7 +2474,7 @@ int G__preprocessor( char *outname,const char *inname,int cppflag ,const char *includepath) { /* char *envcpp; */ - char tmpfile[G__MAXFILENAME]; + G__FastAllocString tmpfile(G__MAXFILENAME); int tmplen; FILE *fp; int flag=0; @@ -2627,7 +2622,7 @@ int G__preprocessor( char *outname,const char *inname,int cppflag } else { /* otherwise, simply copy the inname */ - strcpy(tmpfile,inname); + tmpfile = inname; tmplen=0; } @@ -2651,11 +2646,11 @@ int G__preprocessor( char *outname,const char *inname,int cppflag temp.Format("%s %s %s -I. %s %s -D__CINT__ -I%s/%s/include -I%s/%s/stl -I%s/%s/lib %s -o%s" ,G__ccom ,macros,undeflist,ppopt ,includepath, ,G__cintsysdir, G__CFG_COREVERSION, G__cintsysdir,G__CFG_COREVERSION - ,G__cintsysdir, G__CFG_COREVERSION, tmpfile,outname); + ,G__cintsysdir, G__CFG_COREVERSION, tmpfile(),outname); } else { temp.Format("%s %s %s %s -I. %s -D__CINT__ %s -o%s" ,G__ccom - ,macros,undeflist,ppopt ,includepath ,tmpfile,outname); + ,macros,undeflist,ppopt ,includepath ,tmpfile(),outname); } #elif defined(G__BORLAND) /************************************************************** @@ -2667,11 +2662,11 @@ int G__preprocessor( char *outname,const char *inname,int cppflag temp.Format("%s %s %s -I. %s %s -D__CINT__ -I%s/%s/include -I%s/%s/stl -I%s/%s/lib -o%s %s" ,G__ccom ,macros,undeflist,ppopt ,includepath ,G__cintsysdir,G__CFG_COREVERSION,G__cintsysdir,G__CFG_COREVERSION, - G__cintsysdir,G__CFG_COREVERSION,outname,tmpfile); + G__cintsysdir,G__CFG_COREVERSION,outname,tmpfile()); } else { temp.Format("%s %s %s %s -I. %s -D__CINT__ -o%s %s" ,G__ccom - ,macros,undeflist,ppopt ,includepath ,outname,tmpfile); + ,macros,undeflist,ppopt ,includepath ,outname,tmpfile()); } #else /************************************************************** @@ -2685,11 +2680,11 @@ int G__preprocessor( char *outname,const char *inname,int cppflag temp.Format("%s %s %s -I. %s %s -D__CINT__ -I%s/%s/include -I%s/%s/stl -I%s/%s/lib %s > %s" ,G__ccom ,macros,undeflist,ppopt ,includepath ,G__cintsysdir,G__CFG_COREVERSION,G__cintsysdir,G__CFG_COREVERSION, - G__cintsysdir,G__CFG_COREVERSION,tmpfile,outname); + G__cintsysdir,G__CFG_COREVERSION,tmpfile(),outname); } else { temp.Format("%s %s %s %s -I. %s -D__CINT__ %s > %s" ,G__ccom - ,macros,undeflist,ppopt ,includepath ,tmpfile,outname); + ,macros,undeflist,ppopt ,includepath ,tmpfile(),outname); } #endif if(G__debugtrace||G__steptrace||G__step||G__asm_dbg) { diff --git a/cint/cint/src/macro.cxx b/cint/cint/src/macro.cxx index c77d11775887acb6890ad16f84439e6555a5317b..e9d6d874da16b4b23760c77cf4480b48d8d96854 100644 --- a/cint/cint/src/macro.cxx +++ b/cint/cint/src/macro.cxx @@ -180,7 +180,7 @@ static void G__createmacro(char* new_name, char* initvalue) // // Note: This routine is part of the parser proper. // - char line[G__ONELINE]; + G__FastAllocString line(G__ONELINE); int c; char *p, *null_fgets; fpos_t pos; @@ -235,10 +235,10 @@ static void G__createmacro(char* new_name, char* initvalue) } if (G__dispsource) { G__fprinterr(G__serr, "\\\n%-5d", G__ifile.line_number); - G__fprinterr(G__serr, "%s", line); + G__fprinterr(G__serr, "%s", line()); } ++G__mline; - fprintf(G__mfp, "%s\n", line); + fprintf(G__mfp, "%s\n", line()); } while (c != '\n' && c != '\r'); p = strrchr(line, ';'); @@ -276,7 +276,7 @@ static int G__createfuncmacro(char* new_name) // struct G__Deffuncmacro *deffuncmacro; int hash, i; - char paralist[G__ONELINE]; + G__FastAllocString paralist(G__ONELINE); int c; if (G__ifile.filenum > G__gettempfilenum()) { G__fprinterr(G__serr, "Limitation: Macro function can not be defined in a command line or a tempfile\n"); @@ -297,7 +297,7 @@ static int G__createfuncmacro(char* new_name) G__hash(new_name, hash, i) deffuncmacro->hash = hash; /* read parameter list */ - c = G__fgetstream(paralist, ")"); + c = G__fgetstream(paralist, 0, ")"); G__ASSERT(')' == c); G__getparameterlist(paralist, &deffuncmacro->def_para); /* store file pointer, line number and position */ @@ -325,8 +325,8 @@ static int G__replacefuncmacro(const char* item, G__Callfuncmacro* callfuncmacro fpos_t pos; int c; int semicolumn; - char symbol[G__ONELINE]; - const char *punctuation = " \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; + G__FastAllocString symbol(G__ONELINE); + static const char *punctuation = " \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; int double_quote = 0, single_quote = 0; fpos_t backup_pos; if (!G__mfp) { @@ -361,12 +361,12 @@ static int G__replacefuncmacro(const char* item, G__Callfuncmacro* callfuncmacro semicolumn = 0; while (1) { G__disp_mask = 10000; // FIXME: Crazy! - c = G__fgetstream(symbol, punctuation); + c = G__fgetstream(symbol, 0, punctuation); if ('\0' != symbol[0]) { if (!double_quote && !single_quote) { G__argsubstitute(symbol, callpara, defpara); } - fprintf(G__mfp, "%s", symbol); + fprintf(G__mfp, "%s", symbol()); fgetpos(G__mfp, &backup_pos); semicolumn = 0; } @@ -478,14 +478,14 @@ static int G__getparameterlist(char* paralist, G__Charlist* charlist) { // -- FIXME: Describe this function! int isrc; - char string[G__ONELINE]; + G__FastAllocString string(G__ONELINE); int c; charlist->string = 0; charlist->next = 0; c = ','; isrc = 0; while (',' == c || ' ' == c) { - c = G__getstream_template(paralist, &isrc, string, " \t,)\0"); + c = G__getstream_template(paralist, &isrc, string, 0, " \t,)\0"); if (c == '\t') c = ' '; if (charlist->string) charlist->string = (char*) realloc(charlist->string, strlen(charlist->string) + strlen(string) + 2); @@ -526,8 +526,8 @@ void G__define() // // #define [NAME] [VALUE] \n => G__letvariable("NAME","VALUE") // - char new_name[G__ONELINE]; - char initvalue[G__ONELINE]; + G__FastAllocString new_name(G__ONELINE); + G__FastAllocString initvalue(G__ONELINE); G__value evalval; int c; fpos_t pos; @@ -536,7 +536,7 @@ void G__define() // ^ // read macro name // - c = G__fgetname(new_name, "(\n\r\\"); + c = G__fgetname(new_name, 0, "(\n\r\\"); // // #define macro value // ^ @@ -565,7 +565,7 @@ void G__define() // Remember position in case it is too hard for us to handle. fgetpos(G__ifile.fp, &pos); // Grab first part. - c = G__fgetstream(initvalue, "\n\r\\/"); + c = G__fgetstream(initvalue, 0, "\n\r\\/"); // Read and remove comments until done. while (c == '/') { // -- Possible comment coming next. @@ -583,14 +583,14 @@ void G__define() // -- C style comment, ignore. G__skip_comment(); // Scan in next part. - c = G__fgetstream(initvalue + strlen(initvalue), "\n\r\\/"); + c = G__fgetstream(initvalue, strlen(initvalue), "\n\r\\/"); break; default: // -- Not a comment, take character. // Accumulate character. sprintf(initvalue + strlen(initvalue), "/%c", c); // Scan in next part. - c = G__fgetstream(initvalue + strlen(initvalue), "\n\r\\/"); + c = G__fgetstream(initvalue, strlen(initvalue), "\n\r\\/"); break; } } @@ -683,12 +683,7 @@ G__value G__execfuncmacro(const char* item, int* done) // // Separate macro func name. // - char buf[G__ONELINE]; - char* funcmacro = buf; - if (strlen(item) > (G__ONELINE - 10)) { - funcmacro = (char*) malloc(strlen(item) + 10); - } - strcpy(funcmacro, item); + G__FastAllocString funcmacro(item); char* p = strchr(funcmacro, '('); *p = '\0'; // @@ -714,9 +709,6 @@ G__value G__execfuncmacro(const char* item, int* done) // if (!found) { *done = 0; - if (funcmacro != buf) { - free(funcmacro); - } return G__null; } // @@ -785,9 +777,6 @@ G__value G__execfuncmacro(const char* item, int* done) // We are done. // *done = 1; - if (funcmacro != buf) { - free(funcmacro); - } return result; } @@ -802,12 +791,7 @@ int G__execfuncmacro_noexec(const char* macroname) // // Separate macro func name. // - char buf[G__ONELINE]; - char* funcmacro = buf; - if (strlen(macroname) > (G__ONELINE - 10)) { - funcmacro = (char*) malloc(strlen(macroname) + 10); - } - strcpy(funcmacro, macroname); + G__FastAllocString funcmacro(macroname); char* p = strchr(funcmacro, '('); if (p) { *p = '\0'; @@ -841,17 +825,15 @@ int G__execfuncmacro_noexec(const char* macroname) // if (!found) { // -- - if (funcmacro != buf) { - free(funcmacro); - } return 0; } // // Snarf the arg list. // *p = '('; - int c = G__fgetstream_spaces(p + 1 , ")"); + int c = G__fgetstream_spaces(funcmacro, p - funcmacro.data() + 1, ")"); i = strlen(funcmacro); + funcmacro.Resize(i + 2); funcmacro[i++] = c; funcmacro[i] = '\0'; // @@ -915,9 +897,6 @@ int G__execfuncmacro_noexec(const char* macroname) // #define BEGIN_NS(N) namespace N { // #define END_NS(N) } // - if (funcmacro != buf) { - free(funcmacro); - } return 1; } diff --git a/cint/cint/src/malloc.cxx b/cint/cint/src/malloc.cxx index 9474a65fe688fd1edb0ab20a3f33762c0521fc88..ccb5c772476d10cd85d4bcdd6029e6cc36faf69c 100644 --- a/cint/cint/src/malloc.cxx +++ b/cint/cint/src/malloc.cxx @@ -93,11 +93,11 @@ void G__shminit() /* Prepare keys */ key_t mykey; const char projid = 'Q'; - char keyfile[256]; + G__FastAllocString keyfile(256); int* poffset; G__getcintsysdir(); - sprintf(keyfile, "%s/cint", G__cintsysdir); + keyfile.Format("%s/cint", G__cintsysdir); mykey = ftok(keyfile, projid); /* printf("mykey=%x\n",mykey); */ @@ -141,12 +141,12 @@ extern "C" { //______________________________________________________________________________ static long G__getstaticobject() { - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); if (G__memberfunc_tagnum != -1) { - sprintf(temp, "%s\\%x\\%x\\%x", G__varname_now, G__func_page, G__func_now, G__memberfunc_tagnum); + temp.Format("%s\\%x\\%x\\%x", G__varname_now, G__func_page, G__func_now, G__memberfunc_tagnum); } else { - sprintf(temp, "%s\\%x\\%x", G__varname_now, G__func_page, G__func_now); + temp.Format("%s\\%x\\%x", G__varname_now, G__func_page, G__func_now); } int hash = 0; int i = 0; @@ -161,7 +161,7 @@ static long G__getstaticobject() } } if (!G__const_noerror) { - G__fprinterr(G__serr, "Error: No memory for static %s ", temp); + G__fprinterr(G__serr, "Error: No memory for static %s ", temp()); G__genericerror(0); } return 0; diff --git a/cint/cint/src/new.cxx b/cint/cint/src/new.cxx index 905c2c01065b485a8b11f46a9bae6fcbf2780748..696c237f3d82fa46f64c0e556e3292924d7f9204 100644 --- a/cint/cint/src/new.cxx +++ b/cint/cint/src/new.cxx @@ -38,10 +38,10 @@ G__value G__new_operator(const char* expression) // new (arena)type //char expression[G__LONGLINE]; //strcpy (expression,express); - char arena[G__ONELINE]; + G__FastAllocString arena(G__ONELINE); long memarena = 0; int arenaflag = 0; - char construct[G__LONGLINE]; + G__FastAllocString construct(G__LONGLINE); char *type; char *basictype; char *initializer; @@ -148,10 +148,10 @@ G__value G__new_operator(const char* expression) tagnum = G__defined_tagname(basictype, 1); } if (tagnum != -1) { - sprintf(construct, "%s()", G__struct.name[tagnum]); + construct.Format("%s()", G__struct.name[tagnum]); } else { - sprintf(construct, "%s()", basictype); + construct.Format("%s()", basictype); } if (G__asm_wholefunction) { G__abortbytecode(); @@ -183,20 +183,20 @@ G__value G__new_operator(const char* expression) *initializer = '('; } if (tagnum != -1) { - sprintf(construct, "%s%s", G__struct.name[tagnum], initializer); + construct.Format("%s%s", G__struct.name[tagnum], initializer); } else { - strcpy(construct, basictype); + construct = basictype; } *initializer = '\0'; } else { pinc = 1; if (tagnum != -1) { - sprintf(construct, "%s()", G__struct.name[tagnum]); + construct.Format("%s()", G__struct.name[tagnum]); } else { - sprintf(construct, "%s()", basictype); + construct.Format("%s()", basictype); } } } @@ -501,7 +501,7 @@ G__value G__new_operator(const char* expression) ++bp; { int nx = 0; - char tmpx[G__ONELINE]; + G__FastAllocString tmpx(G__ONELINE); int cx = G__getstream(bp, &nx, tmpx, "),"); if (cx == ',') { *ep = ')'; @@ -580,7 +580,7 @@ G__value G__new_operator(const char* expression) // construct = "TYPE" , bp = "ARG" typenum = G__defined_typename(construct); if (typenum != -1) { - strcpy(construct, G__type2string(G__newtype.type[typenum], G__newtype.tagnum[typenum], -1, G__newtype.reftype[typenum], 0)); + construct = G__type2string(G__newtype.type[typenum], G__newtype.tagnum[typenum], -1, G__newtype.reftype[typenum], 0); } hash = strlen(construct); store_var_type = G__var_type; @@ -693,7 +693,7 @@ int G__getarrayindex(const char* indexlist) // [x][y][z] get x*y*z int p_inc = 1; int p = 1; - char index[G__ONELINE]; + G__FastAllocString index(G__ONELINE); int c; int store_var_type = G__var_type; G__var_type = 'p'; @@ -738,7 +738,7 @@ void G__delete_operator(char* expression, int isarray) int cpplink = 0; int zeroflag = 0; G__value buf; - char destruct[G__ONELINE]; + G__FastAllocString destruct(G__ONELINE); if (G__cintv6) { // -- THIS CASE IS NEVER USED. G__bc_delete_operator(expression, isarray); @@ -787,9 +787,9 @@ void G__delete_operator(char* expression, int isarray) G__store_struct_offset = buf.obj.i; G__typenum = buf.typenum; G__tagnum = buf.tagnum; - sprintf(destruct, "~%s()", G__struct.name[G__tagnum]); + destruct.Format("~%s()", G__struct.name[G__tagnum]); if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for '%s'\n", G__store_struct_offset, destruct, expression); + G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for '%s'\n", G__store_struct_offset, destruct(), expression); } done = 0; if ( diff --git a/cint/cint/src/newlink.cxx b/cint/cint/src/newlink.cxx index e8bee201d0504a2745148770b3f866123d49f6d4..145234c9c994fee33aaf750187efeb1954be0561 100644 --- a/cint/cint/src/newlink.cxx +++ b/cint/cint/src/newlink.cxx @@ -454,13 +454,13 @@ char* G__fulltypename(int typenum) **************************************************************************/ int G__debug_compiledfunc_arg(FILE *fout,G__ifunc_table_internal *ifunc,int ifn,G__param *libp) { - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); int i; fprintf(fout,"\n!!!Calling compiled function %s()\n",ifunc->funcname[ifn]); G__in_pause=1; for(i=0;i<libp->paran;i++) { G__valuemonitor(libp->para[i],temp); - fprintf(fout," arg%d = %s\n",i+1,temp); + fprintf(fout," arg%d = %s\n",i+1,temp()); #ifdef G__NEVER if('u'==libp->para[i].type && -1!=libp->para[i].tagnum && libp->para[i].obj.i) { @@ -2115,11 +2115,11 @@ int G__stub_method_calling(G__value *result7, G__param *libp, } new_ifunc = G__struct.memfunc[tagnum]; - char funcname[G__MAXNAME]; + G__FastAllocString funcname(G__MAXNAME); if(ifunc->funcname[ifn][0]=='~') - sprintf(funcname, "~%s", G__struct.name[new_ifunc->tagnum]); + funcname.Format("~%s", G__struct.name[new_ifunc->tagnum]); else - sprintf(funcname, "%s", ifunc->funcname[ifn]); + funcname = ifunc->funcname[ifn]; new_ifunc = G__get_methodhandle4(funcname, &fpara, new_ifunc, &pifn, &poffset, 1, 1, 0); } @@ -3139,7 +3139,7 @@ char *G__map_cpp_name(const char *in) **************************************************************************/ char *G__map_cpp_funcname(int tagnum,const char * /* funcname */,int ifn,int page) { - static char mapped_name[G__MAXNAME]; + static G__FastAllocString mapped_name(G__MAXNAME); const char *dllid; if(G__DLLID[0]) dllid=G__DLLID; @@ -3147,10 +3147,10 @@ char *G__map_cpp_funcname(int tagnum,const char * /* funcname */,int ifn,int pag else dllid=""; if(-1==tagnum) { - sprintf(mapped_name,"G__%s__%d_%d",G__map_cpp_name(dllid),ifn,page); + mapped_name.Format("G__%s__%d_%d",G__map_cpp_name(dllid),ifn,page); } else { - sprintf(mapped_name,"G__%s_%d_%d_%d",G__map_cpp_name(dllid),tagnum,ifn,page); + mapped_name.Format("G__%s_%d_%d_%d",G__map_cpp_name(dllid),tagnum,ifn,page); } return(mapped_name); @@ -3319,11 +3319,11 @@ void G__cpplink_protected_stub(FILE *fp,FILE *hfp) void G__cpplink_linked_taginfo(FILE *fp,FILE *hfp) { int i; - char buf[G__MAXFILENAME]; + G__FastAllocString buf(G__MAXFILENAME); FILE* pfp; if(G__privateaccess) { char *xp; - strcpy(buf,G__CPPLINK_H); + buf = G__CPPLINK_H; xp = strstr(buf,".h"); if(xp) strcpy(xp,"P.h"); pfp = fopen(buf,"r"); @@ -3679,12 +3679,11 @@ static void G__write_windef_header() void G__set_globalcomp(const char *mode,const char *linkfilename,const char *dllid) { FILE *fp; - char buf[G__LONGLINE]; - char linkfilepref[G__LONGLINE]; - char linkfilepostf[20]; + G__FastAllocString buf(G__LONGLINE); + G__FastAllocString linkfilepref(linkfilename); + G__FastAllocString linkfilepostf(20); char *p; - strcpy(linkfilepref,linkfilename); p = strrchr(linkfilepref,'/'); /* ../aaa/bbb/ccc.cxx */ #ifdef G__WIN32 if (!p) p = strrchr(linkfilepref,'\\'); /* in case of Windows pathname */ @@ -3692,11 +3691,11 @@ void G__set_globalcomp(const char *mode,const char *linkfilename,const char *dll if (!p) p = linkfilepref; /* /ccc.cxx */ p = strrchr (p, '.'); /* .cxx */ if(p) { - strcpy(linkfilepostf,p+1); + linkfilepostf = p+1; *p = '\0'; } else { - sprintf(linkfilepostf,"C"); + linkfilepostf = "C"; } G__globalcomp = atoi(mode); /* this is redundant */ @@ -3717,21 +3716,22 @@ void G__set_globalcomp(const char *mode,const char *linkfilename,const char *dll switch(G__globalcomp) { case G__CPPLINK: - sprintf(buf,"%s.h",linkfilepref); + buf = linkfilepref; + buf += ".h"; G__CPPLINK_H = (char*)malloc(strlen(buf)+1); strcpy(G__CPPLINK_H,buf); - sprintf(buf,"%s.%s",linkfilepref,linkfilepostf); + buf.Format("%s.%s",linkfilepref(),linkfilepostf()); G__CPPLINK_C = (char*)malloc(strlen(buf)+1); strcpy(G__CPPLINK_C,buf); #ifdef G__GENWINDEF if (G__PROJNAME[0]) - sprintf(buf,"%s.def",G__PROJNAME); + buf.Format("%s.def",G__PROJNAME); else if (G__DLLID[0]) - sprintf(buf,"%s.def",G__DLLID); + buf.Format("%s.def",G__DLLID); else - sprintf(buf,"%s.def","G__lib"); + buf.Format("%s.def","G__lib"); G__WINDEF = (char*)malloc(strlen(buf)+1); strcpy(G__WINDEF,buf); G__write_windef_header(); @@ -3774,16 +3774,16 @@ void G__set_globalcomp(const char *mode,const char *linkfilename,const char *dll } break; case G__CLINK: - sprintf(buf,"%s.h",linkfilepref); + buf.Format("%s.h",linkfilepref()); G__CLINK_H = (char*)malloc(strlen(buf)+1); strcpy(G__CLINK_H,buf); - sprintf(buf,"%s.c",linkfilepref); + buf.Format("%s.c",linkfilepref()); G__CLINK_C = (char*)malloc(strlen(buf)+1); strcpy(G__CLINK_C,buf); #ifdef G__GENWINDEF - sprintf(buf,"%s.def",G__PROJNAME); + buf.Format("%s.def",G__PROJNAME); G__WINDEF = (char*)malloc(strlen(buf)+1); strcpy(G__WINDEF,buf); G__write_windef_header(); @@ -3806,21 +3806,21 @@ void G__set_globalcomp(const char *mode,const char *linkfilename,const char *dll } break; case R__CPPLINK: - sprintf(buf,"%s.h",linkfilepref); + buf.Format("%s.h",linkfilepref()); G__CPPLINK_H = (char*)malloc(strlen(buf)+1); strcpy(G__CPPLINK_H,buf); - sprintf(buf,"%s.%s",linkfilepref,linkfilepostf); + buf.Format("%s.%s",linkfilepref(),linkfilepostf()); G__CPPLINK_C = (char*)malloc(strlen(buf)+1); strcpy(G__CPPLINK_C,buf); #ifdef G__GENWINDEF if (G__PROJNAME[0]) - sprintf(buf,"%s.def",G__PROJNAME); + buf.Format("%s.def",G__PROJNAME); else if (G__DLLID[0]) - sprintf(buf,"%s.def",G__DLLID); + buf.Format("%s.def",G__DLLID); else - sprintf(buf,"%s.def","G__lib"); + buf.Format("%s.def","G__lib"); G__WINDEF = (char*)malloc(strlen(buf)+1); strcpy(G__WINDEF,buf); G__write_windef_header(); @@ -3898,7 +3898,7 @@ void G__gen_cppheader(char *headerfilein) { FILE *fp; static char hdrpost[10]=""; - char headerfile[G__ONELINE]; + G__FastAllocString headerfile(G__ONELINE); char* p; switch(G__globalcomp) { @@ -3915,7 +3915,7 @@ void G__gen_cppheader(char *headerfilein) * if header file is already created *************************************************************/ - strcpy(headerfile,headerfilein); + headerfile = headerfilein; /************************************************************* * if preprocessed file xxx.i is given rename as xxx.h *************************************************************/ @@ -3940,21 +3940,21 @@ void G__gen_cppheader(char *headerfilein) /* backslash escape sequence */ p=strchr(headerfile,'\\'); if(p) { - char temp2[G__ONELINE]; + G__FastAllocString temp2(G__ONELINE); int i=0,j=0; while(headerfile[i]) { switch(headerfile[i]) { case '\\': - temp2[j++] = headerfile[i]; - temp2[j++] = headerfile[i++]; + temp2.Set(j++, headerfile[i]); + temp2.Set(j++, headerfile[i++]); break; default: - temp2[j++] = headerfile[i++]; + temp2.Set(j++, headerfile[i++]); break; } } - temp2[j]='\0'; - strcpy(headerfile,temp2); + temp2.Set(j, 0); + headerfile.Swap(temp2); } #ifdef G__ROOT @@ -3968,35 +3968,35 @@ void G__gen_cppheader(char *headerfilein) case G__CPPLINK: fp = fopen(G__CPPLINK_H,"a"); if(!fp) G__fileerror(G__CPPLINK_H); - fprintf(fp,"#include \"%s\"\n",headerfile); + fprintf(fp,"#include \"%s\"\n",headerfile()); fclose(fp); // 10-07-07 if(G__dicttype==kCompleteDictionary || G__dicttype==kFunctionSymbols || G__dicttype==kNoWrappersDictionary) { fp = fopen(G__CPPLINK_C,"a"); if(!fp) G__fileerror(G__CPPLINK_C); - fprintf(fp," G__add_compiledheader(\"%s\");\n",headerfile); + fprintf(fp," G__add_compiledheader(\"%s\");\n",headerfile()); fclose(fp); } break; case G__CLINK: fp = fopen(G__CLINK_H,"a"); if(!fp) G__fileerror(G__CLINK_H); - fprintf(fp,"#include \"%s\"\n",headerfile); + fprintf(fp,"#include \"%s\"\n",headerfile()); fclose(fp); // 10-07-07 if(G__dicttype==kCompleteDictionary || G__dicttype==kFunctionSymbols || G__dicttype==kNoWrappersDictionary) { fp = fopen(G__CLINK_C,"a"); if(!fp) G__fileerror(G__CLINK_C); - fprintf(fp," G__add_compiledheader(\"%s\");\n",headerfile); + fprintf(fp," G__add_compiledheader(\"%s\");\n",headerfile()); fclose(fp); } break; case R__CPPLINK: fp = fopen(G__CPPLINK_H,"a"); if(!fp) G__fileerror(G__CPPLINK_H); - fprintf(fp,"#include \"%s\"\n",headerfile); + fprintf(fp,"#include \"%s\"\n",headerfile()); fclose(fp); break; } @@ -4078,10 +4078,9 @@ void G__add_compiledheader(const char *headerfile) **************************************************************************/ void G__add_macro(const char *macroin) { - char temp[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); FILE *fp; char *p; - char macro[G__LONGLINE]; int store_tagnum = G__tagnum; int store_def_tagnum = G__def_tagnum; int store_tagdefining = G__tagdefining; @@ -4098,7 +4097,7 @@ void G__add_macro(const char *macroin) const char* macroname = macroin; if (macroname[0] == '!') ++macroname; - strcpy(macro,macroname); + G__FastAllocString macro(macroname); G__definemacro=1; if((p=strchr(macro,'='))) { if(G__cpp && '"'==*(p+1)) { @@ -4107,11 +4106,12 @@ void G__add_macro(const char *macroin) macro[strlen(macro)-1]=0; } else { - strcpy(temp,macro); + temp = macro; } } else { - sprintf(temp,"%s=1",macro); + temp = macro; + temp += "=1"; } G__getexpr(temp); G__definemacro=0; @@ -4119,33 +4119,33 @@ void G__add_macro(const char *macroin) if (macroin[0] == '!') goto end_add_macro; - sprintf(temp,"\"-D%s\" ",macro); + temp.Format("\"-D%s\" ", macro()); p = strstr(G__macros,temp); /* " -Dxxx -Dyyy -Dzzz" * p ^ */ if(p) goto end_add_macro; - strcpy(temp,G__macros); - if(strlen(temp)+strlen(macro)+3>G__LONGLINE) { + temp = G__macros; + if(strlen(temp)+strlen(macro)+5 > sizeof(G__macros)) { if(G__dispmsg>=G__DISPWARN) { G__fprinterr(G__serr,"Warning: can not add any more macros in the list\n"); G__printlinenum(); } } else { - sprintf(G__macros,"%s\"-D%s\" ",temp,macro); + sprintf(G__macros,"%s\"-D%s\" ",temp(),macro()); } switch(G__globalcomp) { case G__CPPLINK: fp=fopen(G__CPPLINK_C,"a"); if(!fp) G__fileerror(G__CPPLINK_C); - fprintf(fp," G__add_macro(\"%s\");\n",macro); + fprintf(fp," G__add_macro(\"%s\");\n",macro()); fclose(fp); break; case G__CLINK: fp=fopen(G__CLINK_C,"a"); if(!fp) G__fileerror(G__CLINK_C); - fprintf(fp," G__add_macro(\"%s\");\n",macro); + fprintf(fp," G__add_macro(\"%s\");\n",macro()); fclose(fp); break; } @@ -4165,18 +4165,18 @@ void G__add_macro(const char *macroin) void G__add_ipath(const char *path) { struct G__includepath *ipath; - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); FILE *fp; char *p; char *store_allincludepath; /* strip double quotes if exist */ if('"'==path[0]) { - strcpy(temp,path+1); + temp = path+1; if('"'==temp[strlen(temp)-1]) temp[strlen(temp)-1]='\0'; } else { - strcpy(temp,path); + temp = path; } /* to the end of list */ @@ -4198,9 +4198,9 @@ void G__add_ipath(const char *path) while(temp[i]) if(isspace(temp[i++])) flag=1; G__allincludepath = store_allincludepath; if(flag) - sprintf(G__allincludepath+strlen(G__allincludepath) ,"-I\"%s\" ",temp); + sprintf(G__allincludepath+strlen(G__allincludepath) ,"-I\"%s\" ",temp()); else - sprintf(G__allincludepath+strlen(G__allincludepath) ,"-I%s ",temp); + sprintf(G__allincludepath+strlen(G__allincludepath) ,"-I%s ",temp()); } else { G__genericerror("Internal error: memory allocation failed for includepath buffer"); @@ -4219,21 +4219,21 @@ void G__add_ipath(const char *path) /* backslash escape sequence */ p=strchr(temp,'\\'); if(p) { - char temp2[G__ONELINE]; + G__FastAllocString temp2(G__ONELINE); int i=0,j=0; while(temp[i]) { switch(temp[i]) { case '\\': - temp2[j++] = temp[i]; - temp2[j++] = temp[i++]; + temp2.Set(j++, temp[i]); + temp2.Set(j++, temp[i++]); break; default: - temp2[j++] = temp[i++]; + temp2.Set(j++, temp[i++]); break; } } - temp2[j]='\0'; - strcpy(temp,temp2); + temp2.Set(j, 0); + temp.Swap(temp2); } /* output include path information to interface routine */ @@ -4241,13 +4241,13 @@ void G__add_ipath(const char *path) case G__CPPLINK: fp=fopen(G__CPPLINK_C,"a"); if(!fp) G__fileerror(G__CPPLINK_C); - fprintf(fp," G__add_ipath(\"%s\");\n",temp); + fprintf(fp," G__add_ipath(\"%s\");\n",temp()); fclose(fp); break; case G__CLINK: fp=fopen(G__CLINK_C,"a"); if(!fp) G__fileerror(G__CLINK_C); - fprintf(fp," G__add_ipath(\"%s\");\n",temp); + fprintf(fp," G__add_ipath(\"%s\");\n",temp()); fclose(fp); break; } @@ -4262,18 +4262,18 @@ int G__delete_ipath(const char *path) { struct G__includepath *ipath; struct G__includepath *previpath; - char temp[G__ONELINE]; - char temp2[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); + G__FastAllocString temp2(G__ONELINE); int i=0,flag=0; char *p; /* strip double quotes if exist */ if('"'==path[0]) { - strcpy(temp,path+1); + temp = path+1; if('"'==temp[strlen(temp)-1]) temp[strlen(temp)-1]='\0'; } else { - strcpy(temp,path); + temp = path; } /* to the end of list */ @@ -4305,8 +4305,8 @@ int G__delete_ipath(const char *path) if(!G__allincludepath) return(0); i=0; while(temp[i]) if(isspace(temp[i++])) flag=1; - if(flag) sprintf(temp2,"-I\"%s\" ",temp); - else sprintf(temp2,"-I%s ",temp); + if(flag) temp2.Format("-I\"%s\" ",temp()); + else temp2.Format("-I%s ",temp()); p = strstr(G__allincludepath,temp2); if(p) { @@ -5043,7 +5043,7 @@ void G__make_default_ifunc(G__ifunc_table_internal *ifunc_copy) { struct G__ifunc_table_internal *ifunc = ifunc_copy; struct G__ifunc_table_internal *ifunc_destructor=0; - char funcname[G__MAXNAME*6]; + G__FastAllocString funcname(G__MAXNAME*6); int hash; int j=0,k=0; int i = ifunc->tagnum; @@ -5203,7 +5203,7 @@ void G__make_default_ifunc(G__ifunc_table_internal *ifunc_copy) if ('n' == G__struct.type[i]) isconstructor = 1; if (0 == isconstructor && 0 == G__struct.isabstract[i] && 0 == isnonpublicnew) { // putting automatic default constructor in the ifunc table - sprintf(funcname, "%s", G__struct.name[i]); + funcname = G__struct.name[i]; G__hash(funcname, hash, k); ifunc = G__p_ifunc; @@ -5231,10 +5231,10 @@ void G__make_default_ifunc(G__ifunc_table_internal *ifunc_copy) if ('n' == G__struct.type[i]) iscopyconstructor = 1; if (0 == iscopyconstructor && 0 == G__struct.isabstract[i] && 0 == isnonpublicnew) { // putting automatic copy constructor - sprintf(funcname, "%s", G__struct.name[i]); + funcname = G__struct.name[i]; G__hash(funcname, hash, k); - char paras[G__MAXNAME*6]; + G__FastAllocString paras(G__MAXNAME*6); sprintf(paras, "u '%s' - 11 - -", G__fulltagname(i, 0)); ifunc = G__p_ifunc; @@ -5262,14 +5262,14 @@ void G__make_default_ifunc(G__ifunc_table_internal *ifunc_copy) if ('n' == G__struct.type[i]) isdestructor = 1; if (ifunc_destructor && 'n' != G__struct.type[i]) { // putting automatic destructor - sprintf(funcname, "~%s", G__struct.name[i]); + funcname.Format("~%s", G__struct.name[i]); G__hash(funcname, hash, k); // 25-07-07 // the ifunc field has already been created for the destructor... lets just fill it up /* set entry pointer */ if(!(*ifunc_destructor->funcname[j])) - G__savestring(&ifunc_destructor->funcname[j],(char*)funcname); + G__savestring(&ifunc_destructor->funcname[j],funcname); if(!ifunc_destructor->hash[j]) ifunc_destructor->hash[j] = hash; @@ -5297,10 +5297,11 @@ void G__make_default_ifunc(G__ifunc_table_internal *ifunc_copy) if ('n' == G__struct.type[i]) isassignmentoperator = 1; if (0 == isassignmentoperator) { // putting automatic assignment operator - sprintf(funcname, "operator="); + funcname = "operator="; G__hash(funcname, hash, k); - char paras[G__MAXNAME*6]; + G__FastAllocString paras_sb(G__MAXNAME*6); + char* paras = paras_sb; sprintf(paras, "u '%s' - 11 - -", G__fulltagname(i, 0)); ifunc = G__p_ifunc; @@ -5770,7 +5771,7 @@ FILE *fp; int ifn; struct G__ifunc_table_internal *ifunc) { - char buf[G__LONGLINE]; + G__FastAllocString buf(G__LONGLINE); char *p; int k; if(G__CPPLINK!=G__globalcomp) return; @@ -5783,16 +5784,16 @@ struct G__ifunc_table_internal *ifunc) 'Q'==ifunc->param[ifn][k]->type #endif ) { - strcpy(buf,G__type2string(ifunc->param[ifn][k]->type, + buf = G__type2string(ifunc->param[ifn][k]->type, ifunc->param[ifn][k]->p_tagtable, ifunc->param[ifn][k]->p_typetable,0, ifunc->param[ifn][k]->isconst)); - /*DEBUG*/ printf("buf=%s\n",buf); + /*DEBUG*/ printf("buf=%s\n",buf()); p = strstr(buf,"(*)("); if(p) { p += 2; *p = 0; - fprintf(fp,"typedef %s%s",buf,G__p2f_typedefname(ifn,ifunc->page,k)); + fprintf(fp,"typedef %s%s",buf(),G__p2f_typedefname(ifn,ifunc->page,k)); *p = ')'; fprintf(fp,"%s;\n",p); } @@ -6135,14 +6136,14 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ #ifndef G__SMALLOBJECT int k, m; int isprotecteddtor = G__isprotecteddestructoronelevel(tagnum); - char buf[G__LONGLINE]; /* 1481 */ + G__FastAllocString buf(G__LONGLINE); G__ASSERT( tagnum != -1 ); if ((G__PROTECTED == ifunc->access[ifn]) || (G__PRIVATE == ifunc->access[ifn])) { - sprintf(buf, "%s_PR", G__get_link_tagname(tagnum)); + buf.Format("%s_PR", G__get_link_tagname(tagnum)); } else { - strcpy(buf, G__fulltagname(tagnum, 1)); + buf = G__fulltagname(tagnum, 1); } #ifdef G__CPPIF_EXTERNC @@ -6234,19 +6235,19 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ } else { fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new %s[n];\n", buf); + fprintf(fp, " p = ::new %s[n];\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf()); } fprintf(fp, " }\n"); } @@ -6254,19 +6255,19 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ // Handle regular new. fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else { - fprintf(fp, " p = ::new %s;\n", buf); + fprintf(fp, " p = ::new %s;\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf()); } fprintf(fp, " }\n"); fprintf(fp, " }\n"); @@ -6278,11 +6279,11 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ fprintf(fp, " //m: %d\n", m); fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s(", buf); + fprintf(fp, " p = new %s(", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s(", buf); + fprintf(fp, " p = new %s(", buf()); } else { - fprintf(fp, " p = ::new %s(", buf); + fprintf(fp, " p = ::new %s(", buf()); } if (m > 2) { fprintf(fp, "\n"); @@ -6317,11 +6318,11 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ fprintf(fp, ");\n"); fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s(", buf); + fprintf(fp, " p = new((void*) gvp) %s(", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s(", buf); + fprintf(fp, " p = new((void*) gvp) %s(", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s(", buf); + fprintf(fp, " p = ::new((void*) gvp) %s(", buf()); } if (m > 2) { fprintf(fp, "\n"); @@ -6368,11 +6369,11 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ fprintf(fp, " //m: %d\n", m); fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s(", buf); + fprintf(fp, " p = new %s(", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s(", buf); + fprintf(fp, " p = new %s(", buf()); } else { - fprintf(fp, " p = ::new %s(", buf); + fprintf(fp, " p = ::new %s(", buf()); } if (m > 2) { fprintf(fp, "\n"); @@ -6406,11 +6407,11 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ fprintf(fp, ");\n"); fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s(", buf); + fprintf(fp, " p = new((void*) gvp) %s(", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s(", buf); + fprintf(fp, " p = new((void*) gvp) %s(", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s(", buf); + fprintf(fp, " p = ::new((void*) gvp) %s(", buf()); } if (m > 2) { fprintf(fp, "\n"); @@ -6455,19 +6456,19 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ } else { fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new %s[n];\n", buf); + fprintf(fp, " p = ::new %s[n];\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf()); } fprintf(fp, " }\n"); } @@ -6476,19 +6477,19 @@ void G__cppif_genconstructor(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G_ // Handle regular new. fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else { - fprintf(fp, " p = ::new %s;\n", buf); + fprintf(fp, " p = ::new %s;\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf()); } fprintf(fp, " }\n"); fprintf(fp, " }\n"); @@ -6888,22 +6889,10 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, #ifndef G__SMALLOBJECT /* int k,m; */ int page; -#define G__OLDIMPLEMENtATION1972 -#ifndef G__OLDIMPLEMENtATION1972 - char buf1[G__MAXNAME]; - char buf2[G__MAXNAME]; - char buf3[G__MAXNAME]; - char *funcname=buf1; - char *temp=buf2; - char *dtorname=buf3; -#else - char funcname[G__MAXNAME*6]; - char temp[G__MAXNAME*6]; -#endif + G__FastAllocString funcname(G__MAXNAME); + G__FastAllocString temp(G__MAXNAME); + G__FastAllocString dtorname(G__MAXNAME); int isprotecteddtor = G__isprotecteddestructoronelevel(tagnum); -#ifdef G__OLDIMPLEMENtATION1972 - char dtorname[G__LONGLINE]; -#endif G__ASSERT( tagnum != -1 ); @@ -6915,16 +6904,6 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, ++page; } -#ifndef G__OLDIMPLEMENtATION1972 - if(strlen(G__struct.name[tagnum])>G__MAXNAME-2) { - funcname = (char*)malloc(strlen(G__struct.name[tagnum])+5); - dtorname = (char*)malloc(strlen(G__struct.name[tagnum])+5); - } - if(strlen(G__fulltagname(tagnum,1))>G__MAXNAME-2) { - dtorname = (char*)malloc(strlen(G__fulltagname(tagnum,1))+5); - } -#endif - /********************************************************************* * default constructor *********************************************************************/ @@ -6995,10 +6974,9 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, else #endif { - char buf[G__LONGLINE]; - strcpy(buf, G__fulltagname(tagnum, 1)); + G__FastAllocString buf(G__fulltagname(tagnum, 1)); - strcpy(funcname, G__struct.name[tagnum]); + funcname = G__struct.name[tagnum]; fprintf(fp, "// automatic default constructor\n"); #ifdef G__CPPIF_STATIC @@ -7051,19 +7029,19 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, } else { fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s[n];\n", buf); + fprintf(fp, " p = new %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new %s[n];\n", buf); + fprintf(fp, " p = ::new %s[n];\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = new((void*) gvp) %s[n];\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s[n];\n", buf()); } fprintf(fp, " }\n"); } @@ -7072,19 +7050,19 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, // Handle regular new. fprintf(fp, " if ((gvp == (char*)G__PVOID) || (gvp == 0)) {\n"); if (!has_a_new) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else if (has_a_new1arg && (has_own_new1arg || !has_own_new2arg)) { - fprintf(fp, " p = new %s;\n", buf); + fprintf(fp, " p = new %s;\n", buf()); } else { - fprintf(fp, " p = ::new %s;\n", buf); + fprintf(fp, " p = ::new %s;\n", buf()); } fprintf(fp, " } else {\n"); if (!has_a_new) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else if (has_a_new2arg && (has_own_new2arg || !has_own_new1arg)) { - fprintf(fp, " p = new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = new((void*) gvp) %s;\n", buf()); } else { - fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf); + fprintf(fp, " p = ::new((void*) gvp) %s;\n", buf()); } fprintf(fp, " }\n"); fprintf(fp, " }\n"); @@ -7173,7 +7151,7 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, else #endif // G__NOSTUBS { - sprintf(funcname, "%s", G__struct.name[tagnum]); + funcname = G__struct.name[tagnum]; fprintf(fp, "// automatic copy constructor\n"); @@ -7190,10 +7168,10 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, fprintf(fp, "\n{\n"); fprintf(fp, " %s* p;\n", G__fulltagname(tagnum, 1)); - strcpy(temp, G__fulltagname(tagnum, 1)); + temp = G__fulltagname(tagnum, 1); fprintf(fp, " void* tmp = (void*) G__int(libp->para[0]);\n"); - fprintf(fp, " p = new %s(*(%s*) tmp);\n", temp, temp); + fprintf(fp, " p = new %s(*(%s*) tmp);\n", temp(), temp()); fprintf(fp, " result7->obj.i = (long) p;\n"); fprintf(fp, " result7->ref = (long) p;\n"); @@ -7228,8 +7206,8 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, // index in the ifunc long pifn; long poffset; - char funcname[G__MAXNAME*6]; - sprintf(funcname, "~%s", G__struct.name[tagnum]); + G__FastAllocString funcname(G__MAXNAME*6); + funcname.Format("~%s", G__struct.name[tagnum]); // Single Constructor has only a parameter. The size of the object G__param para_des; @@ -7264,8 +7242,7 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, else #endif { - char buf[G__LONGLINE]; - strcpy(buf, G__fulltagname(tagnum, 1)); + G__FastAllocString buf(G__fulltagname(tagnum, 1)); bool has_a_delete = G__struct.funcs[tagnum] & G__HAS_OPERATORDELETE; @@ -7283,11 +7260,11 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, has_own_delete2arg = (ireffound != 0); } - sprintf(funcname, "~%s", G__struct.name[tagnum]); - sprintf(dtorname, "G__T%s", G__map_cpp_name(G__fulltagname(tagnum, 0))); + funcname.Format("~%s", G__struct.name[tagnum]); + dtorname.Format("G__T%s", G__map_cpp_name(G__fulltagname(tagnum, 0))); fprintf(fp,"// automatic destructor\n"); - fprintf(fp, "typedef %s %s;\n", G__fulltagname(tagnum, 0), dtorname); + fprintf(fp, "typedef %s %s;\n", G__fulltagname(tagnum, 0), dtorname()); #ifdef G__CPPIF_STATIC fprintf(fp,"static int %s(G__value* result7, G__CONST char* funcname, struct G__param* libp, int hash)", G__map_cpp_funcname(tagnum, funcname, ifn, page)); @@ -7316,21 +7293,21 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, fprintf(fp, " if (n) {\n"); fprintf(fp, " if (gvp == (char*)G__PVOID) {\n"); - fprintf(fp, " delete[] (%s*) soff;\n", buf); + fprintf(fp, " delete[] (%s*) soff;\n", buf()); fprintf(fp, " } else {\n"); fprintf(fp, " G__setgvp((long) G__PVOID);\n"); fprintf(fp, " for (int i = n - 1; i >= 0; --i) {\n"); - fprintf(fp, " ((%s*) (soff+(sizeof(%s)*i)))->~%s();\n", buf, buf, dtorname); + fprintf(fp, " ((%s*) (soff+(sizeof(%s)*i)))->~%s();\n", buf(), buf(), dtorname()); fprintf(fp, " }\n"); fprintf(fp, " G__setgvp((long)gvp);\n"); fprintf(fp, " }\n"); fprintf(fp, " } else {\n"); fprintf(fp, " if (gvp == (char*)G__PVOID) {\n"); //fprintf(fp, " G__operator_delete((void*) soff);\n"); - fprintf(fp, " delete (%s*) soff;\n", buf); + fprintf(fp, " delete (%s*) soff;\n", buf()); fprintf(fp, " } else {\n"); fprintf(fp, " G__setgvp((long) G__PVOID);\n"); - fprintf(fp, " ((%s*) (soff))->~%s();\n", buf, dtorname); + fprintf(fp, " ((%s*) (soff))->~%s();\n", buf(), dtorname()); fprintf(fp, " G__setgvp((long)gvp);\n"); fprintf(fp, " }\n"); fprintf(fp, " }\n"); @@ -7388,7 +7365,7 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, // (CInt will try to declare them later on anyways) if(G__is_tagnum_safe(tagnum)) { - sprintf(funcname, "operator="); + funcname = "operator="; fprintf(fp,"%s& (%s::*G__assignop_%s)(const %s&) = &%s::operator=;\n", G__fulltagname(tagnum, 0), G__fulltagname(tagnum, 0), G__map_cpp_funcname(tagnum, funcname, ifn, page), G__fulltagname(tagnum, 0), G__fulltagname(tagnum, 0) ); fprintf(fp," (void)(G__assignop_%s);\n", G__map_cpp_funcname(tagnum, funcname, ifn, page)); } @@ -7396,7 +7373,7 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, else #endif { - sprintf(funcname, "operator="); + funcname = "operator="; fprintf(fp, "// automatic assignment operator\n"); #ifdef G__CPPIF_STATIC @@ -7410,13 +7387,13 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, fprintf( fp, "extern \"C\" int %s(G__value* result7, G__CONST char* funcname, struct G__param* libp, int hash)", G__map_cpp_funcname(tagnum, funcname, ifn, page)); #endif /* G__CPPIF_STATIC */ fprintf(fp, "\n{\n"); - strcpy(temp, G__type2string('u', tagnum, -1, 0, 0)); - fprintf(fp, " %s* dest = (%s*) G__getstructoffset();\n", temp, temp); + temp = G__type2string('u', tagnum, -1, 0, 0); + fprintf(fp, " %s* dest = (%s*) G__getstructoffset();\n", temp(), temp()); if ((1 >= G__struct.size[tagnum]) && (0 == G__struct.memvar[tagnum]->allvar)) { } else { - fprintf(fp, " *dest = *(%s*) libp->para[0].ref;\n", temp); + fprintf(fp, " *dest = *(%s*) libp->para[0].ref;\n", temp()); } - fprintf(fp, " const %s& obj = *dest;\n", temp); + fprintf(fp, " const %s& obj = *dest;\n", temp()); fprintf(fp, " result7->ref = (long) (&obj);\n"); fprintf(fp, " result7->obj.i = (long) (&obj);\n"); G__cppif_dummyfuncname(fp); @@ -7431,12 +7408,6 @@ void G__cppif_gendefault(FILE *fp, FILE* /*hfp*/, int tagnum, } #endif -#ifndef G__OLDIMPLEMENtATION1972 - if(funcname!=buf1) free((void*)funcname); - if(temp!=buf2) free((void*)temp); - if(dtorname!=buf3) free((void*)dtorname); - // -#endif // #endif // G__SMALLOBJECT } @@ -7581,32 +7552,8 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ #ifndef G__SMALLOBJECT int k, m; -#ifndef G__OLDIMPLEMENTATION1823 - char buf2[G__LONGLINE]; - char *endoffunc = buf2; -#else - char endoffunc[G__LONGLINE]; -#endif - -#ifndef G__OLDIMPLEMENTATION1823 - char buf[G__BUFLEN*4]; - char *castname = buf; -#else - char castname[G__ONELINE]; -#endif - -#ifndef G__OLDIMPLEMENTATION1823 - // Expand castname and endoffunc if necessary. - if (tagnum != -1) { - int len = strlen(G__fulltagname(tagnum, 1)); - if (len > (G__BUFLEN * 4) - 30) { - castname = (char*) malloc(len + 30); - } - if (len > (G__LONGLINE - 256)) { - endoffunc = (char*) malloc(len + 256); - } - } -#endif + G__FastAllocString endoffunc(G__LONGLINE); + G__FastAllocString castname(G__ONELINE); #ifdef G__CPPIF_EXTERNC G__p2f_typedef(fp, ifn, ifunc) ; @@ -7655,9 +7602,9 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ if (-1 != tagnum) { if ((ifunc->access[ifn] == G__PROTECTED) || ((ifunc->access[ifn] == G__PRIVATE) && (G__struct.protectedaccess[tagnum] & G__PRIVATEACCESS))) { - sprintf(castname, "%s_PR", G__get_link_tagname(tagnum)); + castname.Format("%s_PR", G__get_link_tagname(tagnum)); } else { - strcpy(castname, G__fulltagname(tagnum, 1)); + castname = G__fulltagname(tagnum, 1); } } @@ -7692,12 +7639,12 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ fprintf(fp,"%s::", G__fulltagname(tagnum, 1)); } else { if (ifunc->staticalloc[ifn]) { - fprintf(fp, "%s::", castname); + fprintf(fp, "%s::", castname()); } else { if (ifunc->isconst[ifn] & G__CONSTFUNC) { - fprintf(fp, "((const %s*) G__getstructoffset())->", castname); + fprintf(fp, "((const %s*) G__getstructoffset())->", castname()); } else { - fprintf(fp, "((%s*) G__getstructoffset())->", castname); + fprintf(fp, "((%s*) G__getstructoffset())->", castname()); } } } @@ -7736,7 +7683,7 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ } // // Output the function body. - fprintf(fp, ")%s\n", endoffunc); + fprintf(fp, ")%s\n", endoffunc()); // // End the case for m number of parameters given. fprintf(fp, " break;\n"); @@ -7755,7 +7702,7 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ if (ifunc->ansi[ifn] == 2 && m==ifunc->para_nu[ifn]) { // all code is already generated by G__x8664_vararg() G__x8664_vararg_epilog(fp, ifn, ifunc); - fprintf(fp, "%s\n", endoffunc); + fprintf(fp, "%s\n", endoffunc()); } else { #endif // @@ -7765,12 +7712,12 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ fprintf(fp, "%s::", G__fulltagname(tagnum, 1)); else { if (ifunc->staticalloc[ifn]) { - fprintf(fp, "%s::", castname); + fprintf(fp, "%s::", castname()); } else { if (ifunc->isconst[ifn] & G__CONSTFUNC) { - fprintf(fp, "((const %s*) G__getstructoffset())->", castname); + fprintf(fp, "((const %s*) G__getstructoffset())->", castname()); } else { - fprintf(fp,"((%s*) G__getstructoffset())->", castname); + fprintf(fp,"((%s*) G__getstructoffset())->", castname()); } } } @@ -7818,7 +7765,7 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ } // // Output the function body. - fprintf(fp, ")%s\n", endoffunc); + fprintf(fp, ")%s\n", endoffunc()); #if defined(__x86_64__) && (defined(__linux) || defined(__APPLE__)) } // end G__x8664_vararg_epilog #endif @@ -7828,24 +7775,17 @@ void G__cppif_genfunc(FILE *fp, FILE * /* hfp */, int tagnum, int ifn, G__ifunc_ G__cppif_dummyfuncname(fp); fprintf(fp,"}\n\n"); -#ifndef G__OLDIMPLEMENTATION1823 - if (castname != buf) { - free((void*) castname); - } - if (endoffunc != buf2) { - free((void*) endoffunc); - } - // -#endif // G__OLDIMPLEMENTATION1823 // #endif // G__SMALLOBJECT } +} // extern "C" + /************************************************************************** * G__cppif_returntype() * **************************************************************************/ -int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char *endoffunc) +int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, G__FastAllocString& endoffunc) { #ifndef G__SMALLOBJECT int type, tagnum, typenum, reftype, isconst; @@ -7911,23 +7851,23 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char fprintf(fp, "%s %s obj = ", indent, typestring); } if ((typenum != -1) && G__newtype.nindex[typenum]) { - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (obj);\n%s}", indent, indent, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (obj);\n%s}", indent, indent, indent); return 0; } switch (type) { case 'd': case 'f': - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s result7->obj.d = (double) (obj);\n%s}", indent, indent, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s result7->obj.d = (double) (obj);\n%s}", indent, indent, indent); break; case 'u': if (G__struct.type[tagnum] == 'e') { - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (obj);\n%s}", indent, indent, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (obj);\n%s}", indent, indent, indent); } else { - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (&obj);\n%s}", indent, indent, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (&obj);\n%s}", indent, indent, indent); } break; default: - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s G__letint(result7, '%c', (long)obj);\n%s}", indent, indent, type, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s G__letint(result7, '%c', (long)obj);\n%s}", indent, indent, type, indent); break; } return 0; @@ -7936,7 +7876,7 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char // Function return type is a pointer, handle and return. if (isupper(type)) { fprintf(fp, "%sG__letint(result7, %d, (long) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return(0); } @@ -7944,11 +7884,11 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char switch (type) { case 'y': fprintf(fp, "%s", indent); - sprintf(endoffunc, ";\n%sG__setnull(result7);", indent); + endoffunc.Format(";\n%sG__setnull(result7);", indent); return 0; case '1': fprintf(fp, "%sG__letint(result7, %d, (long) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'e': case 'c': @@ -7961,24 +7901,24 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char case 'k': case 'g': fprintf(fp, "%sG__letint(result7, %d, (long) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'n': fprintf(fp, "%sG__letLonglong(result7, %d, (G__int64) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'm': fprintf(fp, "%sG__letULonglong(result7, %d, (G__uint64) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'q': fprintf(fp, "%sG__letLongdouble(result7, %d, (long double) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'f': case 'd': fprintf(fp, "%sG__letdouble(result7, %d, (double) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; return 0; case 'u': switch (G__struct.type[tagnum]) { @@ -7999,7 +7939,7 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char } #endif fprintf(fp, "%sconst %s& obj = ", indent, typestring); - sprintf(endoffunc, ";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (&obj);\n%s}", indent, indent, indent); + endoffunc.Format(";\n%s result7->ref = (long) (&obj);\n%s result7->obj.i = (long) (&obj);\n%s}", indent, indent, indent); } else { if (G__globalcomp == G__CPPLINK) { fprintf(fp, "%s{\n", indent); @@ -8010,7 +7950,7 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char fprintf(fp, "%s %s* pobj;\n", indent, G__type2string('u', tagnum, deftyp, 0, 0)); fprintf(fp, "%s %s xobj = ", indent, G__type2string('u', tagnum, deftyp, 0, 0)); } - sprintf(endoffunc, ";\n" + endoffunc.Format(";\n" "%s pobj = new %s(xobj);\n" "%s result7->obj.i = (long) ((void*) pobj);\n" "%s result7->ref = result7->obj.i;\n" @@ -8021,13 +7961,13 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char fprintf(fp, "%sresult7->obj.i = G__gettempbufpointer();\n", indent); fprintf(fp, "%sresult7->ref = G__gettempbufpointer();\n", indent); fprintf(fp, "%s*((%s *) result7->obj.i) = ", indent, G__type2string(type, tagnum, typenum, reftype, 0)); - sprintf(endoffunc, ";"); + endoffunc = ";"; } } break; default: fprintf(fp, "%sG__letint(result7, %d, (long) ", indent, type); - sprintf(endoffunc, ");"); + endoffunc = ");"; break; } return 0; @@ -8036,6 +7976,7 @@ int G__cppif_returntype(FILE *fp, int ifn, G__ifunc_table_internal *ifunc, char #endif // G__SMALLOBJECT } +extern "C" { /************************************************************************** * G__cppif_paratype() @@ -8348,9 +8289,9 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) { #ifndef G__SMALLOBJECT int i; - char tagname[G__MAXNAME*8]; - char mappedtagname[G__MAXNAME*6]; - char buf[G__ONELINE]; + G__FastAllocString tagname(G__MAXNAME*8); + G__FastAllocString mappedtagname(G__MAXNAME*6); + G__FastAllocString buf(G__ONELINE); fprintf(fp,"\n/*********************************************************\n"); fprintf(fp,"* Class,struct,union,enum tag information setup\n"); @@ -8400,7 +8341,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) G__getcommentstring(buf,i,&G__struct.comment[i]); - strcpy(tagname,G__fulltagname(i,0)); + tagname = G__fulltagname(i,0); if(-1!=G__struct.line_number[i] && (-1==G__struct.parent_tagnum[i]||G__nestedclass) ) { @@ -8413,9 +8354,9 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf); + ,buf()); else if('n'==G__struct.type[i]) { - strcpy(mappedtagname,G__map_cpp_name(tagname)); + mappedtagname = G__map_cpp_name(tagname); fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),0,%d,%d,%s,G__setup_memvar%s,G__setup_memfunc%s);\n" ,G__mark_linked_tagnum(i) /* ,G__type2string('u',i,-1,0,0) */ @@ -8426,10 +8367,10 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf,mappedtagname,mappedtagname); + ,buf(),mappedtagname(),mappedtagname()); } else if(0==G__struct.name[i][0]) { - strcpy(mappedtagname,G__map_cpp_name(tagname)); + mappedtagname = G__map_cpp_name(tagname); if(G__CPPLINK==G__globalcomp) { fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),%s,%d,%d,%s,G__setup_memvar%s,G__setup_memfunc%s);\n" ,G__mark_linked_tagnum(i) @@ -8441,7 +8382,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname,mappedtagname); + ,buf() ,mappedtagname(),mappedtagname()); } else { fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),%s,%d,%d,%s,G__setup_memvar%s,NULL);\n" @@ -8454,11 +8395,11 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname); + ,buf(),mappedtagname()); } } else { - strcpy(mappedtagname,G__map_cpp_name(tagname)); + mappedtagname = G__map_cpp_name(tagname); if(G__CPPLINK==G__globalcomp && '$'!=G__struct.name[i][0]) { if(G__ONLYMETHODLINK==G__struct.globalcomp[i]) fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),sizeof(%s),%d,%d,%s,NULL,G__setup_memfunc%s);\n" @@ -8471,7 +8412,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname); + ,buf(),mappedtagname()); else if(G__suppress_methods) fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),sizeof(%s),%d,%d,%s,G__setup_memvar%s,NULL);\n" @@ -8484,7 +8425,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname); + ,buf(),mappedtagname()); else fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),sizeof(%s),%d,%d,%s,G__setup_memvar%s,G__setup_memfunc%s);\n" ,G__mark_linked_tagnum(i) @@ -8496,7 +8437,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname,mappedtagname); + ,buf(),mappedtagname(),mappedtagname()); } else if('$'==G__struct.name[i][0]&& isupper(G__newtype.type[G__defined_typename(G__struct.name[i]+1)])) { @@ -8510,7 +8451,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf); + ,buf()); } else { fprintf(fp," G__tagtable_setup(G__get_linked_tagnum(&%s),sizeof(%s),%d,%d,%s,G__setup_memvar%s,NULL);\n" @@ -8523,7 +8464,7 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf ,mappedtagname); + ,buf(),mappedtagname()); } } @@ -8538,11 +8479,11 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) #else ,G__struct.isabstract[i]+G__struct.funcs[i]*0x100 #endif - ,buf); + ,buf()); } if('e'!=G__struct.type[i]) { if(strchr(tagname,'<')) { /* template class */ - fprintf(hfp,"typedef %s G__%s;\n",tagname,G__map_cpp_name(tagname)); + fprintf(hfp,"typedef %s G__%s;\n",tagname(),G__map_cpp_name(tagname)); } } } @@ -8563,10 +8504,10 @@ void G__cpplink_tagtable(FILE *fp, FILE *hfp) **************************************************************************/ static char* G__vbo_funcname(int tagnum, int basetagnum, int basen) { - static char result[G__LONGLINE*2]; - char temp[G__LONGLINE]; - strcpy(temp,G__map_cpp_name(G__fulltagname(tagnum,1))); - sprintf(result,"G__2vbo_%s_%s_%d",temp + static char result[G__LONGLINE*16]; + G__FastAllocString temp(G__LONGLINE); + temp = G__map_cpp_name(G__fulltagname(tagnum,1)); + sprintf(result,"G__2vbo_%s_%s_%d",temp() ,G__map_cpp_name(G__fulltagname(basetagnum,1)),basen); return(result); } @@ -8580,7 +8521,6 @@ void G__cppif_inheritance(FILE *fp) int i; int basen; int basetagnum; - char temp[G__LONGLINE*2]; fprintf(fp,"\n/*********************************************************\n"); fprintf(fp,"* virtual base class offset calculation interface\n"); @@ -8605,8 +8545,8 @@ void G__cppif_inheritance(FILE *fp) basetagnum=G__struct.baseclass[i]->herit[basen]->basetagnum; fprintf(fp,"static long %s(long pobject) {\n" ,G__vbo_funcname(i,basetagnum,basen)); - strcpy(temp,G__fulltagname(i,1)); - fprintf(fp," %s *G__Lderived=(%s*)pobject;\n",temp,temp); + G__FastAllocString temp(G__fulltagname(i,1)); + fprintf(fp," %s *G__Lderived=(%s*)pobject;\n",temp(),temp()); fprintf(fp," %s *G__Lbase=G__Lderived;\n",G__fulltagname(basetagnum,1)); fprintf(fp," return((long)G__Lbase-(long)G__Lderived);\n"); fprintf(fp,"}\n\n"); @@ -8631,7 +8571,7 @@ void G__cpplink_inheritance(FILE *fp) int i; int basen; int basetagnum; - char temp[G__MAXNAME*6]; + G__FastAllocString temp(G__MAXNAME*6); int flag; fprintf(fp,"\n/*********************************************************\n"); @@ -8671,14 +8611,13 @@ void G__cpplink_inheritance(FILE *fp) basetagnum=G__struct.baseclass[i]->herit[basen]->basetagnum; fprintf(fp," {\n"); #ifdef G__VIRTUALBASE - strcpy(temp,G__mark_linked_tagnum(basetagnum)); + temp = G__mark_linked_tagnum(basetagnum); if(G__struct.baseclass[i]->herit[basen]->property&G__ISVIRTUALBASE) { - char temp2[G__LONGLINE*2]; - strcpy(temp2,G__vbo_funcname(i,basetagnum,basen)); + G__FastAllocString temp2(G__vbo_funcname(i,basetagnum,basen)); fprintf(fp," G__inheritance_setup(G__get_linked_tagnum(&%s),G__get_linked_tagnum(&%s),(long)%s,%d,%ld);\n" ,G__mark_linked_tagnum(i) - ,temp - ,temp2 + ,temp() + ,temp2() ,G__struct.baseclass[i]->herit[basen]->baseaccess ,(long)G__struct.baseclass[i]->herit[basen]->property ); @@ -8696,39 +8635,39 @@ void G__cpplink_inheritance(FILE *fp) flag2=1; } } - strcpy(temp,G__fulltagname(basetagnum,1)); + temp = G__fulltagname(basetagnum,1); if(!flag2) fprintf(fp," %s *G__Lpbase=(%s*)G__Lderived;\n" - ,temp,G__fulltagname(basetagnum,1)); + ,temp(),G__fulltagname(basetagnum,1)); else { G__fprinterr(G__serr, "Warning: multiple ambiguous inheritance %s and %s. Cint will not get correct base object address\n" - ,temp,G__fulltagname(i,1)); + ,temp(),G__fulltagname(i,1)); fprintf(fp," %s *G__Lpbase=(%s*)((long)G__Lderived);\n" - ,temp,G__fulltagname(basetagnum,1)); + ,temp(),G__fulltagname(basetagnum,1)); } - strcpy(temp,G__mark_linked_tagnum(basetagnum)); + temp = G__mark_linked_tagnum(basetagnum); fprintf(fp," G__inheritance_setup(G__get_linked_tagnum(&%s),G__get_linked_tagnum(&%s),(long)G__Lpbase-(long)G__Lderived,%d,%ld);\n" ,G__mark_linked_tagnum(i) - ,temp + ,temp() ,G__struct.baseclass[i]->herit[basen]->baseaccess ,(long)G__struct.baseclass[i]->herit[basen]->property ); } #else - strcpy(temp,G__fulltagname(basetagnum,1)); + temp = G__fulltagname(basetagnum,1); if(G__struct.baseclass[i]->herit[basen]->property&G__ISVIRTUALBASE) { fprintf(fp," %s *pbase=(%s*)0x1000;\n" - ,temp,G__fulltagname(basetagnum,1)); + ,temp(),G__fulltagname(basetagnum,1)); } else { fprintf(fp," %s *pbase=(%s*)G__Lderived;\n" - ,temp,G__fulltagname(basetagnum,1)); + ,temp(),G__fulltagname(basetagnum,1)); } - strcpy(temp,G__mark_linked_tagnum(basetagnum)); + temp = G__mark_linked_tagnum(basetagnum); fprintf(fp," G__inheritance_setup(G__get_linked_tagnum(&%s),G__get_linked_tagnum(&%s),(long)pbase-(long)G__Lderived,%d,%ld);\n" ,G__mark_linked_tagnum(i) - ,temp + ,temp() ,G__struct.baseclass[i]->herit[basen]->baseaccess ,G__struct.baseclass[i]->herit[basen]->property ); @@ -8756,9 +8695,9 @@ void G__cpplink_typetable(FILE *fp, FILE *hfp) { int i; int j; - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); char *p; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); fprintf(fp,"\n/*********************************************************\n"); @@ -8785,10 +8724,10 @@ void G__cpplink_typetable(FILE *fp, FILE *hfp) if(strncmp("G__p2mf",G__newtype.name[i],7)==0 && G__CPPLINK==G__globalcomp){ G__ASSERT(i>0); - strcpy(temp,G__newtype.name[i-1]); + temp = G__newtype.name[i-1]; p = strstr(temp,"::*"); *(p+3)='\0'; - fprintf(hfp,"typedef %s%s)%s;\n",temp,G__newtype.name[i],p+4); + fprintf(hfp,"typedef %s%s)%s;\n",temp(),G__newtype.name[i],p+4); } if('u'==tolower(G__newtype.type[i])) fprintf(fp," G__search_typename2(\"%s\",%d,G__get_linked_tagnum(&%s),%d," @@ -8820,9 +8759,9 @@ void G__cpplink_typetable(FILE *fp, FILE *hfp) if(-1!=G__newtype.comment[i].filenum) { G__getcommenttypedef(temp,&G__newtype.comment[i],i); if(temp[0]) G__add_quotation(temp,buf); - else strcpy(buf,"NULL"); + else buf = "NULL"; } - else strcpy(buf,"NULL"); + else buf = "NULL"; if(G__newtype.nindex[i]>G__MAXVARDIM) { /* This is just a work around */ G__fprinterr(G__serr,"CINT INTERNAL ERROR? typedef %s[%d] 0x%lx\n" @@ -8831,7 +8770,7 @@ void G__cpplink_typetable(FILE *fp, FILE *hfp) G__newtype.nindex[i] = 0; if(G__newtype.index[i]) free((void*)G__newtype.index[i]); } - fprintf(fp," G__setnewtype(%d,%s,%d);\n",G__globalcomp,buf + fprintf(fp," G__setnewtype(%d,%s,%d);\n",G__globalcomp,buf() ,G__newtype.nindex[i]); if(G__newtype.nindex[i]) { for(j=0;j<G__newtype.nindex[i];j++) { @@ -8876,9 +8815,9 @@ static int G__hascompiledoriginalbase(int tagnum) **************************************************************************/ void G__cpplink_memvar(FILE *fp) { - char value[G__MAXNAME*6]; - char ttt[G__MAXNAME*6]; - char commentbuf[G__LONGLINE]; + G__FastAllocString value(G__MAXNAME*6); + G__FastAllocString ttt(G__MAXNAME*6); + G__FastAllocString commentbuf(G__LONGLINE); fprintf(fp, "\n/*********************************************************\n"); fprintf(fp, "* Data Member information setup/\n"); fprintf(fp, "*********************************************************/\n"); @@ -9095,7 +9034,7 @@ void G__cpplink_memvar(FILE *fp) ) { // -- Enumerator in a static enum has a special initializer. // FIXME: CAUTION: This implementation cause error on enum in nested class. - sprintf(ttt, "%s::%s", G__fulltagname(i, 1), var->varnamebuf[j]); + ttt.Format("%s::%s", G__fulltagname(i, 1), var->varnamebuf[j]); int store_var_type = G__var_type; G__var_type = 'p'; G__value buf; @@ -9107,7 +9046,7 @@ void G__cpplink_memvar(FILE *fp) // Take the value from var->p instead. If var is an enum constant // it will be stored as an int, so convert it accordingly. bool isInt = var->type[j] == 'i'; - sprintf(value, "*(%s*)0x%lx", + value.Format("*(%s*)0x%lx", isInt ? "int" : G__type2string(var->type[j], var->p_tagtable[j], var->p_typetable[j], 0, 0), var->p[j]); buf = G__calc_internal(value); @@ -9117,7 +9056,7 @@ void G__cpplink_memvar(FILE *fp) G__var_type = store_var_type; G__string(buf, value); G__quotedstring(value, ttt); - fprintf(fp, "=%s\"", ttt); + fprintf(fp, "=%s\"", ttt()); } else { // -- @@ -9131,7 +9070,7 @@ void G__cpplink_memvar(FILE *fp) // Comment string. // G__getcommentstring(commentbuf, i, &var->comment[j]); - fprintf(fp, ",%s);\n", commentbuf); + fprintf(fp, ",%s);\n", commentbuf()); } G__var_type = 'p'; } @@ -9189,10 +9128,10 @@ void G__cpplink_memfunc(FILE *fp) int i,j,k; int hash,page; struct G__ifunc_table_internal *ifunc; - char funcname[G__MAXNAME*6]; + G__FastAllocString funcname(G__MAXNAME*6); int isconstructor,iscopyconstructor,isdestructor,isassignmentoperator; /* int isvirtualdestructor; */ - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); int isnonpublicnew; /* struct G__ifunc_table *baseifunc; */ /* int baseifn; */ @@ -9549,8 +9488,8 @@ void G__cpplink_memfunc(FILE *fp) // its expression must be known to CInt, which migth not be true at run-time // for CPP defines. So replace macros with their actual values when generating // the dictionary - char res[G__ONELINE]; // possible overflow - char tmp[G__ONELINE]; // possible overflow + G__FastAllocString res(G__ONELINE); + G__FastAllocString tmp(G__ONELINE); char *str = ifunc->param[j][k]->def; int pos_res=0; int pos_str=0; @@ -9560,17 +9499,17 @@ void G__cpplink_memfunc(FILE *fp) // Copy everything if it doesnt start with a letter while(!isalpha(str[pos_str]) && str[pos_str]!='\0'){ - res[pos_res] = str[pos_str]; + res.Set(pos_res, str[pos_str]); pos_res++; pos_str++; } - res[pos_res] = '\0'; + res.Set(pos_res, 0); // if it's a letter, then look for the end of the name while(isdigit(str[pos_str]) || isalpha(str[pos_str]) || str[pos_str]=='_'){ - tmp[pos_tmp] = str[pos_str]; + tmp.Set(pos_tmp, str[pos_str]); pos_tmp++; pos_str++; } - tmp[pos_tmp] = '\0'; + tmp.Set(pos_tmp, 0); pos_tmp++; if(pos_tmp>1){ @@ -9595,8 +9534,9 @@ void G__cpplink_memfunc(FILE *fp) } else { // If we dont think this is a macro, the copy the same thing - strcpy(&res[pos_res], tmp); - pos_res += strlen(tmp); + res.Set(pos_res, 0); + res += tmp; + pos_res += strlen(tmp); } } } @@ -9616,7 +9556,7 @@ void G__cpplink_memfunc(FILE *fp) fprintf(fp, "\""); G__getcommentstring(buf, i, &ifunc->comment[j]); - fprintf(fp, ", %s", buf); + fprintf(fp, ", %s", buf()); #ifdef G__TRUEP2F if ( (ifunc->staticalloc[j] || 'n' == G__struct.type[i]) @@ -9740,7 +9680,7 @@ void G__cpplink_memfunc(FILE *fp) if (0 == isconstructor) isconstructor = G__isprivateconstructor(i, 0); if ('n' == G__struct.type[i]) isconstructor = 1; if (0 == isconstructor && 0 == G__struct.isabstract[i] && 0 == isnonpublicnew) { - sprintf(funcname, "%s", G__struct.name[i]); + funcname = G__struct.name[i]; G__hash(funcname, hash, k); fprintf(fp, " // automatic default constructor\n"); @@ -9749,7 +9689,7 @@ void G__cpplink_memfunc(FILE *fp) else fprintf(fp, " G__memfunc_setup2("); - fprintf(fp, "\"%s\", %d, ", funcname, hash); + fprintf(fp, "\"%s\", %d, ", funcname(), hash); // 04-07-07 print the mangled name after the funcname and hash if(G__dicttype!=kCompleteDictionary) { @@ -9789,7 +9729,7 @@ void G__cpplink_memfunc(FILE *fp) if (0 == iscopyconstructor) iscopyconstructor = G__isprivateconstructor(i, 1); if ('n' == G__struct.type[i]) iscopyconstructor = 1; if (0 == iscopyconstructor && 0 == G__struct.isabstract[i] && 0 == isnonpublicnew) { - sprintf(funcname, "%s", G__struct.name[i]); + funcname = G__struct.name[i]; G__hash(funcname, hash, k); fprintf(fp, " // automatic copy constructor\n"); @@ -9798,7 +9738,7 @@ void G__cpplink_memfunc(FILE *fp) else fprintf(fp, " G__memfunc_setup2("); - fprintf(fp, "\"%s\", %d, ", funcname, hash); + fprintf(fp, "\"%s\", %d, ", funcname(), hash); // 04-07-07 print the mangled name after the funcname and hash if(G__dicttype!=kCompleteDictionary) { @@ -9838,7 +9778,7 @@ void G__cpplink_memfunc(FILE *fp) if (0 == isdestructor) isdestructor = G__isprivatedestructor(i); if ('n' == G__struct.type[i]) isdestructor = 1; if (0 == isdestructor && 'n' != G__struct.type[i]) { - sprintf(funcname, "~%s", G__struct.name[i]); + funcname.Format("~%s", G__struct.name[i]); G__hash(funcname, hash, k); fprintf(fp, " // automatic destructor\n"); @@ -9847,7 +9787,7 @@ void G__cpplink_memfunc(FILE *fp) else fprintf(fp, " G__memfunc_setup2("); - fprintf(fp, "\"%s\", %d, ", funcname, hash); + fprintf(fp, "\"%s\", %d, ", funcname(), hash); //04-07-07 print the mangled name after the funcname and hash if(G__dicttype!=kCompleteDictionary){ if( isdestructor && ifunc_destructor->mangled_name[j]) @@ -9890,7 +9830,7 @@ void G__cpplink_memfunc(FILE *fp) if (0 == isassignmentoperator) isassignmentoperator = G__isprivateassignopr(i); if ('n' == G__struct.type[i]) isassignmentoperator = 1; if (0 == isassignmentoperator) { - sprintf(funcname, "operator="); + funcname = "operator="; G__hash(funcname, hash, k); fprintf(fp, " // automatic assignment operator\n"); @@ -9899,7 +9839,7 @@ void G__cpplink_memfunc(FILE *fp) else fprintf(fp, " G__memfunc_setup2("); - fprintf(fp, "\"%s\", %d, ", funcname, hash); + fprintf(fp, "\"%s\", %d, ", funcname(), hash); // 04-07-07 print the mangled name after the funcname and hash if(G__dicttype!=kCompleteDictionary) { @@ -9961,7 +9901,8 @@ void G__cpplink_global(FILE *fp) struct G__var_array *var; int pvoidflag; G__value buf; - char value[G__ONELINE],ttt[G__ONELINE]; + G__FastAllocString value(G__ONELINE); + G__FastAllocString ttt(G__ONELINE); int divn=0; int maxfnc=100; int fnc=0; @@ -10067,10 +10008,10 @@ void G__cpplink_global(FILE *fp) G__string(buf, value); G__quotedstring(value, ttt); if ((tolower(var->type[j]) == 'p') || (var->type[j] == 'T')) { - fprintf(fp, "=%s\",1,(char*)NULL);\n", ttt); + fprintf(fp, "=%s\",1,(char*)NULL);\n", ttt()); } else { - fprintf(fp, "=%s\",0,(char*)NULL);\n", ttt); + fprintf(fp, "=%s\",0,(char*)NULL);\n", ttt()); } } else { @@ -10241,7 +10182,7 @@ void G__cpplink_func(FILE *fp) { int j,k; struct G__ifunc_table_internal *ifunc; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); int divn=0; int maxfnc=100; int fnc=0; @@ -10385,7 +10326,7 @@ void G__cpplink_func(FILE *fp) fprintf(fp,"%d " ,ifunc->param[j][k]->reftype+ifunc->param[j][k]->isconst*10); if(ifunc->param[j][k]->def) - fprintf(fp,"'%s' ",G__quotedstring(ifunc->param[j][k]->def,buf)); + fprintf(fp,"'%s' ",G__quotedstring(ifunc->param[j][k]->def,buf)); else fprintf(fp,"- "); if(ifunc->param[j][k]->name) fprintf(fp,"%s",ifunc->param[j][k]->name); @@ -10457,12 +10398,7 @@ int G__tagtable_setup(int tagnum,int size,int cpplink,int isabstract,const char ,G__incsetup setup_memvar, G__incsetup setup_memfunc) { char *p; -#ifndef G__OLDIMPLEMENTATION1823 - char xbuf[G__BUFLEN]; - char *buf=xbuf; -#else - char buf[G__ONELINE]; -#endif + G__FastAllocString buf(G__ONELINE); if (G__struct.incsetup_memvar[tagnum]==0) G__struct.incsetup_memvar[tagnum] = new std::list<G__incsetup>(); @@ -10542,12 +10478,7 @@ int G__tagtable_setup(int tagnum,int size,int cpplink,int isabstract,const char G__struct.incsetup_memfunc[tagnum]->push_back(setup_memfunc); } /* add template names */ -#ifndef G__OLDIMPLEMENTATION1823 - if(strlen(G__struct.name[tagnum])>G__BUFLEN-10) { - buf = (char*)malloc(strlen(G__struct.name[tagnum])+10); - } -#endif - strcpy(buf,G__struct.name[tagnum]); + buf = G__struct.name[tagnum]; if((p=strchr(buf,'<'))) { *p='\0'; if(!G__defined_templateclass(buf)) { @@ -10563,9 +10494,6 @@ int G__tagtable_setup(int tagnum,int size,int cpplink,int isabstract,const char G__tagdefining = store_tagdefining; } } -#ifndef G__OLDIMPLEMENTATION1823 - if(buf!=xbuf) free((void*)buf); -#endif return(0); } @@ -11342,11 +11270,13 @@ int G__memfunc_setup2(const char *funcname,int hash,const char *mangled_name #endif } +} // extern "C" + /************************************************************************** * G__separate_parameter() * **************************************************************************/ -int G__separate_parameter(char *original,int *pos,char *param) +int G__separate_parameter(const char *original,int *pos, G__FastAllocString& param) { #ifndef G__SMALLOBJECT int single_quote=0; @@ -11362,6 +11292,7 @@ int G__separate_parameter(char *original,int *pos,char *param) single_arg_quote = 1; } + int iParam = 0; int i = startPos; bool done = false; for(; !done; ++i) { @@ -11387,7 +11318,8 @@ int G__separate_parameter(char *original,int *pos,char *param) case '\\': if (single_quote || double_quote) { // prevent special treatment of next char - *(param++) = c; + + param.Set(iParam++, c); c = original[++i]; } break; @@ -11396,11 +11328,11 @@ int G__separate_parameter(char *original,int *pos,char *param) break; } - *(param++) = c; + param.Set(iParam++, c); } - if (argStartsWithSingleQuote && ! *(param - 1) && *(param - 2) == '\'' ) - *(param - 2) = 0; // skip trailing ' + if (argStartsWithSingleQuote && ! param[iParam - 1] && param[iParam - 2] == '\'' ) + param.Set(iParam - 2, 0); // skip trailing ' *pos = i; if (i > startPos) --i; @@ -11411,6 +11343,8 @@ int G__separate_parameter(char *original,int *pos,char *param) #endif } +extern "C" { + /************************************************************************** * G__parse_parameter_link() * @@ -11424,12 +11358,12 @@ int G__parse_parameter_link(char* paras) int reftype_const; int typenum; G__value* para_default = 0; - char c_type[10]; - char tagname[G__MAXNAME*6]; - char type_name[G__MAXNAME*6]; - char c_reftype_const[10]; - char c_default[G__MAXNAME*2]; - char c_paraname[G__MAXNAME*2]; + G__FastAllocString c_type(10); + G__FastAllocString tagname(G__MAXNAME*6); + G__FastAllocString type_name(G__MAXNAME*6); + G__FastAllocString c_reftype_const(10); + G__FastAllocString c_default(G__MAXNAME*2); + G__FastAllocString c_paraname(G__MAXNAME*2); int os = 0; int store_loadingDLL = G__loadingDLL; @@ -11654,13 +11588,15 @@ int G__set_sizep2memfunc(FILE *fp) return(0); } +} // extern "C" + /************************************************************************** * G__getcommentstring() * **************************************************************************/ -int G__getcommentstring(char *buf,int tagnum,G__comment_info *pcomment) +int G__getcommentstring(G__FastAllocString& buf,int tagnum,G__comment_info *pcomment) { - char temp[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); G__getcomment(temp,pcomment,tagnum); if('\0'==temp[0]) { sprintf(buf,"(char*)NULL"); @@ -11671,6 +11607,8 @@ int G__getcommentstring(char *buf,int tagnum,G__comment_info *pcomment) return(1); } +extern "C" { + /************************************************************************** * G__pragmalinkenum() **************************************************************************/ @@ -11783,7 +11721,7 @@ static void G__linknestedtypedef(int tagnum,int globalcomp) void G__specify_link(int link_stub) { int c; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); int globalcomp=G__NOLINK; /* int store_globalcomp; */ int i; @@ -11802,7 +11740,7 @@ void G__specify_link(int link_stub) int done=0; /* Get link language interface */ - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); if(strncmp(buf,"postproc",5)==0) { int store_globalcomp2 = G__globalcomp; @@ -11811,10 +11749,10 @@ void G__specify_link(int link_stub) G__globalcomp = G__NOLINK; G__store_globalcomp = G__NOLINK; G__prerun = 0; - c = G__fgetname_template(buf,";"); + c = G__fgetname_template(buf, 0, ";"); if(G__LOADFILE_SUCCESS<=G__loadfile(buf)) { - char buf2[G__ONELINE]; - c = G__fgetstream(buf2,";"); + G__FastAllocString buf2(G__ONELINE); + c = G__fgetstream(buf2, 0, ";"); G__calc(buf2); G__unloadfile(buf); } @@ -11881,7 +11819,7 @@ void G__specify_link(int link_stub) if(';'==c) return; /* Get type of language construct */ - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); if(G__MACROLINK==globalcomp&&strncmp(buf,"function",3)!=0) { G__fprinterr(G__serr,"Warning: #pragma link MACRO only valid for global function. Ignored\n"); @@ -11952,7 +11890,7 @@ void G__specify_link(int link_stub) } // fetch next token - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); } @@ -12007,7 +11945,7 @@ void G__specify_link(int link_stub) if(strncmp(buf,"class+protected",6)==0) protectedaccess = 1; #endif #endif - c = G__fgetstream_template(buf,";\n\r"); + c = G__fgetstream_template(buf, 0, ";\n\r"); for (iirf = 0; iirf < 3; iirf++) { if (buf[strlen(buf)-1] == '-') { rfNoStreamer = 1; @@ -12142,11 +12080,11 @@ void G__specify_link(int link_stub) if(!done && G__NOLINK!=globalcomp) { #ifdef G__ROOT if(G__dispmsg>=G__DISPERR) { - G__fprinterr(G__serr,"Error: link requested for unknown class %s",buf); + G__fprinterr(G__serr,"Error: link requested for unknown class %s",buf()); G__genericerror((char*)NULL); #else if(G__dispmsg>=G__DISPNOTE) { - G__fprinterr(G__serr,"Note: link requested for unknown class %s",buf); + G__fprinterr(G__serr,"Note: link requested for unknown class %s",buf()); G__printlinenum(); #endif } @@ -12162,7 +12100,7 @@ void G__specify_link(int link_stub) fpos_t pos; int store_line = G__ifile.line_number; fgetpos(G__ifile.fp,&pos); - c = G__fgetstream_template(buf,";\n\r<>"); + c = G__fgetstream_template(buf, 0, ";\n\r<>"); if(G__CPPLINK==globalcomp) globalcomp=G__METHODLINK; @@ -12173,23 +12111,23 @@ void G__specify_link(int link_stub) store_line = G__ifile.line_number; fgetpos(G__ifile.fp,&pos); buf[len] = G__fgetc(); - if(buf[len]==c||'='==buf[len]) c=G__fgetstream_template(buf+len+1,";\n\r"); + if(buf[len]==c||'='==buf[len]) c=G__fgetstream_template(buf, len+1, ";\n\r"); else { fsetpos(G__ifile.fp,&pos); G__ifile.line_number = store_line; if(G__dispsource) G__disp_mask = 1; - c = G__fgetstream_template(buf+len,";\n\r"); + c = G__fgetstream_template(buf, len, ";\n\r"); } } else { fsetpos(G__ifile.fp,&pos); G__ifile.line_number = store_line; - c = G__fgetstream_template(buf,";\n\r"); + c = G__fgetstream_template(buf, 0, ";\n\r"); } #else /* 828 */ - c = G__fgetstream_template(buf,";\n\r"); + c = G__fgetstream_template(buf, 0, ";\n\r"); #endif /* 828 */ @@ -12200,8 +12138,10 @@ void G__specify_link(int link_stub) else if(strcmp(p,")")==0) p=0; } if(p) { - char funcname[G__LONGLINE]; - char param[G__LONGLINE]; + G__FastAllocString funcname_sb(G__LONGLINE); + char* funcname = funcname_sb; + G__FastAllocString param_sb(G__LONGLINE); + char* param = param_sb; if(')' == *(p+1) && '('== *(p+2) ) p = strchr(p+1,'('); *p='\0'; strcpy(funcname,buf); @@ -12352,11 +12292,11 @@ void G__specify_link(int link_stub) if(!done && G__NOLINK!=globalcomp) { #ifdef G__ROOT if(G__dispmsg>=G__DISPERR) { - G__fprinterr(G__serr,"Error: link requested for unknown function %s",buf); + G__fprinterr(G__serr,"Error: link requested for unknown function %s",buf()); G__genericerror((char*)NULL); #else if(G__dispmsg>=G__DISPNOTE) { - G__fprinterr(G__serr,"Note: link requested for unknown function %s",buf); + G__fprinterr(G__serr,"Note: link requested for unknown function %s",buf()); G__printlinenum(); #endif } @@ -12367,14 +12307,14 @@ void G__specify_link(int link_stub) * #pragma link [spec] operators [classname]; *************************************************************************/ else if(strncmp(buf,"operators",3)==0) { - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); // Do not (yet) support wildcarding int cltag = G__defined_tagname(buf,1); if (cltag<0) { #ifdef G__ROOT if(G__dispmsg>=G__DISPERR) { - G__fprinterr(G__serr,"Error: link requested for operators or unknown class %s",buf); + G__fprinterr(G__serr,"Error: link requested for operators or unknown class %s",buf()); G__genericerror((char*)NULL); } #else @@ -12422,7 +12362,7 @@ void G__specify_link(int link_stub) * #pragma link [spec] global [name]; *************************************************************************/ else if(strncmp(buf,"global",3)==0) { - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); p = strrchr(buf,'*'); if(p) { #if defined(G__REGEXP) @@ -12495,7 +12435,7 @@ void G__specify_link(int link_stub) } if(!done && G__NOLINK!=globalcomp) { if(G__dispmsg>=G__DISPNOTE) { - G__fprinterr(G__serr,"Note: link requested for unknown global variable %s",buf); + G__fprinterr(G__serr,"Note: link requested for unknown global variable %s",buf()); G__printlinenum(); } } @@ -12507,7 +12447,7 @@ void G__specify_link(int link_stub) * introduced. Keeping this just for future needs. *************************************************************************/ else if(strncmp(buf,"all_datamembers",5)==0) { - if(';'!=c) c = G__fgetstream_template(buf,";\n\r"); + if(';'!=c) c = G__fgetstream_template(buf, 0, ";\n\r"); if(buf[0]) { struct G__var_array *var; int ig15; @@ -12541,7 +12481,7 @@ void G__specify_link(int link_stub) *************************************************************************/ else if(strncmp(buf,"all_methods",5)==0|| strncmp(buf,"all_functions",5)==0) { - if(';'!=c) c = G__fgetstream_template(buf,";\n\r"); + if(';'!=c) c = G__fgetstream_template(buf, 0, ";\n\r"); if(G__CPPLINK==globalcomp) globalcomp=G__METHODLINK; if(buf[0]) { struct G__ifunc_table_internal *ifunc; @@ -12583,7 +12523,7 @@ void G__specify_link(int link_stub) * #pragma link [spec] typedef [name]; *************************************************************************/ else if(strncmp(buf,"typedef",3)==0) { - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); p = strrchr(buf,'*'); if(p && *(p+1)=='>') p=(char*)NULL; if(p) { @@ -12660,11 +12600,11 @@ void G__specify_link(int link_stub) if(!done && G__NOLINK!=globalcomp) { #ifdef G__ROOT if(G__dispmsg>=G__DISPERR) { - G__fprinterr(G__serr,"Error: link requested for unknown typedef %s",buf); + G__fprinterr(G__serr,"Error: link requested for unknown typedef %s",buf()); G__genericerror((char*)NULL); #else if(G__dispmsg>=G__DISPNOTE) { - G__fprinterr(G__serr,"Note: link requested for unknown typedef %s",buf); + G__fprinterr(G__serr,"Note: link requested for unknown typedef %s",buf()); G__printlinenum(); #endif } @@ -12675,7 +12615,7 @@ void G__specify_link(int link_stub) * #pragma link [spec] ioctortype [item]; *************************************************************************/ else if(strncmp(buf,"ioctortype",3)==0) { - c = G__fgetname(buf,";\n\r"); + c = G__fgetname(buf, 0, ";\n\r"); if (G__p_ioctortype_handler) G__p_ioctortype_handler(buf); } #endif @@ -12689,18 +12629,19 @@ void G__specify_link(int link_stub) struct stat statBufItem; struct stat statBuf; #ifdef G__WIN32 - char fullItem[_MAX_PATH], fullIndex[_MAX_PATH]; + G__FastAllocString fullItem[_MAX_PATH], fullIndex_sb(_MAX_PATH); + char* fullItem[_MAX_PATH], fullIndex = fullItem[_MAX_PATH], fullIndex_sb; #endif fgetpos(G__ifile.fp,&pos); - c = G__fgetname(buf,";\n\r"); + c = G__fgetname(buf, 0, ";\n\r"); if(strcmp(buf,"class")==0||strcmp(buf,"struct")==0|| strcmp(buf,"namespace")==0) { - if(isspace(c)) c = G__fgetstream_template(buf,";\n\r"); + if(isspace(c)) c = G__fgetstream_template(buf, 0, ";\n\r"); tagflag = 1; } else { fsetpos(G__ifile.fp,&pos); - c = G__fgetstream_template(buf,";\n\r<>"); + c = G__fgetstream_template(buf, 0, ";\n\r<>"); unsigned int buflen = strlen(buf) - 1; if (buf[0]=='"' && buf[buflen]=='"') { // Skip the quotes (that allowed us to keep the spaces. @@ -12881,7 +12822,7 @@ void G__specify_link(int link_stub) } } if(!done && G__NOLINK!=globalcomp) { - G__fprinterr(G__serr,"Warning: link requested for unknown srcfile %s",buf); + G__fprinterr(G__serr,"Warning: link requested for unknown srcfile %s",buf()); G__printlinenum(); } } @@ -12890,7 +12831,7 @@ void G__specify_link(int link_stub) * #pragma link [spec] all [item]; *************************************************************************/ else if(strncmp(buf,"all",2)==0) { - c = G__fgetname_template(buf,";\n\r"); + c = G__fgetname_template(buf, 0, ";\n\r"); if(strncmp(buf,"class",3)==0) { for(i=0;i<G__struct.alltag;i++) { if(G__NOLINK==globalcomp || @@ -13552,14 +13493,14 @@ long double* G__Longdoubleref(G__value *buf) {return G__refT<long double>(buf);} void G__specify_extra_include() { int i; int c; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); char *tobecopied; if (!G__extra_include) { G__extra_include = (char**)malloc(G__MAXFILE*sizeof(char*)); for(i=0;i<G__MAXFILE;i++) G__extra_include[i]=(char*)malloc(G__MAXFILENAME*sizeof(char)); }; - c = G__fgetstream_template(buf,";\n\r<>"); + c = G__fgetstream_template(buf, 0, ";\n\r<>"); if ( 1 ) { /* should we check if the file exist ? */ tobecopied = buf; if (buf[0]=='\"' || buf[0]=='\'') tobecopied++; @@ -13576,7 +13517,8 @@ void G__specify_extra_include() { void G__gen_extra_include() { char * tempfile; FILE *fp,*ofp; - char line[BUFSIZ]; + G__FastAllocString line_sb(BUFSIZ); + char* line = line_sb; int i; if (G__extra_inc_n) { diff --git a/cint/cint/src/opr.cxx b/cint/cint/src/opr.cxx index 61040baf518f7863dd389a48e7f8871c2fce4cc9..023632caa6e47b8e1ff6d9a4a0c73580f4a25dff 100644 --- a/cint/cint/src/opr.cxx +++ b/cint/cint/src/opr.cxx @@ -1886,7 +1886,7 @@ int G__scopeoperator(char* name, int* phash, long* pstruct_offset, int* ptagnum) int offset; int offset_sum; int i; - char temp[G__MAXNAME*2]; + G__FastAllocString temp(G__MAXNAME*2); char* pparen; re_try_after_std: // search for pattern "::" @@ -1903,7 +1903,7 @@ int G__scopeoperator(char* name, int* phash, long* pstruct_offset, int* ptagnum) // or fully qualified scope! if (pc == name) { /* strip scope operator, set hash and return */ - strcpy(temp, name + 2); + temp = name + 2; strcpy(name, temp); G__hash(name, (*phash), i) /* If we do no have anymore scope operator, we know the request of @@ -1914,7 +1914,7 @@ int G__scopeoperator(char* name, int* phash, long* pstruct_offset, int* ptagnum) #ifndef G__STD_NAMESPACE if (strncmp(name, "std::", 5) == 0 && G__ignore_stdnamespace) { // strip scope operator, set hash and return - strcpy(temp, name + 5); + temp = name + 5; strcpy(name, temp); G__hash(name, (*phash), i) goto re_try_after_std; @@ -1922,7 +1922,6 @@ int G__scopeoperator(char* name, int* phash, long* pstruct_offset, int* ptagnum) #endif // otherwise, specific class scope offset_sum = 0; - strcpy(temp, name); if (*name == '~') { // -- Explicit destructor of the form: ~A::B(). scope = name + 1; @@ -1974,7 +1973,7 @@ int G__scopeoperator(char* name, int* phash, long* pstruct_offset, int* ptagnum) G__inc_cp_asm(2, 0); } #endif - strcpy(temp, member); + temp = member; if (*name == '~') { // -- Explicit destructor. strcpy(name + 1, temp); @@ -2078,7 +2077,6 @@ int G__getunaryop(char unaryop, const char* expression, char* buf, G__value* pre int G__iosrdstate(G__value* pios) { // -- ios rdstate condition test - char buf[G__MAXNAME]; G__value result; int ig2; long store_struct_offset; @@ -2107,33 +2105,26 @@ int G__iosrdstate(G__value* pios) #endif // G__ASM /* call ios::rdstate() */ - sprintf(buf, "rdstate()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("rdstate()", &ig2, G__TRYMEMFUNC); if (ig2) rdstateflag = 1; if (0 == ig2) { - sprintf(buf, "operator int()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator int()", &ig2, G__TRYMEMFUNC); } if (0 == ig2) { - sprintf(buf, "operator bool()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator bool()", &ig2, G__TRYMEMFUNC); } if (0 == ig2) { - sprintf(buf, "operator long()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator long()", &ig2, G__TRYMEMFUNC); } if (0 == ig2) { - sprintf(buf, "operator short()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator short()", &ig2, G__TRYMEMFUNC); } if (0 == ig2) { - sprintf(buf, "operator char*()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator char*()", &ig2, G__TRYMEMFUNC); } if (0 == ig2) { - sprintf(buf, "operator const char*()" /* ,pios->obj.i */); - result = G__getfunction(buf, &ig2, G__TRYMEMFUNC); + result = G__getfunction("operator const char*()", &ig2, G__TRYMEMFUNC); } /* restore environment */ @@ -2172,10 +2163,10 @@ int G__iosrdstate(G__value* pios) int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) { int ig2; - char expr[G__LONGLINE]; - char opr[12]; - char arg1[G__LONGLINE]; - char arg2[G__LONGLINE]; + G__FastAllocString expr(G__LONGLINE); + G__FastAllocString opr(12); + G__FastAllocString arg1(G__LONGLINE); + G__FastAllocString arg2(G__LONGLINE); long store_struct_offset; int store_tagnum; int store_isconst; @@ -2197,35 +2188,35 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) case '<': case '@': /* power */ case '!': - sprintf(opr, "operator%c", operatortag); + opr.Format("operator%c", operatortag); break; case 'A': /* logic and && */ - sprintf(opr, "operator&&"); + opr = "operator&&"; break; case 'O': /* logic or || */ - sprintf(opr, "operator||"); + opr = "operator||"; break; case 'R': /* right shift >> */ - sprintf(opr, "operator>>"); + opr = "operator>>"; break; case 'L': /* left shift << */ - sprintf(opr, "operator<<"); + opr = "operator<<"; break; case 'E': - sprintf(opr, "operator=="); + opr = "operator=="; break; case 'N': - sprintf(opr, "operator!="); + opr = "operator!="; break; case 'G': - sprintf(opr, "operator>="); + opr = "operator>="; break; case 'l': - sprintf(opr, "operator<="); + opr = "operator<="; break; case '\0': @@ -2233,49 +2224,49 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) return(0); case G__OPR_ADDASSIGN: - sprintf(opr, "operator+="); + opr = "operator+="; break; case G__OPR_SUBASSIGN: - sprintf(opr, "operator-="); + opr = "operator-="; break; case G__OPR_MODASSIGN: - sprintf(opr, "operator%%="); + opr = "operator%%="; break; case G__OPR_MULASSIGN: - sprintf(opr, "operator*="); + opr = "operator*="; break; case G__OPR_DIVASSIGN: - sprintf(opr, "operator/="); + opr = "operator/="; break; case G__OPR_RSFTASSIGN: - sprintf(opr, "operator>>="); + opr = "operator>>="; break; case G__OPR_LSFTASSIGN: - sprintf(opr, "operator<<="); + opr = "operator<<="; break; case G__OPR_BANDASSIGN: - sprintf(opr, "operator&="); + opr = "operator&="; break; case G__OPR_BORASSIGN: - sprintf(opr, "operator|="); + opr = "operator|="; break; case G__OPR_EXORASSIGN: - sprintf(opr, "operator^="); + opr = "operator^="; break; case G__OPR_ANDASSIGN: - sprintf(opr, "operator&&="); + opr = "operator&&="; break; case G__OPR_ORASSIGN: - sprintf(opr, "operator||="); + opr = "operator||="; break; case G__OPR_POSTFIXINC: case G__OPR_PREFIXINC: - sprintf(opr, "operator++"); + opr = "operator++"; break; case G__OPR_POSTFIXDEC: case G__OPR_PREFIXDEC: - sprintf(opr, "operator--"); + opr = "operator--"; break; default: @@ -2325,7 +2316,7 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) switch (operatortag) { case G__OPR_POSTFIXINC: case G__OPR_POSTFIXDEC: - sprintf(expr, "%s(1)", opr); + expr.Format("%s(1)", opr()); #ifdef G__ASM if (G__asm_noverflow) { G__asm_inst[G__asm_cp] = G__LD; @@ -2343,7 +2334,7 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) break; default: postfixflag = 0; - sprintf(expr, "%s()", opr); + expr.Format("%s()", opr()); break; } @@ -2379,7 +2370,7 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) switch (operatortag) { case G__OPR_POSTFIXINC: case G__OPR_POSTFIXDEC: - sprintf(expr, "%s(%s,1)", opr, G__setiparseobject(&expressionin, arg1)); + expr.Format("%s(%s,1)", opr(), G__setiparseobject(&expressionin, arg1)); #ifdef G__ASM if (G__asm_noverflow) { // -- We are generating bytecode. @@ -2396,7 +2387,7 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) #endif // G__ASM break; default: - sprintf(expr, "%s(%s)", opr, G__setiparseobject(&expressionin, arg1)); + expr.Format("%s(%s)", opr(), G__setiparseobject(&expressionin, arg1)); break; } buffer = G__getfunction(expr, &ig2, G__TRYNORMAL); @@ -2456,10 +2447,10 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) pos = strchr(arg2, ')'); *pos = '\0'; if (expressionin.ref < 0) { - sprintf(expr, "*%s*)(%ld)", arg2, expressionin.ref); + expr.Format("*%s*)(%ld)", arg2(), expressionin.ref); } else { - sprintf(expr, "*%s*)%ld", arg2, expressionin.ref); + expr.Format("*%s*)%ld", arg2(), expressionin.ref); } strcpy(arg2, expr); } else if (expressionin.type == 'm') { @@ -2470,7 +2461,7 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) } } if (defined->type == 'u') { - sprintf(expr, "%s(%s)", opr, arg2); + expr.Format("%s(%s)", opr(), arg2()); store_struct_offset = G__store_struct_offset; store_tagnum = G__tagnum; G__store_struct_offset = defined->obj.i; @@ -2503,26 +2494,26 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) pos = strchr(arg1, ')'); *pos = '\0'; if (defined->ref < 0) { - sprintf(expr, "*%s*)(%ld)", arg1, defined->ref); + expr.Format("*%s*)(%ld)", arg1(), defined->ref); } else { - sprintf(expr, "*%s*)%ld", arg1, defined->ref); + expr.Format("*%s*)%ld", arg1(), defined->ref); } strcpy(arg1, expr); } } - sprintf(expr, "%s(%s,%s)", opr, arg1, arg2); + expr.Format("%s(%s,%s)", opr(), arg1(), arg2()); buffer = G__getfunction(expr, &ig2, G__TRYNORMAL); // // Need to check ANSI/ISO standard. What happens if operator // function defined in a namespace is used in other namespace. // if (!ig2 && (expressionin.tagnum != -1) && (G__struct.parent_tagnum[expressionin.tagnum] != -1)) { - sprintf(expr, "%s::%s(%s,%s)", G__fulltagname(G__struct.parent_tagnum[expressionin.tagnum], 1), opr , arg1 , arg2); + expr.Format("%s::%s(%s,%s)", G__fulltagname(G__struct.parent_tagnum[expressionin.tagnum], 1), opr(), arg1(), arg2()); buffer = G__getfunction(expr, &ig2, G__TRYNORMAL); } if (!ig2 && (defined->tagnum != -1) && (G__struct.parent_tagnum[defined->tagnum] != -1)) { - sprintf(expr, "%s::%s(%s,%s)", G__fulltagname(G__struct.parent_tagnum[defined->tagnum], 1), opr , arg1 , arg2); + expr.Format("%s::%s(%s,%s)", G__fulltagname(G__struct.parent_tagnum[defined->tagnum], 1), opr(), arg1(), arg2()); buffer = G__getfunction(expr, &ig2, G__TRYNORMAL); } @@ -2593,10 +2584,10 @@ int G__overloadopr(int operatortag, G__value expressionin, G__value* defined) if (0 == ig2) { if (-1 != defined->tagnum) { G__fprinterr(G__serr, "Error: %s not defined for %s" - , opr, G__fulltagname(defined->tagnum, 1)); + , opr(), G__fulltagname(defined->tagnum, 1)); } else { - G__fprinterr(G__serr, "Error: %s not defined", expr); + G__fprinterr(G__serr, "Error: %s not defined", expr()); } G__genericerror((char*)NULL); } @@ -2714,7 +2705,6 @@ int G__parenthesisovld(G__value* result3, char* funcname, G__param* libp, int fl int store_tagnum; int funcmatch; int hash; - char realname[G__ONELINE]; int store_exec_memberfunc; int store_memberfunc_tagnum; int store_memberfunc_struct_offset; @@ -2765,7 +2755,7 @@ int G__parenthesisovld(G__value* result3, char* funcname, G__param* libp, int fl } #endif - sprintf(realname, "operator()"); + static const char* realname = "operator()"; G__hash(realname, hash, known); G__fixedscope = 0; @@ -2823,8 +2813,8 @@ int G__tryindexopr(G__value* result7, G__value* para, int paran, int ig25) // * paran -> ig25 // 2) try operator[]() function while ig25<paran // - char expr[G__ONELINE]; - char arg2[G__MAXNAME]; + G__FastAllocString expr(G__ONELINE); + G__FastAllocString arg2(G__MAXNAME); char *pos; int store_tagnum; int store_typenum; @@ -2914,14 +2904,14 @@ int G__tryindexopr(G__value* result7, G__value* para, int paran, int ig25) pos = strchr(arg2, ')'); *pos = '\0'; if (para[ig25].ref < 0) - sprintf(expr, "*%s*)(%ld)", arg2, para[ig25].ref); + expr.Format("*%s*)(%ld)", arg2(), para[ig25].ref); else - sprintf(expr, "*%s*)%ld", arg2, para[ig25].ref); - strcpy(arg2, expr); + expr.Format("*%s*)%ld", arg2(), para[ig25].ref); + arg2 = expr; } } - sprintf(expr, "operator[](%s)", arg2); + expr.Format("operator[](%s)", arg2()); store_asm_exec = G__asm_exec; G__asm_exec = 0; *result7 = G__getfunction(expr, &known, G__CALLMEMFUNC); diff --git a/cint/cint/src/parse.cxx b/cint/cint/src/parse.cxx index 628523484f5c06a2d49831c118a51a1055968810..584c294ad4e0ea0a6dbe9770e71683ad4c746030 100644 --- a/cint/cint/src/parse.cxx +++ b/cint/cint/src/parse.cxx @@ -39,6 +39,19 @@ public: }; #endif +static int G__setline(G__FastAllocString& statement, int c, int* piout); +static int G__pp_ifdefextern(G__FastAllocString& temp); +static int G__exec_try(G__FastAllocString& statement); +static int G__exec_throw(G__FastAllocString& statement); +static int G__exec_function(G__FastAllocString& statement, int* pc, int* piout, int* plargestep, G__value* presult); +static G__value G__exec_switch_case(G__FastAllocString& casepara); +static G__value G__exec_loop(const char* forinit, char* condition, const std::list<G__FastAllocString>& foraction = std::list<G__FastAllocString>()); +static int G__defined_type(G__FastAllocString& type_name, int len); +static int G__keyword_anytime_5(G__FastAllocString& statement); +static int G__keyword_anytime_6(G__FastAllocString& statement); +static int G__keyword_anytime_7(G__FastAllocString& statement); +static int G__keyword_anytime_8(G__FastAllocString& statement); + extern "C" { //______________________________________________________________________________ @@ -59,25 +72,18 @@ extern void G__CMP2_equal(G__value*, G__value*); // v6_pcode.cxx #ifdef G__WIN32 static void G__toUniquePath(char* s); #endif // G__WIN32 -static int G__setline(char* statement, int c, int* piout); -static int G__pp_ifdefextern(char* temp); static void G__pp_undef(); -static int G__exec_try(char* statement); static int G__ignore_catch(); -static int G__exec_throw(char* statement); -static int G__exec_function(char* statement, int* pc, int* piout, int* plargestep, G__value* presult); static struct G__breakcontinue_list* G__alloc_breakcontinue_list(); static void G__store_breakcontinue_list(int destination, int breakcontinue); static void G__free_breakcontinue_list(G__breakcontinue_list* pbreakcontinue); static void G__set_breakcontinue_destination(int break_dest, int continue_dest, G__breakcontinue_list* pbreakcontinue); static G__value G__exec_switch(); -static G__value G__exec_switch_case(char* casepara); static G__value G__exec_if(); static G__value G__exec_else_if(); static G__value G__exec_do(); static G__value G__exec_for(); static G__value G__exec_while(); -static G__value G__exec_loop(char* forinit, char* condition, int naction, char** foraction); static G__value G__return_value(const char* statement); static int G__search_gotolabel(char* label, fpos_t* pfpos, int line, int* pmparen); static int G__label_access_scope(char* statement, int* piout, int* pspaceflag, int mparen); @@ -85,11 +91,6 @@ static int G__IsFundamentalDecl(); static void G__unsignedintegral(); static void G__externignore(); static void G__parse_friend(); -static int G__keyword_anytime_5(char* statement); -static int G__keyword_anytime_6(char* statement); -static int G__keyword_anytime_7(char* statement); -static int G__keyword_anytime_8(char* statement); -static int G__defined_type(char* type_name, int len); // externally visible G__value G__alloc_exceptionbuffer(int tagnum); @@ -160,12 +161,14 @@ static void G__toUniquePath(char* s) } #endif // G__WIN32 +} // extern "C" + //______________________________________________________________________________ -static int G__setline(char* statement, int c, int* piout) +static int G__setline(G__FastAllocString& statement, int c, int* piout) { // -- FIXME: Describe this function! if ((c != '\n') && (c != '\r')) { - c = G__fgetname(statement + 1, "\n\r"); + c = G__fgetname(statement, 1, "\n\r"); // // if (!isdigit(statement[1])) { @@ -182,14 +185,14 @@ static int G__setline(char* statement, int c, int* piout) else { // -- We have #<line> ...". G__ifile.line_number = atoi(statement + 1) - 1; - c = G__fgetname(statement, "\n\r"); + c = G__fgetname(statement, 0, "\n\r"); if (statement[0] == '"') { // -- We have #<line> "<filename>". G__getcintsysdir(); - char sysinclude[G__MAXFILENAME]; - sprintf(sysinclude, "%s/%s/include/", G__cintsysdir, G__CFG_COREVERSION); - char sysstl[G__MAXFILENAME]; - sprintf(sysstl, "%s/%s/stl/", G__cintsysdir, G__CFG_COREVERSION); + G__FastAllocString sysinclude(G__MAXFILENAME); + sysinclude.Format("%s/%s/include/", G__cintsysdir, G__CFG_COREVERSION); + G__FastAllocString sysstl(G__MAXFILENAME); + sysstl.Format("%s/%s/stl/", G__cintsysdir, G__CFG_COREVERSION); int len = strlen(sysinclude); int lenstl = strlen(sysstl); #ifdef G__WIN32 @@ -318,13 +321,13 @@ static int G__setline(char* statement, int c, int* piout) } //______________________________________________________________________________ -static int G__pp_ifdefextern(char* temp) +static int G__pp_ifdefextern(G__FastAllocString& temp) { // -- FIXME: Describe this function! fpos_t pos; fgetpos(G__ifile.fp, &pos); int linenum = G__ifile.line_number; - int cin = G__fgetname(temp, "\"}#"); + int cin = G__fgetname(temp, 0, "\"}#"); if (cin == '}') { // -- // @@ -334,8 +337,8 @@ static int G__pp_ifdefextern(char* temp) // G__fignoreline(); do { - cin = G__fgetstream(temp, "#"); - cin = G__fgetstream(temp, "\n\r"); + cin = G__fgetstream(temp, 0, "#"); + cin = G__fgetstream(temp, 0, "\n\r"); } while (strcmp(temp, "endif")); return G__IFDEF_ENDBLOCK; @@ -360,30 +363,30 @@ static int G__pp_ifdefextern(char* temp) int flag = 0; int store_iscpp = G__iscpp; int store_externblock_iscpp = G__externblock_iscpp; - char fname[G__MAXFILENAME]; - cin = G__fgetstream(fname, "\""); + G__FastAllocString fname(G__MAXFILENAME); + cin = G__fgetstream(fname, 0, "\""); temp[0] = 0; do { - cin = G__fgetstream(temp, "{\r\n"); + cin = G__fgetstream(temp, 0, "{\r\n"); } while (!temp[0] && ((cin == '\r') || (cin == '\n'))); if (temp[0] || (cin != '{')) { goto goback; } - cin = G__fgetstream(temp, "\n\r"); + cin = G__fgetstream(temp, 0, "\n\r"); if ((cin == '}') && !strcmp(fname, "C")) { goto goback; } - cin = G__fgetstream(temp, "#\n\r"); + cin = G__fgetstream(temp, 0, "#\n\r"); if (((cin == '\n') || (cin == '\r')) && !temp[0]) { - cin = G__fgetstream(temp, "#\n\r"); + cin = G__fgetstream(temp, 0, "#\n\r"); } if (cin != '#') { goto goback; } - cin = G__fgetstream(temp, "\n\r"); + cin = G__fgetstream(temp, 0, "\n\r"); if (((cin == '\n') || (cin == '\r')) && !temp[0]) { - cin = G__fgetstream(temp, "#\n\r"); + cin = G__fgetstream(temp, 0, "#\n\r"); } if (strcmp(temp, "endif")) { goto goback; @@ -413,12 +416,14 @@ static int G__pp_ifdefextern(char* temp) return G__IFDEF_NORMAL; } +extern "C" { + //______________________________________________________________________________ static void G__pp_undef() { // -- FIXME: Describe this function! - char temp[G__MAXNAME]; - G__fgetname(temp, "\n\r"); + G__FastAllocString temp(G__MAXNAME); + G__fgetname(temp, 0, "\n\r"); struct G__var_array* var = &G__global; while (var) { for (int i = 0; i < var->allvar; ++i) { @@ -448,8 +453,10 @@ static void G__pp_undef() // Exceptions. try, throw, catch // +} // extern "C" + //______________________________________________________________________________ -static int G__exec_try(char* statement) +static int G__exec_try(G__FastAllocString& statement) { // -- FIXME: Describe this function! int brace_level = 0; @@ -462,6 +469,9 @@ static int G__exec_try(char* statement) return 0; } + +extern "C" { + //______________________________________________________________________________ static int G__ignore_catch() { @@ -507,19 +517,23 @@ static int G__ignore_catch() return 0; } +} // extern "C" + + //______________________________________________________________________________ -static int G__exec_throw(char* statement) +static int G__exec_throw(G__FastAllocString& statement) { // -- Handle the "throw" expression. int iout = 0; - char buf[G__ONELINE]; - G__fgetstream(buf, ";"); + G__FastAllocString buf(G__ONELINE); + G__fgetstream(buf, 0, ";"); if (isdigit(buf[0]) || (buf[0] == '.')) { - strcpy(statement, buf); + statement = buf; iout = 5; } else { - sprintf(statement, "new %s", buf); + statement = "new "; + statement += buf; iout = strlen(statement); } G__exceptionbuffer = G__null; @@ -599,7 +613,7 @@ static int G__exec_throw(char* statement) // //______________________________________________________________________________ -static int G__exec_function(char* statement, int* pc, int* piout, int* plargestep, G__value* presult) +static int G__exec_function(G__FastAllocString& statement, int* pc, int* piout, int* plargestep, G__value* presult) { // -- Function call. // @@ -609,7 +623,7 @@ static int G__exec_function(char* statement, int* pc, int* piout, int* plargeste //fprintf(stderr, "G__exec_function: Function call is followed by an operator.\n"); if ((*pc != ';') && (*pc != ',')) { statement[(*piout)++] = *pc; - *pc = G__fgetstream_new(statement + (*piout) , ";"); + *pc = G__fgetstream_new(statement , (*piout), ";"); } if (G__breaksignal) { int ret = G__beforelargestep(statement, piout, plargestep); @@ -632,7 +646,7 @@ static int G__exec_function(char* statement, int* pc, int* piout, int* plargeste //fprintf(stderr, "G__exec_function: Function call is followed by '('.\n"); int len = strlen(statement); statement[len++] = *pc; - *pc = G__fgetstream_newtemplate(statement + len, ")"); + *pc = G__fgetstream_newtemplate(statement, len, ")"); len = strlen(statement); statement[len++] = *pc; statement[len] = 0; @@ -640,7 +654,7 @@ static int G__exec_function(char* statement, int* pc, int* piout, int* plargeste while (*pc != ';') { len = strlen(statement); statement[len++] = *pc; - *pc = G__fgetstream_newtemplate(statement + len, ");"); + *pc = G__fgetstream_newtemplate(statement, len, ");"); if (*pc == ';') { break; } @@ -682,7 +696,7 @@ static int G__exec_function(char* statement, int* pc, int* piout, int* plargeste if (!(*piout)) { // -- It was not a macro. if (G__dispmsg >= G__DISPWARN) { - G__fprinterr(G__serr, "Warning: %s Missing ';'", statement); + G__fprinterr(G__serr, "Warning: %s Missing ';'", statement()); G__printlinenum(); } } @@ -700,6 +714,8 @@ static int G__exec_function(char* statement, int* pc, int* piout, int* plargeste return 0; } +extern "C" { + //______________________________________________________________________________ //______________________________________________________________________________ // @@ -843,8 +859,8 @@ static G__value G__exec_switch() // // Scan the switch condition. // - char condition[G__ONELINE]; - G__fgetstream(condition, ")"); + G__FastAllocString condition(G__ONELINE); + G__fgetstream(condition, 0, ")"); //{ // char buf[128]; // G__fgetstream_peek(buf, 30); @@ -1175,8 +1191,10 @@ static G__value G__exec_switch() return result; } +} //extern "C" + //______________________________________________________________________________ -static G__value G__exec_switch_case(char* casepara) +static G__value G__exec_switch_case(G__FastAllocString& casepara) { // -- Handle a case expression inside a switch statement. // @@ -1291,6 +1309,8 @@ static G__value G__exec_switch_case(char* casepara) return result; } +extern "C" { + //______________________________________________________________________________ static G__value G__exec_if() { @@ -1312,16 +1332,15 @@ static G__value G__exec_if() // // Get the text of the if condition from the input file. // - char* condition = (char*) malloc(G__LONGLINE); - G__fgetstream_new(condition, ")"); - condition = (char*) realloc((void*) condition, strlen(condition) + 10); + G__FastAllocString condition(G__LONGLINE); + G__fgetstream_new(condition, 0, ")"); + condition.Resize(strlen(condition) + 10); // // If the previous read hit a breakpoint, pause, and exit if requested. // if (G__breaksignal) { if (G__beforelargestep(condition, &iout, &largestep) > 1) { G__ifswitch = store_ifswitch; - free(condition); //fprintf(stderr, "---end if\n"); return G__null; } @@ -1405,7 +1424,6 @@ static G__value G__exec_if() } #endif // G__ASM G__ifswitch = store_ifswitch; - free(condition); //fprintf(stderr, "---end if\n"); return result; } @@ -1576,7 +1594,6 @@ static G__value G__exec_if() } #endif // G__ASM G__ifswitch = store_ifswitch; - free(condition); //fprintf(stderr, "---end if\n"); return G__null; } @@ -1628,7 +1645,6 @@ static G__value G__exec_if() } #endif // G__ASM G__ifswitch = store_ifswitch; - free(condition); //fprintf(stderr, "---end if\n"); return G__null; } @@ -1770,7 +1786,6 @@ static G__value G__exec_if() } #endif // G__ASM G__ifswitch = store_ifswitch; - free(condition); //fprintf(stderr, "---end if\n"); return result; } @@ -1809,7 +1824,6 @@ static G__value G__exec_if() #endif // G__ASM // Restore state. G__ifswitch = store_ifswitch; - free(condition); // And return. //{ // char buf[128]; @@ -2219,10 +2233,10 @@ static G__value G__exec_do() // G__fgetstream_peek(buf, 10); // fprintf(stderr, "G__exec_do: peek ahead: '%s'\n", buf); //} - char condition[G__ONELINE]; - G__fgetstream(condition, "("); + G__FastAllocString condition(G__ONELINE); + G__fgetstream(condition, 0, "("); if (strcmp(condition, "while")) { - G__fprinterr(G__serr, "Syntax error: do {} %s(); Should be do {} while (); FILE: %s LINE: %d\n", condition, G__ifile.name, G__ifile.line_number); + G__fprinterr(G__serr, "Syntax error: do {} %s(); Should be do {} while (); FILE: %s LINE: %d\n", condition(), G__ifile.name, G__ifile.line_number); } // // do { ... } while (...); @@ -2235,7 +2249,7 @@ static G__value G__exec_do() // G__fgetstream_peek(buf, 10); // fprintf(stderr, "G__exec_do: peek ahead: '%s'\n", buf); //} - G__fgetstream(condition, ")"); + G__fgetstream(condition, 0, ")"); //{ // char buf[128]; // G__fgetstream_peek(buf, 10); @@ -2623,55 +2637,46 @@ static G__value G__exec_for() G__ifswitch = store_ifswitch; return G__null; } - char* condition = (char*) malloc(G__LONGLINE); - int c = G__fgetstream(condition, ";)"); + G__FastAllocString condition(G__LONGLINE); + int c = G__fgetstream(condition, 0, ";)"); if (c == ')') { // -- Syntax error, the third clause of the for was missing. G__genericerror("Error: for statement syntax error"); G__ifswitch = store_ifswitch; - free(condition); return G__null; } // If there is no condition text, make it always true, as the standard requires. if (!condition[0]) { - strcpy(condition, "1"); + condition = "1"; } // FIXME: Why do we make the condition buffer bigger? - condition = (char*) realloc(condition, strlen(condition) + 10); + condition.Resize(strlen(condition) + 10); // // Collect the third clause of the for, // separating it on commas. // - char foractionbuf[G__ONELINE]; - char* foraction[10]; - int naction = 0; - char* p = foractionbuf; + std::list<G__FastAllocString> foraction; do { // -- Collect one clause of a comma operator expression. // Scan until a comma or the end of the head of the for. - c = G__fgetstream(p, "),"); + foraction.push_back(G__FastAllocString()); + c = G__fgetstream(foraction.back(), 0, "),"); if (G__return > G__RETURN_NORMAL) { // FIXME: Is this error message correct? G__fprinterr(G__serr, "Error: for statement syntax error. ';' needed\n"); // Restore the ifswitch state. G__ifswitch = store_ifswitch; // Cleanup malloc'ed memory. - free(condition); // And exit in error. return G__null; } - // Collect this clause. - foraction[naction++] = p; - // Move past scanned text in buffer. - p += strlen(p) + 1; } while (c != ')'); // // Execute the body of the loop. // - G__value result = G__exec_loop(0, condition, naction, foraction); + G__value result = G__exec_loop(0, condition, foraction); // Cleanup malloc'ed memory. - free(condition); // Restore the ifswitch state. G__ifswitch = store_ifswitch; // And we are done. @@ -2699,24 +2704,26 @@ static G__value G__exec_while() // // Scan in the while condition. // - char* condition = (char*) malloc(G__LONGLINE); - G__fgetstream(condition, ")"); + G__FastAllocString condition(G__LONGLINE); + G__fgetstream(condition, 0, ")"); // FIXME: Why do we make the condition buffer bigger? - condition = (char*) realloc((void*) condition, strlen(condition) + 10); + condition.Resize(strlen(condition) + 10); // // Execute the body of the loop. // - G__value result = G__exec_loop(0, condition, 0, 0); + G__value result = G__exec_loop(0, condition); // Cleanup malloc'ed memory. - free(condition); // Restore the ifswitch state. G__ifswitch = store_ifswitch; // And we are done. return result; } +} // extern "C" + //______________________________________________________________________________ -static G__value G__exec_loop(char* forinit, char* condition, int naction, char** foraction) +static G__value G__exec_loop(const char* forinit, char* condition, + const std::list<G__FastAllocString>& foraction) { // -- Execute a loop, handles most of for, and while. // @@ -3109,10 +3116,11 @@ static G__value G__exec_loop(char* forinit, char* condition, int naction, char** // // Execute the bottom of loop expression. // - if (naction) { + if (!foraction.empty()) { //fprintf(stderr, "G__exec_loop: begin executing loop actions ...\n"); - for (int i = 0; i < naction; ++i) { - G__getexpr(foraction[i]); + for (std::list<G__FastAllocString>::const_iterator i = foraction.begin(), + e = foraction.end(); i != e; ++i) { + G__getexpr(*i); } //fprintf(stderr, "G__exec_loop: end executing loop actions.\n"); } @@ -3296,6 +3304,8 @@ static G__value G__exec_loop(char* forinit, char* condition, int naction, char** return result; } +extern "C" { + //______________________________________________________________________________ // // Jump statements. return, goto @@ -3429,9 +3439,9 @@ static int G__search_gotolabel(char* label, fpos_t* pfpos, int line, int* pmpare int single_quote = 0; int double_quote = 0; do { - char token[G__LONGLINE]; + G__FastAllocString token(G__LONGLINE); // The extraneous punctuation is here to keep from overflowing token. - c = G__fgetstream(token, "'\"{}:();"); + c = G__fgetstream(token, 0, "'\"{}:();"); if (c == EOF) { break; } @@ -3497,7 +3507,7 @@ static int G__label_access_scope(char* statement, int* piout, int* pspaceflag, i int line; int store_tagdefining; fpos_t pos; - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); // Look ahead to see if we have a "::". int c = G__fgetc(); if (c == ':') { @@ -3521,7 +3531,7 @@ static int G__label_access_scope(char* statement, int* piout, int* pspaceflag, i fgetpos(G__ifile.fp, &pos); line = G__ifile.line_number; if (G__dispsource) G__disp_mask = 1000; - c = G__fgetname_template(temp, "(;&*"); + c = G__fgetname_template(temp, 0, "(;&*"); if (isspace(c) || (c == '&') || (c == '*')) { c = G__fgetspace(); for (; (c == '&') || (c == '*');) { @@ -3649,13 +3659,13 @@ static int G__IsFundamentalDecl() // -- Used only by G__keyword_anytime_5. // -- FIXME: We don't check for float, double, or long double! // -- FIXME: We don't accept a macro which expands to a fundamental type. - char type_name[G__ONELINE]; + G__FastAllocString type_name(G__ONELINE); // Store file position. int linenum = G__ifile.line_number; fpos_t pos; fgetpos(G__ifile.fp, &pos); G__disp_mask = 1000; - /*int c =*/ G__fgetname_template(type_name, "("); + /*int c =*/ G__fgetname_template(type_name, 0, "("); int result = 1; if (!strcmp(type_name, "class") || !strcmp(type_name, "struct") || !strcmp(type_name, "union")) { result = 0; @@ -3717,8 +3727,8 @@ static void G__unsignedintegral() fgetpos(G__ifile.fp, &pos); G__unsigned = -1; // Scan the next identifier token in. - char name[G__MAXNAME]; - G__fgetname(name, "("); + G__FastAllocString name(G__MAXNAME); + G__fgetname(name, 0, "("); // // And compare against the integral types. // @@ -3826,8 +3836,8 @@ static void G__externignore() { // -- Handle extern "...", EXTERN "..." int flag = 0; - char fname[G__MAXFILENAME]; - int c = G__fgetstream(fname, "\""); + G__FastAllocString fname(G__MAXFILENAME); + int c = G__fgetstream(fname, 0, "\""); int store_iscpp = G__iscpp; // FIXME: We should handle "C++" as well! if (!strcmp(fname, "C")) { @@ -3881,24 +3891,24 @@ static void G__parse_friend() fpos_t pos; fgetpos(G__ifile.fp, &pos); int line_number = G__ifile.line_number; - char classname[G__LONGLINE]; - int c = G__fgetname_template(classname, ";"); + G__FastAllocString classname(G__LONGLINE); + int c = G__fgetname_template(classname, 0, ";"); int tagtype = 0; if (c == ';') { tagtype = 'c'; } else if (isspace(c)) { if (!strcmp(classname, "class")) { - c = G__fgetname_template(classname, ";"); + c = G__fgetname_template(classname, 0, ";"); tagtype = 'c'; } else if (!strcmp(classname, "struct")) { - c = G__fgetname_template(classname, ";"); + c = G__fgetname_template(classname, 0, ";"); tagtype = 's'; } else { if (!strcmp(classname, "const") || !strcmp(classname, "volatile") || !strcmp(classname, "register")) { - c = G__fgetname_template(classname, ";"); + c = G__fgetname_template(classname, 0, ";"); } if ((c == ';') || (c == ',')) { tagtype = 'c'; @@ -3963,10 +3973,10 @@ static void G__parse_friend() } } if (c != ';') { - c = G__fgetstream(classname, ";,"); + c = G__fgetstream(classname, 0, ";,"); } else { - classname[0] = '\0'; + classname[0] = 0; } } } @@ -4004,8 +4014,11 @@ static void G__parse_friend() } #endif // G__FRIEND +} // extern "C" + + //______________________________________________________________________________ -static int G__keyword_anytime_5(char* statement) +static int G__keyword_anytime_5(G__FastAllocString& statement) { // -- Handle a function-local const declaration, or #else, #elif, and #line int c = 0; @@ -4080,7 +4093,7 @@ static int G__keyword_anytime_5(char* statement) } //______________________________________________________________________________ -static int G__keyword_anytime_6(char* statement) +static int G__keyword_anytime_6(G__FastAllocString& statement) { // -- Handle "static", "return", "#ifdef", "#endif", "#undef", and "#ident" if (!strcmp(statement, "static")) { @@ -4162,7 +4175,7 @@ static int G__keyword_anytime_6(char* statement) } //______________________________________________________________________________ -static int G__keyword_anytime_7(char* statement) +static int G__keyword_anytime_7(G__FastAllocString& statement) { // -- Handle "#define", "#ifndef", and "#pragma". /*********************************** @@ -4209,7 +4222,7 @@ static int G__keyword_anytime_7(char* statement) } //______________________________________________________________________________ -static int G__keyword_anytime_8(char* statement) +static int G__keyword_anytime_8(G__FastAllocString& statement) { // -- Handle "template" and "explicit" keywords. // @@ -4222,7 +4235,7 @@ static int G__keyword_anytime_8(char* statement) int c; fpos_t pos; int line_number; - char tcname[G__ONELINE]; + G__FastAllocString tcname(G__ONELINE); line_number = G__ifile.line_number; fgetpos(G__ifile.fp, &pos); c = G__fgetspace(); @@ -4236,10 +4249,10 @@ static int G__keyword_anytime_8(char* statement) tcname[0] = c; fseek(G__ifile.fp, -1, SEEK_CUR); G__disp_mask = 1; - c = G__fgetname_template(tcname, ";"); + c = G__fgetname_template(tcname, 0, ";"); if (strcmp(tcname, "class") == 0 || strcmp(tcname, "struct") == 0) { - c = G__fgetstream_template(tcname, ";"); + c = G__fgetstream_template(tcname, 0, "0, ;"); } else if (isspace(c)) { int len = strlen(tcname); @@ -4256,7 +4269,7 @@ static int G__keyword_anytime_8(char* statement) } else { tcname[len] = store_c; - c = G__fgetstream_template(tcname + strlen(tcname), ";"); + c = G__fgetstream_template(tcname, strlen(tcname), ";"); } } if (!G__defined_templateclass(tcname)) { @@ -4271,7 +4284,7 @@ static int G__keyword_anytime_8(char* statement) return 0; } -static int G__defined_type(char* type_name, int len) +static int G__defined_type(G__FastAllocString& type_name, int len) { // -- Handle a possible declaration, return 0 if not, return 1 if good. // @@ -4285,6 +4298,7 @@ static int G__defined_type(char* type_name, int len) // -- We have found a destructor declaration in prerun. G__var_type = 'y'; int cin = G__fignorestream("("); + type_name.Resize(len + 2); type_name[len++] = cin; type_name[len] = '\0'; G__make_ifunctable(type_name); @@ -4304,8 +4318,7 @@ static int G__defined_type(char* type_name, int len) fgetpos(G__ifile.fp, &pos); int line = G__ifile.line_number; // Remember the passed type_name in case we fail. - char store_typename[G__LONGLINE]; - strcpy(store_typename, type_name); + G__FastAllocString store_typename(type_name); // Remember tagnum and typenum in case we fail. int store_tagnum = G__tagnum; int store_typenum = G__typenum; @@ -4381,7 +4394,7 @@ static int G__defined_type(char* type_name, int len) else if ((len > 1) && (type_name[len-1] == '*')) { int cin2; len -= 1; - type_name[len] = '\0'; + type_name[len] = 0; fsetpos(G__ifile.fp, &pos); G__ifile.line_number = line; // To know how much to rewind we need to know if there is a fakespace. @@ -4444,15 +4457,15 @@ static int G__defined_type(char* type_name, int len) // Declare the undefined name as a class. G__tagnum = G__search_tagname(type_name, 'c'); // Output the info to the given file. - fprintf(G__fpundeftype, "class %s; /* %s %d */\n", type_name , G__ifile.name, G__ifile.line_number); - fprintf(G__fpundeftype, "#pragma link off class %s;\n\n", type_name); + fprintf(G__fpundeftype, "class %s; /* %s %d */\n", type_name(), G__ifile.name, G__ifile.line_number); + fprintf(G__fpundeftype, "#pragma link off class %s;\n\n", type_name()); G__struct.globalcomp[G__tagnum] = G__NOLINK; } else { // -- Was not a known type, return. fsetpos(G__ifile.fp, &pos); G__ifile.line_number = line; - strcpy(type_name, store_typename); + type_name = store_typename; G__tagnum = store_tagnum; G__typenum = store_typenum; G__reftype = G__PARANORMAL; @@ -4484,6 +4497,8 @@ static int G__defined_type(char* type_name, int len) return 1; } +extern "C" { + //______________________________________________________________________________ //______________________________________________________________________________ // @@ -4515,7 +4530,7 @@ int G__free_exceptionbuffer() if ('u' == G__exceptionbuffer.type && G__exceptionbuffer.obj.i && -1 != G__exceptionbuffer.tagnum) { // destruct before free - char destruct[G__ONELINE]; + G__FastAllocString destruct(G__ONELINE); int store_tagnum = G__tagnum; int dmy = 0; G__tagnum = G__exceptionbuffer.tagnum; @@ -4523,10 +4538,10 @@ int G__free_exceptionbuffer() G__globalvarpointer = G__store_struct_offset; } else G__globalvarpointer = G__PVOID; - sprintf(destruct, "~%s()", G__fulltagname(G__tagnum, 1)); + destruct.Format("~%s()", G__fulltagname(G__tagnum, 1)); if (G__dispsource) { G__fprinterr(G__serr, "!!!Destructing exception buffer %s %lx" - , destruct, G__exceptionbuffer.obj.i); + , destruct(), G__exceptionbuffer.obj.i); G__printlinenum(); } G__getfunction(destruct, &dmy , G__TRYDESTRUCTOR); @@ -4628,8 +4643,8 @@ int G__defined_macro(const char* macro) int G__pp_command() { // -- FIXME: Describe this function! - char condition[G__ONELINE]; - int c = G__fgetname(condition, "\n\r"); + G__FastAllocString condition(G__ONELINE); + int c = G__fgetname(condition, 0, "\n\r"); if (isdigit(condition[0])) { if ((c != '\n') && (c != '\r')) { G__fignoreline(); @@ -4658,15 +4673,15 @@ int G__pp_command() void G__pp_skip(int elifskip) { // -- FIXME: Describe this function! - char oneline[G__LONGLINE*2]; - char argbuf[G__LONGLINE*2]; - char *arg[G__ONELINE]; + G__FastAllocString oneline(G__LONGLINE*2); + G__FastAllocString argbuf(G__LONGLINE*2); + char* arg[G__ONELINE]; int argn; FILE *fp; int nest = 1; - char condition[G__ONELINE]; - char temp[G__ONELINE]; + G__FastAllocString condition(G__ONELINE); + G__FastAllocString temp(G__ONELINE); int i; fp = G__ifile.fp; @@ -4682,7 +4697,7 @@ void G__pp_skip(int elifskip) /******************************************************** * Read lines until end of conditional compilation ********************************************************/ - while (nest && G__readline(fp, oneline, argbuf, &argn, arg) != 0) { + while (nest && G__readline_FastAlloc(fp, oneline, argbuf, &argn, arg) != 0) { /************************************************ * If input line is "abcdefg hijklmn opqrstu" * @@ -4726,9 +4741,9 @@ void G__pp_skip(int elifskip) if (!G__xrefflag) { G__asm_noverflow = 0; } - strcpy(condition, ""); + condition = ""; for (i = directiveArgI + 1; i <= argn; i++) { - strcat(condition, arg[i]); + condition += arg[i]; } i = strlen(oneline) - 1; while (i >= 0 && (oneline[i] == '\n' || oneline[i] == '\r')) { @@ -4737,7 +4752,7 @@ void G__pp_skip(int elifskip) if (oneline[i] == '\\') { int len = strlen(condition); while (1) { - G__fgetstream(condition + len, "\n\r"); + G__fgetstream(condition, len, "\n\r"); if (condition[len] == '\\' && (condition[len+1] == '\n' || condition[len+1] == '\r')) { char* p = condition + len; @@ -4768,11 +4783,12 @@ void G__pp_skip(int elifskip) if (!posCommentEnd) { if (G__skip_comment()) break; - if (G__fgetstream(posComment, "\r\n") == EOF) + if (G__fgetstream(condition, posComment - condition.data(), "\r\n") == EOF) break; } else { - strcpy(temp, posCommentEnd + 2); + temp = posCommentEnd + 2; + condition.Resize(posComment - condition.data() + strlen(temp) + 1); strcpy(posComment, temp); } posComment = strstr(posComment, "/*"); @@ -4823,14 +4839,14 @@ void G__pp_skip(int elifskip) int G__pp_if() { // -- FIXME: Describe this function! - char condition[G__LONGLINE]; + G__FastAllocString condition(G__LONGLINE); int c, len = 0; int store_no_exec_compile; int store_asm_wholefunction; int store_asm_noverflow; int haveOpenDefined = -1; // need to convert defined FOO to defined(FOO) do { - c = G__fgetstream(condition + len, " \n\r"); + c = G__fgetstream(condition, len, " \n\r"); len = strlen(condition); if (len > 0 && (condition[len] == '\n' || condition[len] == '\r')) --len; if (haveOpenDefined != -1) { @@ -4843,6 +4859,7 @@ int G__pp_if() --len; } else { + condition.Resize(len + 2); condition[len] = ')'; condition[len + 1] = 0; // this might be the end, so terminate it ++len; @@ -4852,6 +4869,7 @@ int G__pp_if() else if (c == ' ' && len > 6 && !strcmp(condition + len - 7, "defined")) { haveOpenDefined = len; + condition.Resize(len + 2); condition[len] = '('; ++len; } @@ -4907,10 +4925,10 @@ int G__pp_ifdef(int def) { // -- FIXME: Describe this function! // def: 1 for ifdef; 0 for ifndef - char temp[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); int notfound = 1; - G__fgetname(temp, "\n\r"); + G__fgetname(temp, 0, "\n\r"); notfound = G__defined_macro(temp) ^ 1; @@ -4930,8 +4948,11 @@ int G__pp_ifdef(int def) return(G__IFDEF_NORMAL); } +} // extern "C" + + //______________________________________________________________________________ -int G__exec_catch(char* statement) +int G__exec_catch(G__FastAllocString& statement) { // -- Handle the "catch" statement. int c; @@ -4942,7 +4963,7 @@ int G__exec_catch(char* statement) // catch (ehclass& obj) { } // ^^^^^^^ do { - c = G__fgetstream(statement, "(};"); + c = G__fgetstream(statement, 0, "(};"); } while ('}' == c); if ((c != '(') || strcmp(statement, "catch")) { @@ -4952,7 +4973,7 @@ int G__exec_catch(char* statement) line_number = G__ifile.line_number; // catch (ehclass& obj) { } // ^^^^^^^^ - c = G__fgetname_template(statement, ")&*"); + c = G__fgetname_template(statement, 0, ")&*"); if (statement[0] == '.') { // catch all exceptions // catch(...) { } @@ -4966,13 +4987,13 @@ int G__exec_catch(char* statement) else { std::string excType(statement); if (excType == "const") { - c = G__fgetname_template(statement, ")&*"); + c = G__fgetname_template(statement, 0, ")&*"); excType += " "; excType += statement; } while (c == '*' || c == '&') { excType += c; - c = G__fgetname_template(statement, ")&*"); + c = G__fgetname_template(statement, 0, ")&*"); } G__value sType = G__string2type(excType.c_str()); @@ -5013,6 +5034,8 @@ int G__exec_catch(char* statement) return 0; } +extern "C"{ + //______________________________________________________________________________ int G__skip_comment() { @@ -5134,7 +5157,7 @@ G__value G__exec_statement(int* mparen) int fake_space = 0; int discard_space = 0; int discarded_space = 0; - char statement[G__LONGLINE]; + G__FastAllocString statement(G__LONGLINE); G__value result = G__null; //fprintf(stderr, "\nG__exec_statement: Begin.\n"); fpos_t start_pos; @@ -5159,7 +5182,7 @@ G__value G__exec_statement(int* mparen) } discard_space = 0; read_again: - statement[iout] = '\0'; + statement.Set(iout, 0); if (!G__prerun) { //fprintf(stderr, "G__exec_statement: c: '%c' pr: %d ne: %d nec: %d ano: %d mp: %d io: %d st: '%s'\n", c, G__prerun, G__no_exec, G__no_exec_compile, G__asm_noverflow, *mparen, iout, statement); } @@ -5198,7 +5221,7 @@ G__value G__exec_statement(int* mparen) commentflag = 0; // ignore these character if (single_quote || double_quote) { - statement[iout++] = c; + statement.Set(iout++, c); } else { after_replacement: @@ -5207,7 +5230,7 @@ G__value G__exec_statement(int* mparen) } if (spaceflag == 1) { // -- Take action on space, even if skipping code. Do preprocessing and look for declarations. - statement[iout] = '\0'; + statement.Set(iout, 0); // search keyword G__preproc_again: if ((statement[0] == '#') && isdigit(statement[1])) { @@ -5270,13 +5293,13 @@ G__value G__exec_statement(int* mparen) if ((*mparen == 1) && !strcmp(statement, "case")) { //fprintf(stderr, "G__exec_statement: Saw a case.\n"); // Scan the case label in. - char casepara[G__ONELINE]; - G__fgetstream(casepara, ":"); + G__FastAllocString casepara(G__ONELINE); + G__fgetstream(casepara, 0, ":"); c = G__fgetc(); while (c == ':') { - strcat(casepara, "::"); + casepara += "::"; int lenxxx = strlen(casepara); - G__fgetstream(casepara + lenxxx, ":"); + G__fgetstream(casepara, lenxxx, ":"); c = G__fgetc(); } // Backup one character. @@ -5472,7 +5495,7 @@ G__value G__exec_statement(int* mparen) // -- Take action on space, we are not skipping code. // // Terminate the accumulated statement text. - statement[iout] = '\0'; + statement.Set(iout, 0); // Hack, fixup read of xxx** or xxx*&. if ( // -- If we have xxx** or xxx*&. @@ -5556,15 +5579,15 @@ G__value G__exec_statement(int* mparen) if (G__dispsource) { G__disp_mask = 1; } - statement[iout++] = ' '; + statement.Set(iout++, ' '); spaceflag |= 1; // a little later this string will be passed to subfunctions // that expect the string to be terminated - statement[iout] = '\0'; + statement.Set(iout, '0'); } else { - statement[0] = c; - c = G__fgetstream_template(statement + 1, ";"); + statement.Set(0, c); + c = G__fgetstream_template(statement, 1, ";"); result = G__new_operator(statement); // Reset the statement buffer. iout = 0; @@ -5705,17 +5728,17 @@ G__value G__exec_statement(int* mparen) // FIXME: The line number, dispmask, and macro expansion state may be wrong now! fseek(G__ifile.fp, -1, SEEK_CUR); // And insert a fake space into the statement. - statement[iout++] = ' '; + statement.Set(iout++, ' '); // And terminate the buffer. - statement[iout] = '\0'; + statement.Set(iout, 0); // Flag that any whitespace should now trigger a semantic action. spaceflag |= 1; } else { // Insert a fake space into the statement (right after the 'new'). - statement[iout++] = ' '; + statement.Set(iout++, ' '); // Then add in the character that terminated the peek ahead. - statement[iout++] = c; + statement.Set(iout++, c); // Skip showing the next character. // FIXME: This is wrong! if (G__dispsource) { @@ -5723,11 +5746,11 @@ G__value G__exec_statement(int* mparen) G__disp_mask = 1; } // Scan the reset of the parenthesised new expression. - c = G__fgetstream_template(statement + iout, ")"); + c = G__fgetstream_template(statement, iout, ")"); iout = strlen(statement); - statement[iout++] = c; + statement.Set(iout++, c); // And terminate the statement buffer. - statement[iout] = '\0'; + statement.Set(iout, 0); // Flag that any whitespace should now trigger a semantic action. spaceflag |= 1; } @@ -5739,7 +5762,7 @@ G__value G__exec_statement(int* mparen) // Check if current security level allows the use of the goto statement. G__CHECK(G__SECURE_GOTO, 1, return G__null); // Scan in the goto label. - c = G__fgetstream(statement, ";"); + c = G__fgetstream(statement, 0, ";"); #ifdef G__ASM if (G__asm_wholefunction == G__ASM_FUNC_COMPILE) { G__add_jump_bytecode(statement); @@ -6060,7 +6083,7 @@ G__value G__exec_statement(int* mparen) if (!strcmp(statement, "return")) { // -- Handle 'return ...'; // ^ - G__fgetstream_new(statement, ";"); + G__fgetstream_new(statement, 0, ";"); result = G__return_value(statement); if (G__no_exec_compile) { if (!*mparen) { @@ -6077,19 +6100,19 @@ G__value G__exec_statement(int* mparen) if (!strcmp(statement, "delete")) { // -- Handle 'delete ...'. // ^ - int c = G__fgetstream(statement , "[;"); + int c = G__fgetstream(statement, 0, "[;"); iout = 0; if (c == '[') { if (!statement[0]) { - c = G__fgetstream(statement, "]"); - c = G__fgetstream(statement, ";"); + c = G__fgetstream(statement, 0, "]"); + c = G__fgetstream(statement, 0, ";"); iout = 1; } else { - strcpy(statement + strlen(statement), "["); - c = G__fgetstream(statement + strlen(statement), "]"); - strcpy(statement + strlen(statement), "]"); - c = G__fgetstream(statement + strlen(statement), ";"); + statement += "["; + c = G__fgetstream(statement, strlen(statement), "]"); + statement += "]"; + c = G__fgetstream(statement, strlen(statement), ";"); } } // Note: iout == 1, if 'delete[]' @@ -6284,7 +6307,7 @@ G__value G__exec_statement(int* mparen) if (!strcmp(statement, "delete[]")) { // Handle 'delete[] ...'. // ^ - G__fgetstream(statement, ";"); + G__fgetstream(statement, 0, ";"); int largestep = 0; if (G__breaksignal) { int ret = G__beforelargestep(statement, &iout, &largestep); @@ -6317,17 +6340,17 @@ G__value G__exec_statement(int* mparen) // ^ int store_tagnum; do { - char oprbuf[G__ONELINE]; + G__FastAllocString oprbuf(G__ONELINE); iout = strlen(statement); - c = G__fgetname(oprbuf, "("); + c = G__fgetname(oprbuf, 0, "("); switch (oprbuf[0]) { case '*': case '&': - strcpy(statement + iout, oprbuf); + statement += oprbuf; break; default: - statement[iout] = ' '; - strcpy(statement + iout + 1, oprbuf); + statement += " "; + statement += oprbuf; } } while (c != '('); @@ -6335,7 +6358,7 @@ G__value G__exec_statement(int* mparen) if (statement[iout-1] == ' ') { --iout; } - statement[iout] = '\0'; + statement.Set(iout, 0); result = G__string2type(statement + 9); store_tagnum = G__tagnum; G__var_type = result.type; @@ -6345,8 +6368,8 @@ G__value G__exec_statement(int* mparen) G__constvar = result.obj.i; // see G__string2type int store_reftype = G__reftype; G__reftype = result.obj.reftype.reftype; - statement[iout] = '('; - statement[iout+1] = '\0'; + statement.Set(iout++, '('); + statement.Set(iout, 0); G__make_ifunctable(statement); G__tagnum = store_tagnum; G__constvar = store_constvar; @@ -6496,7 +6519,7 @@ G__value G__exec_statement(int* mparen) { char* replace = (char*) G__replacesymbol(statement); if (replace != statement) { - strcpy(statement, replace); + statement = replace; iout = strlen(statement); goto after_replacement; } @@ -6514,11 +6537,11 @@ G__value G__exec_statement(int* mparen) case ';': if (single_quote || double_quote) { - statement[iout++] = c; + statement.Set(iout++, c); } else { // -- We have reached the end of the statement. - statement[iout] = '\0'; + statement.Set(iout, 0); //fprintf(stderr, "G__exec_statement: seen ';': G__no_exec: %d mparen: %d statement: '%s'\n", G__no_exec, *mparen, statement); if ( G__breaksignal && @@ -6559,7 +6582,7 @@ G__value G__exec_statement(int* mparen) return G__block_break; } // Reset the statement buffer. - statement[0] = '\0'; + statement[0] = 0; iout = 0; // Flag that any following whitespace does not trigger any semantic action. spaceflag = 0; @@ -6575,7 +6598,7 @@ G__value G__exec_statement(int* mparen) if (!strcmp(statement, "return")) { result = G__return_value(""); if (G__no_exec_compile) { - statement[0] = '\0'; + statement[0] = 0; if (!*mparen) { return G__null; } @@ -6619,7 +6642,7 @@ G__value G__exec_statement(int* mparen) return G__block_continue; } // Reset the statement buffer. - statement[0] = '\0'; + statement[0] = 0; iout = 0; // Flag that any following whitespace does not trigger any semantic action. spaceflag = 0; @@ -6629,7 +6652,7 @@ G__value G__exec_statement(int* mparen) if (!strncmp(statement, "return\"", 7) || !strncmp(statement, "return'", 7)) { result = G__return_value(statement + 6); if (G__no_exec_compile) { - statement[0] = '\0'; + statement[0] = 0; if (!*mparen) { return G__null; } @@ -6677,8 +6700,8 @@ G__value G__exec_statement(int* mparen) !double_quote ) { // -- Handle an assignment. - statement[iout] = '='; - c = G__fgetstream_new(statement + iout + 1, ";,{}"); + statement.Set(iout, '='); + c = G__fgetstream_new(statement, iout + 1, ";,{}"); if ((c == '}') || (c == '{')) { G__syntaxerror(statement); --*mparen; @@ -6721,7 +6744,7 @@ G__value G__exec_statement(int* mparen) spaceflag = 0; } else { - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; } @@ -6733,15 +6756,15 @@ G__value G__exec_statement(int* mparen) return G__null; } // FIXME: We should test G__funcheader here as well! - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; break; case '(': //fprintf(stderr, "\nG__exec_statement: Enter left parenthesis case.\n"); - statement[iout++] = c; - statement[iout] = '\0'; + statement.Set(iout++, c); + statement.Set(iout, 0); if (single_quote || double_quote) { break; } @@ -6812,16 +6835,16 @@ G__value G__exec_statement(int* mparen) if (!strcmp(statement, "return(")) { // // following part used to be - // G__fgetstream(statement,")"); + // G__fgetstream(statement, 0, ")"); // fseek(G__ifile.fp, -1, SEEK_CUR); if (G__dispsource) { G__disp_mask = 1; } - G__fgetstream_new(statement, ";"); + G__fgetstream_new(statement, 0, ";"); result = G__return_value(statement); if (G__no_exec_compile) { - statement[0] = '\0'; + statement[0] = 0; if (!*mparen) { return G__null; } @@ -6905,22 +6928,23 @@ G__value G__exec_statement(int* mparen) // -- Handle keyword "case", even if skipping code. //fprintf(stderr, "G__exec_statement: Saw a case.\n"); // Scan the case label in. - char casepara[G__ONELINE]; + G__FastAllocString casepara(G__ONELINE); casepara[0] = '('; { int lencasepara = 1; - c = G__fgetstream(casepara+lencasepara, ":"); + c = G__fgetstream(casepara, lencasepara, ":"); if (c==')') { lencasepara = strlen(casepara); + casepara.Resize(lencasepara + 2); casepara[lencasepara] = ')'; ++lencasepara; - G__fgetstream(casepara+lencasepara, ":"); + G__fgetstream(casepara, lencasepara, ":"); } c = G__fgetc(); while (c == ':') { - strcat(casepara, "::"); + casepara += "::"; lencasepara = strlen(casepara); - G__fgetstream(casepara + lencasepara, ":"); + G__fgetstream(casepara, lencasepara, ":"); c = G__fgetc(); } } @@ -7030,10 +7054,11 @@ G__value G__exec_statement(int* mparen) ) { // Read to 'func(xxxxxx)' // ^ - c = G__fgetstream_new(statement + iout , ")"); + c = G__fgetstream_new(statement , iout, ")"); iout = strlen(statement); + statement.Resize(iout + 2); statement[iout++] = c; - statement[iout] = '\0'; + statement[iout] = 0; // Skip any following whitespace. c = G__fgetspace(); // if 'func(xxxxxx) \n nextexpr' macro @@ -7043,8 +7068,8 @@ G__value G__exec_statement(int* mparen) if (!strncmp(statement, "new ", 4) || !strncmp(statement, "new(", 4)) { // -- We have a new expression, either placement or parenthesized typename. // Grab the rest of the line. - statement[iout++] = c; - c = G__fgetstream_template(statement + iout, ";"); + statement.Set(iout++, c); + c = G__fgetstream_template(statement, iout, ";"); // Find the position of the first open parenthesis. char* pnew = strchr(statement, '('); G__ASSERT(pnew); @@ -7070,9 +7095,9 @@ G__value G__exec_statement(int* mparen) } else if (iout > 3) { // -- Nope, just a parenthesized construct, accumulate it and keep going. - c = G__fgetstream_new(statement + iout, ")"); + c = G__fgetstream_new(statement, iout, ")"); iout = strlen(statement); - statement[iout++] = c; + statement.Set(iout++, c); } } else if (!*mparen && (iout == 3) && !strcmp(statement, "if(")) { @@ -7093,22 +7118,23 @@ G__value G__exec_statement(int* mparen) // -- Handle keyword "case", even if skipping code. //fprintf(stderr, "G__exec_statement: Saw a case.\n"); // Scan the case label in. - char casepara[G__ONELINE]; + G__FastAllocString casepara(G__ONELINE); casepara[0] = '('; { int lencasepara = 1; - c = G__fgetstream(casepara+lencasepara, ":"); + c = G__fgetstream(casepara, lencasepara, ":"); if (c==')') { lencasepara = strlen(casepara); + casepara.Resize(lencasepara + 2); casepara[lencasepara] = ')'; ++lencasepara; - G__fgetstream(casepara+lencasepara, ":"); + G__fgetstream(casepara, lencasepara, ":"); } c = G__fgetc(); while (c == ':') { - strcat(casepara, "::"); + casepara += "::"; lencasepara = strlen(casepara); - G__fgetstream(casepara + lencasepara, ":"); + G__fgetstream(casepara, lencasepara, ":"); c = G__fgetc(); } } @@ -7159,12 +7185,12 @@ G__value G__exec_statement(int* mparen) return G__start; } if (single_quote || double_quote) { - statement[iout++] = c; + statement.Set(iout++, c); } else { G__constvar = G__VARIABLE; G__static_alloc = 0; - statement[iout] = '\0'; + statement.Set(iout, 0); ++*mparen; //fprintf(stderr, "G__exec_statement: seen '{': G__no_exec: %d mparen: %d: statement '%s'\n", G__no_exec, *mparen, statement); if (!G__no_exec) { @@ -7223,14 +7249,14 @@ G__value G__exec_statement(int* mparen) case '}': if (single_quote || double_quote) { - statement[iout++] = c; + statement.Set(iout++, c); } else { --*mparen; //fprintf(stderr, "G__exec_statement: seen '}': G__no_exec: %d mparen: %d\n", G__no_exec, *mparen); if (*mparen <= 0) { if (iout && (G__globalcomp == G__NOLINK)) { - statement[iout] = '\0'; + statement.Set(iout, 0); G__missingsemicolumn(statement); } if (*mparen < 0) { @@ -7268,7 +7294,7 @@ G__value G__exec_statement(int* mparen) if (G__dispsource) { G__disp_mask = 1; } - G__fgetstream_new(statement, ";"); + G__fgetstream_new(statement, 0, ";"); result = G__return_value(statement); if (G__no_exec_compile) { if (!*mparen) { @@ -7287,7 +7313,7 @@ G__value G__exec_statement(int* mparen) G__fignorestream("}"); return result; } - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. // FIXME: Why this strange value? spaceflag = 5; @@ -7301,7 +7327,7 @@ G__value G__exec_statement(int* mparen) else { double_quote = 0; if (G__prerun) { - statement[iout] = '\0'; + statement.Set(iout, 0); G__strip_quotation(conststring); } } @@ -7312,7 +7338,7 @@ G__value G__exec_statement(int* mparen) if (!double_quote) { single_quote ^= 1; } - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. // FIXME: Why this strange value? spaceflag = 5; @@ -7329,7 +7355,7 @@ G__value G__exec_statement(int* mparen) } else { commentflag = 1; - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; } @@ -7360,7 +7386,7 @@ G__value G__exec_statement(int* mparen) } } else { - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; if (!double_quote && !single_quote) { @@ -7370,7 +7396,7 @@ G__value G__exec_statement(int* mparen) break; case '&': - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; if (!double_quote && !single_quote) { @@ -7379,11 +7405,11 @@ G__value G__exec_statement(int* mparen) break; case ':': - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; if (!double_quote && !single_quote) { - statement[iout] = '\0'; + statement.Set(iout, 0); int stat = G__label_access_scope(statement, &iout, &spaceflag, *mparen); if (stat) { return G__null; @@ -7393,7 +7419,7 @@ G__value G__exec_statement(int* mparen) #ifdef G__TEMPLATECLASS case '<': - statement[iout] = '\0'; + statement.Set(iout, 0); if ((iout == 8) && !strcmp(statement, "template")) { G__declare_template(); if (!*mparen || (G__return > G__RETURN_NORMAL)) { @@ -7446,14 +7472,14 @@ G__value G__exec_statement(int* mparen) // x cout<<a; this is rare. // O Vector<Array<T> > This has to be handled here // - statement[iout++] = c; - c = G__fgetstream_template(statement + iout, ">"); + statement.Set(iout++, c); + c = G__fgetstream_template(statement, iout, ">"); G__ASSERT(c == '>'); iout = strlen(statement); if (statement[iout-1] == '>') { - statement[iout++] = ' '; + statement.Set(iout++, ' '); } - statement[iout++] = c; + statement.Set(iout++, c); spaceflag = 1; // Try to accept statements with no space between // the closing '>' and the identifier. Ugly, though. @@ -7469,7 +7495,7 @@ G__value G__exec_statement(int* mparen) } } else { - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; } @@ -7479,7 +7505,7 @@ G__value G__exec_statement(int* mparen) case EOF: { - statement[iout] = '\0'; + statement.Set(iout, 0); G__eof = 1; int mparen_line = 0; if (*mparen) { @@ -7505,14 +7531,14 @@ G__value G__exec_statement(int* mparen) strcmp(statement, "#endif") && // Not an endif, and (statement[0] != 0x1a /*FIXME: What is this? */) // Not ??? ) { - G__fprinterr(G__serr, "Report: Unrecognized string '%s' ignored", statement); + G__fprinterr(G__serr, "Report: Unrecognized string '%s' ignored", statement()); G__printlinenum(); } } return G__null; case '\\': - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; c = G__fgetc(); @@ -7525,16 +7551,16 @@ G__value G__exec_statement(int* mparen) if (discarded_space && (c != '[') && (c != ']') && iout && (statement[iout-1] != ':')) { // -- Since the character following a discarded space // is *not* a separator, we have to keep the space. - statement[iout++] = ' '; + statement.Set(iout++, ' '); } - statement[iout++] = c; + statement.Set(iout++, c); // Flag that any following whitespace should trigger a semantic action. spaceflag |= 1; #ifdef G__MULTIBYTE if (G__IsDBCSLeadByte(c)) { c = G__fgetc(); G__CheckDBCS2ndByte(c); - statement[iout++] = c; + statement.Set(iout++, c); } #endif // G__MULTIBYTE break; diff --git a/cint/cint/src/pause.cxx b/cint/cint/src/pause.cxx index be942a7ab671541c83faa531c76b7131e146c18a..14561bc7c6c396c473ee394385136eb946ee7aa8 100644 --- a/cint/cint/src/pause.cxx +++ b/cint/cint/src/pause.cxx @@ -240,35 +240,36 @@ void G__UnlockCriticalSection() int G__autoloading(char *com) { int i = 0, j = 0; - char classname[G__ONELINE]; + G__FastAllocString classname(G__ONELINE); while (com[i] && !isalpha(com[i])) ++i; - while (com[i] && (isalnum(com[i]) || '_' == com[i])) classname[j++] = com[i++]; - classname[j] = 0; + while (com[i] && (isalnum(com[i]) || '_' == com[i])) + classname.Set(j++, com[i++]); + classname.Set(j, 0); if (0 == strcmp(classname, "new")) { j = 0; while (com[i] && !isalpha(com[i])) ++i; - while (com[i] && (isalnum(com[i]) || '_' == com[i])) classname[j++] = com[i++]; - classname[j] = 0; + while (com[i] && (isalnum(com[i]) || '_' == com[i])) + classname.Set(j++, com[i++]); + classname.Set(j, 0); } if (classname[0] && -1 == G__defined_tagname(classname, 2)) { const char *dllpost = G__getmakeinfo1("DLLPOST"); - char fname[G__MAXFILENAME]; - char prompt[G__ONELINE]; - FILE *fp; - sprintf(fname, "%s%s", classname, dllpost); - fp = fopen(fname, "r"); + G__FastAllocString fname(classname); + fname += dllpost; + FILE *fp = fopen(fname, "r"); if (!fp) return 0; else fclose(fp); - sprintf(prompt, "Will you try loading %s(y/n)? ", fname); - strcpy(prompt, G__input(prompt)); + G__FastAllocString prompt(G__ONELINE); + prompt.Format("Will you try loading %s(y/n)? ", fname()); + prompt = G__input(prompt); if (tolower(prompt[0]) != 'y') return(0); G__security_recover(G__sout); /* QUESTIONABLE */ switch (G__loadfile(fname)) { case G__LOADFILE_SUCCESS: - fprintf(G__sout, "%s loaded\n", fname); + fprintf(G__sout, "%s loaded\n", fname()); return(1); default: - fprintf(G__sout, "Error: failed to load %s\n", fname); + fprintf(G__sout, "Error: failed to load %s\n", fname()); return(0); } } @@ -438,9 +439,9 @@ void G__rewind_undo_position() G__decrement_undo_index(&undoindex); if (undodictpos[undoindex].var && G__is_valid_dictpos(&undodictpos[undoindex])) { - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); G__show_undo_position(undoindex); - strcpy(buf, G__input("Are you sure? (y/n) ")); + buf = G__input("Are you sure? (y/n) "); if ('y' == tolower(buf[0])) { G__scratch_upto(&undodictpos[undoindex]); undodictpos[undoindex].var = (struct G__var_array*)NULL; @@ -565,7 +566,8 @@ void G__rewinddictionary() static int G__atevaluate(G__value buf) { G__value result; - char com[G__ONELINE], buf2[G__ONELINE]; + G__FastAllocString com(G__ONELINE); + G__FastAllocString buf2(G__ONELINE); int known = 0; int store_break = G__break; int store_step = G__step; @@ -585,7 +587,7 @@ static int G__atevaluate(G__value buf) if ('Q' == buf.type || 'a' == buf.type) return(0); #endif G__valuemonitor(buf, buf2); - sprintf(com, "G__ateval(%s)", buf2); + com.Format("G__ateval(%s)", buf2()); G__break = 0; G__step = 0; G__dispsource = 0; @@ -609,11 +611,11 @@ static int G__atevaluate(G__value buf) static void G__display_tempobj(FILE *fout) { struct G__tempobject_list *p = G__p_tempbuf; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); fprintf(fout, "current tempobj stack level = %d\n", G__templevel); do { G__valuemonitor(p->obj, buf); - fprintf(fout, "level%-3d %2d %s\n", p->level, p->cpplink, buf); + fprintf(fout, "level%-3d %2d %s\n", p->level, p->cpplink, buf()); p = p->prev; } while (p); @@ -627,7 +629,7 @@ static void G__display_tempobj(FILE *fout) ************************************************************************/ static void G__display_keyword(FILE* fout, const char* keyword, FILE* keyfile) { - char line[G__LONGLINE]; + G__FastAllocString line(G__LONGLINE); char *null_fgets; if (keyfile) { fseek(keyfile, 0L, SEEK_SET); @@ -650,7 +652,7 @@ static void G__display_keyword(FILE* fout, const char* keyword, FILE* keyfile) int G__reloadfile(char *filename, bool keep) { int i, j = 0; - char *storefname[G__MAXFILE]; + char* storefname[G__MAXFILE]; int storecpp[G__MAXFILE]; int storen = 0; int flag = 0; @@ -735,27 +737,15 @@ int G__reloadfile(char *filename, bool keep) void G__display_classkeyword(FILE *fout, const char *classnamein, const char *keyword, int base) { // -- -#ifndef G__OLDIMPLEMENTATION1823 - char buf[G__BUFLEN]; - char *classname = buf; -#else - char classname[G__ONELINE]; -#endif + G__FastAllocString classname(classnamein); int istmpnam = 0; -#ifndef G__OLDIMPLEMENTATION1823 - if (strlen(classnamein) > G__BUFLEN - 5) { - classname = (char*)malloc(strlen(classnamein) + 5); - } -#endif - G__more_pause((FILE*)NULL, 0); - strcpy(classname, classnamein); if (keyword && keyword[0]) { #ifndef G__TMPFILE - char tname[L_tmpnam+10]; + G__FastAllocString tname(L_tmpnam+10); #else - char tname[G__MAXFILENAME]; + G__FastAllocString tname(G__MAXFILENAME); #endif FILE *G__temp; do { @@ -784,9 +774,6 @@ void G__display_classkeyword(FILE *fout, const char *classnamein, const char *ke else { G__display_class(fout, classname, base, 0); } -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != classname) free((void*)classname); -#endif // -- } @@ -884,16 +871,16 @@ int G__pause() int more = 0; void(*oldhandler)(int) = 0; char* p = 0; - char cintname[G__ONELINE]; - char filename[G__ONELINE]; - char command[G__LONGLINE]; - char prompt[G__ONELINE]; + G__FastAllocString cintname(G__ONELINE); + G__FastAllocString filename(G__ONELINE); + G__FastAllocString command(G__LONGLINE); + G__FastAllocString prompt(G__ONELINE); p = strrchr(G__nam, G__psep[0]); if (p && *(p + 1)) { - strcpy(cintname, p + 1); + cintname = p + 1; } else { - strcpy(cintname, G__nam); + cintname = G__nam; } prompt[0] = '\0'; // Do not pause while skipping code. @@ -927,11 +914,11 @@ int G__pause() while (1) { // Set prompt string. if (prompt[0]) { - strcpy(command, prompt); + command = prompt; } else { if (!view.file.name[0]) { - sprintf(command, "%s> ", cintname); + command.Format("%s> ", cintname()); } else { p = strrchr(view.file.name, G__psep[0]); @@ -941,7 +928,7 @@ int G__pause() else { strcpy(filename, view.file.name); } - sprintf(command, "FILE:%s LINE:%d %s> ", G__stripfilename(filename), view.file.line_number, cintname); + command.Format("FILE:%s LINE:%d %s> ", G__stripfilename(filename), view.file.line_number, cintname()); } } if (!more) { @@ -984,7 +971,7 @@ int G__pause() // -- } char* tmp = G__input(command); - strcpy(command, tmp); + command = tmp; if (!more) { G__in_pause = 0; G__RESET_TEMPENV; @@ -1015,16 +1002,16 @@ int G__pause() ******************************************************************/ int G__update_stdio() { - char command[G__LONGLINE]; + G__FastAllocString command(G__LONGLINE); G__intp_sout = G__sout; G__intp_serr = G__serr; G__intp_sin = G__sin; - sprintf(command, "stderr=%ld", (long)G__intp_serr); + command.Format("stderr=%ld", (long)G__intp_serr); G__getexpr(command); - sprintf(command, "stdout=%ld", (long)G__intp_sout); + command.Format("stdout=%ld", (long)G__intp_sout); G__getexpr(command); - sprintf(command, "stdin=%ld", (long)G__intp_sin); + command.Format("stdin=%ld", (long)G__intp_sin); G__getexpr(command); return(0); } @@ -1052,7 +1039,7 @@ static void G__redirectoutput(char *com char *blacket; /* int issemicolumn; */ const char *openmode; - char filename[G__MAXFILENAME]; + G__FastAllocString filename(G__MAXFILENAME); int i = 0; int j = 1; int mode = 0; /* 0:stdout, 1:stderr, 2:stdout+stderr */ @@ -1096,12 +1083,12 @@ static void G__redirectoutput(char *com * ^ -------- */ while ((*(redirect + j))) { if (!isspace(*(redirect + j))) { - filename[i++] = *(redirect + j); + filename.Set(i++, *(redirect + j)); } else if (i) break; ++j; } - filename[i] = '\0'; + filename.Set(i, 0); strcpy(pipefile, filename); /* get filename to redirect @@ -1166,7 +1153,7 @@ static void G__redirectoutput(char *com G__sout = *psout; G__unredirectoutput(psout, &donttouch, &donttouch, "", ""); G__fprinterr(G__serr, "Error: cannot open pipe output file %s!\n", - filename); + filename()); } else G__redirect_on(); @@ -1183,7 +1170,7 @@ static void G__redirectoutput(char *com G__serr = *pserr; G__unredirectoutput(&donttouch, pserr, &donttouch, "", ""); G__fprinterr(G__serr, "Error: cannot open error pipe output file %s!\n", - filename); + filename()); } /*DEBUG G__dumpfile = G__serr; */ break; @@ -1234,12 +1221,12 @@ static void G__redirectoutput(char *com j = 1; while ((*(redirectin + j))) { if (!isspace(*(redirectin + j))) { - filename[i++] = *(redirectin + j); + filename.Set(i++, *(redirectin + j)); } else if (i) break; ++j; } - filename[i] = '\0'; + filename.Set(i, 0); *redirectin = '\0'; --redirectin; @@ -1254,7 +1241,7 @@ static void G__redirectoutput(char *com G__sin = *psin; G__unredirectoutput(&donttouch, &donttouch, psin, "", ""); G__fprinterr(G__serr, "Error: cannot open input pipe from file %s!\n", - filename); + filename()); } } } @@ -1516,9 +1503,9 @@ static void G__remove_input_tmpfile(G__input_file& ftemp) int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt) { FILE *tempfp; /* used for input dump file */ - char command[G__LONGLINE]; - char syscom[G__LONGLINE]; - char editor[64]; + G__FastAllocString command(G__LONGLINE); + G__FastAllocString syscom(G__LONGLINE); + G__FastAllocString editor(64); int temp, temp1 = 0, temp2; int index = -1; int ignore = G__PAUSE_NORMAL; @@ -1530,10 +1517,10 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt /* pass to parent otherwise not re-entrant */ #ifdef G__TMPFILE static char tname[G__MAXFILENAME]; - char sname[G__MAXFILENAME]; + G__FastAllocString sname(G__MAXFILENAME); #else static char tname[L_tmpnam+10]; - char sname[L_tmpnam+10]; + G__FastAllocString sname(L_tmpnam+10); #endif struct G__input_file ftemp; ftemp.fp = 0; @@ -1545,12 +1532,12 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt FILE *G__temp; char *evalbase; int base = 0 /* ,digit */ , num; - char evalresult[G__ONELINE]; + G__FastAllocString evalresult(G__ONELINE); FILE* store_stderr = NULL; FILE* store_stdout = NULL; FILE* store_stdin = NULL; - char keyword[G__ONELINE]; - char pipefile[G__MAXFILENAME]; + G__FastAllocString keyword(G__ONELINE); + G__FastAllocString pipefile(G__MAXFILENAME); int dmy = 0; int noprintflag = 0; int istmpnam = 0; @@ -1577,7 +1564,7 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt temp = 0; while (isspace(line[temp])) ++temp; if (*more == 0) { - strcpy(command, line + temp); + command = line + temp; com = strchr(command, '\n'); if (com) *com = '\0'; else { @@ -1586,11 +1573,11 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt } if (G__INPUTROOTMODE&G__rootmode) { if (command[0] == '.') { - strcpy(syscom, command + 1); - strcpy(command, syscom); + syscom = command + 1; + command = syscom; } else if (strcmp(command, "?") == 0) { - strcpy(command, "help"); + command = "help"; } else if ('\0' != command[0] && command[0] != '{') { #ifndef G__OLDIMPLEMENTATION1774 @@ -1618,7 +1605,7 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt temp = strlen(command) - 1; while (isspace(command[temp])) --temp; if (command[temp] == ';') { - sprintf(syscom, "{%s}", command); + syscom.Format("{%s}", command()); #ifndef G__OLDIMPLEMENTATION1774 if (G__INPUTCXXMODE != G__rootmode) noprintflag = 1; #else @@ -1626,14 +1613,14 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt #endif } else { - sprintf(syscom, "{%s;}", command); + syscom.Format("{%s;}", command()); } - strcpy(command, syscom); + command = syscom; } } } else { - sprintf(command, "{%s", line + temp); + command.Format("{%s", line + temp); com = strchr(command, '\n'); if (com) *com = '\0'; else { @@ -1795,8 +1782,7 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt else if (strncmp("rm", com, 2) == 0 || strncmp("del", com, 4) == 0 || strncmp("rmdir", com, 5) == 0) { - char localbuf[80]; - strcpy(localbuf, G__input("Are you sure(y/n)? ")); + G__FastAllocString localbuf(G__input("Are you sure(y/n)? ")); if (tolower(localbuf[0]) == 'y') system(com); else fprintf(G__sout, "aborted\n"); } @@ -2226,7 +2212,7 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt if (!s) s = strrchr(string + temp, '\\'); if (!s) s = string + temp; else s++; - strcpy(syscom, s); + syscom = s; s = syscom; while (s && *s) { if ('-' == (*s)) *s = '_'; @@ -2234,9 +2220,9 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt } string = strchr(com + 1, '('); if (string) - strcat(syscom, string); + syscom += string; else - strcat(syscom, "()"); + syscom += "()"; buf = G__calc_internal(syscom); if (rslt) *rslt = buf; G__in_pause = 1; @@ -2244,19 +2230,19 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt G__in_pause = 0; #ifndef G__OLDIMPLEMENTATION1259 if (buf.isconst&(G__CONSTVAR | G__CONSTFUNC)) { - char tmp[G__ONELINE]; - sprintf(tmp, "(const %s", syscom + 1); - strcpy(syscom, tmp); + G__FastAllocString tmp(G__ONELINE); + tmp.Format("(const %s", syscom + 1); + syscom = tmp; } if (buf.isconst&G__PCONSTVAR) { - char tmp2[G__ONELINE]; + G__FastAllocString tmp2(G__ONELINE); char *ptmp = strchr(syscom, ')'); - strcpy(tmp2, ptmp); + tmp2 = ptmp; strcpy(ptmp, "const"); - strcat(syscom, tmp2); + syscom += tmp2; } #endif - if (buf.type && 0 == G__atevaluate(buf)) fprintf(G__sout, "%s\n", syscom); + if (buf.type && 0 == G__atevaluate(buf)) fprintf(G__sout, "%s\n", syscom()); #ifdef G__SECURITY *err |= G__security_recover(G__serr); #endif @@ -2586,10 +2572,9 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt /******************************************************* * Execute shell command *******************************************************/ - char *combuf = (char*)malloc(strlen(string) + 30); - sprintf(combuf, "sh -I -c %s", string); + G__FastAllocString combuf(strlen(string) + 30); + combuf.Format("sh -I -c %s", string); system(combuf); - free((void*)combuf); } else if (strncmp("!", com, 1) == 0) { /******************************************************* @@ -2776,8 +2761,8 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt } } else if (strncmp("f", com, 1) == 0) { - strcpy(syscom, string); - strcpy(command, syscom); + syscom = string; + command = syscom; /******************************************************* * Set view file *******************************************************/ @@ -2797,7 +2782,7 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt } else if (strncmp("+", com, 1) == 0 || strncmp("-", com, 1) == 0) { temp = atoi(command); - sprintf(command, "%d", view.file.line_number + temp); + command.Format("%d", view.file.line_number + temp); goto vcommand; } else if (strncmp("proto", com, 3) == 0) { @@ -2805,8 +2790,8 @@ int G__process_cmd(char* line, char* prompt, int* more, int* err, G__value* rslt G__display_proto(G__sout, string); } else if (strncmp("view", com, 1) == 0) { - strcpy(syscom, string); - strcpy(command, syscom); + syscom = string; + command = syscom; vcommand: /******************************************************* * Display source code @@ -2939,7 +2924,7 @@ vcommand: } else if (strncmp(command, "qqq", 3) == 0 || strncmp(command, "QQQ", 3) == 0) { fprintf(G__sout, "*** Process will be killed ***\n"); - strcpy(command, G__input("Are you sure(y/Y/n)? ")); + command = G__input("Are you sure(y/Y/n)? "); if (command[0] == 'Y') { G__fprinterr(G__serr, " Bye... (try 'qqqqq' if still running)\n"); exit(EXIT_FAILURE); @@ -3054,14 +3039,14 @@ vcommand: if (com[0] == 'E') { if (command[temp] == '\0') { if ('\0' == G__tempc[0]) G__tmpnam(G__tempc); /* E command, rare case */ - sprintf(syscom, "%s %s", editor, G__tempc); + syscom.Format("%s %s", editor(), G__tempc); system(syscom); - sprintf(syscom, G__tempc); + syscom = G__tempc; } else { - sprintf(syscom, "%s %s", editor, command + temp); + syscom.Format("%s %s", editor(), command + temp); system(syscom); - sprintf(syscom, command + temp); + syscom = command + temp; } } else { @@ -3074,7 +3059,7 @@ vcommand: G__UnlockCriticalSection(); return(ignore); } - sprintf(syscom, command + temp); + syscom = command + temp; } /******************************************************* * Execute temp file @@ -3098,19 +3083,18 @@ vcommand: G__in_pause = 0; #ifndef G__OLDIMPLEMENTATION1259 if (buf.isconst&(G__CONSTVAR | G__CONSTFUNC)) { - char tmp[G__ONELINE]; - sprintf(tmp, "(const %s", syscom + 1); - strcpy(syscom, tmp); + G__FastAllocString tmp(G__ONELINE); + tmp.Format("(const %s", syscom + 1); + syscom = tmp; } if (buf.isconst&G__PCONSTVAR) { - char tmp2[G__ONELINE]; char *ptmp = strchr(syscom, ')'); - strcpy(tmp2, ptmp); + G__FastAllocString tmp2(ptmp); strcpy(ptmp, "const"); - strcat(syscom, tmp2); + syscom += tmp2; } #endif - if (buf.type && 0 == G__atevaluate(buf)) fprintf(G__sout, "%s\n", syscom); + if (buf.type && 0 == G__atevaluate(buf)) fprintf(G__sout, "%s\n", syscom()); #endif G__RESET_TEMPENV; } @@ -3265,16 +3249,15 @@ multi_line_command: G__in_pause = 0; #ifndef G__OLDIMPLEMENTATION1259 if (buf.isconst&(G__CONSTVAR | G__CONSTFUNC)) { - char tmp[G__LONGLINE]; - sprintf(tmp, "(const %s", syscom + 1); - strcpy(syscom, tmp); + G__FastAllocString tmp(G__LONGLINE); + tmp.Format("(const %s", syscom + 1); + syscom = tmp; } if (buf.isconst&G__PCONSTVAR) { - char tmp2[G__LONGLINE]; char *ptmp = strchr(syscom, ')'); - strcpy(tmp2, ptmp); + G__FastAllocString tmp2(ptmp); strcpy(ptmp, "const"); - strcat(syscom, tmp2); + syscom += tmp2; } #endif G__RESET_TEMPENV; @@ -3285,7 +3268,7 @@ multi_line_command: } if (buf.type && 0 == G__atevaluate(buf) && !noprintflag - ) fprintf(G__sout, "%s\n", syscom); + ) fprintf(G__sout, "%s\n", syscom()); noprintflag = 0; G__command_eval = 0 ; G__free_tempobject(); @@ -3315,8 +3298,8 @@ multi_line_command: * Evaluate statement *******************************************************/ G__more_pause((FILE*)NULL, 1); - strcpy(syscom, string); - strcpy(command, syscom); + syscom = string; + command = syscom; if (strlen(command) > 0) { G__redirectoutput(command, &store_stdout, &store_stderr, &store_stdin, 1, keyword, pipefile); #ifdef G__ASM @@ -3402,26 +3385,26 @@ multi_line_command: G__valuemonitor(buf, syscom); } else if (base == 100) { - sprintf(syscom, "{d=%g i=%ld,reftype=%d} type=%c,tag=%d,type=%d,ref=%lx,isconst=%d" + syscom.Format("{d=%g i=%ld,reftype=%d} type=%c,tag=%d,type=%d,ref=%lx,isconst=%d" , buf.obj.d, buf.obj.i, buf.obj.reftype.reftype , buf.type, buf.tagnum, buf.typenum, buf.ref, buf.isconst); } else { G__getbase(buf.obj.i , base , 0, evalresult); - sprintf(syscom, "0%c%s" , evalbase[temp1] , evalresult); + syscom.Format("0%c%s" , evalbase[temp1] , evalresult()); } G__in_pause = 0; - fprintf(G__sout, "%s\n", syscom); + fprintf(G__sout, "%s\n", syscom()); } else { for (temp = 0;temp < num;temp++) { if (temp % 2 == 0) { - sprintf(syscom, "&%s+%d" , command + 1 , temp); + syscom.Format("&%s+%d" , command + 1 , temp); buf = G__calc_internal(syscom); if (rslt) *rslt = buf; fprintf(G__sout, "\n0x%lx: " , buf.obj.i); } - sprintf(syscom, "*(&%s+%d)" , command + 1 , temp); + syscom.Format("*(&%s+%d)" , command + 1 , temp); buf = G__calc_internal(syscom); if (rslt) *rslt = buf; G__in_pause = 1; @@ -3430,10 +3413,10 @@ multi_line_command: } else { G__getbase(buf.obj.i, base , 0, evalresult); - sprintf(syscom, "0%c%s" , evalbase[temp1] , evalresult); + syscom.Format("0%c%s" , evalbase[temp1] , evalresult()); } G__in_pause = 0; - fprintf(G__sout, "%30s ", syscom); + fprintf(G__sout, "%30s ", syscom()); } fprintf(G__sout, "\n"); } @@ -3450,16 +3433,15 @@ multi_line_command: G__in_pause = 0; #ifndef G__OLDIMPLEMENTATION1259 if (buf.isconst&(G__CONSTVAR | G__CONSTFUNC)) { - char tmp[G__ONELINE]; - sprintf(tmp, "(const %s", syscom + 1); - strcpy(syscom, tmp); + G__FastAllocString tmp(G__ONELINE); + tmp.Format("(const %s", syscom + 1); + syscom = tmp; } if (buf.isconst&G__PCONSTVAR) { - char tmp2[G__ONELINE]; char *ptmp = strchr(syscom, ')'); - strcpy(tmp2, ptmp); + G__FastAllocString tmp2(ptmp); strcpy(ptmp, "const"); - strcat(syscom, tmp2); + syscom += tmp2; } #endif } @@ -3470,7 +3452,7 @@ multi_line_command: #endif G__var_type = store_var_type; if (buf.type && 0 == G__atevaluate(buf)) { - fprintf(G__sout, "%s\n", syscom); + fprintf(G__sout, "%s\n", syscom()); if ('u' == buf.type && buf.obj.i) { G__objectmonitor(G__sout, buf.obj.i, buf.tagnum, ""); } diff --git a/cint/cint/src/pcode.cxx b/cint/cint/src/pcode.cxx index cee029b8e59c6f6d9b413cdeb7a69e213e4a2a7f..4e905f56b1539a6aaf3b307bb829c173fa653d60 100644 --- a/cint/cint/src/pcode.cxx +++ b/cint/cint/src/pcode.cxx @@ -2675,7 +2675,7 @@ void G__get__tm__(char *buf) char* G__get__date__() { int i=0,j=0; - char buf[80]; + G__FastAllocString buf(80); static char result[80]; G__get__tm__(buf); while(buf[i] && !isspace(buf[i])) ++i; /* skip 'Sun' */ @@ -2696,7 +2696,7 @@ char* G__get__date__() char* G__get__time__() { int i=0,j=0; - char buf[80]; + G__FastAllocString buf(80); static char result[80]; G__get__tm__(buf); while(buf[i] && !isspace(buf[i])) ++i; /* skip 'Sun' */ @@ -7431,7 +7431,7 @@ int G__dasm(FILE *fout,int isthrow) else { fpos_t store_pos; struct G__input_file store_ifile = G__ifile; - char statement[G__LONGLINE]; + G__FastAllocString statement(G__LONGLINE); #if defined(G__NONSCALARFPOS2) fpos_t pos; pos.__pos = (off_t)G__asm_inst[pc+3]; diff --git a/cint/cint/src/pragma.cxx b/cint/cint/src/pragma.cxx index ce27c564e6eaa3053e99e21f7745fb2d3f4e694d..f880fe6bdb820708688d80a64ec278a1a86b4091 100644 --- a/cint/cint/src/pragma.cxx +++ b/cint/cint/src/pragma.cxx @@ -82,8 +82,8 @@ void G__freepragma(G__AppPragma *paddpragma) int G__read_setmode(int *pmode) { int c; - char command[G__ONELINE]; - c=G__fgetstream(command,";\n\r"); + G__FastAllocString command(G__ONELINE); + c=G__fgetstream(command, 0, ";\n\r"); if(strcmp(command,"on")==0||'\0'==command[0]) *pmode=1; else if(strcmp(command,"ON")==0) *pmode=1; else if(strcmp(command,"off")==0) *pmode=0; @@ -105,10 +105,10 @@ static int G__addpreprocessfile() { int c; struct G__Preprocessfilekey *pkey; - char keystring[G__ONELINE]; + G__FastAllocString keystring(G__ONELINE); /* Get the key string for preprocessed header file group */ - c=G__fgetstream(keystring,";\n\r"); + c=G__fgetstream(keystring, 0, ";\n\r"); /* Get to the end of the preprocessed file key list */ pkey = &G__preprocessfilekey; @@ -133,7 +133,7 @@ extern int G__rootCcomment; /* used and defined in sizeof.c */ static void G__do_not_include() { int c; - char fnameorig[G__ONELINE]; + G__FastAllocString fnameorig(G__ONELINE); char *fname; int len; int hash; @@ -142,7 +142,7 @@ static void G__do_not_include() /* if(!G__IsInMacro()) return; */ /* Get the key string for preprocessed header file group */ - c=G__fgetstream(fnameorig,";\n\r"); + c=G__fgetstream(fnameorig, 0, ";\n\r"); switch(fnameorig[0]) { case '\'': @@ -197,12 +197,12 @@ void G__force_bytecode_compilation() **************************************************************************/ int G__pragma() { - char command[G__ONELINE]; + G__FastAllocString command(G__ONELINE); int c; int store_no_exec_compile; /* static int store_asm_loopcompile=4; */ - c = G__fgetname(command,";\n\r"); + c = G__fgetname(command, 0, ";\n\r"); if(strcmp(command,"include")==0) { @@ -220,14 +220,14 @@ int G__pragma() c='\n'; } else if(strcmp(command,"permanent_link")==0) { - c=G__fgetstream(command,";\n\r"); + c=G__fgetstream(command, 0, ";\n\r"); G__ispragmainclude = 1; G__loadsystemfile(command); G__ispragmainclude = 0; c='\n'; } else if(strcmp(command,"includepath")==0) { - c=G__fgetstream(command,";\n\r"); + c=G__fgetstream(command, 0, ";\n\r"); G__add_ipath(command); } else if(strcmp(command,"preprocessor")==0) { @@ -283,13 +283,13 @@ int G__pragma() } else if(strcmp(command,"mask_newdelete")==0) { - c = G__fgetstream(command,";\n\r"); + c = G__fgetstream(command, 0, ";\n\r"); G__is_operator_newdelete |= G__int(G__calc_internal(command)); } #ifdef G__SECURITY else if(strcmp(command,"security")==0) { - c = G__fgetstream(command,";\n\r"); + c = G__fgetstream(command, 0, ";\n\r"); G__security = G__getsecuritycode(command); /* if('\n'!=c&&'\r'!=c) G__fignoreline(); */ } @@ -297,7 +297,7 @@ int G__pragma() #ifdef G__ASM_WHOLEFUNC else if(strcmp(command,"optimize")==0) { - c = G__fgetstream(command,";\n\r"); + c = G__fgetstream(command, 0, ";\n\r"); G__asm_loopcompile = G__int(G__calc_internal(command)); G__asm_loopcompile_mode = G__asm_loopcompile; /* if('\n'!=c&&'\r'!=c) G__fignoreline(); */ @@ -391,13 +391,13 @@ int G__pragma() else if(strcmp(command,"message")==0) { c=G__fgetline(command); - G__fprinterr(G__serr,"%s\n",command); + G__fprinterr(G__serr,"%s\n",command()); } else if(strcmp(command,"eval")==0) { store_no_exec_compile = G__no_exec_compile; G__no_exec_compile=0; - c=G__fgetstream(command,";"); + c=G__fgetstream(command, 0, ";"); fprintf(G__sout," evaluate (%d) ",store_no_exec_compile); G__calc_internal(command); G__no_exec_compile=store_no_exec_compile; @@ -445,7 +445,7 @@ int G__pragma() else { int c2; - char args[4096]; + G__FastAllocString args(4096*4); args[0]='\0'; if('\n'!=c&&'\r'!=c) c = G__fgetline(args); /* Back up before a line terminator, to get errors reported correctly. */ @@ -556,8 +556,7 @@ int G__security_handle(G__UINT32 category) **************************************************************************/ int G__setautoccnames() { - char backup[G__MAXFILE]; - char fname[G__MAXFILE]; + G__FastAllocString backup(G__MAXFILE); char *p; FILE *fpto; FILE *fpfrom; @@ -570,25 +569,25 @@ int G__setautoccnames() if(!p) p = strrchr(G__srcfile[G__ifile.filenum].filename,':'); if(!p) p = G__srcfile[G__ifile.filenum].filename; else ++p; - strcpy(fname,p); + G__FastAllocString fname(p); p = strrchr(fname,'.'); if(p) *p = '\0'; /* assign autocc filenames */ if(G__iscpp) - sprintf(G__autocc_c,"G__AC%s%s",fname,G__getmakeinfo1("CPPSRCPOST")); + sprintf(G__autocc_c,"G__AC%s%s",fname(),G__getmakeinfo1("CPPSRCPOST")); else - sprintf(G__autocc_c,"G__AC%s%s",fname,G__getmakeinfo1("CSRCPOST")); - sprintf(G__autocc_h,"G__AC%s",fname); + sprintf(G__autocc_c,"G__AC%s%s",fname(),G__getmakeinfo1("CSRCPOST")); + sprintf(G__autocc_h,"G__AC%s",fname()); #ifdef G__WIN32 - sprintf(G__autocc_sl,"G__AC%s%s",fname,G__getmakeinfo1("DLLPOST")); + sprintf(G__autocc_sl,"G__AC%s%s",fname(),G__getmakeinfo1("DLLPOST")); #else - sprintf(G__autocc_sl,"./G__AC%s%s",fname,G__getmakeinfo1("DLLPOST")); + sprintf(G__autocc_sl,"./G__AC%s%s",fname(),G__getmakeinfo1("DLLPOST")); #endif - sprintf(G__autocc_mak,"G__AC%s.mak",fname); + sprintf(G__autocc_mak,"G__AC%s.mak",fname()); /* copy autocc file backup */ - sprintf(backup,"G__%s",G__autocc_c); + backup.Format("G__%s",G__autocc_c); fpfrom=fopen(G__autocc_c,"r"); if(fpfrom) { fpto=fopen(backup,"w"); @@ -623,8 +622,9 @@ int G__setautoccnames() **************************************************************************/ int G__autocc() { - char temp[G__LONGLINE]; - char ansi[10],cpp[10]; + G__FastAllocString temp(G__LONGLINE); + char ansi[10]; + char cpp[10]; fclose(G__fpautocc); G__fpautocc=(FILE*)NULL; @@ -638,44 +638,44 @@ int G__autocc() else cpp[0]='\0'; if(G__iscpp) { - sprintf(temp ,"makecint -mk %s %s %s %s %s -dl %s -H %s" + temp.Format("makecint -mk %s %s %s %s %s -dl %s -H %s" ,G__autocc_mak ,ansi,cpp,G__allincludepath,G__macros,G__autocc_sl,G__autocc_c); } else { - sprintf(temp ,"makecint -mk %s %s %s %s %s -dl %s -h %s" + temp.Format("makecint -mk %s %s %s %s %s -dl %s -h %s" ,G__autocc_mak ,ansi,cpp,G__allincludepath,G__macros,G__autocc_sl,G__autocc_c); } - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); #if defined(G__SYMANTEC) && !defined(G__HAVE_CONFIG) - sprintf(temp,"smake -f %s",G__autocc_mak); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + temp.Format("smake -f %s",G__autocc_mak); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); #elif defined(G__BORLAND) && !defined(G__HAVE_CONFIG) - sprintf(temp,"make.exe -f %s",G__autocc_mak); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + temp.Format("make.exe -f %s",G__autocc_mak); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); #elif defined(G__VISUAL) && !defined(G__HAVE_CONFIG) - sprintf(temp,"nmake /f %s CFG=\"%s - Win32 Release\"" + temp.Format("nmake /f %s CFG=\"%s - Win32 Release\"" ,G__autocc_mak,G__autocc_h); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); FILE *fp = fopen(G__autocc_sl,"r"); if(fp) { fclose(fp); - sprintf(temp,"del %s",G__autocc_sl); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + temp.Format("del %s",G__autocc_sl); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); } - sprintf(temp,"move Release\\%s %s",G__autocc_sl,G__autocc_sl); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + temp.Format("move Release\\%s %s",G__autocc_sl,G__autocc_sl); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); #else - sprintf(temp,"make -f %s",G__autocc_mak); - if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp); + temp.Format("make -f %s",G__autocc_mak); + if(G__asm_dbg) G__fprinterr(G__serr,"%s\n",temp()); system(temp); #endif @@ -691,15 +691,15 @@ int G__autocc() **************************************************************************/ int G__appendautocc(FILE *fp) { - char G__oneline[G__LONGLINE*2]; - char G__argbuf[G__LONGLINE*2]; - char *arg[G__ONELINE]; + G__FastAllocString G__oneline(G__LONGLINE*2); + G__FastAllocString G__argbuf(G__LONGLINE*2); + char* arg[G__ONELINE]; int argn; FILE *G__fp; G__fp=G__ifile.fp; - while(G__readline(G__fp,G__oneline,G__argbuf,&argn,arg)!=0) { + while(G__readline_FastAlloc(G__fp,G__oneline,G__argbuf,&argn,arg)!=0) { ++G__ifile.line_number; if((argn>=3 && strcmp(arg[1],"#")==0 && strcmp(arg[2],"pragma")==0 && strcmp(arg[3],"endcompile")==0) || @@ -737,10 +737,10 @@ int G__appendautocc(FILE *fp) **************************************************************************/ int G__isautoccupdate() { - char backup[G__MAXFILE]; + G__FastAllocString backup(G__MAXFILE); int result; FILE *fp; - sprintf(backup,"G__%s",G__autocc_c); + backup.Format("G__%s",G__autocc_c); result=G__difffile(G__autocc_c,backup); remove(backup); if(0==result) { diff --git a/cint/cint/src/quote.cxx b/cint/cint/src/quote.cxx index 628789570f3cee2e8dcfe6804c286b1fa03186bc..74a02857a24aaf9a5d0210b83b6061b39c35a9da 100644 --- a/cint/cint/src/quote.cxx +++ b/cint/cint/src/quote.cxx @@ -399,45 +399,48 @@ G__value G__strip_singlequotation(char *string) return(result); } +} // extern "C" + /****************************************************************** * char *G__add_quotation(string) * * Called by * ******************************************************************/ -char *G__add_quotation(char *string,char *temp) +char *G__add_quotation(const char* string,G__FastAllocString& temp) { int c; short i=0,l=0; - temp[i++]='"'; + temp.Set(i++, '"'); while((c=string[l++])!='\0') { switch(c) { case '\n': - temp[i++]='\\'; - temp[i++]='n'; - break; + temp.Set(i++, '\\'); + temp.Set(i++, 'n'); + break; case '\r': - temp[i++]='\\'; - temp[i++]='r'; - break; + temp.Set(i++, '\\'); + temp.Set(i++, 'r'); + break; case '\\': - temp[i++]='\\'; - temp[i++]='\\'; - break; + temp.Set(i++, '\\'); + temp.Set(i++, '\\'); + break; case '"': - temp[i++]='\\'; - temp[i++]='"'; - break; + temp.Set(i++, '\\'); + temp.Set(i++, '"'); + break; default: - temp[i++]=c; - break; + temp.Set(i++, c); + break; } } - temp[i++]='"'; - temp[i]='\0'; - return(temp); + temp.Set(i++, '"'); + temp.Set(i, 0); + return temp; } +extern "C" { /****************************************************************** * char *G__tocharexpr(result7) @@ -450,15 +453,15 @@ char *G__tocharexpr(char *result7) return(NULL); } - +} // extern "C" /**************************************************************** * char *G__string() * ****************************************************************/ -char *G__string(G__value buf,char *temp) +char *G__string(G__value buf, G__FastAllocString& temp) { - char temp1[G__MAXNAME]; + G__FastAllocString temp1(G__MAXNAME); switch(buf.type) { case '\0': temp[0]='\0'; /* sprintf(temp,""); */ @@ -473,19 +476,21 @@ char *G__string(G__value buf,char *temp) break; case 'd': case 'f': - sprintf(temp,"%.17e",buf.obj.d); + temp.Format("%.17e",buf.obj.d); break; case 'w': G__logicstring(buf,1,temp1); - sprintf(temp,"0b%s",temp1); + temp.Format("0b%s",temp1()); break; default: - sprintf(temp,"%ld",buf.obj.i); + temp.Format("%ld",buf.obj.i); break; } return(temp); } +extern "C" { + /**************************************************************** * char *G__quotedstring() * @@ -517,7 +522,7 @@ char *G__quotedstring(char *buf,char *result) ****************************************************************/ char *G__logicstring(G__value buf,int dig,char *result) { - char tristate[G__MAXNAME]; + G__FastAllocString tristate(G__MAXNAME); unsigned int hilo,hiz,i,ii,flag; switch(buf.type) { case 'd': /* double */ diff --git a/cint/cint/src/rflx_gensrc.cxx b/cint/cint/src/rflx_gensrc.cxx index 1de2864912c996696bcfa78c35db9d91cdbeb74a..8fb4672843bae679d3788ffcfc9e703981967d59 100644 --- a/cint/cint/src/rflx_gensrc.cxx +++ b/cint/cint/src/rflx_gensrc.cxx @@ -570,7 +570,8 @@ void rflx_gensrc::gen_datamemberdefs(G__ClassInfo & ci) m_cd << "OffsetOf" << offnum << "(" << fclname << ", " << dm.Name() << "), "; m_cd << dm_modifiers << ")"; // comment - char buf[16*1024]; buf[0] = 0; + G__FastAllocString buf(16*1024); + buf[0] = 0; G__var_array* va = (G__var_array*)dm.Handle(); G__getcomment(buf,&va->comment[dm.Index()],va->tagnum); if (buf[0]) { diff --git a/cint/cint/src/scrupto.cxx b/cint/cint/src/scrupto.cxx index f1dced4c8d1984e2eb85a29c4019d6437caf35e5..59beca7eae1e464db941ee28c94fe75c03ae6a48 100644 --- a/cint/cint/src/scrupto.cxx +++ b/cint/cint/src/scrupto.cxx @@ -422,8 +422,8 @@ static int G__free_struct_upto(int tagnum) // -- Call the destructor and free the variable value storage. if ((var->type[i] == 'u') && var->p[i]) { // -- Static class object member try destructor. - char com[G__ONELINE]; - sprintf(com, "~%s()", G__struct.name[var->p_tagtable[i]]); + G__FastAllocString com(G__ONELINE); + com.Format("~%s()", G__struct.name[var->p_tagtable[i]]); long store_struct_offset = G__store_struct_offset; int store_tagnum = G__tagnum; G__store_struct_offset = var->p[i]; @@ -604,20 +604,16 @@ static int G__destroy_upto_vararray(G__var_array* var, int global, int ig15) !G__prerun // We are executing. ) { // -- Variable is of class type, we must call a destructor. - char vv[G__BUFLEN]; - char* temp = vv; + G__FastAllocString temp(G__BUFLEN); long store_struct_offset = G__store_struct_offset; G__store_struct_offset = var->p[idx]; int store_tagnum = G__tagnum; G__tagnum = var->p_tagtable[idx]; int store_return = G__return; G__return = G__RETURN_NON; - if (strlen(G__struct.name[G__tagnum]) > (G__BUFLEN - 5)) { - temp = (char*) malloc(strlen(G__struct.name[G__tagnum]) + 5); - } - sprintf(temp, "~%s()", G__struct.name[G__tagnum]); + temp.Format("~%s()", G__struct.name[G__tagnum]); if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for %s ary%d:link%d", G__store_struct_offset, temp, var->varnamebuf[idx], var->varlabel[idx][1] /* number of elements */, G__struct.iscpplink[G__tagnum]); + G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for %s ary%d:link%d", G__store_struct_offset, temp(), var->varnamebuf[idx], var->varlabel[idx][1] /* number of elements */, G__struct.iscpplink[G__tagnum]); } int store_prerun = G__prerun; G__prerun = 0; @@ -669,7 +665,7 @@ static int G__destroy_upto_vararray(G__var_array* var, int global, int ig15) for (int i = num_of_elements - 1; i >= 0; --i) { G__store_struct_offset = var->p[idx] + (i * size); if (G__dispsource) { - G__fprinterr(G__serr, "\n0x%lx.%s", G__store_struct_offset, temp); + G__fprinterr(G__serr, "\n0x%lx.%s", G__store_struct_offset, temp()); } int known = 0; G__getfunction(temp, &known, G__TRYDESTRUCTOR); @@ -679,10 +675,6 @@ static int G__destroy_upto_vararray(G__var_array* var, int global, int ig15) } } } - if (vv != temp) { - free(temp); - temp = 0; - } G__prerun = store_prerun; G__store_struct_offset = store_struct_offset; G__tagnum = store_tagnum; diff --git a/cint/cint/src/shl.cxx b/cint/cint/src/shl.cxx index 72cf75aac48c880efb425550f94163e665150774..3d6fac44ee3ebbc1452f74dd9fae36ea7107b85b 100644 --- a/cint/cint/src/shl.cxx +++ b/cint/cint/src/shl.cxx @@ -334,14 +334,14 @@ void *G__shl_findsym(G__SHLHANDLE *phandle,const char *sym,short /* type */) struct dsc$descriptor_s sym_d; struct dsc$descriptor_s phandle_d; #endif - char sym_underscore[G__ONELINE]; + G__FastAllocString sym_underscore(strlen(sym) + 2); if(G__sym_underscore) { sym_underscore[0]='_'; strcpy(sym_underscore+1,sym); } else { - strcpy(sym_underscore,sym); + sym_underscore = sym; } if(!(*phandle)) return(func); @@ -829,10 +829,8 @@ int G__shl_load(char *shlfile) int store_globalcomp; char *p; char *post; - char dllid[G__ONELINE]; int (*sharedlib_func)(); int error=0,cintdll=0; - char dllidheader[G__ONELINE]; #ifdef G__ROOT /* this pointer must be set before calling dlopen! */ @@ -910,13 +908,17 @@ int G__shl_load(char *shlfile) } #endif + size_t lendllidheader = strlen(p) + 1; + G__FastAllocString dllidheader(lendllidheader); strcpy(dllidheader,p); post = strchr(dllidheader,'.'); if(post) *post = '\0'; - sprintf(dllid,"G__cpp_dllrev"); + G__FastAllocString dllid(lendllidheader); { + dllid = "G__cpp_dllrev"; + } sharedlib_func= - (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); + (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); if(sharedlib_func && ((*sharedlib_func)()>G__ACCEPTDLLREV_UPTO || (*sharedlib_func)()<G__ACCEPTDLLREV_FROM)) { G__check_setup_version((*sharedlib_func)(),shlfile); @@ -927,9 +929,9 @@ int G__shl_load(char *shlfile) if(G__asm_dbg) G__show_dllrev(shlfile,sharedlib_func); } - sprintf(dllid,"G__cpp_dllrev%s",dllidheader); + dllid.Format("G__cpp_dllrev%s",dllidheader()); sharedlib_func= - (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); + (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); if(sharedlib_func && ((*sharedlib_func)()>G__ACCEPTDLLREV_UPTO || (*sharedlib_func)()<G__ACCEPTDLLREV_FROM)) { G__check_setup_version((*sharedlib_func)(),shlfile); @@ -940,9 +942,9 @@ int G__shl_load(char *shlfile) if(G__asm_dbg) G__show_dllrev(shlfile,sharedlib_func); } - sprintf(dllid,"G__c_dllrev"); + dllid = "G__c_dllrev"; sharedlib_func= - (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); + (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); if(sharedlib_func && ((*sharedlib_func)()>G__ACCEPTDLLREV_UPTO || (*sharedlib_func)()<G__ACCEPTDLLREV_FROM)) { G__check_setup_version((*sharedlib_func)(),shlfile); @@ -953,9 +955,9 @@ int G__shl_load(char *shlfile) if(G__asm_dbg) G__show_dllrev(shlfile,sharedlib_func); } - sprintf(dllid,"G__c_dllrev%s",dllidheader); + dllid.Format("G__c_dllrev%s",dllidheader()); sharedlib_func= - (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); + (int (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); if(sharedlib_func && ((*sharedlib_func)()>G__ACCEPTDLLREV_UPTO || (*sharedlib_func)()<G__ACCEPTDLLREV_FROM)) { G__check_setup_version((*sharedlib_func)(),shlfile); @@ -988,7 +990,7 @@ int G__shl_load(char *shlfile) G__globalcomp=G__NOLINK; - sprintf(dllid,"G__cpp_setup%s",dllidheader); + dllid.Format("G__cpp_setup%s",dllidheader()); G__CALL_SETUP("G__set_cpp_environment"); G__CALL_SETUP("G__cpp_setup_tagtable"); G__CALL_SETUP("G__cpp_setup_inheritance"); @@ -998,13 +1000,13 @@ int G__shl_load(char *shlfile) G__CALL_SETUP("G__cpp_setup_global"); G__CALL_SETUP("G__cpp_setup_func"); if(sharedlib_func==NULL) { - G__CALL_SETUP(dllid); + G__CALL_SETUP(dllid); } #ifdef G__ROOT if (sharedlib_func==NULL) G__call_setup_funcs(); #endif - sprintf(dllid,"G__c_setup%s",dllidheader); + dllid.Format("G__c_setup%s",dllidheader()); G__CALL_SETUP("G__set_c_environment"); G__CALL_SETUP("G__c_setup_typetable"); /* G__CALL_SETUP("G__c_setup_memvar"); */ @@ -1012,12 +1014,12 @@ int G__shl_load(char *shlfile) G__CALL_SETUP("G__c_setup_func"); G__CALL_SETUP("G__c_setup_tagtable"); if(sharedlib_func==NULL) { - G__CALL_SETUP(dllid); + G__CALL_SETUP(dllid); } if(0==G__sizep2memfunc) { - sprintf(dllid,"G__get_sizep2memfunc%s",dllidheader); - p = strchr(dllid,'.'); + dllid.Format("G__get_sizep2memfunc%s",dllidheader()); + p = strchr(dllid,'.'); if(p) *p = '\0'; G__CALL_SETUP(dllid); } @@ -1039,9 +1041,9 @@ int G__shl_load(char *shlfile) (void (*)())G__shl_findsym(&G__sl_handle[allsl].handle,"G__cpp_setup" ,TYPE_PROCEDURE); if(!initsl) { - sprintf(dllid,"G__cpp_setup%s",dllidheader); + dllid.Format("G__cpp_setup%s",dllidheader()); initsl = - (void (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); + (void (*)())G__shl_findsym(&G__sl_handle[allsl].handle,dllid,TYPE_PROCEDURE); } if (initsl) G__initpermanentsl->push_back(initsl); G__sl_handle[allsl].ispermanent = true; @@ -1168,7 +1170,7 @@ int G__isinterpretedp2f(void *p2f) G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,int *known3) { G__value result3; - char result7[G__ONELINE]; + G__FastAllocString result7(G__ONELINE); int ig15,ig35; struct G__ifunc_table_internal *ifunc; #ifdef G__SHAREDLIB @@ -1201,13 +1203,13 @@ G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,in parameter1[strlen(parameter1)-1]='\0'; switch(parameter1[0]) { case '[': - sprintf(result7,"operator[](%s)",parameter1+1); + result7.Format("operator[](%s)",parameter1+1); break; case '(': - sprintf(result7,"operator()(%s)",parameter1+1); + result7.Format("operator()(%s)",parameter1+1); break; } - result3 = G__getfunction(result7,known3,G__CALLMEMFUNC); + result3 = G__getfunction(result7(),known3,G__CALLMEMFUNC); #ifdef G__ASM if(G__asm_noverflow) { G__asm_inst[G__asm_cp] = G__POPSTROS; @@ -1240,14 +1242,14 @@ G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,in result7[0]='\0'; #ifdef G__TRUEP2F ifunc=G__p2f2funchandle_internal((void*)result3.obj.i,G__p_ifunc,&ig15); - if(ifunc) sprintf(result7,"%s%s",ifunc->funcname[ig15],parameter1); + if(ifunc) result7.Format("%s%s",ifunc->funcname[ig15],parameter1); #ifdef G__PTR2MEMFUNC else { int itag; for(itag=0;itag<G__struct.alltag;itag++) { ifunc=G__p2f2funchandle_internal((void*)result3.obj.i,G__struct.memfunc[itag],&ig15); if(ifunc && ifunc->staticalloc[ig15]) { - sprintf(result7,"%s::%s%s",G__fulltagname(itag,1),ifunc->funcname[ig15],parameter1); + result7.Format("%s::%s%s",G__fulltagname(itag,1),ifunc->funcname[ig15],parameter1); break; } } @@ -1258,7 +1260,7 @@ G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,in do { for(ig15=0;ig15<ifunc->allifunc;ig15++) { if(strcmp(ifunc->funcname[ig15],(char *)result3.obj.i)==0){ - sprintf(result7,"%s%s",(char *)result3.obj.i,parameter1); + result7.Format("%s%s",(char *)result3.obj.i,parameter1); } } } while(ifunc=ifunc->next) ; @@ -1272,7 +1274,7 @@ G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,in while( (((long)(G__completionlist[ig15].name))!=0) && (ig35==0)) { if((long)G__completionlist[ig15].pfunc==result3.obj.i){ - sprintf(result7,"%s%s" ,G__completionlist[ig15].name ,parameter1); + result7.Format("%s%s" ,G__completionlist[ig15].name ,parameter1); ig35=1; } ++ig15; @@ -1288,7 +1290,7 @@ G__value G__pointer2func(G__value *obj_p2f,char *parameter0 ,char *parameter1,in while( (((long)(G__completionlist[ig15].name))!=0) && (ig35==0)) { if(strcmp(G__completionlist[ig15].name,(char *)result3.obj.i)==0) { - sprintf(result7,"%s%s",G__completionlist[ig15].name,parameter1); + result7.Format("%s%s",G__completionlist[ig15].name,parameter1); ig35=1; } ++ig15; @@ -1335,26 +1337,27 @@ void G__removetagid(char *buf) ******************************************************************/ int G__getp2ftype(struct G__ifunc_table_internal *ifunc,int ifn) { - char temp[G__MAXNAME*2],temp1[G__MAXNAME]; + G__FastAllocString temp(G__MAXNAME*2); + G__FastAllocString temp1(G__MAXNAME); char *p; int typenum; int i; - strcpy(temp1, G__type2string(ifunc->type[ifn],ifunc->p_tagtable[ifn] + temp1 = G__type2string(ifunc->type[ifn],ifunc->p_tagtable[ifn] ,ifunc->p_typetable[ifn],ifunc->reftype[ifn] - ,ifunc->isconst[ifn])); + ,ifunc->isconst[ifn]); G__removetagid(temp1); - if(isupper(ifunc->type[ifn])) sprintf(temp,"%s *(*)(",temp1); - else sprintf(temp,"%s (*)(",temp1); + if(isupper(ifunc->type[ifn])) temp.Format("%s *(*)(",temp1()); + else temp.Format("%s (*)(",temp1()); p = temp + strlen(temp); for(i=0;i<ifunc->para_nu[ifn];i++) { if(i) *p++ = ','; - strcpy(temp1,G__type2string(ifunc->param[ifn][i]->type + temp1 = G__type2string(ifunc->param[ifn][i]->type ,ifunc->param[ifn][i]->p_tagtable ,ifunc->param[ifn][i]->p_typetable ,ifunc->param[ifn][i]->reftype - ,ifunc->param[ifn][i]->isconst)); + ,ifunc->param[ifn][i]->isconst); G__removetagid(temp1); strcpy(p,temp1); p = temp + strlen(temp); @@ -2057,15 +2060,15 @@ void* G__FindSymbol(struct G__ifunc_table_internal *ifunc,int ifn) char *funcname=ifunc->funcname[ifn]; void *p2f=0; if(G__ShlHandle) { - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); /* funcname, VC++, GCC, C function */ p2f = (void*)G__shl_findsym(&G__ShlHandle,funcname,TYPE_PROCEDURE); /* _funcname, BC++, C function */ if(!p2f) { - buf[0]='_'; - strcpy(buf+1,funcname); + buf = "_"; + buf += funcname; p2f = (void*)G__shl_findsym(&G__ShlHandle,buf,TYPE_PROCEDURE); } diff --git a/cint/cint/src/sizeof.cxx b/cint/cint/src/sizeof.cxx index 43a37a93cec30e424152da7c028dbdc5c1ac612f..1a681213ba76f0be1596e11269858966bf9d8345 100644 --- a/cint/cint/src/sizeof.cxx +++ b/cint/cint/src/sizeof.cxx @@ -141,7 +141,8 @@ int G__Lsizeof(const char *type_name) int tagnum,typenum; int result; int pointlevel=0; - char namebody[G__MAXNAME+20]; + G__FastAllocString namebody_sb(G__MAXNAME+20); + char* namebody = namebody_sb; char *p; int i; @@ -285,7 +286,8 @@ int G__Lsizeof(const char *type_name) G__hash(namebody,hash,ig15) var = G__getvarentry(namebody,hash,&ig15,&G__global,G__p_local); if (!var) { - char temp[G__ONELINE]; + G__FastAllocString temp_sb(G__ONELINE); + char* temp = temp_sb; if (G__memberfunc_tagnum != -1) { // questionable sprintf(temp, "%s\\%x\\%x\\%x", namebody, G__func_page, G__func_now, G__memberfunc_tagnum); } @@ -393,7 +395,8 @@ long *G__typeid(const char *typenamein) int len; int pointlevel=0,isref=0; int tag_type_info; - char typenamebuf[G__MAXNAME*2]; + G__FastAllocString typenamebuf_sb(G__MAXNAME*2); + char* typenamebuf = typenamebuf_sb; char *type_name; int isconst = 0; diff --git a/cint/cint/src/struct.cxx b/cint/cint/src/struct.cxx index 26c291d23fd1df0bb886c9b3e9b5306a576c9a39..3c55c39adbb56ac42e561e64c9d875b602beecfb 100644 --- a/cint/cint/src/struct.cxx +++ b/cint/cint/src/struct.cxx @@ -45,6 +45,20 @@ int G__defined_tagname(const char* tagname, int noerror); int G__search_tagname(const char* tagname, int type); +//______________________________________________________________________________ +char* G__savestring(char** pbuf, char* name) +{ + // -- FIXME: Describe this function! + G__ASSERT(pbuf); + if (*pbuf) { + free((void*)(*pbuf)); + *pbuf = 0; + } + *pbuf = (char*) malloc(strlen(name) + 1); + return strcpy(*pbuf, name); +} + + //______________________________________________________________________________ #define G__CLASS_AUTOLOAD 'a' static int G__enable_autoloading = 1; @@ -189,13 +203,13 @@ int G__using_namespace() // Note: using directive appears in global scope is not implemented yet // int result = 0; - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); // Check if using directive or declaration. - int c = G__fgetname_template(buf, ";"); + int c = G__fgetname_template(buf, 0, ";"); if (!strcmp(buf, "namespace")) { // -- Using directive, treat as inheritance. int basetagnum, envtagnum; - c = G__fgetstream_template(buf, ";"); + c = G__fgetstream_template(buf, 0, ";"); #ifndef G__STD_NAMESPACE if (';' == c && strcmp(buf, "std") == 0 && G__ignore_stdnamespace) { return 1; @@ -203,7 +217,7 @@ int G__using_namespace() #endif // G__STD_NAMESPACE basetagnum = G__defined_tagname(buf, 2); if (basetagnum == -1) { - G__fprinterr(G__serr, "Error: namespace %s is not defined", buf); + G__fprinterr(G__serr, "Error: namespace %s is not defined", buf()); G__genericerror(0); return 0; } @@ -274,8 +288,7 @@ int G__using_namespace() else { ++pc; } - char varname[G__ONELINE]; - strcpy(varname, buf); + G__FastAllocString varname(buf); // Allocate a variable array entry which shares value storage with the found variable. int store_globalvarpointer = G__globalvarpointer; G__globalvarpointer = var->p[ig15]; @@ -586,19 +599,15 @@ void G__define_struct(char type) // ^ // Now read tagname. // - char tagname[G__LONGLINE]; - int c = G__fgetname_template(tagname, "{:;=&"); - if (strlen(tagname) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", tagname, G__LONGLINE); - G__genericerror(0); - } + G__FastAllocString tagname(G__LONGLINE); + int c = G__fgetname_template(tagname, 0, "{:;=&"); while (c == ':') { // -- Check for and handle nested name specifier. c = G__fgetc(); if (c == ':') { - strcat(tagname, "::"); + tagname += "::"; int len = strlen(tagname); - c = G__fgetname_template(tagname + len, "{:;=&"); + c = G__fgetname_template(tagname, len, "{:;=&"); } else { fseek(G__ifile.fp, -1, SEEK_CUR); @@ -655,8 +664,8 @@ void G__define_struct(char type) } else if ((c == '=') && (type == 'n')) { // -- We have: namespace alias=nsn; treat as typedef, handle and return. - char basename[G__LONGLINE]; - c = G__fgetstream_template(basename, ";"); + G__FastAllocString basename(G__LONGLINE); + c = G__fgetstream_template(basename, 0, ";"); int tagdefining = G__defined_tagname(basename, 0); if (tagdefining != -1) { int typenum; @@ -785,16 +794,12 @@ void G__define_struct(char type) // Reset virtualbase flag. int isvirtualbase = 0; // Read base class name. - char basename[G__LONGLINE]; + G__FastAllocString basename(G__LONGLINE); #ifdef G__TEMPLATECLASS - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); #else // G__TEMPLATECLASS - c = G__fgetname(basename, "{,"); + c = G__fgetname(basename, 0, "{,"); #endif // G__TEMPLATECLASS - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } // [struct|class] <tagname> : <private|protected|public|virtual> base1 , base2 {} // ^ or ^ if (!strcmp(basename, "virtual")) { @@ -804,12 +809,8 @@ void G__define_struct(char type) G__genericerror("Limitation: virtual base class not supported in interpretation"); } #endif // G__VIRTUALBASE - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); isvirtualbase = G__ISVIRTUALBASE; - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } } int baseaccess = G__PUBLIC; if (type == 'c') { @@ -818,38 +819,26 @@ void G__define_struct(char type) if (!strcmp(basename, "public")) { baseaccess = G__PUBLIC; #ifdef G__TEMPLATECLASS - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); #else // G__TEMPLATECLASS - c = G__fgetname(basename, "{,"); + c = G__fgetname(basename, 0, "{,"); #endif // G__TEMPLATECLASS - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } } else if (!strcmp(basename, "private")) { baseaccess = G__PRIVATE; #ifdef G__TEMPLATECLASS - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); #else // G__TEMPLATECLASS - c = G__fgetname(basename, "{,"); + c = G__fgetname(basename, 0, "{,"); #endif // G__TEMPLATECLASS - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } } else if (!strcmp(basename, "protected")) { baseaccess = G__PROTECTED; #ifdef G__TEMPLATECLASS - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); #else // G__TEMPLATECLASS - c = G__fgetname(basename, "{,"); + c = G__fgetname(basename, 0, "{,"); #endif // G__TEMPLATECLASS - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } } if (!strcmp(basename, "virtual")) { // -- @@ -857,12 +846,8 @@ void G__define_struct(char type) if ((G__globalcomp == G__NOLINK) && (G__store_globalcomp == G__NOLINK)) G__genericerror("Limitation: virtual base class not supported in interpretation"); #endif // G__VIRTUALBASE - c = G__fgetname_template(basename, "{,"); + c = G__fgetname_template(basename, 0, "{,"); isvirtualbase = G__ISVIRTUALBASE; - if (strlen(basename) >= G__LONGLINE) { - G__fprinterr(G__serr, "Limitation: class name '%s' too long. Must be < %d", basename, G__LONGLINE); - G__genericerror(0); - } } if (strlen(basename) && isspace(c)) { // Maybe basename is namespace that got cut because @@ -874,7 +859,7 @@ void G__define_struct(char type) // // class MyClass : public MyNamespace:: MyTopClass // - char temp[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); int namespace_tagnum = G__defined_tagname(basename, 2); while ( // -- @@ -886,8 +871,8 @@ void G__define_struct(char type) ) ) { // -- - c = G__fgetname_template(temp, "{,"); - strcat(basename, temp); + c = G__fgetname_template(temp, 0, "{,"); + basename += temp; namespace_tagnum = G__defined_tagname(basename, 2); } } @@ -1084,16 +1069,16 @@ void G__define_struct(char type) G__enumdef = 1; do { int store_decl = 0; - char memname[G__ONELINE]; - c = G__fgetstream(memname, "=,}"); + G__FastAllocString memname(G__ONELINE); + c = G__fgetstream(memname, 0, "=,}"); if (c == '=') { char store_var_typeX = G__var_type; int store_tagnumX = G__tagnum; int store_def_tagnumX = G__def_tagnum; G__var_type = 'p'; G__tagnum = G__def_tagnum = -1; - char val[G__ONELINE]; - c = G__fgetstream(val, ",}"); + G__FastAllocString val(G__ONELINE); + c = G__fgetstream(val, 0, ",}"); int store_prerun = G__prerun; G__prerun = 0; enumval = G__getexpr(val); @@ -1240,8 +1225,8 @@ void G__define_struct(char type) int linenum; fgetpos(G__ifile.fp, &pos); linenum = G__ifile.line_number; - char basename[G__LONGLINE]; - c = G__fgetstream(basename, ";"); + G__FastAllocString basename(G__LONGLINE); + c = G__fgetstream(basename, 0, ";"); if (basename[0]) { fsetpos(G__ifile.fp, &pos); G__ifile.line_number = linenum; @@ -1269,12 +1254,12 @@ void G__define_struct(char type) fgetpos(G__ifile.fp, &store_pos); int store_linenum = G__ifile.line_number; G__disp_mask = 1000; // FIXME: Crazy! - char buf[G__ONELINE]; - int ch = G__fgetname(buf, ";,("); + G__FastAllocString buf(G__ONELINE); + int ch = G__fgetname(buf, 0, ";,("); int errflag = 0; if (isspace(ch) && (buf[0] != '*') && !strchr(buf, '[')) { - char tmp[G__ONELINE]; - ch = G__fgetname(tmp, ";,("); + G__FastAllocString tmp(G__ONELINE); + ch = G__fgetname(tmp, 0, ";,("); if (isalnum(tmp[0])) { errflag = 1; } @@ -1526,8 +1511,8 @@ int G__defined_tagname(const char* tagname, int noerror) int i; int len; char* p; - char temp[G__LONGLINE]; - char atom_tagname[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); + G__FastAllocString atom_tagname(G__LONGLINE); int env_tagnum; int store_var_type; switch (tagname[0]) { @@ -1544,7 +1529,7 @@ int G__defined_tagname(const char* tagname, int noerror) // handles X<X<int>> as X<X<int> > while (0 != (p = (char*) strstr(tagname, ">>"))) { ++p; - strcpy(temp, p); + temp = p; *p = ' '; ++p; strcpy(p, temp); @@ -1553,7 +1538,7 @@ int G__defined_tagname(const char* tagname, int noerror) p = (char*) tagname; while (0 != (p = (char*) strstr(p, " >"))) { if ('>' != *(p - 1)) { - strcpy(temp, p + 1); + temp = p + 1; strcpy(p, temp); } ++p; @@ -1561,7 +1546,7 @@ int G__defined_tagname(const char* tagname, int noerror) // handles X <int> as X<int> p = (char*) tagname; while (0 != (p = strstr(p, " <"))) { - strcpy(temp, p + 1); + temp = p + 1; strcpy(p, temp); ++p; } @@ -1572,7 +1557,7 @@ int G__defined_tagname(const char* tagname, int noerror) p += 2; } else { - strcpy(temp, p + 2); + temp = p + 2; strcpy(p + 1, temp); ++p; } @@ -1580,14 +1565,14 @@ int G__defined_tagname(const char* tagname, int noerror) // handles X< int> as X<int> p = (char*) tagname; while (0 != (p = strstr(p, "< "))) { - strcpy(temp, p + 2); + temp = p + 2; strcpy(p + 1, temp); ++p; } // handles X<int, int> as X<int,int> p = (char*) tagname; while (0 != (p = strstr(p, ", "))) { - strcpy(temp, p + 2); + temp = p + 2; strcpy(p + 1, temp); ++p; } @@ -1604,16 +1589,16 @@ int G__defined_tagname(const char* tagname, int noerror) p = strstr(p, "const const "); } if (isspace(tagname[0])) { - strcpy(temp, tagname + 1); + temp = tagname + 1; } else { - strcpy(temp, tagname); + temp = tagname; } p = (char*)G__find_last_scope_operator(temp); if (p) { // A::B::C means we want A::B::C, not A::C, even if it exists. enclosing = false; - strcpy(atom_tagname, p + 2); + atom_tagname = p + 2; *p = '\0'; if (p == temp) { env_tagnum = -1; // global scope @@ -1641,7 +1626,7 @@ int G__defined_tagname(const char* tagname, int noerror) } } else { - strcpy(atom_tagname, temp); + atom_tagname = temp; env_tagnum = G__get_envtagnum(); } // Search for old tagname. @@ -1688,7 +1673,7 @@ try_again: i = -1; } if (!len) { - strcpy(atom_tagname, "$"); + atom_tagname = "$"; len = 1; goto try_again; } @@ -1765,15 +1750,8 @@ int G__search_tagname(const char* tagname, int type) int i; int len; char* p; -#ifndef G__OLDIMPLEMENTATION1823 - char buf[G__BUFLEN*2]; - char buf2[G__BUFLEN*2]; - char* temp = buf; - char* atom_tagname = buf2; -#else // G__OLDIMPLEMENTATION1823 - char temp[G__LONGLINE]; - char atom_tagname[G__LONGLINE]; -#endif // G__OLDIMPLEMENTATION1823 + G__FastAllocString temp(G__LONGLINE); + G__FastAllocString atom_tagname(G__LONGLINE); int noerror = 0; if (type == G__CLASS_AUTOLOAD) { /* no need to issue error message while uploading @@ -1791,15 +1769,9 @@ int G__search_tagname(const char* tagname, int type) // Search for old tagname // Only auto-load struct if not ref / ptr i = G__defined_tagname(tagname, isPointer ? 3 : 2); -#ifndef G__OLDIMPLEMENTATION1823 - if (strlen(tagname) > ((2 * G__BUFLEN) - 10)) { - temp = (char*) malloc(strlen(tagname) + 10); - atom_tagname = (char*) malloc(strlen(tagname) + 10); - } -#endif // G__OLDIMPLEMENTATION1823 p = (char*)G__strrstr( tagname, "::"); if (p && !strchr(p, '>')) { - strcpy(atom_tagname, tagname); + atom_tagname = tagname; p = (char*)G__strrstr(atom_tagname, "::"); *p = 0; // first try a typedef, so we don't trigger autoloading here: @@ -1819,16 +1791,12 @@ int G__search_tagname(const char* tagname, int type) if (i == G__MAXSTRUCT) { G__fprinterr(G__serr, "Limitation: Number of struct/union tag exceed %d FILE:%s LINE:%d\nFatal error, exit program. Increase G__MAXSTRUCT in G__ci.h and recompile %s\n", G__MAXSTRUCT, G__ifile.name, G__ifile.line_number, G__nam); G__eof = 1; -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != temp) free((void*)temp); - if (buf2 != atom_tagname) free((void*)atom_tagname); -#endif // G__OLDIMPLEMENTATION1823 return -1; } - strcpy(temp, tagname); + temp = tagname; p = (char*)G__find_last_scope_operator(temp); if (p) { - strcpy(atom_tagname, p + 2); + atom_tagname = p + 2; *p = '\0'; #ifndef G__STD_NAMESPACE if (strcmp(temp, "std") == 0 && G__ignore_stdnamespace) { @@ -1851,10 +1819,10 @@ int G__search_tagname(const char* tagname, int type) } } G__struct.parent_tagnum[i] = env_tagnum; - strcpy(atom_tagname, temp); + atom_tagname = temp; } if (!strncmp("G__NONAME", atom_tagname, 9)) { - atom_tagname[0] = '\0'; + atom_tagname[0] = 0; len = 0; } else { @@ -1966,14 +1934,6 @@ int G__search_tagname(const char* tagname, int type) G__struct.type[i] = type; ++G__struct.nactives; } -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != temp) { - free(temp); - } - if (buf2 != atom_tagname) { - free(atom_tagname); - } -#endif // G__OLDIMPLEMENTATION1823 // Return tagnum. return i; } diff --git a/cint/cint/src/stub.cxx b/cint/cint/src/stub.cxx index ce5d2b1fe0220340f1e1da434054e2a6c26908ae..64829c5a0cf135611031e820dbf08e231b81434b 100644 --- a/cint/cint/src/stub.cxx +++ b/cint/cint/src/stub.cxx @@ -94,60 +94,60 @@ void G__setint(G__value *pbuf,long l,void *pl * G__cppstub_setparam() * **************************************************************************/ -static void G__cppstub_setparam(char *pformat,char *pbody +static void G__cppstub_setparam(G__FastAllocString& pformat,G__FastAllocString& pbody ,int /* tagnum */,int ifn,G__ifunc_table_internal *ifunc,int k) { - char paraname[G__MAXNAME]; - char temp[G__ONELINE]; + G__FastAllocString paraname(G__MAXNAME); + G__FastAllocString temp(G__ONELINE); - if(ifunc->param[ifn][k]->name) strcpy(paraname,ifunc->param[ifn][k]->name); - else sprintf(paraname,"a%d",k); + if(ifunc->param[ifn][k]->name) paraname = ifunc->param[ifn][k]->name; + else paraname.Format("a%d",k); - if(k) strcat(pformat,","); - strcat(pbody,","); + if(k) pformat += ","; + pbody += ","; if(ifunc->param[ifn][k]->reftype) { - sprintf(temp,"*(%s*)(%%ld)" + temp.Format("*(%s*)(%%ld)" ,G__type2string(ifunc->param[ifn][k]->type ,ifunc->param[ifn][k]->p_tagtable ,ifunc->param[ifn][k]->p_typetable ,0 ,ifunc->param[ifn][k]->isconst)); - strcat(pformat,temp); - sprintf(temp,"(long)(&%s)",paraname); - strcat(pbody,temp); + pformat += temp; + temp.Format("(long)(&%s)",paraname()); + pbody += temp; } else { switch(ifunc->param[ifn][k]->type) { case 'u': - sprintf(temp,"(%s)(%%ld)" + temp.Format("(%s)(%%ld)" ,G__type2string(ifunc->param[ifn][k]->type ,ifunc->param[ifn][k]->p_tagtable ,ifunc->param[ifn][k]->p_typetable ,0 ,ifunc->param[ifn][k]->isconst)); - strcat(pformat,temp); - sprintf(temp,"&%s",paraname); - strcat(pbody,temp); + pformat += temp; + temp.Format("&%s",paraname()); + pbody += temp; break; case 'd': case 'f': - sprintf(temp,"(%s)%%g" + temp.Format("(%s)%%g" ,G__type2string(ifunc->param[ifn][k]->type ,ifunc->param[ifn][k]->p_tagtable ,ifunc->param[ifn][k]->p_typetable ,0 ,ifunc->param[ifn][k]->isconst)); - strcat(pformat,temp); - sprintf(temp,"%s",paraname); - strcat(pbody,temp); + pformat += temp; + temp = paraname; + pbody += temp; break; default: - sprintf(temp,"(%s)(%%ld)" + temp.Format("(%s)(%%ld)" ,G__type2string(ifunc->param[ifn][k]->type ,ifunc->param[ifn][k]->p_tagtable ,ifunc->param[ifn][k]->p_typetable ,0 ,ifunc->param[ifn][k]->isconst)); - strcat(pformat,temp); - sprintf(temp,"(long)%s",paraname); - strcat(pbody,temp); + pformat += temp; + temp.Format("(long)%s",paraname()); + pbody += temp; break; } } @@ -182,8 +182,8 @@ static void G__cppstub_gendestructor(FILE * /* fp */,int tagnum static void G__cppstub_genfunc(FILE *fp,int tagnum,int ifn,G__ifunc_table_internal *ifunc) { int k; - char pformat[G__ONELINE]; - char pbody[G__LONGLINE]; + G__FastAllocString pformat(G__ONELINE); + G__FastAllocString pbody(G__LONGLINE); /******************************************************************* * Function header @@ -275,7 +275,7 @@ static void G__cppstub_genfunc(FILE *fp,int tagnum,int ifn,G__ifunc_table_intern G__cppstub_setparam(pformat,pbody,tagnum,ifn,ifunc,k); } fprintf(fp," sprintf(funccall,\"%s(%s)\"%s);\n" - ,ifunc->funcname[ifn],pformat,pbody); + ,ifunc->funcname[ifn],pformat(),pbody()); fprintf(fp," buf=G__calc(funccall);\n"); /******************************************************************* diff --git a/cint/cint/src/symbols.cxx b/cint/cint/src/symbols.cxx index 45b2138b3fd7c3c188d231a4f0a1a3898f6be1e7..ddcd95038b522b46c95fe531b94c14793dc37b2a 100644 --- a/cint/cint/src/symbols.cxx +++ b/cint/cint/src/symbols.cxx @@ -425,7 +425,7 @@ void MapDependantTypesX() // defines. int more = 0; - char prompt[G__ONELINE]; + G__FastAllocString prompt(G__ONELINE); // Like MapDependantTypes but for the class TGX11 diff --git a/cint/cint/src/tmplt.cxx b/cint/cint/src/tmplt.cxx index 7763113585cae3a04c479d0fc453510e95513053..bfd7933feb3957e886bedab64633e7e2a4f029de 100644 --- a/cint/cint/src/tmplt.cxx +++ b/cint/cint/src/tmplt.cxx @@ -124,10 +124,10 @@ void G__instantiate_templateclasslater(G__Definedtemplateclass *deftmpclass) int store_def_tagnum=G__def_tagnum; int store_tagdefining=G__tagdefining; int store_def_struct_member=G__def_struct_member; - char tagname[G__LONGLINE]; + G__FastAllocString tagname(G__LONGLINE); while(ilist) { G__ASSERT(ilist->i>=0); - strcpy(tagname,G__struct.name[ilist->i]); + tagname = G__struct.name[ilist->i]; if(-1!=G__struct.parent_tagnum[ilist->i]) { G__def_tagnum=G__struct.parent_tagnum[ilist->i]; G__tagdefining=G__struct.parent_tagnum[ilist->i]; @@ -156,22 +156,22 @@ void G__instantiate_templatememfunclater(G__Definedtemplateclass *deftmpclass { struct G__IntList* ilist=deftmpclass->instantiatedtagnum; struct G__Charlist call_para; - char templatename[G__LONGLINE]; - char tagname[G__LONGLINE]; + G__FastAllocString templatename(G__LONGLINE); + G__FastAllocString tagname(G__LONGLINE); char *arg; int npara=0; int store_def_tagnum=G__def_tagnum; int store_tagdefining=G__tagdefining; int store_def_struct_member=G__def_struct_member; - char cnull[1]; cnull[0]=0; + char cnull[1] = {0}; while(ilist) { G__ASSERT(0<=ilist->i); if (G__struct.name[ilist->i]==0) { ilist = ilist->next; continue; } - strcpy(tagname,G__struct.name[ilist->i]); - strcpy(templatename,tagname); + tagname = G__struct.name[ilist->i]; + templatename = tagname; arg = strchr(templatename,'<'); if(arg) { *arg='\0'; @@ -284,6 +284,8 @@ int G__settemplatealias(const char *tagnamein,char *tagname,int tagnum } #endif +} // extern "C" + #ifdef G__TEMPLATECLASS /*********************************************************************** @@ -291,7 +293,7 @@ int G__settemplatealias(const char *tagnamein,char *tagname,int tagnum * * Concatinate templatename and template arguments ***********************************************************************/ -int G__cattemplatearg(char *tagname,G__Charlist *charlist) +int G__cattemplatearg(G__FastAllocString& tagname,G__Charlist *charlist) { char *p; p=strchr(tagname,'<'); @@ -303,15 +305,17 @@ int G__cattemplatearg(char *tagname,G__Charlist *charlist) /* B<int,5*2> * ^ => p */ while(charlist->next) { - strcpy(p,charlist->string); - p+=strlen(charlist->string); - charlist=charlist->next; - if(charlist->next) { - *p=','; ++p; - } else { - if (*(p-1) == '>') { - *p = ' '; ++p; - } + size_t lenArg = strlen(charlist->string); + tagname.Resize(p - tagname + lenArg + 4); // trailing >, maybe space + memcpy(p,charlist->string, lenArg + 1); + p += lenArg; + charlist=charlist->next; + if(charlist->next) { + *p=','; ++p; + } else { + if (*(p-1) == '>') { + *p = ' '; ++p; + } } } *p='>'; ++p; @@ -319,6 +323,8 @@ int G__cattemplatearg(char *tagname,G__Charlist *charlist) return 0; } +extern "C" { + /*********************************************************************** * G__catparam() * @@ -354,7 +360,8 @@ struct G__Templatearg *G__read_formal_templatearg() { struct G__Templatearg *targ=NULL; struct G__Templatearg *p=NULL; - char type[G__MAXNAME],name[G__MAXNAME]; + G__FastAllocString type(G__MAXNAME); + G__FastAllocString name(G__MAXNAME); int c; int stat=1; @@ -376,14 +383,14 @@ struct G__Templatearg *G__read_formal_templatearg() /* template<class T,class E,int S> ... * ^ */ - c = G__fgetname(type,"<"); - if (strcmp (type, "const") == 0 && c == ' ') c=G__fgetname(type,"<"); + c = G__fgetname(type, 0, "<"); + if (strcmp (type, "const") == 0 && c == ' ') c=G__fgetname(type, 0, "<"); if(strcmp(type,"class")==0 || strcmp(type,"typename")==0) { p->type = G__TMPLT_CLASSARG; } else if('<'==c && strcmp(type,"template")==0) { c=G__fignorestream(">"); - c=G__fgetname(type,""); + c=G__fgetname(type, 0, ""); G__ASSERT(0==strcmp(type,"class")||0==strcmp(type,"typename")); p->type = G__TMPLT_TMPLTARG; } @@ -396,7 +403,7 @@ struct G__Templatearg *G__read_formal_templatearg() int linenum; fgetpos(G__ifile.fp,&pos); linenum = G__ifile.line_number; - c = G__fgetname(name,",>="); + c = G__fgetname(name, 0, ",>="); if(strcmp(name,"int")==0) p->type = G__TMPLT_UINTARG; else if(strcmp(name,"short")==0) p->type = G__TMPLT_USHORTARG; else if(strcmp(name,"char")==0) p->type = G__TMPLT_UCHARARG; @@ -404,7 +411,7 @@ struct G__Templatearg *G__read_formal_templatearg() p->type = G__TMPLT_ULONGARG; fgetpos(G__ifile.fp,&pos); linenum = G__ifile.line_number; - c = G__fgetname(name,",>="); + c = G__fgetname(name, 0, ",>="); if(strcmp(name,"int")==0) { p->type = G__TMPLT_ULONGARG; } @@ -435,7 +442,7 @@ struct G__Templatearg *G__read_formal_templatearg() } else { if(G__dispsource) { - G__fprinterr(G__serr,"Limitation: template argument type '%s' may cause problem",type); + G__fprinterr(G__serr,"Limitation: template argument type '%s' may cause problem",type()); G__printlinenum(); } p->type = G__TMPLT_INTARG; @@ -444,7 +451,7 @@ struct G__Templatearg *G__read_formal_templatearg() /* template<class T,class E,int S> ... * ^ */ - c = G__fgetstream(name,",>="); /* G__fgetstream_tmplt() ? */ + c = G__fgetstream(name, 0, ",>="); /* G__fgetstream_tmplt() ? */ while(name[0] && '*'==name[strlen(name)-1]) { if(G__TMPLT_CLASSARG==p->type) p->type = G__TMPLT_POINTERARG1; else p->type+=G__TMPLT_POINTERARG1; @@ -454,7 +461,7 @@ struct G__Templatearg *G__read_formal_templatearg() strcpy(p->string,name); if('='==c) { - c = G__fgetstream_template(name,",>"); /* G__fgetstream_tmplt() ? */ + c = G__fgetstream_template(name, 0, ",>"); /* G__fgetstream_tmplt() ? */ p->default_parameter=(char*)malloc(strlen(name)+1); strcpy(p->default_parameter,name); } @@ -482,7 +489,7 @@ struct G__Templatearg *G__read_specializationarg(char *source) { struct G__Templatearg *targ=0; struct G__Templatearg *p=0; - char type[G__MAXNAME]; + G__FastAllocString type(G__MAXNAME); bool done = false; int i,j,nest; int isrc=0; @@ -520,9 +527,9 @@ struct G__Templatearg *G__read_specializationarg(char *source) case '>': --nest; if (nest<0) { i=len; done = true; continue; } break; case ',': if (nest==0) { isrc = i+1; i=len; continue; } break; } - type[j++] = source[i]; + type.Set(j++, source[i]); } - type[j] = 0; + type.Set(j, 0); len = strlen(type); if('&'==type[len-1]) { p->type |= G__TMPLT_REFERENCEARG; @@ -617,7 +624,7 @@ static void G__modify_callpara(G__Templatearg *spec_arg if(spec_p>0 && spec_p<=call_p) { int i; int n = spec_p/G__TMPLT_POINTERARG1; - char buf[10]; + G__FastAllocString buf(n + 1); for(i=0;i<n;i++) buf[i]='*'; buf[n]=0; G__delete_end_string(pcall_para->string,buf); @@ -996,12 +1003,11 @@ struct G__Definetemplatefunc *G__defined_templatememfunc(const char *name) char *p; char *p1; char *p2; - char atom_name[G__LONGLINE]; + G__FastAllocString atom_name(name); int store_asm_noverflow = G__asm_noverflow ; struct G__Definetemplatefunc *result= NULL; /* separate "t" and "Handle" */ - strcpy(atom_name,name); p1 = strrchr(atom_name,'.'); p2 = (char*)G__strrstr(atom_name,"->"); if(!p1 && !p2) return(result); @@ -1064,7 +1070,6 @@ struct G__Definetemplatefunc *G__defined_templatefunc(const char *name) struct G__Definetemplatefunc *deftmplt; int hash,temp; long dmy_struct_offset=0; - char atom_name[G__LONGLINE]; int env_tagnum=G__get_envtagnum(); int scope_tagnum = -1; struct G__inheritance *baseclass; @@ -1080,7 +1085,7 @@ struct G__Definetemplatefunc *G__defined_templatefunc(const char *name) baseclass = (struct G__inheritance*)NULL; /* scope operator resolution, A::templatename<int> ... */ - strcpy(atom_name,name); + G__FastAllocString atom_name(name); G__hash(atom_name,hash,temp) G__scopeoperator(atom_name,&hash,&dmy_struct_offset,&scope_tagnum); @@ -1151,7 +1156,6 @@ struct G__Definedtemplateclass *G__defined_templateclass(const char *name) struct G__Definedtemplateclass *deftmplt; int hash,temp; long dmy_struct_offset=0; - char atom_name[G__LONGLINE]; int env_tagnum=G__get_envtagnum(); int scope_tagnum = -1; struct G__inheritance *baseclass; @@ -1170,7 +1174,7 @@ struct G__Definedtemplateclass *G__defined_templateclass(const char *name) baseclass = (struct G__inheritance*)NULL; /* scope operator resolution, A::templatename<int> ... */ - strcpy(atom_name,name); + G__FastAllocString atom_name(name); G__hash(atom_name,hash,temp) int scope = G__scopeoperator(atom_name,&hash,&dmy_struct_offset,&scope_tagnum); @@ -1248,7 +1252,7 @@ struct G__Definedtemplateclass *G__defined_templateclass(const char *name) int G__explicit_template_specialization() { #if !defined(G__OLDIMPLEMENTATION1792) - char buf[G__ONELINE]; + G__FastAllocString buf(G__ONELINE); int cin; /* store file position */ @@ -1258,12 +1262,11 @@ int G__explicit_template_specialization() G__disp_mask = 1000; /* forward proving */ - cin = G__fgetname_template(buf,":{;"); + cin = G__fgetname_template(buf, 0, ":{;"); if(strcmp(buf,"class")==0 || strcmp(buf,"struct")==0) { /* template<> class A<int> { A(A& x); A& operator=(A& x); }; * ^ */ char *pp; - char templatename[G__ONELINE]; int npara=0; int envtagnum = G__get_envtagnum(); struct G__Charlist call_para; @@ -1276,8 +1279,8 @@ int G__explicit_template_specialization() /* def_para.next = (struct G__Templatearg *)NULL; */ - cin = G__fgetname_template(buf,":{;"); - strcpy(templatename,buf); + cin = G__fgetname_template(buf, 0, ":{;"); + G__FastAllocString templatename(buf); pp=strchr(templatename,'<'); if(pp) *pp=0; @@ -1350,14 +1353,14 @@ int G__explicit_template_specialization() ***********************************************************************/ void G__declare_template() { - char temp[G__LONGLINE]; + G__FastAllocString temp(G__LONGLINE); + G__FastAllocString temp2(G__LONGLINE); + G__FastAllocString temp3(G__LONGLINE); fpos_t pos; int store_line_number; struct G__Templatearg *targ; int c; char *p; - char temp2[G__LONGLINE]; - char temp3[G__LONGLINE]; int ismemvar=0; int isforwarddecl = 0; int isfrienddecl = 0; @@ -1387,12 +1390,12 @@ void G__declare_template() /* if(G__dispsource) G__disp_mask=1000; */ do { - c=G__fgetname_template(temp,"(<"); + c=G__fgetname_template(temp, 0, "(<"); if (strcmp(temp,"friend")==0) { isfrienddecl = 1; // We do not need to autoload friend declaration. autoload_old = G__set_class_autoloading(0); - c=G__fgetname_template(temp,"(<"); + c=G__fgetname_template(temp, 0, "(<"); } } while(strcmp(temp,"inline")==0||strcmp(temp,"const")==0 || strcmp(temp,"typename")==0 || strcmp(temp,"static") == 0 @@ -1402,7 +1405,7 @@ void G__declare_template() if(strcmp(temp,"class")==0 || strcmp(temp,"struct")==0) { fpos_t fppreclassname; fgetpos(G__ifile.fp, &fppreclassname); - c = G__fgetstream_template(temp,":{;"); /* read template name */ + c = G__fgetstream_template(temp, 0, ":{;"); /* read template name */ bool haveFuncReturn = false; // whether we have "class A<T>::B f()" if(';'==c) { isforwarddecl = 1; @@ -1416,7 +1419,7 @@ void G__declare_template() haveFuncReturn = true; // put temp back onto the stream, get up to '<' fsetpos(G__ifile.fp, &fppreclassname); - c = G__fgetname_template(temp,"(<"); + c = G__fgetname_template(temp, 0, "(<"); } else fsetpos(G__ifile.fp, &fpprepeek); } @@ -1450,21 +1453,21 @@ void G__declare_template() * also the return value could be a pointer or reference or const * or any combination of the 3 * ^>^ */ - c = G__fgetstream_template(temp3,">"); - c = G__fgetname_template(temp2,"*&(;"); + c = G__fgetstream_template(temp3, 0, ">"); + c = G__fgetname_template(temp2, 0, "*&(;"); if (c=='*' && strncmp(temp2,"operator",strlen("operator"))==0) { - strcat(temp2,"*"); - c = G__fgetname_template(temp2+strlen(temp2),"*&(;="); + temp2 += "*"; + c = G__fgetname_template(temp2, strlen(temp2), "*&(;="); } else if (c=='&' && strncmp(temp2,"operator",strlen("operator"))==0) { - strcat(temp2,"&"); - c = G__fgetname_template(temp2+strlen(temp2),"*(;="); + temp2 += "&"; + c = G__fgetname_template(temp2, strlen(temp2), "*(;="); } while (c=='&'||c=='*') { /* we skip all the & and * we see and what's in between. This should be removed from the func name (what we are looking for) anything preceding combinations of *,& and const. */ - c = G__fgetname_template(temp2,"*&(;="); + c = G__fgetname_template(temp2, 0, "*&(;="); size_t len = strlen(temp2); static size_t oplen( strlen( "::operator" ) ); @@ -1472,29 +1475,29 @@ void G__declare_template() ||(len>=oplen && !strncmp(temp2+(len-oplen),"::operator",oplen))) && strchr("&*=", c)) { while (c=='&'||c=='*'||c=='=') { - temp2[len + 1] = 0; - temp2[len] = c; + temp2.Set(len + 1, 0); + temp2.Set(len, c); ++len; - c = G__fgetname_template(temp2 + len,"*&(;="); + c = G__fgetname_template(temp2, len, "*&(;="); } } } if(0==temp2[0]) { /* constructor template in class definition */ - strcat(temp,"<"); - strcat(temp,temp3); - strcat(temp,">"); + temp += "<"; + temp += temp3; + temp += ">"; } if(isspace(c)) { if(strcmp(temp2,"::~")==0) - c = G__fgetname_template(temp2+3,"(;"); + c = G__fgetname_template(temp2, 3, "(;"); else if(strcmp(temp2,"::")==0) - c = G__fgetname_template(temp2+2,"(;"); + c = G__fgetname_template(temp2, 2, "(;"); else if((p=strstr(temp2,"::"))&&strcmp(p,"::operator")==0) { /* A<T> A<T>::operator T () { } */ c='<'; /* this is a flag indicating this is a member function tmplt */ } else if(strcmp(temp2,"operator")==0) { - c = G__fgetstream(temp2+8,"("); + c = G__fgetstream(temp2, 8, "("); } } #ifdef G__OLDIMPLEMENTATION2157_YET @@ -1528,11 +1531,11 @@ void G__declare_template() if(p!=temp2) { p=strchr(temp2,'<'); *p='\0'; /* non constructor/destructor member function */ - strcpy(temp,temp2); + temp = temp2; } } else { - if(temp2[0]) strcpy(temp,temp2); + if(temp2[0]) temp = temp2; } } else if('<'==c) { @@ -1554,10 +1557,10 @@ void G__declare_template() G__disp_mask = 1000; fgetpos(G__ifile.fp,&posx); linex = G__ifile.line_number; - c=G__fgetname(temp,"&*(;<"); + c=G__fgetname(temp, 0, "&*(;<"); if(0==strcmp(temp,"const")) { G__constvar = G__CONSTVAR; - if(G__dispsource) G__fprinterr(G__serr,"%s",temp); + if(G__dispsource) G__fprinterr(G__serr,"%s",temp()); if(!isspace(c)) fseek(G__ifile.fp,-1,SEEK_CUR); } else { @@ -1565,7 +1568,7 @@ void G__declare_template() fsetpos(G__ifile.fp,&posx); G__ifile.line_number = linex; } - c=G__fgetstream(temp,"(;<"); + c=G__fgetstream(temp, 0, "(;<"); /* Judge by c? '(' global or '<' member */ } /* @@ -1594,18 +1597,12 @@ void G__declare_template() else if(isspace(c) && strcmp(temp,"operator")==0) { unsigned int len = 8; do { - temp[len++] = ' '; - temp[len] = '\0'; + temp.Set(len++, ' '); + temp.Set(len, 0); char* ptr = temp + len; - c=G__fgetname_template(ptr,"("); + c=G__fgetname_template(temp, ptr - temp.data(), "("); len = strlen(temp); - if (len >= G__LONGLINE) - { - temp[G__LONGLINE-1] = '\0'; - G__fprinterr(G__serr,"line too long. '%s'\n", temp); - break; - } } while (c != '('); } else if (c == '(' && strstr(temp,"::")) { @@ -1620,7 +1617,7 @@ void G__declare_template() posLastScope = posScope; std::string funcname(classname.substr(posLastScope + 2)); if (classname.compare(posLastScope - funcname.length(), funcname.length(), funcname) != 0) { - G__fprinterr(G__serr,"Error: expected templated constructor, got a templated function with a return type containing a '(': %s\n", temp); + G__fprinterr(G__serr,"Error: expected templated constructor, got a templated function with a return type containing a '(': %s\n", temp()); // try to ignore it... } else { // do nothing, just like for the in-class case. @@ -1630,15 +1627,15 @@ void G__declare_template() // template<..> inline|const type f(T a,S b) { ... } // ^ do { - c=G__fgetname_template(temp,"(<&*"); + c=G__fgetname_template(temp, 0, "(<&*"); if(strcmp(temp,"operator")==0) { if (isspace(c)){ - c=G__fgetstream(temp+8,"("); - if('('==c&&0==strcmp(temp,"operator(")) c=G__fgetname(temp+9,"("); + c=G__fgetstream(temp, 8, "("); + if('('==c&&0==strcmp(temp,"operator(")) c=G__fgetname(temp, 9, "("); } else if (c=='&' || c=='*') { - temp[8]=c; - temp[9]=0; - c=G__fgetstream(temp+9,"("); + temp.Set(8, c); + temp.Set(9, 0); + c=G__fgetstream(temp, 9, "("); } } } while('('!=c && '<'!=c) ; @@ -1663,12 +1660,12 @@ void G__declare_template() /* global function template */ if(strcmp(temp,"operator")==0) { /* in case of operator< operator<= operator<< */ - temp[8]=c; /* operator< */ - c=G__fgetstream(temp+9,"("); + temp.Set(8, c); /* operator< */ + c=G__fgetstream(temp, 9, "("); if (temp[8] == '(') { if (c == ')') { - temp[9] = c; - c=G__fgetstream(temp+10,"("); + temp.Set(9, c); + c=G__fgetstream(temp, 10, "("); } else { G__genericerror("Error: operator() overloading syntax error"); @@ -1809,42 +1806,30 @@ static void G__templatemaptypename(char *string) * * Returns a malloc'd string. **************************************************************************/ -char* G__expand_def_template_arg (char *str_in, G__Templatearg *def_para,G__Charlist * charlist) +static char* G__expand_def_template_arg (G__FastAllocString& str_in, G__Templatearg *def_para,G__Charlist * charlist) { - const char *punctuation=" \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; - int siz_out = strlen (str_in) * 2; - char* str_out; - char* temp; - int iout; - int iin; - int single_quote; - int double_quote; + static const char *punctuation=" \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; + G__FastAllocString str_out(strlen(str_in) * 2); + G__FastAllocString temp(str_out.Capacity()); + int iin = 0; + int iout = 0; + int single_quote = 0; + int double_quote = 0; char c; int isconst=0; - if (siz_out < 10) - siz_out = 10; - - temp = (char*) malloc (siz_out + 1); - - str_out = (char*) malloc (siz_out + 1); str_out[0] = 0; - iout = 0; - iin = 0; /* The text has been through the reader once, so we shouldn't have to worry about comments. We should still be prepared to handle quotes though. */ - single_quote = double_quote = 0; - do { - int lreslt; - char* reslt = temp; - c = G__getstream (str_in, &iin, temp, punctuation); + char* reslt = temp; + if (*reslt != '\0' && 0 == single_quote && 0 == double_quote) { struct G__Charlist* cl = charlist; struct G__Templatearg* ta = def_para; @@ -1860,50 +1845,47 @@ char* G__expand_def_template_arg (char *str_in, G__Templatearg *def_para,G__Char } } + int lreslt = strlen(reslt); /* ??? Does this handle backslash escapes properly? */ if('\''==c && 0==double_quote) single_quote = single_quote ^ 1 ; else if('"'==c && 0==single_quote) double_quote = double_quote ^ 1 ; - lreslt = strlen (reslt); - if (iout + lreslt + 1 > siz_out) { - siz_out = (iout + lreslt + 1) * 2; - str_out = (char*) realloc (str_out, siz_out + 1); - } - { - int rlen = strlen(reslt); if(isconst && strncmp(reslt,"const ",6)==0 && - rlen>0 && '*'==reslt[rlen-1]) { + lreslt>0 && '*'==reslt[lreslt-1]) { + str_out.Resize(lreslt + 6 + iout + 1 + 6); strcpy(str_out+iout,reslt+6); - strcat (str_out, " const"); + str_out += " const"; iout += lreslt; isconst=0; } else if (isconst && iout>=6 && strncmp(str_out+iout-6,"const ",6)==0 && - rlen>0 && '*'==reslt[rlen-1]) { + lreslt>0 && '*'==reslt[lreslt-1]) { + str_out.Resize(lreslt + iout - 6 + 1 + 6); strcpy(str_out+iout-6,reslt); - strcat(str_out, " const"); + str_out += " const"; iout += lreslt; isconst=0; } else { - strcpy (str_out + iout, reslt); + str_out.Resize(lreslt + iout + 1); + strcpy(str_out + iout, reslt); iout += lreslt; - if(strcmp(reslt,"const")==0 && ' '==c) isconst=1; + if (strcmp(reslt,"const")==0 && ' '==c) isconst=1; else isconst=0; } } - str_out[iout++] = c; + str_out.Set(iout++, c); } while (c != '\0'); - str_out[iout] = '\0'; - - free (temp); + str_out.Set(iout, 0); - return str_out; + char* out = (char*)malloc(iout + 1); + memcpy(out, str_out, iout + 1); + return out; } /************************************************************************** @@ -1919,8 +1901,8 @@ int G__gettemplatearglist(const char *paralist,G__Charlist *charlist_in struct G__Charlist *charlist = charlist_in; struct G__Templatearg *def_para = def_para_in; int isrc; - char string[G__LONGLINE]; - char temp[G__LONGLINE]; + G__FastAllocString string(G__LONGLINE); + G__FastAllocString temp(G__LONGLINE); int c; G__value buf; int searchflag=0; @@ -1940,15 +1922,15 @@ int G__gettemplatearglist(const char *paralist,G__Charlist *charlist_in isrc=0; while(','==c) { if('\0'==paralist[0]) break; - c = G__getstream_template(paralist,&isrc,string,",>\0"); + c = G__getstream_template(paralist,&isrc,string, 0, ",>\0"); if(def_para) { switch(def_para->type) { case G__TMPLT_CLASSARG: - strcpy(temp,string); + temp = string; G__templatemaptypename(temp); if(strcmp(temp,string)!=0) { searchflag=1; - strcpy(string,temp); + string.Swap(temp); } break; case G__TMPLT_TMPLTARG: @@ -2201,7 +2183,6 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) int typenum; int tagnum; int hash,temp; - char templatename[G__LONGLINE]; char *arg; struct G__Definedtemplateclass *deftmpclass; struct G__Charlist call_para; @@ -2211,7 +2192,6 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) int npara=0; int store_tagdefining; int store_def_tagnum; - char atom_name[G__LONGLINE]; int env_tagnum=G__get_envtagnum(); int scope_tagnum = -1; struct G__inheritance *baseclass; @@ -2223,8 +2203,7 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) #ifndef G__OLDIMPLEMENTATION1712 int store_templatearg_enclosedscope; #endif - char tagname[G__LONGLINE]; - strcpy(tagname,tagnamein); + G__FastAllocString tagname(tagnamein); typenum =G__defined_typename(tagname); if(-1!=typenum) return(G__newtype.tagnum[typenum]); @@ -2241,9 +2220,9 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) call_para.next = (struct G__Charlist*)NULL; /* separate template name and argument into templatename and arg */ - strcpy(templatename,tagname); + G__FastAllocString templatename(tagname); arg = strchr(templatename,'<'); - char cnull[1]; cnull[0]=0; + char cnull[1] = {0}; if(arg) { *arg='\0'; ++arg; @@ -2258,11 +2237,12 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) else baseclass = (struct G__inheritance*)NULL; + G__FastAllocString atom_name(templatename); + /* scope operator resolution, A::templatename<int> ... */ { char *patom; char *p; - strcpy(atom_name,templatename); patom = atom_name; while( (p=(char*)G__find_first_scope_operator(patom)) ) patom = p+2; if(patom==atom_name) { @@ -2274,8 +2254,8 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) if(strlen(atom_name)==0||strcmp(atom_name,"::")==0) scope_tagnum = -1; else scope_tagnum = G__defined_tagname(atom_name,0); p = atom_name; - while(*patom) *p++ = *patom++; - *p = 0; + while(*patom) atom_name.Set(p++ - atom_name, *patom++); + atom_name.Set(p - atom_name, 0); G__hash(atom_name,hash,temp) #define G__OLDIMPLEMENTATION1830 /* side effect t1011.h */ } @@ -2338,7 +2318,7 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) /* if no such template, error */ if(!deftmpclass->next) { if (noerror==0) { - G__fprinterr(G__serr,"Error: no such template %s",tagname); + G__fprinterr(G__serr,"Error: no such template %s",tagname()); G__genericerror((char*)NULL); } return(-1); @@ -2347,7 +2327,7 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) if(!deftmpclass->def_fp) { if (noerror==0) { G__fprinterr(G__serr,"Limitation: Can't instantiate precompiled template %s" - ,tagname); + ,tagname()); G__genericerror(NULL); } return(-1); @@ -2428,8 +2408,8 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) ) { int i=0; char *p = strrchr(templatename,':'); - while(*p) templatename[i++] = *(++p); - sprintf(tagname,"%s<%s",templatename,arg); + while(*p) templatename.Set(i++, *(++p)); + sprintf(tagname,"%s<%s",templatename(),arg); } /* resolve template specialization */ @@ -2527,7 +2507,7 @@ int G__instantiate_templateclass(const char *tagnamein, int noerror) * Replace template string and prerun * **************************************************************************/ -void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *callpara +void G__replacetemplate(const char* templatename,const char *tagname,G__Charlist *callpara ,FILE *def_fp,int line,int filenum,fpos_t *pdef_pos ,G__Templatearg *def_para,int isclasstemplate ,int npara @@ -2540,8 +2520,8 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call fpos_t pos; int c,c2; int mparen; - char symbol[G__LONGLINE]; - const char *punctuation=" \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; + G__FastAllocString symbol(G__LONGLINE); + static const char *punctuation=" \t\n;:=+-)(*&^%$#@!~'\"\\|][}{/?.>,<"; int double_quote=0,single_quote=0; struct G__input_file store_ifile; int store_prerun; @@ -2635,7 +2615,7 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call while(1) { G__disp_mask = 10000; SET_READINGFILE; /* ON777 */ - c = G__fgetstream(symbol,punctuation); + c = G__fgetstream(symbol, 0, punctuation); SET_WRITINGFILE; /* ON777 */ if('~'==c) isnew=1; else if(','==c) isnew=0; @@ -2667,23 +2647,27 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call if (c == '(') { // operator() () size_t len = strlen(symbol); + symbol.Resize(len + 2); symbol[len + 1] = 0; symbol[len] = '('; ++len; - c=G__fgetstream(symbol + len,")"); // add '(' + c=G__fgetstream(symbol, len, ")"); // add '(' len = strlen(symbol); + symbol.Resize(len + 2); symbol[len + 1] = 0; symbol[len] = ')'; ++len; - c=G__fgetstream(symbol + len, punctuation); // add ')' + c=G__fgetstream(symbol, len, punctuation); // add ')' } else if (c == '<') { // operator <, <=, << size_t len = strlen(symbol); + symbol.Resize(len + 2); symbol[len + 1] = 0; symbol[len] = '<'; ++len; c = G__fgetc(); if (c == '<' || c == '=') { + symbol.Resize(len + 2); symbol[len + 1] = 0; symbol[len] = c; c = G__fgetc(); @@ -2692,42 +2676,51 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call size_t len = strlen(symbol); size_t templsubst_upto = 8; do { + symbol.Resize(len + 2); symbol[len + 1] = 0; symbol[len] = c; ++len; c = G__fgetc(); // replace T of "operator T const*" - if(c && (c == ' ' || strchr(punctuation,c))) { - if (G__templatesubstitute(symbol + templsubst_upto + 1,callpara,def_para,templatename + if(len > templsubst_upto + 1 && c && (c == ' ' || strchr(punctuation,c))) { + G__FastAllocString subsubst(symbol + templsubst_upto + 1); + if (G__templatesubstitute(subsubst,callpara,def_para,templatename ,tagname,c,npara,1) && '>'!=c) { - char ignorebuf[G__LONGLINE]; - c=G__fgetstream(ignorebuf,">"); + G__FastAllocString ignorebuf(G__LONGLINE); + c=G__fgetstream(ignorebuf, 0, ">"); G__ASSERT('>'==c); c='>'; } + symbol.Set(templsubst_upto + 1, 0); + symbol += subsubst; len = strlen(symbol); templsubst_upto = len; } } while (c != '(' && c != '<'); // deficiency: no conversion to templated class // replace T of "operator const T" - if(symbol[templsubst_upto] == ' ' || strchr(punctuation, symbol[templsubst_upto])) - if (G__templatesubstitute(symbol + templsubst_upto + 1,callpara,def_para,templatename + if(len > templsubst_upto + 1 + && (symbol[templsubst_upto] == ' ' || strchr(punctuation, symbol[templsubst_upto]))) { + G__FastAllocString subsubst(symbol + templsubst_upto + 1); + if (G__templatesubstitute(subsubst,callpara,def_para,templatename ,tagname,c,npara,1) && '>'!=c) { - char ignorebuf[G__LONGLINE]; - c=G__fgetstream(ignorebuf,">"); + G__FastAllocString ignorebuf(G__LONGLINE); + c=G__fgetstream(ignorebuf, 0, ">"); G__ASSERT('>'==c); c='>'; } + symbol.Set(templsubst_upto + 1, 0); + symbol += subsubst; + } } SET_WRITINGFILE; /* ON777 */ isnew=1; } if(G__templatesubstitute(symbol,callpara,def_para,templatename ,tagname,c,npara,isnew) && '>'!=c) { - char ignorebuf[G__LONGLINE]; + G__FastAllocString ignorebuf(G__LONGLINE); SET_READINGFILE; /* ON777 */ - c=G__fgetstream(ignorebuf,">"); + c=G__fgetstream(ignorebuf, 0, ">"); SET_WRITINGFILE; /* ON777 */ G__ASSERT('>'==c); c='>'; @@ -2735,13 +2728,13 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call } if(const_c && '*'==symbol[strlen(symbol)-1]) { fsetpos(G__mfp,&const_pos); - fprintf(G__mfp,"%s",symbol); + fprintf(G__mfp,"%s",symbol()); fprintf(G__mfp," const%c",const_c); /* printing %c is not perfect */ const_c = 0; } else if(const_c&&(strstr(symbol,"*const")||strstr(symbol,"* const"))) { fsetpos(G__mfp,&const_pos); - fprintf(G__mfp,"%s",symbol); + fprintf(G__mfp,"%s",symbol()); fprintf(G__mfp,"%c",const_c); /* printing %c is not perfect */ const_c = 0; } @@ -2753,9 +2746,9 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call else { const_c = 0; } - fprintf(G__mfp,"%s",symbol); + fprintf(G__mfp,"%s",symbol()); } - if(G__dispsource) G__fprinterr(G__serr,"%s",symbol); + if(G__dispsource) G__fprinterr(G__serr,"%s",symbol()); } if(1==slash) { @@ -2764,8 +2757,8 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call SET_READINGFILE; /* ON777 */ G__fgetline(symbol); SET_WRITINGFILE; /* ON777 */ - fprintf(G__mfp,"/%s\n",symbol); - if(G__dispsource) G__fprinterr(G__serr,"/%s\n",symbol); + fprintf(G__mfp,"/%s\n",symbol()); + if(G__dispsource) G__fprinterr(G__serr,"/%s\n",symbol()); ++G__mline; continue; } @@ -2822,11 +2815,11 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call && ';'!=c ) { SET_READINGFILE; /* ON777 */ - G__fgetstream(symbol,";"); + G__fgetstream(symbol, 0, ";"); const_c = 0; SET_WRITINGFILE; /* ON777 */ - fprintf(G__mfp,"%s ;",symbol); - if(G__dispsource) G__fprinterr(G__serr,"%s ;",symbol); + fprintf(G__mfp,"%s ;",symbol()); + if(G__dispsource) G__fprinterr(G__serr,"%s ;",symbol()); } else if(';'==c) { fputc(c,G__mfp); @@ -2936,13 +2929,15 @@ void G__replacetemplate(char *templatename,const char *tagname,G__Charlist *call if(store_mfline) fsetpos(G__mfp,&store_mfpos); } +} // extern "C" + /************************************************************************** * G__templatesubstitute() * * Substitute macro argument * **************************************************************************/ -int G__templatesubstitute(char *symbol,G__Charlist *callpara +int G__templatesubstitute(G__FastAllocString& symbol,G__Charlist *callpara ,G__Templatearg *defpara,const char *templatename ,const char *tagname,int c,int npara ,int isnew @@ -2954,7 +2949,7 @@ int G__templatesubstitute(char *symbol,G__Charlist *callpara /* template name substitution */ if(strcmp(symbol,templatename)==0) { if('<'!=c) { - strcpy(symbol,tagname); + symbol = tagname; state=0; return(flag); } @@ -2967,10 +2962,10 @@ int G__templatesubstitute(char *symbol,G__Charlist *callpara while(defpara) { if(strcmp(defpara->string,symbol)==0) { if(callpara->string) { - strcpy(symbol,callpara->string); + symbol = callpara->string; } else if(defpara->default_parameter) { - strcpy(symbol,defpara->default_parameter); + symbol = defpara->default_parameter; } else { G__fprinterr(G__serr,"Error: template argument for %s missing" @@ -2982,9 +2977,8 @@ int G__templatesubstitute(char *symbol,G__Charlist *callpara ('*'==symbol[strlen(symbol)-1] || strchr(symbol,' ') || strchr(symbol,'<') ) ) { - char temp[G__LONGLINE]; - strcpy(temp,symbol); - sprintf(symbol,"(%s)",temp); + G__FastAllocString temp(symbol); + symbol.Format("(%s)",temp()); } if(state) { if(state==npara @@ -3003,11 +2997,13 @@ int G__templatesubstitute(char *symbol,G__Charlist *callpara } /* this is only workaround for STL Allocator */ - if(strcmp(symbol,"Allocator")==0) strcpy(symbol,G__Allocator); + if(strcmp(symbol,"Allocator")==0) symbol = G__Allocator; return(flag); } +extern "C" { + /************************************************************************** * G__freedeftemplateclass() **************************************************************************/ @@ -3169,7 +3165,7 @@ int G__matchtemplatefunc(G__Definetemplatefunc *deftmpfunc /* int fparadefault; */ int fargtmplt; int i; - char paratype[G__LONGLINE]; + G__FastAllocString paratype(G__LONGLINE); int *fntarg; int fnt; char **fntargc; @@ -3235,7 +3231,7 @@ int G__matchtemplatefunc(G__Definetemplatefunc *deftmpfunc if(bn>=0) basetagnum = G__struct.baseclass[tagnum]->herit[bn]->basetagnum; ++bn; bmatch=1; - strcpy(paratype,G__fulltagname(basetagnum,0)); + paratype = G__fulltagname(basetagnum,0); cntarg[cnt++]=paratype; /* T <x,E,y> */ p = strchr(paratype,'<'); if(!p) {/* unmatch */ @@ -3310,9 +3306,9 @@ int G__matchtemplatefunc(G__Definetemplatefunc *deftmpfunc } /* template argument (T a) */ if(G__PARAREFERENCE==reftype) - strcpy(paratype,G__type2string(type,tagnum,-1,0,0)); + paratype = G__type2string(type,tagnum,-1,0,0); else - strcpy(paratype,G__type2string(type,tagnum,-1,reftype,0)); + paratype = G__type2string(type,tagnum,-1,reftype,0); if(strncmp(paratype,"class ",6)==0) { int j=0,i=6; do { @@ -3473,7 +3469,7 @@ int G__templatefunc(G__value *result,const char *funcname,G__param *libp ); } - char clnull[1]; clnull[0]=0; + char clnull[1] = {0}; if(pexplicitarg) { int tmp=0; char *p = pexplicitarg-1; @@ -3553,8 +3549,8 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ struct G__Definetemplatefunc *deftmpfunc; /* fpos_t store_pos; */ /* int store_line; */ - char paraname[G__MAXNAME]; - char temp[G__LONGLINE]; + G__FastAllocString paraname(G__MAXNAME); + G__FastAllocString temp(G__LONGLINE); /* struct G__Templatearg *tmparg; */ int c,tmp; int unsigned_flag,reftype,pointlevel; @@ -3649,7 +3645,7 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ * ^ ^ */ do { /* read typename */ - c = G__fgetname_template(paraname,",)<*&="); + c = G__fgetname_template(paraname, 0, ",)<*&="); } while(strcmp(paraname,"class")==0 || strcmp(paraname,"struct")==0 || strcmp(paraname,"const")==0 || strcmp(paraname,"volatile")==0 || strcmp(paraname,"typename")==0 @@ -3660,18 +3656,18 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ /* template<class T,template<class U> class E> type func(T a,E<T> b) { * ^ ^ */ - /* if(isspace(c)) c = G__fgetname(temp,"<,()*&[="); */ + /* if(isspace(c)) c = G__fgetname(temp, 0, "<,()*&[="); */ /* template<class T,template<class U> class E> type func(T a,E<T> b) { * ^ ^ */ /* 1. function parameter, fixed fundamental type */ if(strcmp(paraname,"unsigned")==0) { unsigned_flag = -1; - if('*'!=c && '&'!=c) c = G__fgetname(paraname,",)*&="); + if('*'!=c && '&'!=c) c = G__fgetname(paraname, 0, ",)*&="); } else if(strcmp(paraname,"signed")==0) { unsigned_flag = 0; - if('*'!=c && '&'!=c) c = G__fgetname(paraname,",)*&="); + if('*'!=c && '&'!=c) c = G__fgetname(paraname, 0, ",)*&="); } if(strcmp(paraname,"int")==0) { deftmpfunc->func_para.type[tmp] = 'i' + unsigned_flag; @@ -3688,7 +3684,7 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ else if(strcmp(paraname,"long")==0) { deftmpfunc->func_para.type[tmp] = 'l' + unsigned_flag; if('*'!=c && '&'!=c) { - c = G__fgetname(paraname,",)*&[="); + c = G__fgetname(paraname, 0, ",)*&[="); if(strcmp(paraname,"double")==0) deftmpfunc->func_para.type[tmp]='d'; } } @@ -3738,7 +3734,7 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ } } ++nt; - c = G__fgetstream(paraname,",>"); + c = G__fgetstream(paraname, 0, ",>"); } while(','==c); if('>'==c) { ntarg[nt]=G__istemplatearg(paraname,deftmpfunc->def_para); @@ -3813,19 +3809,19 @@ int G__createtemplatefunc(char *funcname,G__Templatearg *targ break; case '[': c=G__fignorestream("]"); - c = G__fgetname(temp,",()*&[="); + c = G__fgetname(temp, 0, ",()*&[="); ++pointlevel; break; case '*': ++pointlevel; - c = G__fgetname(temp,",()*&[="); + c = G__fgetname(temp, 0, ",()*&[="); break; case '&': ++reftype; - c = G__fgetname(temp,",()*&[="); + c = G__fgetname(temp, 0, ",()*&[="); break; default: - c = G__fgetname(temp,",()*&[="); + c = G__fgetname(temp, 0, ",()*&[="); break; } } diff --git a/cint/cint/src/typedef.cxx b/cint/cint/src/typedef.cxx index 8c750f07b8c81dad07feab21026430c294bc52e6..a431cb25cbf1174ddce4254c828d5863b99735dd 100644 --- a/cint/cint/src/typedef.cxx +++ b/cint/cint/src/typedef.cxx @@ -52,16 +52,15 @@ static void G__shiftstring(char* s, int n) static int G__defined_typename_exact(char* type_name) { // Search already defined typedef names, -1 is returned if not found - int i, flag = 0, len; + int i, flag = 0; char ispointer = 0; - char temp[G__LONGLINE]; + int len = strlen(type_name) + 1; + G__FastAllocString temp(len); char *p; - char temp2[G__LONGLINE]; + G__FastAllocString temp2(type_name); int env_tagnum; char *par; - strcpy(temp2, type_name); - /* find 'xxx::yyy' */ p = (char*)G__find_last_scope_operator(temp2); @@ -70,7 +69,7 @@ static int G__defined_typename_exact(char* type_name) if (par && p && par < p) p = (char*)NULL; if (p) { - strcpy(temp, p + 2); + temp = p + 2; *p = '\0'; if (temp2 == p) env_tagnum = -1; /* global scope */ #ifndef G__STD_NAMESPACE @@ -88,7 +87,7 @@ static int G__defined_typename_exact(char* type_name) } } else { - strcpy(temp, temp2); + temp = temp2; env_tagnum = G__get_envtagnum(); } @@ -220,18 +219,17 @@ void G__define_type() // ^ fpos_t rewind_fpos; int c; - char type1[G__LONGLINE]; - char tagname[G__LONGLINE]; - char type_name[G__LONGLINE]; - char temp[G__LONGLINE]; + G__FastAllocString type1(G__LONGLINE); + G__FastAllocString tagname(G__LONGLINE); + G__FastAllocString type_name(G__LONGLINE); + G__FastAllocString temp(G__LONGLINE); int isnext; fpos_t next_fpos; int store_tagnum; int store_def_struct_member = 0; struct G__var_array* store_local; - char category[10]; - char memname[G__MAXNAME]; - char val[G__ONELINE]; + G__FastAllocString memname(G__MAXNAME); + G__FastAllocString val(G__ONELINE); char type; char tagtype = 0; int unsigned_flag = 0; @@ -245,7 +243,7 @@ void G__define_type() int itemp; int nindex = 0; int index[G__MAXVARDIM]; - char aryindex[G__MAXNAME]; + G__FastAllocString aryindex(G__MAXNAME); char* p; int store_var_type; int typenum; @@ -280,7 +278,7 @@ void G__define_type() * read type */ - c = G__fgetname_template(type1, "*{"); + c = G__fgetname_template(type1, 0, "*{"); if (c == '*') { strcat(type1, "*"); c = ' '; @@ -298,12 +296,12 @@ void G__define_type() if (!strcmp(type1, "const")) { isconst |= G__CONSTVAR; } - c = G__fgetname_template(type1, "{"); + c = G__fgetname_template(type1, 0, "{"); } if (!strcmp(type1, "::")) { // FIXME: This makes no sense, there cannot be typedef ::{...}; // skip a :: without a namespace in front of it (i.e. global namespace!) c = G__fgetspace(); // skip the next ':' - c = G__fgetname_template(type1, "{"); + c = G__fgetname_template(type1, 0, "{"); } if (!strncmp(type1, "::", 2)) { // Strip a leading :: (global namespace operator) // A leading '::' causes other typename matching functions to fail so @@ -319,14 +317,14 @@ void G__define_type() if (c == ':') { c = G__fgetspace(); // skip the next ':' strcat(type1, "::"); - c = G__fgetname_template(temp, "{"); + c = G__fgetname_template(temp, 0, "{"); strcat(type1, temp); } else if ((c == '<') || (c == ',') || (type1[len-1] == '<') || (type1[len-1] == ',')) { type1[len++] = c; do { // ignore white space inside template // humm .. thoes this translate correctly nested templates? - c = G__fgetstream_template(type1 + len, ">"); + c = G__fgetstream_template(type1, len, ">"); len = strlen(type1); } while (isspace(c)); @@ -355,11 +353,11 @@ void G__define_type() if (!strcmp(type1, "unsigned")) { unsigned_flag = 1; - c = G__fgetname(type1, ""); + c = G__fgetname(type1, 0, ""); } else if (!strcmp(type1, "signed")) { unsigned_flag = 0; - c = G__fgetname(type1, ""); + c = G__fgetname(type1, 0, ""); } else if (!strcmp(type1, "unsigned*")) { unsigned_flag = 1; @@ -451,7 +449,7 @@ void G__define_type() if (strcmp(type1, "class") == 0) tagtype = 'c'; if (strcmp(type1, "union") == 0) tagtype = 'u'; if (strcmp(type1, "enum") == 0) tagtype = 'e'; - tagname[0] = '\0'; + tagname[0] = 0; /* typedef [struct|union|enum]{ member } newtype; * ^ */ @@ -463,7 +461,7 @@ void G__define_type() * read tagname */ if (c != '{') { - c = G__fgetname(tagname, "{"); + c = G__fgetname(tagname, 0, "{"); } @@ -565,19 +563,21 @@ void G__define_type() tagtype = G__struct.type[itemp]; #ifndef G__OLDIMPLEMENTATION1503 if (G__struct.parent_tagnum[itemp] != -1) { - sprintf(tagname, "%s::%s", G__fulltagname(G__struct.parent_tagnum[itemp], 0), G__struct.name[itemp]); + tagname = G__fulltagname(G__struct.parent_tagnum[itemp], 0); + tagname += "::"; + tagname += G__struct.name[itemp]; } else { - strcpy(tagname, G__struct.name[itemp]); + tagname = G__struct.name[itemp]; } #else // G__OLDIMPLEMENTATION1503 - strcpy(tagname, G__fulltagname(itemp, 0)); + tagname = G__fulltagname(itemp, 0); #endif // G__OLDIMPLEMENTATION1503 ++G__struct.istypedefed[itemp]; } else { tagtype = 0; - tagname[0] = '\0'; + tagname[0] = 0; } typedef2 = 1; } @@ -593,10 +593,10 @@ void G__define_type() */ if (rawunsigned) { - strcpy(type_name, type1); + type_name = type1; } else { - c = G__fgetname_template(type_name, ";,["); + c = G__fgetname_template(type_name, 0, ";,["); } if ( @@ -624,8 +624,8 @@ void G__define_type() else if (type == 'k') { type = 'm'; } - strcpy(tagname, ""); - c = G__fgetname(type_name, ";,["); + tagname = ""; + c = G__fgetname(type_name, 0, ";,["); } if ( !strncmp(type_name, "double", strlen("double")) && @@ -648,9 +648,9 @@ void G__define_type() if (type == 'l') { // int tmptypenum; type = 'q'; - strcpy(tagname, ""); + tagname = ""; } - c = G__fgetname(type_name, ";,["); + c = G__fgetname(type_name, 0, ";,["); } /* in case of @@ -676,73 +676,73 @@ void G__define_type() long rewindlen = (strlen(type_name) + 1) - strlen("int"); fseek(G__ifile.fp, -rewindlen , SEEK_CUR); } - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); } if (!strcmp(type_name, "*")) { fpos_t tmppos; fgetpos(G__ifile.fp, &tmppos); int tmpline = G__ifile.line_number; - c = G__fgetname(type_name + 1, ";,["); + c = G__fgetname(type_name, 1, ";,["); if (isspace(c) && !strcmp(type_name, "*const")) { isconst |= G__PCONSTVAR; - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } else { G__disp_mask = strlen(type_name) - 1; G__ifile.line_number = tmpline; fsetpos(G__ifile.fp, &tmppos); - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } } else if (!strcmp(type_name, "**")) { fpos_t tmppos; fgetpos(G__ifile.fp, &tmppos); int tmpline = G__ifile.line_number; - c = G__fgetname(type_name + 1, ";,["); + c = G__fgetname(type_name, 1, ";,["); if (isspace(c) && !strcmp(type_name, "*const")) { isconst |= G__PCONSTVAR; - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } else { G__disp_mask = strlen(type_name) - 1; G__ifile.line_number = tmpline; fsetpos(G__ifile.fp, &tmppos); - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } isorgtypepointer = 1; type = toupper(type); } else if (!strcmp(type_name, "&")) { reftype = G__PARAREFERENCE; - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); } else if (!strcmp(type_name, "*&")) { reftype = G__PARAREFERENCE; type = toupper(type); - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); } else if (!strcmp(type_name, "*const")) { isconst |= G__PCONSTVAR; - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } #ifndef G__OLDIMPLEMENTATION1856 else if (!strcmp(type_name, "const*")) { isconst |= G__CONSTVAR; type = toupper(type); - c = G__fgetstream(type_name, "*&;,["); + c = G__fgetstream(type_name, 0, "*&;,["); if ((c == '*') && (type_name[0] != '*')) { if (!strcmp(type_name, "const")) { isconst |= G__CONSTVAR; } type_name[0] = '*'; - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } if ((c == '&') && (type_name[0] != '&')) { reftype = G__PARAREFERENCE; if (!strcmp(type_name, "const")) { isconst |= G__CONSTVAR; } - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); } } else if (!strcmp(type_name, "const**")) { @@ -750,27 +750,27 @@ void G__define_type() isorgtypepointer = 1; type = toupper(type); type_name[0] = '*'; - c = G__fgetstream(type_name + 1, "*;,["); + c = G__fgetstream(type_name, 1, "*;,["); } else if (!strcmp(type_name, "const*&")) { isconst |= G__CONSTVAR; reftype = G__PARAREFERENCE; type = toupper(type); - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); } #endif if (isspace(c)) { if ((type_name[0] == '(') && (c != ';') && (c != ',')) { do { - c = G__fgetstream(type_name + strlen(type_name), ";,"); - sprintf(type_name + strlen(type_name), "%c", c); + c = G__fgetstream(type_name, strlen(type_name), ";,"); + type_name.Set(strlen(type_name), c); } while ((c != ';') && (c != ',')); - type_name[strlen(type_name)-1] = '\0'; + type_name[strlen(type_name)-1] = 0; } else if (!strcmp(type_name, "const")) { isconst |= G__PCONSTVAR; - c = G__fgetstream(type_name, ";,["); + c = G__fgetstream(type_name, 0, ";,["); if (!strncmp(type_name, "*const*", 7)) { isconst |= G__CONSTVAR; isorgtypepointer = 1; @@ -791,11 +791,11 @@ void G__define_type() else if (!strcmp(type_name, "const*")) { isconst |= G__PCONSTVAR; type_name[0] = '*'; - c = G__fgetstream(type_name + 1, ";,["); + c = G__fgetstream(type_name, 1, ";,["); } else { - char ltemp1[G__LONGLINE]; - c = G__fgetstream(ltemp1, ";,["); + G__FastAllocString ltemp1(G__LONGLINE); + c = G__fgetstream(ltemp1, 0, ";,["); if (ltemp1[0] == '(') { type = 'q'; } @@ -810,7 +810,7 @@ void G__define_type() while (c == '[') { store_var_type = G__var_type; G__var_type = 'p'; - c = G__fgetstream(aryindex, "]"); + c = G__fgetstream(aryindex, 0, "]"); index[nindex++] = G__int(G__getexpr(aryindex)); c = G__fignorestream("[,;"); G__var_type = store_var_type; @@ -822,32 +822,32 @@ void G__define_type() if (p == type_name) { // function to pointer 'typedef type (*newtype)();' // handle this as 'typedef void* newtype;' - strcpy(val, p + 1); + val = p + 1; p = strchr(val, ')'); *p = '\0'; - strcpy(type_name, val); + type_name = val; type = 'y'; p = strstr(type_name, "::*"); if (p) { // pointer to member function 'typedef type (A::*p)(); - strcpy(val, p + 3); - strcpy(type_name, val); + val = p + 3; + type_name = val; type = 'a'; } } else if ((p == (type_name + 1)) && (type_name[0] == '*')) { // function to pointer 'typedef type *(*newtype)();' // handle this as 'typedef void* newtype;' - strcpy(val, p + 1); + val = p + 1; p = strchr(val, ')'); *p = '\0'; - strcpy(type_name, val); + type_name = val; type = 'Q'; p = strstr(type_name, "::*"); if (p) { // pointer to member function 'typedef type (A::*p)(); - strcpy(val, p + 3); - strcpy(type_name, val); + val = p + 3; + type_name = val; type = 'a'; } } @@ -902,8 +902,8 @@ void G__define_type() ++ix; } } - strcpy(val, type_name); - strcpy(type_name, val + ix); + val = type_name; + type_name = val + ix; } // typedef oldtype &newtype if (type_name[0] == '&') { @@ -914,8 +914,8 @@ void G__define_type() reftype = G__PARAREFERENCE; } if (strlen(type_name) > 1) { - strcpy(val, type_name); - strcpy(type_name, val + 1); + val = type_name; + type_name = val + 1; } } // @@ -968,10 +968,11 @@ void G__define_type() G__newtype.hash[typenum] = len; if (!tagname[0]) { if (G__globalcomp == G__CPPLINK) { - sprintf(tagname, "%s", type_name); + tagname = type_name; } else { - sprintf(tagname, "$%s", type_name); + tagname = "$"; + tagname += type_name; } taglen = strlen(tagname); } @@ -1027,13 +1028,13 @@ void G__define_type() G__constvar = G__CONSTVAR; G__enumdef = 1; do { - c = G__fgetstream(memname, "=,}"); + c = G__fgetstream(memname, 0, "=,}"); if (c == '=') { int store_prerun = G__prerun; char store_var_type = G__var_type; G__var_type = 'p'; G__prerun = 0; - c = G__fgetstream(val, ",}"); + c = G__fgetstream(val, 0, ",}"); enumval = G__getexpr(val); G__prerun = store_prerun; G__var_type = store_var_type; @@ -1065,20 +1066,9 @@ void G__define_type() // in case of struct,union // else { - switch (tagtype) { - case 's': - sprintf(category, "struct"); - break; - case 'c': - sprintf(category, "class"); - break; - case 'u': - sprintf(category, "union"); - break; - default: - /* enum already handled above */ - G__fprinterr(G__serr, "Error: Illegal tagtype. struct,union,enum expected\n"); - break; + if (tagtype != 's' && tagtype != 'c' && tagtype != 'u') { + /* enum already handled above */ + G__fprinterr(G__serr, "Error: Illegal tagtype. struct,union,enum expected\n"); } store_local = G__p_local; G__p_local = G__struct.memvar[G__tagnum]; @@ -1140,7 +1130,7 @@ void G__define_type() } if (isnext) { fsetpos(G__ifile.fp, &next_fpos); - c = G__fgetstream(type_name, ",;"); + c = G__fgetstream(type_name, 0, ",;"); goto next_name; } if (G__fons_comment) { @@ -1180,15 +1170,6 @@ int G__defined_typename_noerror(const char* type_name, int noerror) int i; int len; char ispointer = 0; -#ifndef G__OLDIMPLEMENTATION1823 - char buf[G__BUFLEN]; - char buf2[G__BUFLEN]; - char* temp = buf; - char* temp2 = buf2; -#else - char temp[G__LONGLINE]; - char temp2[G__LONGLINE]; -#endif char* p; int env_tagnum; int typenum = -1; @@ -1196,13 +1177,7 @@ int G__defined_typename_noerror(const char* type_name, int noerror) unsigned long thisflag = 0; char* par; -#ifndef G__OLDIMPLEMENTATION1823 - if (strlen(type_name) > (G__BUFLEN - 10)) { - temp2 = (char*) malloc(strlen(type_name) + 10); - temp = (char*) malloc(strlen(type_name) + 10); - } -#endif - strcpy(temp2, type_name); + G__FastAllocString temp2(type_name); // find 'xxx::yyy' // const ns::T - the const does not belong to the ns! @@ -1212,6 +1187,7 @@ int G__defined_typename_noerror(const char* type_name, int noerror) } p = (char*) G__find_last_scope_operator(skipconst); + G__FastAllocString temp(strlen(skipconst)); // abandon scope operator if 'zzz (xxx::yyy)www' par = strchr(skipconst, '('); @@ -1220,7 +1196,7 @@ int G__defined_typename_noerror(const char* type_name, int noerror) } if (p) { - strcpy(temp, p + 2); + temp = p + 2; *p = '\0'; if (skipconst == p) { env_tagnum = -1; // global scope @@ -1240,7 +1216,7 @@ int G__defined_typename_noerror(const char* type_name, int noerror) } } else { - strcpy(temp, skipconst); + temp = skipconst; env_tagnum = G__get_envtagnum(); } @@ -1308,14 +1284,6 @@ int G__defined_typename_noerror(const char* type_name, int noerror) } else { i = G__newtype.alltype; } -#ifndef G__OLDIMPLEMENTATION1823 - if (temp != buf) { - free(temp); - } - if (temp2 != buf2) { - free(temp2); - } -#endif return typenum; } @@ -1341,8 +1309,7 @@ int G__search_typename(const char* typenamein, int typein, int tagnum, int refty int i, flag = 0, len; char ispointer = 0; - char type_name[G__LONGLINE]; - strcpy(type_name, typenamein); + G__FastAllocString type_name(typenamein); /* keep uniqueness for pointer to function typedefs */ #ifndef G__OLDIMPLEMENTATION2191 if ('1' == typein) G__make_uniqueP2Ftypedef(type_name); diff --git a/cint/cint/src/val2a.cxx b/cint/cint/src/val2a.cxx index 759cc3cb0e50c450e0ab7ebe1056b6c055130cd3..067af15c56f1dfe322443e9b957c9a5ab4dbfda4 100644 --- a/cint/cint/src/val2a.cxx +++ b/cint/cint/src/val2a.cxx @@ -16,12 +16,10 @@ #include "common.h" #include "value.h" -extern "C" { - //______________________________________________________________________________ -char* G__valuemonitor(G__value buf, char* temp) +char* G__valuemonitor(G__value buf, G__FastAllocString& temp) { - char temp2[G__ONELINE]; + G__FastAllocString temp2(G__ONELINE); if (buf.typenum != -1) { switch (buf.type) { @@ -29,13 +27,13 @@ char* G__valuemonitor(G__value buf, char* temp) case 'f': /* typedef can be local to a class */ if (buf.obj.d < 0.0) - sprintf(temp, "(%s)(%.17e)" + temp.Format("(%s)(%.17e)" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0 , 0) , G__convertT<double>(&buf)); else - sprintf(temp, "(%s)%.17e" + temp.Format("(%s)%.17e" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0 , 0) @@ -43,27 +41,27 @@ char* G__valuemonitor(G__value buf, char* temp) break; case 'b': if (G__in_pause) - sprintf(temp, "(unsigned char)%u", G__convertT<unsigned char>(&buf)); + temp.Format("(unsigned char)%u", G__convertT<unsigned char>(&buf)); else - sprintf(temp, "(unsignedchar)%u", G__convertT<unsigned char>(&buf)); + temp.Format("(unsignedchar)%u", G__convertT<unsigned char>(&buf)); break; case 'r': if (G__in_pause) - sprintf(temp, "(unsigned short)%u", G__convertT<unsigned short>(&buf)); + temp.Format("(unsigned short)%u", G__convertT<unsigned short>(&buf)); else - sprintf(temp, "(unsignedshort)%u", G__convertT<unsigned short>(&buf)); + temp.Format("(unsignedshort)%u", G__convertT<unsigned short>(&buf)); break; case 'h': if (G__in_pause) - sprintf(temp, "(unsigned int)%u", G__convertT<unsigned int>(&buf)); + temp.Format("(unsigned int)%u", G__convertT<unsigned int>(&buf)); else - sprintf(temp, "(unsignedint)%u", G__convertT<unsigned int>(&buf)); + temp.Format("(unsignedint)%u", G__convertT<unsigned int>(&buf)); break; case 'k': if (G__in_pause) - sprintf(temp, "(unsigned long)%lu", G__convertT<unsigned long>(&buf)); + temp.Format("(unsigned long)%lu", G__convertT<unsigned long>(&buf)); else - sprintf(temp, "(unsignedlong)%lu", G__convertT<unsigned long>(&buf)); + temp.Format("(unsignedlong)%lu", G__convertT<unsigned long>(&buf)); break; default: if (islower(buf.type)) { @@ -73,37 +71,37 @@ char* G__valuemonitor(G__value buf, char* temp) strcmp(G__struct.name[buf.tagnum], "G__ulonglong") == 0 || strcmp(G__struct.name[buf.tagnum], "G__longdouble") == 0) { if (G__in_pause) { - char llbuf[100]; - sprintf(temp, "(%s)" + G__FastAllocString llbuf(100); + temp.Format("(%s)" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0)); if (strcmp(G__struct.name[buf.tagnum], "G__longlong") == 0) { - sprintf(llbuf - , "G__printformatll((char*)(%ld),\"%%lld\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatll((char*)(%ld),\"%%lld\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } else if (strcmp(G__struct.name[buf.tagnum], "G__ulonglong") == 0) { - sprintf(llbuf - , "G__printformatull((char*)(%ld),\"%%llu\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatull((char*)(%ld),\"%%llu\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } else if (strcmp(G__struct.name[buf.tagnum], "G__longdouble") == 0) { - sprintf(llbuf - , "G__printformatld((char*)(%ld),\"%%LG\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatld((char*)(%ld),\"%%LG\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } } else G__setiparseobject(&buf, temp); } else { - sprintf(temp, "(class %s)%ld" + temp.Format("(class %s)%ld" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0) , buf.obj.i); @@ -112,12 +110,12 @@ char* G__valuemonitor(G__value buf, char* temp) else #if defined(G__WIN32) if (buf.type == 'n' && buf.obj.ll < 0) - sprintf(temp, "(%s)(%I64d)" + temp.Format("(%s)(%I64d)" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0, 0) , buf.obj.ll); else if (buf.type == 'm' || buf.type == 'n') - sprintf(temp, "(%s)%I64u" + temp.Format("(%s)%I64u" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0, 0) , buf.obj.ull); @@ -125,12 +123,12 @@ char* G__valuemonitor(G__value buf, char* temp) else #else if (buf.type == 'n' && buf.obj.ll < 0) - sprintf(temp, "(%s)(%lld)" + temp.Format("(%s)(%lld)" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0, 0) , buf.obj.ll); else if (buf.type == 'm' || buf.type == 'n') - sprintf(temp, "(%s)%llu" + temp.Format("(%s)%llu" , G__type2string(buf.type , buf.tagnum , buf.typenum , 0, 0) , buf.obj.ull); @@ -138,12 +136,12 @@ char* G__valuemonitor(G__value buf, char* temp) else #endif if (buf.obj.i < 0) { - sprintf(temp, "(%s)(%ld)" + temp.Format("(%s)(%ld)" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0) , G__convertT<long>(&buf)); } else { - sprintf(temp, "(%s)%ld" + temp.Format("(%s)%ld" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0) , G__convertT<long>(&buf)); @@ -152,12 +150,12 @@ char* G__valuemonitor(G__value buf, char* temp) else { if ('C' == buf.type && G__in_pause && buf.obj.i > 0x10000 && G__PARANORMAL == buf.obj.reftype.reftype) - sprintf(temp, "(%s 0x%lx)\"%s\"" + temp.Format("(%s 0x%lx)\"%s\"" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0) , buf.obj.i, (char*)buf.obj.i); else - sprintf(temp, "(%s)0x%lx" + temp.Format("(%s)0x%lx" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0) , buf.obj.i); @@ -168,176 +166,177 @@ char* G__valuemonitor(G__value buf, char* temp) switch (buf.type) { case '\0': - sprintf(temp, "NULL"); + temp.Format("NULL"); break; case 'b': if (G__in_pause) - sprintf(temp, "(unsigned char)%u", G__convertT<unsigned char>(&buf)); + temp.Format("(unsigned char)%u", G__convertT<unsigned char>(&buf)); else - sprintf(temp, "(unsignedchar)%u", G__convertT<unsigned char>(&buf)); + temp.Format("(unsignedchar)%u", G__convertT<unsigned char>(&buf)); break; case 'B': if (G__in_pause) - sprintf(temp, "(unsigned char*)0x%lx", buf.obj.i); + temp.Format("(unsigned char*)0x%lx", buf.obj.i); else - sprintf(temp, "(unsignedchar*)0x%lx", buf.obj.i); + temp.Format("(unsignedchar*)0x%lx", buf.obj.i); break; case 'T': case 'C': if (buf.obj.i != 0) { if (G__in_pause && G__PARANORMAL == buf.obj.reftype.reftype) { if (strlen((char*)buf.obj.i) > G__ONELINE - 25) { + temp2.Resize(G__ONELINE - 24); strncpy(temp2, (char*)buf.obj.i, G__ONELINE - 25); temp2[G__ONELINE-25] = 0; - sprintf(temp, "(char* 0x%lx)\"%s\"...", buf.obj.i, temp2); + temp.Format("(char* 0x%lx)\"%s\"...", buf.obj.i, temp2()); } else { - G__add_quotation((char*)buf.obj.i, temp2); - sprintf(temp, "(char* 0x%lx)%s", buf.obj.i, temp2); + G__add_quotation((const char*)buf.obj.i, temp2); + temp.Format("(char* 0x%lx)%s", buf.obj.i, temp2()); } } else { - sprintf(temp, "(char*)0x%lx", buf.obj.i); + temp.Format("(char*)0x%lx", buf.obj.i); } } else { if (G__in_pause) - sprintf(temp, "(char* 0x0)\"\""); + temp.Format("(char* 0x0)\"\""); else - sprintf(temp, "(char*)0x0"); + temp.Format("(char*)0x0"); } break; case 'c': G__charaddquote(temp2, G__convertT<char>(&buf)); if (G__in_pause) - sprintf(temp, "(char %d)%s", G__convertT<char>(&buf), temp2); + temp.Format("(char %d)%s", G__convertT<char>(&buf), temp2()); else - sprintf(temp, "(char)%d", G__convertT<char>(&buf)); + temp.Format("(char)%d", G__convertT<char>(&buf)); break; case 'r': if (G__in_pause) - sprintf(temp, "(unsigned short)%u", G__convertT<unsigned short>(&buf)); + temp.Format("(unsigned short)%u", G__convertT<unsigned short>(&buf)); else - sprintf(temp, "(unsignedshort)%u", G__convertT<unsigned short>(&buf)); + temp.Format("(unsignedshort)%u", G__convertT<unsigned short>(&buf)); break; case 'R': if (G__in_pause) - sprintf(temp, "(unsigned short*)0x%lx", buf.obj.i); + temp.Format("(unsigned short*)0x%lx", buf.obj.i); else - sprintf(temp, "(unsignedshort*)0x%lx", buf.obj.i); + temp.Format("(unsignedshort*)0x%lx", buf.obj.i); break; case 's': if (buf.obj.i < 0) - sprintf(temp, "(short)(%d)", G__convertT<short>(&buf)); + temp.Format("(short)(%d)", G__convertT<short>(&buf)); else - sprintf(temp, "(short)%d", G__convertT<short>(&buf)); + temp.Format("(short)%d", G__convertT<short>(&buf)); break; case 'S': - sprintf(temp, "(short*)0x%lx", buf.obj.i); + temp.Format("(short*)0x%lx", buf.obj.i); break; case 'h': if (G__in_pause) - sprintf(temp, "(unsigned int)%u", G__convertT<unsigned int>(&buf)); + temp.Format("(unsigned int)%u", G__convertT<unsigned int>(&buf)); else - sprintf(temp, "(unsignedint)%u", G__convertT<unsigned int>(&buf)); + temp.Format("(unsignedint)%u", G__convertT<unsigned int>(&buf)); break; case 'H': if (G__in_pause) - sprintf(temp, "(unsigned int*)0x%lx", buf.obj.i); + temp.Format("(unsigned int*)0x%lx", buf.obj.i); else - sprintf(temp, "(unsignedint*)0x%lx", buf.obj.i); + temp.Format("(unsignedint*)0x%lx", buf.obj.i); break; case 'i': if (buf.tagnum != -1) { if (G__struct.type[buf.tagnum] == 'e') { if (buf.obj.i < 0) - sprintf(temp, "(enum %s)(%d)", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); + temp.Format("(enum %s)(%d)", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); else - sprintf(temp, "(enum %s)%d", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); + temp.Format("(enum %s)%d", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); } else { if (buf.obj.i < 0) - sprintf(temp, "(int)(%d)", G__convertT<int>(&buf)); + temp.Format("(int)(%d)", G__convertT<int>(&buf)); else - sprintf(temp, "(int)%d", G__convertT<int>(&buf)); + temp.Format("(int)%d", G__convertT<int>(&buf)); } } else { if (buf.obj.i < 0) - sprintf(temp, "(int)(%d)", G__convertT<int>(&buf)); + temp.Format("(int)(%d)", G__convertT<int>(&buf)); else - sprintf(temp, "(int)%d", G__convertT<int>(&buf)); + temp.Format("(int)%d", G__convertT<int>(&buf)); } break; case 'I': if (buf.tagnum != -1) { if (G__struct.type[buf.tagnum] == 'e') { - sprintf(temp, "(enum %s*)0x%lx", G__fulltagname(buf.tagnum, 1), buf.obj.i); + temp.Format("(enum %s*)0x%lx", G__fulltagname(buf.tagnum, 1), buf.obj.i); } else { - sprintf(temp, "(int*)0x%lx", buf.obj.i); + temp.Format("(int*)0x%lx", buf.obj.i); } } else { - sprintf(temp, "(int*)0x%lx", buf.obj.i); + temp.Format("(int*)0x%lx", buf.obj.i); } break; #if defined(G__WIN32) case 'n': if (buf.obj.ll < 0) - sprintf(temp, "(long long)(%I64d)", buf.obj.ll); + temp.Format("(long long)(%I64d)", buf.obj.ll); else - sprintf(temp, "(long long)%I64d", buf.obj.ll); + temp.Format("(long long)%I64d", buf.obj.ll); break; case 'm': - sprintf(temp, "(unsigned long long)%I64u", buf.obj.ull); + temp.Format("(unsigned long long)%I64u", buf.obj.ull); break; #else case 'n': if (buf.obj.ll < 0) - sprintf(temp, "(long long)(%lld)", buf.obj.ll); + temp.Format("(long long)(%lld)", buf.obj.ll); else - sprintf(temp, "(long long)%lld", buf.obj.ll); + temp.Format("(long long)%lld", buf.obj.ll); break; case 'm': - sprintf(temp, "(unsigned long long)%llu", buf.obj.ull); + temp.Format("(unsigned long long)%llu", buf.obj.ull); break; #endif case 'q': if (buf.obj.ld < 0) - sprintf(temp, "(long double)(%Lg)", buf.obj.ld); + temp.Format("(long double)(%Lg)", buf.obj.ld); else - sprintf(temp, "(long double)%Lg", buf.obj.ld); + temp.Format("(long double)%Lg", buf.obj.ld); break; case 'g': - sprintf(temp, "(bool)%d", G__convertT<bool>(&buf)); + temp.Format("(bool)%d", G__convertT<bool>(&buf)); break; case 'k': if (G__in_pause) - sprintf(temp, "(unsigned long)%lu", G__convertT<unsigned long>(&buf)); + temp.Format("(unsigned long)%lu", G__convertT<unsigned long>(&buf)); else - sprintf(temp, "(unsignedlong)%lu", G__convertT<unsigned long>(&buf)); + temp.Format("(unsignedlong)%lu", G__convertT<unsigned long>(&buf)); break; case 'K': if (G__in_pause) - sprintf(temp, "(unsigned long*)0x%lx", buf.obj.i); + temp.Format("(unsigned long*)0x%lx", buf.obj.i); else - sprintf(temp, "(unsignedlong*)0x%lx", buf.obj.i); + temp.Format("(unsignedlong*)0x%lx", buf.obj.i); break; case 'l': if (buf.obj.i < 0) - sprintf(temp, "(long)(%ld)", buf.obj.i); + temp.Format("(long)(%ld)", buf.obj.i); else - sprintf(temp, "(long)%ld", buf.obj.i); + temp.Format("(long)%ld", buf.obj.i); break; case 'L': - sprintf(temp, "(long*)0x%lx", buf.obj.i); + temp.Format("(long*)0x%lx", buf.obj.i); break; case 'y': if (buf.obj.i < 0) - sprintf(temp, "(void)(%ld)", buf.obj.i); + temp.Format("(void)(%ld)", buf.obj.i); else - sprintf(temp, "(void)%ld", buf.obj.i); + temp.Format("(void)%ld", buf.obj.i); break; #ifndef G__OLDIMPLEMENTATION2191 case '1': @@ -345,37 +344,37 @@ char* G__valuemonitor(G__value buf, char* temp) case 'Q': #endif case 'Y': - sprintf(temp, "(void*)0x%lx", buf.obj.i); + temp.Format("(void*)0x%lx", buf.obj.i); break; case 'E': - sprintf(temp, "(FILE*)0x%lx", buf.obj.i); + temp.Format("(FILE*)0x%lx", buf.obj.i); break; case 'd': if (buf.obj.d < 0.0) - sprintf(temp, "(double)(%.17e)", buf.obj.d); + temp.Format("(double)(%.17e)", buf.obj.d); else - sprintf(temp, "(double)%.17e", buf.obj.d); + temp.Format("(double)%.17e", buf.obj.d); break; case 'D': - sprintf(temp, "(double*)0x%lx", buf.obj.i); + temp.Format("(double*)0x%lx", buf.obj.i); break; case 'f': if (buf.obj.d < 0.0) - sprintf(temp, "(float)(%.17e)", buf.obj.d); + temp.Format("(float)(%.17e)", buf.obj.d); else - sprintf(temp, "(float)%.17e", buf.obj.d); + temp.Format("(float)%.17e", buf.obj.d); break; case 'F': - sprintf(temp, "(float*)0x%lx", buf.obj.i); + temp.Format("(float*)0x%lx", buf.obj.i); break; case 'u': switch (G__struct.type[buf.tagnum]) { case 's': if (buf.obj.i < 0) - sprintf(temp, "(struct %s)(%ld)" + temp.Format("(struct %s)(%ld)" , G__fulltagname(buf.tagnum, 1), buf.obj.i); else - sprintf(temp, "(struct %s)%ld" , G__fulltagname(buf.tagnum, 1), buf.obj.i); + temp.Format("(struct %s)%ld" , G__fulltagname(buf.tagnum, 1), buf.obj.i); break; case 'c': if (-1 != buf.tagnum && @@ -383,30 +382,30 @@ char* G__valuemonitor(G__value buf, char* temp) strcmp(G__struct.name[buf.tagnum], "G__ulonglong") == 0 || strcmp(G__struct.name[buf.tagnum], "G__longdouble") == 0)) { if (G__in_pause) { - char llbuf[100]; - sprintf(temp, "(%s)" + G__FastAllocString llbuf(100); + temp.Format("(%s)" , G__type2string(buf.type , buf.tagnum , buf.typenum , buf.obj.reftype.reftype, 0)); if (strcmp(G__struct.name[buf.tagnum], "G__longlong") == 0) { - sprintf(llbuf - , "G__printformatll((char*)(%ld),\"%%lld\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatll((char*)(%ld),\"%%lld\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } else if (strcmp(G__struct.name[buf.tagnum], "G__ulonglong") == 0) { - sprintf(llbuf - , "G__printformatull((char*)(%ld),\"%%llu\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatull((char*)(%ld),\"%%llu\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } else if (strcmp(G__struct.name[buf.tagnum], "G__longdouble") == 0) { - sprintf(llbuf - , "G__printformatld((char*)(%ld),\"%%LG\",(void*)(%ld))" - , (long)llbuf, buf.obj.i); + llbuf.Format( + "G__printformatld((char*)(%ld),\"%%LG\",(void*)(%ld))" + , (long)(llbuf()), buf.obj.i); G__getitem(llbuf); - strcat(temp, llbuf); + temp += llbuf; } } else @@ -414,73 +413,75 @@ char* G__valuemonitor(G__value buf, char* temp) } else if (buf.obj.i < 0) - sprintf(temp, "(class %s)(%ld)" + temp.Format("(class %s)(%ld)" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); else - sprintf(temp, "(class %s)%ld" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); + temp.Format("(class %s)%ld" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); break; case 'u': if (buf.obj.i < 0) - sprintf(temp, "(union %s)(%ld)" + temp.Format("(union %s)(%ld)" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); else - sprintf(temp, "(union %s)%ld" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); + temp.Format("(union %s)%ld" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); break; case 'e': - sprintf(temp, "(enum %s)%d", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); + temp.Format("(enum %s)%d", G__fulltagname(buf.tagnum, 1), G__convertT<int>(&buf)); break; default: if (buf.obj.i < 0) - sprintf(temp, "(unknown %s)(%ld)" + temp.Format("(unknown %s)(%ld)" , G__struct.name[buf.tagnum] , buf.obj.i); else - sprintf(temp, "(unknown %s)%ld" , G__struct.name[buf.tagnum] , buf.obj.i); + temp.Format("(unknown %s)%ld" , G__struct.name[buf.tagnum] , buf.obj.i); break; } break; case 'U': switch (G__struct.type[buf.tagnum]) { case 's': - sprintf(temp, "(struct %s*)0x%lx" , G__fulltagname(buf.tagnum, 1), buf.obj.i); + temp.Format("(struct %s*)0x%lx" , G__fulltagname(buf.tagnum, 1), buf.obj.i); break; case 'c': - sprintf(temp, "(class %s*)0x%lx" , G__fulltagname(buf.tagnum, 1), buf.obj.i); + temp.Format("(class %s*)0x%lx" , G__fulltagname(buf.tagnum, 1), buf.obj.i); break; case 'u': - sprintf(temp, "(union %s*)0x%lx" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); + temp.Format("(union %s*)0x%lx" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); break; case 'e': - sprintf(temp, "(enum %s*)0x%lx" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); + temp.Format("(enum %s*)0x%lx" , G__fulltagname(buf.tagnum, 1) , buf.obj.i); break; default: - sprintf(temp, "(unknown %s*)0x%lx", G__fulltagname(buf.tagnum, 1), buf.obj.i); + temp.Format("(unknown %s*)0x%lx", G__fulltagname(buf.tagnum, 1), buf.obj.i); break; } break; case 'w': G__logicstring(buf, 1, temp2); - sprintf(temp, "(logic)0b%s", temp2); + temp.Format("(logic)0b%s", temp2()); break; default: if (buf.obj.i < 0) - sprintf(temp, "(unknown)(%ld)", buf.obj.i); + temp.Format("(unknown)(%ld)", buf.obj.i); else - sprintf(temp, "(unknown)%ld", buf.obj.i); + temp.Format("(unknown)%ld", buf.obj.i); break; } if (isupper(buf.type)) { int i; char *p; - char sbuf[G__ONELINE]; + size_t lentemp = strlen(temp); + G__FastAllocString sbuf(lentemp); + temp.Resize(lentemp + 3 + buf.obj.reftype.reftype - G__PARAP2P - 1); p = strchr(temp, '*'); switch (buf.obj.reftype.reftype) { case G__PARAP2P: - strcpy(sbuf, p); + sbuf = p; strcpy(p + 1, sbuf); break; case G__PARAP2P2P: - strcpy(sbuf, p); + sbuf = p; *(p + 1) = '*'; strcpy(p + 2, sbuf); break; @@ -497,6 +498,8 @@ char* G__valuemonitor(G__value buf, char* temp) return(temp); } +extern "C" { + //______________________________________________________________________________ const char* G__access2string(int caccess) { @@ -1030,7 +1033,7 @@ long double G__atolf(const char* expr) //______________________________________________________________________________ char* G__getbase(unsigned int expression, int base, int digit, char* result1) { - char result[G__MAXNAME]; + G__FastAllocString result(G__MAXNAME); int ig18 = 0, ig28 = 0; unsigned int onedig, value; /* bug fix 3 mar 1993 */ @@ -1038,7 +1041,7 @@ char* G__getbase(unsigned int expression, int base, int digit, char* result1) while ((ig28 < digit) || ((digit == 0) && (value != 0))) { onedig = value % base ; - result[ig28] = G__getdigit(onedig); + result.Set(ig28, G__getdigit(onedig)); value = (value - onedig) / base; ig28++ ; } @@ -1630,8 +1633,8 @@ int G__isvalue(const char* temp) //______________________________________________________________________________ G__value G__string2type_body(const char* typenamin, int noerror) { - char typenam[G__MAXNAME*2]; - char temp[G__MAXNAME*2]; + G__FastAllocString typenam(typenamin); + G__FastAllocString temp(G__MAXNAME*2); int len; int plevel = 0; int rlevel = 0; @@ -1642,8 +1645,6 @@ G__value G__string2type_body(const char* typenamin, int noerror) result = G__null; - strcpy(typenam, typenamin); - // 20/04/07 // We need G__get_methodhandle to be able to find functions that // have an ellipsis as the declared parameter. But that thing @@ -1655,25 +1656,25 @@ G__value G__string2type_body(const char* typenamin, int noerror) } if (strncmp(typenam, "volatile ", 9) == 0) { - strcpy(temp, typenam + 9); - strcpy(typenam, temp); + temp = typenam + 9; + typenam.Swap(temp); } else if (strncmp(typenam, "volatile", 8) == 0) { - strcpy(temp, typenam + 8); - strcpy(typenam, temp); + temp = typenam + 8; + typenam.Swap(temp); } if (strncmp(typenam, "const ", 6) == 0) { - strcpy(temp, typenam + 6); - strcpy(typenam, temp); + temp = typenam + 6; + typenam.Swap(temp); isconst = G__CONSTVAR; } else if (strncmp(typenam, "const", 5) == 0 && -1 == G__defined_tagname(typenam, 2) && -1 == G__defined_typename(typenam)) { - strcpy(temp, typenam + 5); - strcpy(typenam, temp); + temp = typenam + 5; + typenam.Swap(temp); isconst = 1; } diff --git a/cint/cint/src/value.cxx b/cint/cint/src/value.cxx index 5916fae5939fafd32deb1df68553bf1931a91b9a..a6d823f4d22b847b94ca3b3348ea40a54602944c 100644 --- a/cint/cint/src/value.cxx +++ b/cint/cint/src/value.cxx @@ -435,7 +435,6 @@ G__value G__tovalue(G__value p) break; case 'u': { - char refopr[G__MAXNAME]; long store_struct_offsetX = G__store_struct_offset; int store_tagnumX = G__tagnum; int done=0; @@ -456,7 +455,7 @@ G__value G__tovalue(G__value p) } #endif G__tagnum = p.tagnum; - strcpy(refopr,"operator*()"); + G__FastAllocString refopr("operator*()"); result=G__getfunction(refopr,&done,G__TRYMEMFUNC); G__tagnum = store_tagnumX; G__store_struct_offset = store_struct_offsetX; @@ -558,7 +557,6 @@ G__value G__letvalue(G__value *p,G__value result) case 'u': { G__value para; - char refopr[G__MAXNAME]; long store_struct_offsetX = G__store_struct_offset; int store_tagnumX = G__tagnum; int done=0; @@ -587,7 +585,7 @@ G__value G__letvalue(G__value *p,G__value result) #endif G__store_struct_offset = p->obj.i; G__tagnum = p->tagnum; - strcpy(refopr,"operator*()"); + G__FastAllocString refopr("operator*()"); para=G__getfunction(refopr,&done,G__TRYMEMFUNC); G__tagnum = store_tagnumX; G__store_struct_offset = store_struct_offsetX; @@ -666,7 +664,6 @@ G__value G__letvalue(G__value *p,G__value result) case 'u': { G__value para; - char refopr[G__MAXNAME]; long store_struct_offsetX = G__store_struct_offset; int store_tagnumX = G__tagnum; int done=0; @@ -694,7 +691,7 @@ G__value G__letvalue(G__value *p,G__value result) #endif G__store_struct_offset = p->obj.i; G__tagnum = p->tagnum; - strcpy(refopr,"operator*()"); + G__FastAllocString refopr("operator*()"); para=G__getfunction(refopr,&done,G__TRYMEMFUNC); G__tagnum = store_tagnumX; G__store_struct_offset = store_struct_offsetX; diff --git a/cint/cint/src/var.cxx b/cint/cint/src/var.cxx index 17306754952e0a14cd2f1910d8ff2f73ede1e509..8890b745ade00859cb4b2335a83e14b994b2b041 100644 --- a/cint/cint/src/var.cxx +++ b/cint/cint/src/var.cxx @@ -103,10 +103,10 @@ static void G__class_2nd_decl(G__var_array* var, int ig15) } int store_decl = G__decl; G__decl = 0; - char temp[G__ONELINE]; - sprintf(temp, "~%s()", G__struct.name[tagnum]); + G__FastAllocString temp(G__ONELINE); + temp.Format("~%s()", G__struct.name[tagnum]); if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp, var->varnamebuf[ig15]); + G__fprinterr(G__serr, "\n!!!Calling destructor 0x%lx.%s for declaration of %s", G__store_struct_offset, temp(), var->varnamebuf[ig15]); } if (G__struct.iscpplink[tagnum] == G__CPPLINK) { // Delete current object. @@ -187,8 +187,8 @@ static void G__class_2nd_decl_i(G__var_array* var, int ig15) #endif // G__ASM_DBG G__asm_inst[G__asm_cp] = G__SETSTROS; G__inc_cp_asm(1, 0); - char temp[G__ONELINE]; - sprintf(temp, "~%s()", G__struct.name[G__tagnum]); + G__FastAllocString temp(G__ONELINE); + temp.Format("~%s()", G__struct.name[G__tagnum]); if (var->varlabel[ig15][1] /* number of elements */ || var->paran[ig15]) { // array int size = G__struct.size[G__tagnum]; @@ -261,8 +261,8 @@ static void G__class_2nd_decl_c(G__var_array* var, int ig15) #endif // G__ASM_DBG G__asm_inst[G__asm_cp] = G__SETSTROS; G__inc_cp_asm(1, 0); - char temp[G__ONELINE]; - sprintf(temp, "~%s()", G__struct.name[G__tagnum]); + G__FastAllocString temp(G__ONELINE); + temp.Format("~%s()", G__struct.name[G__tagnum]); int known = 0; G__getfunction(temp, &known, G__TRYDESTRUCTOR); G__redecl(var, ig15); @@ -421,9 +421,6 @@ static void G__getpointer2pointer(G__value* presult, G__var_array* var, int ig15 break; \ } \ G__var_type = 'p'; \ - if (vv != varname) { \ - free(varname); \ - } \ return result; //______________________________________________________________________________ @@ -551,12 +548,11 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal int store_no_exec = 0; int store_getarraydim = 0; int store_asm_noverflow = 0; - char ttt[G__ONELINE]; - char result7[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); + G__FastAllocString result7(G__ONELINE); char parameter[G__MAXVARDIM][G__ONELINE]; G__value para[G__MAXVARDIM]; - char vv[G__BUFLEN]; - char* varname = vv; + G__FastAllocString varname(G__BUFLEN); //-- G__value result = G__null; #ifdef G__ASM @@ -580,13 +576,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal #endif // G__ASM parameter[0][0] = '\0'; lenitem = std::strlen(item); - if (lenitem > (G__BUFLEN - 10)) { - varname = (char*) malloc(lenitem + 20); - } - if (!varname) { - G__genericerror("Internal error: malloc, G__letvariable(), varname"); - return G__null; - } switch (item[0]) { case '*': // value of pointer @@ -601,9 +590,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal result = G__getexpr(item + 1); G__ASSERT(isupper(result.type) || (result.type == 'u')); G__value tmp = G__letPvalue(&result, expression); - if (vv != varname) { - free((void*) varname); - } return tmp; } { @@ -625,7 +611,7 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal G__reftype = G__PARAP2P + pointlevel - 2; break; } - strcpy(ttt, item + i - 1); + ttt = item + i - 1; strcpy(item, ttt); if (G__var_type == 'p') { G__var_type = 'v'; @@ -643,21 +629,15 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal result = G__getfunction(item, &ig15, G__TRYNORMAL); if (result.isconst & G__CONSTVAR) { G__changeconsterror(item, "ignored const"); - if (vv != varname) { - free((void*) varname); - } return result; } G__value tmp = G__letVvalue(&result, expression); - if (vv != varname) { - free((void*)varname); - } return tmp; } case '&': // -- Should not happen! G__var_type = 'P'; - strcpy(ttt, item + 1); + ttt = item + 1; strcpy(item, ttt); break; case '0': @@ -687,8 +667,8 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal switch (item[ig2]) { case '.': if (!paren && !double_quote && !single_quote) { - strcpy(result7, item); - result7[ig2++] = '\0'; + result7 = item; + result7.Set(ig2++, 0); tagname = result7; membername = result7 + ig2; flag = 1; @@ -696,9 +676,9 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal break; case '-': if (!paren && !double_quote && !single_quote && (item[ig2+1] == '>')) { - strcpy(result7, item); - result7[ig2++] = '\0'; - result7[ig2++] = '\0'; + result7 = item; + result7.Set(ig2++, 0); + result7.Set(ig2++, 0); tagname = result7; membername = result7 + ig2; flag = 2; @@ -739,9 +719,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal paren = 0; if (flag) { result = G__letstructmem(store_var_type, varname, membername, tagname, varglobal, expression, flag, member); - if (varname != vv) { - free(varname); - } return result; } /************************************************************ @@ -773,7 +750,7 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal // -- The identifier is terminated by function parameters or array indexes. break; } - varname[item_cursor] = c; + varname.Set(item_cursor, c); varhash += c; ++item_cursor; } @@ -789,16 +766,13 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal else { para[0] = G__getfunction(item, &found, G__TRYNORMAL); } - if (vv != varname) { - free(varname); - } if (found) { para[1] = G__letVvalue(¶[0], expression); return para[1]; } return G__null; } - varname[item_cursor] = '\0'; + varname.Set(item_cursor, 0); // Get any specified array indexes. // FIXME: Why do we allow curly braces here? paran = 0; @@ -991,20 +965,17 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal (G__tagnum != -1) && (G__struct.iscpplink[G__tagnum] == G__CPPLINK) ) { - char protect_temp[G__ONELINE]; + G__FastAllocString protect_temp(G__ONELINE); long protect_struct_offset = G__store_struct_offset; int done = 0; G__store_struct_offset = G__globalvarpointer; G__globalvarpointer = G__PVOID; - std::sprintf(protect_temp, "~%s()", G__struct.name[G__tagnum]); - G__fprinterr(G__serr, ". %s called\n", protect_temp); + protect_temp.Format("~%s()", G__struct.name[G__tagnum]); + G__fprinterr(G__serr, ". %s called\n", protect_temp()); G__getfunction(protect_temp, &done, G__TRYDESTRUCTOR); G__store_struct_offset = protect_struct_offset; } G__genericerror(0); - if (vv != varname) { - std::free((void*) varname); - } return G__null; } } else if (var->statictype[ig15] == G__LOCALSTATIC && var->p_tagtable[ig15]!=-1 && var->type[ig15]=='u') { @@ -1018,10 +989,10 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal // (this is inpired from code in G__define_var if ( G__struct.iscpplink[var->p_tagtable[ig15]] == G__CPPLINK) { // -- The struct is compiled code. - char temp1[G__ONELINE]; + G__FastAllocString temp1(G__ONELINE); G__value reg = G__null; int known; - sprintf(temp1, "%s()", G__struct.name[var->p_tagtable[ig15]]); + temp1.Format("%s()", G__struct.name[var->p_tagtable[ig15]]); if (G__struct.parent_tagnum[var->p_tagtable[ig15]] != -1) { int store_exec_memberfunc = G__exec_memberfunc; int store_memberfunc_tagnum = G__memberfunc_tagnum; @@ -1048,10 +1019,10 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal else { // -- The struct is interpreted. // Initialize it. - char temp1[G__ONELINE]; + G__FastAllocString temp1(G__ONELINE); // G__value reg = G__null; // int known; - sprintf(temp1, "new %s", G__struct.name[var->p_tagtable[ig15]]); + temp1.Format("new %s", G__struct.name[var->p_tagtable[ig15]]); int store_exec_memberfunc = G__exec_memberfunc; int store_memberfunc_tagnum = G__memberfunc_tagnum; @@ -1186,9 +1157,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal result.typenum = var->p_typetable[ig15]; result.ref = var->p[ig15]; G__var_type = 'p'; - if (vv != varname) { - free((void*) varname); - } return result; } exec_asm_letvar: @@ -1226,9 +1194,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal if (G__reftype && (G__globalvarpointer != G__PVOID)) { var->p[ig15] = G__globalvarpointer; } - if (vv != varname) { - free(varname); - } return result; } // In case of duplicate declaration, make it normal assignment. @@ -1266,9 +1231,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal ) { G__changeconsterror(var->varnamebuf[ig15], "ignored const"); G__var_type = 'p'; - if (vv != varname) { - free(varname); - } return result; } } @@ -1284,9 +1246,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal ) { G__changeconsterror(var->varnamebuf[ig15], "ignored const"); G__var_type = 'p'; - if (vv != varname) { - free(varname); - } return result; } } @@ -1371,9 +1330,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal } } G__var_type = 'p'; - if (vv != varname) { - free((void*)varname); - } return result; } #endif // G__ASM @@ -1396,9 +1352,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal ) ) { G__arrayindexerror(ig15, var, item, linear_index); - if (vv != varname) { - std::free((void*) varname); - } return expression; } #ifdef G__SECURITY @@ -1411,9 +1364,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal ((*((long*)(G__struct_offset + var->p[ig15]))) == 0) ) { G__assign_error(item, &result); - if (vv != varname) { - std::free((void*) varname); - } return G__null; } #endif // G__SECURITY @@ -1450,11 +1400,11 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal // -- ) ) { - G__CHECK(G__SECURE_POINTER_TYPE, 0 != result.obj.i, {if (vv != varname) free(varname); return G__null;}); + G__CHECK(G__SECURE_POINTER_TYPE, 0 != result.obj.i, return G__null); } } - G__CHECK(G__SECURE_POINTER_AS_ARRAY, (var->paran[ig15] < paran && isupper(var->type[ig15])), {if (vv != varname)free((void*)varname);return G__null;}); - G__CHECK(G__SECURE_POINTER_ASSIGN, var->paran[ig15] > paran || isupper(var->type[ig15]), {if (vv != varname)free((void*)varname);return G__null;}); + G__CHECK(G__SECURE_POINTER_AS_ARRAY, (var->paran[ig15] < paran && isupper(var->type[ig15])), return G__null); + G__CHECK(G__SECURE_POINTER_ASSIGN, var->paran[ig15] > paran || isupper(var->type[ig15]), return G__null); #ifdef G__SECURITY if ( G__security & G__SECURE_GARBAGECOLLECTION && @@ -1489,9 +1439,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal mask = mask << var->varlabel[ig15][G__MAXVARDIM-1]; finalval = (original & (~mask)) + ((result.obj.i << var->varlabel[ig15][G__MAXVARDIM-1]) & mask); *((int*) address) = finalval; - if (vv != varname) { - std::free((void*) varname); - } return result; } // @@ -1553,9 +1500,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal // Change the variable into a fixed-size array of characters. var->varlabel[ig15][1] = len; // And return, we are done. - if (vv != varname) { - std::free(varname); - } return result; } G__ASSIGN_VAR(G__CHARALLOC, char, G__int, result.obj.i); @@ -1661,9 +1605,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal G__letint(&result, 'u', result.ref); G__tryindexopr(&result, para, paran, ig25); para[0] = G__letVvalue(&result, expression); - if (vv != varname) { - std::free(varname); - } return para[0]; } else { @@ -1696,9 +1637,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal G__letint(&result, 'u', result.ref); G__tryindexopr(&result, para, paran, ig25); para[0] = G__letVvalue(&result, expression); - if (vv != varname) { - std::free(varname); - } return para[0]; } else { @@ -1754,9 +1692,6 @@ G__value G__letvariable(char* item, G__value expression, G__var_array* varglobal result = G__allocvariable(result, para, varglobal, varlocal, paran, varhash, item, varname, parameter[0][0], member); } G__var_type = 'p'; - if (vv != varname) { - std::free(varname); - } return result; } @@ -1926,8 +1861,7 @@ G__value G__letstructmem(int store_var_type, char* varname, char* membername, ch !strncmp(G__struct.name[result.tagnum], "auto_ptr<", 9) ) { int knownx = 0; - char comm[20]; - strcpy(comm, "operator->()"); + G__FastAllocString comm("operator->()"); result = G__getfunction(comm, &knownx, G__TRYMEMFUNC); if (knownx) { G__tagnum = result.tagnum; @@ -2044,8 +1978,8 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 // and try to call operator=(). It may not be required to search for // non member operator=() function, so, some part of these functions // could be omitted. - char tmp[G__ONELINE]; - char result7[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); + G__FastAllocString result7(G__ONELINE); int ig2 = 0; long store_struct_offset = 0; int largestep = 0; @@ -2101,10 +2035,10 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 ) ) { if (result->obj.i) { - sprintf(tmp, "(%s)(%ld)", G__fulltagname(result->tagnum, 1), result->obj.i); + tmp.Format("(%s)(%ld)", G__fulltagname(result->tagnum, 1), result->obj.i); } else { - sprintf(tmp, "(%s)%ld", G__fulltagname(result->tagnum, 1), result->obj.i); + tmp.Format("(%s)%ld", G__fulltagname(result->tagnum, 1), result->obj.i); } } else { @@ -2113,13 +2047,13 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 G__ASSERT(!G__decl || (G__decl == 1)); if (G__decl) { // -- Copy constructor. - sprintf(result7, "%s(%s)", G__struct.name[var->p_tagtable[ig15]], tmp); + result7.Format("%s(%s)", G__struct.name[var->p_tagtable[ig15]], tmp()); store_tagnum = G__tagnum; G__tagnum = var->p_tagtable[ig15]; store_struct_offset = G__store_struct_offset; G__store_struct_offset = (G__struct_offset + var->p[ig15] + (linear_index * G__struct.size[var->p_tagtable[ig15]])); if (G__dispsource) { - G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration", G__store_struct_offset , result7); + G__fprinterr(G__serr, "\n!!!Calling constructor 0x%lx.%s for declaration", G__store_struct_offset , result7()); } #ifdef G__SECURITY G__castcheckoff = 1; @@ -2154,7 +2088,7 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 } } else if (!ig2 && (result->type == 'U')) { - G__fprinterr(G__serr, "Error: Constructor %s not found", result7); + G__fprinterr(G__serr, "Error: Constructor %s not found", result7()); G__genericerror(0); } } @@ -2209,7 +2143,7 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 // // Search for member function. // - sprintf(result7, "operator=(%s)" , tmp); + result7.Format("operator=(%s)" , tmp()); store_tagnum = G__tagnum; G__tagnum = var->p_tagtable[ig15]; store_struct_offset = G__store_struct_offset; @@ -2218,7 +2152,7 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 para = G__getfunction(result7, &ig2 , G__TRYMEMFUNC); if (!ig2 && (G__tagnum != result->tagnum)) { // -- Copy constructor. - sprintf(result7, "%s(%s)", G__struct.name[G__tagnum], tmp); + result7.Format("%s(%s)", G__struct.name[G__tagnum], tmp()); if (G__struct.iscpplink[G__tagnum] == G__CPPLINK) { G__abortbytecode(); long store_globalvarpointer = G__globalvarpointer; @@ -2249,10 +2183,10 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 #endif // G__ASM addr = G__struct_offset + var->p[ig15] + (linear_index * G__struct.size[var->p_tagtable[ig15]]); if (addr < 0) { - sprintf(result7, "operator=((%s)(%ld),%s)", G__fulltagname(var->p_tagtable[ig15], 1), addr, tmp); + result7.Format("operator=((%s)(%ld),%s)", G__fulltagname(var->p_tagtable[ig15], 1), addr, tmp()); } else { - sprintf(result7, "operator=((%s)%ld,%s)", G__fulltagname(var->p_tagtable[ig15], 1), addr, tmp); + result7.Format("operator=((%s)%ld,%s)", G__fulltagname(var->p_tagtable[ig15], 1), addr, tmp()); } para = G__getfunction(result7, &ig2, G__TRYNORMAL); } @@ -2357,7 +2291,7 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 break; } if (G__var_type == 'v') { - char refopr[G__MAXNAME]; + G__FastAllocString refopr(G__MAXNAME); long store_struct_offsetX = G__store_struct_offset; int store_tagnumX = G__tagnum; int done = 0; @@ -2400,7 +2334,7 @@ void G__letstruct(G__value* result, int linear_index, G__var_array* var, int ig1 G__inc_cp_asm(1, 0); } #endif // G__ASM - strcpy(refopr, "operator*()"); + refopr = "operator*()"; para = G__getfunction(refopr, &done, G__TRYMEMFUNC); G__tagnum = store_tagnumX; G__store_struct_offset = store_struct_offsetX; @@ -2572,16 +2506,8 @@ void G__letstructp(G__value result, long G__struct_offset, int ig15, int linear_ G__value G__classassign(long pdest, int tagnum, G__value result) { // -- FIXME: Describe me! -#ifndef G__OLDIMPLEMENTATION1823 - char buf[G__BUFLEN*2]; - char buf2[G__BUFLEN*2]; - char* ttt = buf; - char* result7 = buf2; - int lenttt; -#else // G__OLDIMPLEMENTATION1823 - char ttt[G__ONELINE]; - char result7[G__ONELINE]; -#endif // G__OLDIMPLEMENTATION1823 + G__FastAllocString ttt(G__ONELINE); + G__FastAllocString result7(G__ONELINE); long store_struct_offset = 0; int store_tagnum = -1; int ig2 = 0; @@ -2595,22 +2521,12 @@ G__value G__classassign(long pdest, int tagnum, G__value result) } if (result.type == 'u') { // -- -#ifndef G__OLDIMPLEMENTATION1823 - char* xp = G__fulltagname(result.tagnum, 1); - lenttt = strlen(xp); - if (lenttt > (2 * G__BUFLEN) - 10) { - ttt = (char*) malloc(lenttt + 20); - result7 = (char*) malloc(lenttt + 30); - } - G__setiparseobject(&result, ttt); -#else // G__OLDIMPLEMENTATION1823 if (result.obj.i < 0) { - sprintf(ttt, "(%s)(%ld)", G__struct.name[result.tagnum], result.obj.i); + ttt.Format("(%s)(%ld)", G__struct.name[result.tagnum], result.obj.i); } else { - sprintf(ttt, "(%s)%ld", G__struct.name[result.tagnum], result.obj.i); + ttt.Format("(%s)%ld", G__struct.name[result.tagnum], result.obj.i); } -#endif // G__OLDIMPLEMENTATION1823 // -- } else { @@ -2676,7 +2592,7 @@ G__value G__classassign(long pdest, int tagnum, G__value result) G__oprovld = 1; #endif // G__ASM // searching for member function - sprintf(result7, "operator=(%s)", ttt); + result7.Format("operator=(%s)", ttt()); store_tagnum = G__tagnum; G__tagnum = tagnum; store_struct_offset = G__store_struct_offset; @@ -2688,25 +2604,7 @@ G__value G__classassign(long pdest, int tagnum, G__value result) // copy constructor // long store_globalvarpointer = 0L; -#ifndef G__OLDIMPLEMENTATION1823 - char* xp2 = G__fulltagname(tagnum, 1); - lenttt = strlen(ttt); - int len2 = strlen(xp2) + lenttt + 10; - if (buf2 == result7) { - if (len2 > (2 * G__BUFLEN)) { - result7 = (char*) malloc(len2); - } - } - else { - if (len2 > (lenttt + 30)) { - free((void*) result7); - result7 = (char*) malloc(len2); - } - } - sprintf(result7, "%s(%s)", xp2, ttt); -#else // G__OLDIMPLEMENTATION1823 - sprintf(result7, "%s(%s)", G__struct.name[tagnum], ttt); -#endif // G__OLDIMPLEMENTATION1823 + result7.Format("%s(%s)", G__struct.name[tagnum], ttt()); if (G__struct.iscpplink[tagnum] == G__CPPLINK) { G__abortbytecode(); store_globalvarpointer = G__globalvarpointer; @@ -2736,10 +2634,10 @@ G__value G__classassign(long pdest, int tagnum, G__value result) } #endif // G__ASM if (pdest < 0) { - sprintf(result7, "operator=((%s)(%ld),%s)", G__fulltagname(tagnum, 1), pdest, ttt); + result7.Format("operator=((%s)(%ld),%s)", G__fulltagname(tagnum, 1), pdest, ttt()); } else { - sprintf(result7, "operator=((%s)%ld,%s)", G__fulltagname(tagnum, 1), pdest, ttt); + result7.Format("operator=((%s)%ld,%s)", G__fulltagname(tagnum, 1), pdest, ttt()); } para = G__getfunction(result7, &ig2 , G__TRYNORMAL); #ifdef G__ASM @@ -2774,14 +2672,6 @@ G__value G__classassign(long pdest, int tagnum, G__value result) #endif // G__ASM if (ig2) { // in case overloaded = or constructor is found -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != ttt) { - free((void*)ttt); - } - if (buf2 != result7) { - free((void*)result7); - } -#endif // G__OLDIMPLEMENTATION1823 return para; } // in case no overloaded = or constructor, memberwise copy. @@ -2823,28 +2713,12 @@ G__value G__classassign(long pdest, int tagnum, G__value result) int done = G__class_conversion_operator(tagnum, &result, ttt); if (done) { // -- -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != ttt) { - free((void*)ttt); - } - if (buf2 != result7) { - free((void*)result7); - } -#endif // G__OLDIMPLEMENTATION1823 return G__classassign(pdest, tagnum, result); } } // Return from this function if this is pure bytecode compilation. if (G__no_exec_compile) { // -- -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != ttt) { - free((void*)ttt); - } - if (buf2 != result7) { - free((void*)result7); - } -#endif // G__OLDIMPLEMENTATION1823 return result; } #endif // G__ASM @@ -2860,14 +2734,6 @@ G__value G__classassign(long pdest, int tagnum, G__value result) else { G__fprinterr(G__serr, "Error: Assignment type incompatible FILE:%s LINE:%d\n", G__ifile.name, G__ifile.line_number); } -#ifndef G__OLDIMPLEMENTATION1823 - if (buf != ttt) { - free((void*)ttt); - } - if (buf2 != result7) { - free((void*)result7); - } -#endif // G__OLDIMPLEMENTATION1823 return result; } @@ -2894,15 +2760,15 @@ int G__class_conversion_operator(int tagnum, G__value* presult, char* /*ttt*/) G__var_type = 'p'; G__store_struct_offset = presult->obj.i; // Synthesize function name. - char tmp[G__ONELINE]; - strcpy(tmp, "operator "); - strcpy(tmp + 9, G__struct.name[tagnum]); - strcpy(tmp + strlen(tmp), "()"); + G__FastAllocString tmp(G__ONELINE); + tmp = "operator "; + tmp += G__struct.name[tagnum]; + tmp += "()"; // Call conversion operator. conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); if (conv_done) { if (G__dispsource) { - G__fprinterr(G__serr, "!!!Conversion operator called 0x%lx.%s\n", G__store_struct_offset, tmp); + G__fprinterr(G__serr, "!!!Conversion operator called 0x%lx.%s\n", G__store_struct_offset, tmp()); } #ifdef G__ASM G__abortbytecode(); @@ -2927,7 +2793,7 @@ int G__fundamental_conversion_operator(int type, int tagnum, int typenum, int re // // Note: Bytecode compilation is alive after conversion operator is used. // - char tmp[G__ONELINE]; + G__FastAllocString tmp(G__ONELINE); G__value conv_result; int conv_done = 0; int conv_tagnum = G__tagnum; @@ -2962,27 +2828,30 @@ int G__fundamental_conversion_operator(int type, int tagnum, int typenum, int re G__inc_cp_asm(1, 0); #endif // G__ASM // Synthesize function name. - strcpy(tmp, "operator "); - strcpy(tmp + 9, G__type2string(type, tagnum, typenum, reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp = "operator "; + tmp += G__type2string(type, tagnum, typenum, reftype, constvar); + tmp += "()"; // Call conversion operator. conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); if (!conv_done && (typenum != -1)) { // Make another try after removing typedef alias. - strcpy(tmp + 9, G__type2string(type, -1, -1 , reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp[9] = 0; + tmp += G__type2string(type, -1, -1 , reftype, constvar); + tmp += "()"; conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); } if (!conv_done) { // Make another try constness reverting. constvar ^= 1; - strcpy(tmp + 9, G__type2string(type, tagnum, typenum, reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp[9] = 0; + tmp += G__type2string(type, tagnum, typenum, reftype, constvar); + tmp += "()"; conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); if (!conv_done && (typenum != -1)) { // Make another try after removing typedef alias. - strcpy(tmp + 9, G__type2string(type, -1, -1 , reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp[9] = 0; + tmp += G__type2string(type, -1, -1 , reftype, constvar); + tmp += "()"; conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); } } @@ -2993,13 +2862,15 @@ int G__fundamental_conversion_operator(int type, int tagnum, int typenum, int re if ((type == G__newtype.type[itype]) && (tagnum == G__newtype.tagnum[itype])) { constvar ^= 1; - strcpy(tmp + 9, G__type2string(type, tagnum, itype, reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp[9] = 0; + tmp += G__type2string(type, tagnum, itype, reftype, constvar); + tmp += "()"; conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); if (!conv_done) { constvar ^= 1; - strcpy(tmp + 9, G__type2string(type, tagnum, typenum, reftype, constvar)); - strcpy(tmp + strlen(tmp), "()"); + tmp[9] = 0; + tmp += G__type2string(type, tagnum, typenum, reftype, constvar); + tmp += "()"; conv_result = G__getfunction(tmp, &conv_done , G__TRYMEMFUNC); } if (conv_done) { @@ -3010,7 +2881,7 @@ int G__fundamental_conversion_operator(int type, int tagnum, int typenum, int re } if (conv_done) { if (G__dispsource) { - G__fprinterr(G__serr, "!!!Conversion operator called 0x%lx.%s\n", G__store_struct_offset, tmp); + G__fprinterr(G__serr, "!!!Conversion operator called 0x%lx.%s\n", G__store_struct_offset, tmp()); } *presult = conv_result; #ifdef G__ASM @@ -3533,20 +3404,20 @@ static G__value G__allocvariable(G__value result, G__value para[], G__var_array* // array named varname\funcname. The // variable can be exclusively accessed // with in a specific function. - char ttt[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); #ifdef G__NEWINHERIT if (G__p_ifunc->tagnum != -1) { - sprintf(ttt, "%s\\%x\\%x\\%x", varname, G__func_page, G__func_now, G__p_ifunc->tagnum); + ttt.Format("%s\\%x\\%x\\%x", varname, G__func_page, G__func_now, G__p_ifunc->tagnum); } else { - sprintf(ttt, "%s\\%x\\%x", varname, G__func_page, G__func_now); + ttt.Format("%s\\%x\\%x", varname, G__func_page, G__func_now); } #else // G__NEWINHERIT if (G__p_ifunc->basetagnum[G__func_now] != -1) { - sprintf(ttt, "%s\\%x\\%x\\%x", varname, G__func_page, G__func_now, G__p_ifunc->basetagnum[G__func_now]); + ttt.Format("%s\\%x\\%x\\%x", varname, G__func_page, G__func_now, G__p_ifunc->basetagnum[G__func_now]); } else { - sprintf(ttt, "%s\\%x\\%x", varname, G__func_page, G__func_now); + ttt.Format("%s\\%x\\%x", varname, G__func_page, G__func_now); } #endif // G__NEWINHERIT std::strcpy(varname, ttt); @@ -4072,7 +3943,7 @@ static G__value G__allocvariable(G__value result, G__value para[], G__var_array* // -- Try to convert the initializer (result), which is of class type, to the type of the variable. int store_decl = G__decl; G__decl = 0; - char ttt[G__ONELINE]; + G__FastAllocString ttt(G__ONELINE); G__fundamental_conversion_operator(var->type[ig15], var->p_tagtable[ig15], var->p_typetable[ig15], var->reftype[ig15], var->constvar[ig15], &result, ttt); G__decl = store_decl; } @@ -5199,6 +5070,7 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ int posbracket = 0; int posparenthesis = 0; G__value result = G__null; + G__FastAllocString varname(2*G__MAXNAME); #ifdef G__ASM // // If we are called by running bytecode, @@ -5325,12 +5197,11 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ // -- This is a member of struct or union accessed by member reference. if (!paren && !double_quote && !single_quote) { // To get full struct member name path when not found. - char tmp[G__ONELINE]; - strcpy(tmp, item); + G__FastAllocString tmp(item); tmp[i++] = '\0'; char* tagname = tmp; char* membername = tmp + i; - char varname[2*G__MAXNAME]; + G__FastAllocString varname(2*G__MAXNAME); G__value val = G__getstructmem(store_var_type, varname, membername, tagname, known, varglobal, 1); return val; } @@ -5339,13 +5210,13 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ // -- This is a member of struct or union accessed by pointer dereference. if (!paren && !double_quote && !single_quote && (item[i+1] == '>')) { // To get full struct member name path when not found. - char tmp[G__ONELINE]; + G__FastAllocString tmp(i + 2); strncpy(tmp, item, i); tmp[i++] = '\0'; tmp[i++] = '\0'; char* tagname = tmp; char* membername = item + i; - char varname[2*G__MAXNAME]; + G__FastAllocString varname(2*G__MAXNAME); G__value val = G__getstructmem(store_var_type, varname, membername, tagname, known, varglobal, 2); return val; } @@ -5401,13 +5272,12 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ // our caller set G__store_struct_offset. G__struct_offset = G__store_struct_offset; } - char varname[2*G__MAXNAME]; { // Collect the variable name and hash value, // stop at parenthesis or square brackets. int cursor = 0; for (cursor = 0; (item[cursor] != '(') && (item[cursor] != '[') && (cursor < lenitem); ++cursor) { - varname[cursor] = item[cursor]; + varname.Set(cursor, item[cursor]); varhash += item[cursor]; } if (item[cursor] == '(') { @@ -5426,7 +5296,7 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ *known = 1; return val; } - varname[cursor++] = '\0'; + varname.Set(cursor++, 0); if (cursor == 1) { // -- No variable name, only an array index. G__getvariable_error(item); @@ -5544,12 +5414,12 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ // var = G__searchvariable(varname, varhash, varlocal, varglobal, &G__struct_offset, &store_struct_offset, &ig15, 0); if (!var && (G__prerun || G__eval_localstatic) && (G__func_now >= 0)) { - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); if (G__tagdefining != -1) { - sprintf(temp, "%s\\%x\\%x\\%x", varname, G__func_page, G__func_now, G__tagdefining); + temp.Format("%s\\%x\\%x\\%x", varname(), G__func_page, G__func_now, G__tagdefining); } else { - sprintf(temp, "%s\\%x\\%x", varname, G__func_page, G__func_now); + temp.Format("%s\\%x\\%x", varname(), G__func_page, G__func_now); } int itmpx = 0; G__hash(temp, varhash, itmpx); @@ -6048,7 +5918,6 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ default : // return value if (G__var_type == 'v') { - char refopr[G__MAXNAME]; long store_struct_offsetX = G__store_struct_offset; int store_tagnumX = G__tagnum; int done = 0; @@ -6058,7 +5927,7 @@ G__value G__getvariable(char* item, int* known, G__var_array* varglobal, G__var_ G__asm_noverflow = 0; G__store_struct_offset = (long) (G__struct_offset + var->p[ig15] + (linear_index * G__struct.size[var->p_tagtable[ig15]])); G__tagnum = var->p_tagtable[ig15]; - strcpy(refopr, "operator*()"); + G__FastAllocString refopr("operator*()"); result = G__getfunction(refopr, &done, G__TRYMEMFUNC); G__asm_exec = store_asm_exec; G__asm_noverflow = store_asm_noverflow; @@ -6607,8 +6476,7 @@ G__value G__getstructmem(int store_var_type, char* varname, char* membername, ch !strncmp(G__struct.name[result.tagnum], "auto_ptr<", 9) ) { int knownx = 0; - char comm[20]; - strcpy(comm, "operator->()"); + G__FastAllocString comm("operator->()"); result = G__getfunction(comm, &knownx, G__TRYMEMFUNC); if (knownx) { G__tagnum = result.tagnum; @@ -7404,8 +7272,7 @@ struct G__var_array* G__searchvariable(char* varname, int varhash, G__var_array* //-- #ifdef G__ROOT if ((varname[0] == '$') && G__GetSpecialObject && (G__GetSpecialObject != G__getreserved)) { - char temp[G__MAXNAME]; - strcpy(temp, varname + 1); + G__FastAllocString temp(varname + 1); strcpy(varname, temp); specialflag = 1; } @@ -7663,14 +7530,14 @@ int G__deletevariable(const char* varname) int i; int done; int store_tagnum; - char temp[G__ONELINE]; + G__FastAllocString temp(G__ONELINE); switch (var->type[ig15]) { case 'u': store_struct_offset = G__store_struct_offset; store_tagnum = G__tagnum; G__store_struct_offset = var->p[ig15]; G__tagnum = var->p_tagtable[ig15]; - sprintf(temp, "~%s()", var->varnamebuf[ig15]); + temp.Format("~%s()", var->varnamebuf[ig15]); // destruction of array if (G__struct.iscpplink[G__tagnum] == G__CPPLINK) { G__store_struct_offset = var->p[ig15]; @@ -7692,7 +7559,7 @@ int G__deletevariable(const char* varname) for (; i >= 0; --i) { G__store_struct_offset = var->p[ig15] + (i * size); if (G__dispsource) { - G__fprinterr(G__serr, "\n0x%lx.%s", G__store_struct_offset, temp); + G__fprinterr(G__serr, "\n0x%lx.%s", G__store_struct_offset, temp()); } done = 0; G__getfunction(temp, &done, G__TRYDESTRUCTOR);