diff options
Diffstat (limited to 'src')
35 files changed, 405 insertions, 571 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt index 5b97a6a94..3aec39b9b 100644 --- a/src/kvilib/CMakeLists.txt +++ b/src/kvilib/CMakeLists.txt @@ -60,7 +60,6 @@ SET(kvilib_SRCS core/KviHeapObject.cpp core/kvi_hstrEqualCIN.cpp core/KviMemory.cpp - core/kvi_memmove.cpp core/KviQString.cpp core/KviCString.cpp ext/KviCommandFormatter.cpp diff --git a/src/kvilib/core/KviCString.cpp b/src/kvilib/core/KviCString.cpp index fb24e87d5..8a4e7a668 100644 --- a/src/kvilib/core/KviCString.cpp +++ b/src/kvilib/core/KviCString.cpp @@ -27,7 +27,7 @@ #define _KVI_STRING_CPP_ #include "KviCString.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMemory.h" #include "KviQString.h" @@ -57,7 +57,7 @@ WORKING CODE, COMMENTED OUT BECAUSE NOT USED AND GENERATES WARNINGS // %W = KviWStr pointer : can't be NULL! // %Q = QString pointer : can't be NULL! -#define _WSTRING_WMEMCPY(_dst,_src,_len) kvi_fastmoveodd((void *)(_dst),(const void *)(_src),sizeof(kvi_wchar_t) * (_len)) +#define _WSTRING_WMEMCPY(_dst,_src,_len) KviMemory::copy((void *)(_dst),(const void *)(_src),sizeof(kvi_wchar_t) * (_len)) #define _WSTRING_STRLEN(_str) kvi_strLen(_str) #define WVSNPRINTF_BODY \ @@ -639,7 +639,7 @@ const char * kvi_extractToken(KviCString &str,const char *aux_ptr,char sep) while(*p && (*p != sep))p++; str.m_len=p-aux_ptr; str.m_ptr = (char *)KviMemory::reallocate(str.m_ptr,str.m_len+1); - kvi_fastmove(str.m_ptr,aux_ptr,str.m_len); + KviMemory::copy(str.m_ptr,aux_ptr,str.m_len); *(str.m_ptr+str.m_len)='\0'; while(*p && (*p == sep))p++; return p; @@ -652,7 +652,7 @@ const char * kvi_extractUpTo(KviCString &str,const char *aux_ptr,char sep) while(*p && (*p != sep))p++; str.m_len=p-aux_ptr; str.m_ptr = (char *)KviMemory::reallocate(str.m_ptr,str.m_len+1); - kvi_fastmove(str.m_ptr,aux_ptr,str.m_len); + KviMemory::copy(str.m_ptr,aux_ptr,str.m_len); *(str.m_ptr+str.m_len)='\0'; return p; } @@ -1043,7 +1043,7 @@ KviCString::KviCString(const char *str) //Deep copy m_len = (int)strlen(str); m_ptr = (char *)KviMemory::allocate(m_len+1); - kvi_fastmove(m_ptr,str,m_len+1); + KviMemory::copy(m_ptr,str,m_len+1); } else { m_ptr = (char *)KviMemory::allocate(1); *m_ptr = '\0'; @@ -1059,7 +1059,7 @@ KviCString::KviCString(const QByteArray &str) //Deep copy m_len = str.length(); m_ptr = (char *)KviMemory::allocate(m_len+1); - kvi_fastmove(m_ptr,str,m_len+1); + KviMemory::copy(m_ptr,str,m_len+1); } else { m_ptr = (char *)KviMemory::allocate(1); *m_ptr = '\0'; @@ -1075,7 +1075,7 @@ KviCString::KviCString(const char *str,int len) KVI_ASSERT(len >= 0); m_len = len; m_ptr = (char *)KviMemory::allocate(m_len+1); - kvi_fastmove(m_ptr,str,m_len); + KviMemory::copy(m_ptr,str,m_len); *(m_ptr+m_len) = '\0'; } @@ -1086,7 +1086,7 @@ KviCString::KviCString(const char *bg,const char *end) KVI_ASSERT(bg <= end); m_len = end-bg; m_ptr = (char *)KviMemory::allocate(m_len +1); - kvi_fastmove(m_ptr,bg,m_len); + KviMemory::copy(m_ptr,bg,m_len); *(m_ptr + m_len)='\0'; } @@ -1125,7 +1125,7 @@ KviCString::KviCString(const KviCString &str) KVI_ASSERT(str.m_ptr); m_len = str.m_len; m_ptr = (char *)KviMemory::allocate(m_len+1); - kvi_fastmove(m_ptr,str.m_ptr,m_len+1); + KviMemory::copy(m_ptr,str.m_ptr,m_len+1); } KviCString::KviCString(const QString &str) @@ -1135,7 +1135,7 @@ KviCString::KviCString(const QString &str) { m_len = sz.length(); m_ptr = (char *)KviMemory::allocate(m_len+1); - kvi_fastmove(m_ptr,sz.data(),m_len+1); + KviMemory::copy(m_ptr,sz.data(),m_len+1); } else { m_ptr = (char *)KviMemory::allocate(1); *m_ptr = '\0'; @@ -1205,7 +1205,7 @@ KviCString & KviCString::operator=(const KviCString &str) KVI_ASSERT(str.m_ptr != m_ptr); m_len = str.m_len; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_fastmove(m_ptr,str.m_ptr,m_len+1); + KviMemory::copy(m_ptr,str.m_ptr,m_len+1); return (*this); } @@ -1213,7 +1213,7 @@ KviCString & KviCString::operator=(const QByteArray &str) { m_len = str.length(); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - if(str.data())kvi_fastmove(m_ptr,str.data(),m_len+1); + if(str.data())KviMemory::copy(m_ptr,str.data(),m_len+1); else *m_ptr = 0; return (*this); } @@ -1224,7 +1224,7 @@ KviCString & KviCString::operator=(const char *str) if(str){ m_len = (int)strlen(str); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_memmove(m_ptr,str,m_len+1); + KviMemory::move(m_ptr,str,m_len+1); } else { m_ptr = (char *)KviMemory::reallocate(m_ptr,1); *m_ptr = '\0'; @@ -1496,7 +1496,7 @@ KviCString & KviCString::setStr(const char *str,int len) if((len < 0) || (len > alen))m_len = alen; else m_len = len; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_memmove(m_ptr,str,m_len); + KviMemory::move(m_ptr,str,m_len); *(m_ptr+m_len) = '\0'; return (*this); } @@ -1507,7 +1507,7 @@ KviCString & KviCString::operator=(const QString &str) if(sz.length() > 0){ m_len = sz.length(); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_fastmove(m_ptr,sz.data(),m_len+1); + KviMemory::copy(m_ptr,sz.data(),m_len+1); } else { m_ptr = (char *)KviMemory::reallocate(m_ptr,1); *m_ptr = '\0'; @@ -1537,7 +1537,7 @@ void KviCString::append(const KviCString &str) { KVI_ASSERT(str.m_ptr); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+str.m_len+1); - kvi_fastmove((m_ptr+m_len),str.m_ptr,str.m_len+1); + KviMemory::copy((m_ptr+m_len),str.m_ptr,str.m_len+1); m_len += str.m_len; } @@ -1546,7 +1546,7 @@ void KviCString::append(const char *str) if(!str)return; int len = (int)strlen(str); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+len+1); - kvi_fastmove((m_ptr+m_len),str,len+1); + KviMemory::copy((m_ptr+m_len),str,len+1); m_len += len; } @@ -1555,7 +1555,7 @@ void KviCString::append(const QString &str) QByteArray sz = KviQString::toUtf8(str); if(sz.length() < 1)return; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+sz.length()+1); - kvi_fastmove((m_ptr+m_len),sz.data(),sz.length()+1); + KviMemory::copy((m_ptr+m_len),sz.data(),sz.length()+1); m_len += sz.length(); } @@ -1565,7 +1565,7 @@ void KviCString::append(const char *str,int len) // KVI_ASSERT(len <= ((int)strlen(str))); KVI_ASSERT(len >= 0); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+len+1); - kvi_fastmove((m_ptr+m_len),str,len); + KviMemory::copy((m_ptr+m_len),str,len); m_len += len; *(m_ptr + m_len)='\0'; } @@ -1609,7 +1609,7 @@ void KviCString::extractFromString(const char *begin,const char *end) KVI_ASSERT(end >= begin); m_len = end-begin; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_fastmove(m_ptr,begin,m_len); + KviMemory::copy(m_ptr,begin,m_len); *(m_ptr + m_len)='\0'; } @@ -1618,8 +1618,8 @@ void KviCString::prepend(const KviCString &str) KVI_ASSERT(str.m_ptr); KVI_ASSERT(str.m_ptr != m_ptr); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+str.m_len+1); - kvi_memmove((m_ptr+str.m_len),m_ptr,m_len+1); //move self - kvi_fastmove(m_ptr,str.m_ptr,str.m_len); + KviMemory::move((m_ptr+str.m_len),m_ptr,m_len+1); //move self + KviMemory::copy(m_ptr,str.m_ptr,str.m_len); m_len += str.m_len; } @@ -1628,8 +1628,8 @@ void KviCString::prepend(const char *str) if(!str)return; int len = (int)strlen(str); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+len+1); - kvi_memmove((m_ptr+len),m_ptr,m_len+1); //move self - kvi_fastmove(m_ptr,str,len); + KviMemory::move((m_ptr+len),m_ptr,m_len+1); //move self + KviMemory::copy(m_ptr,str,len); m_len += len; } @@ -1639,8 +1639,8 @@ void KviCString::prepend(const char *str,int len) KVI_ASSERT(len <= ((int)strlen(str))); KVI_ASSERT(len >= 0); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+len+1); - kvi_memmove((m_ptr+len),m_ptr,m_len+1); //move self - kvi_fastmove(m_ptr,str,len); + KviMemory::move((m_ptr+len),m_ptr,m_len+1); //move self + KviMemory::copy(m_ptr,str,len); m_len += len; } @@ -1933,8 +1933,8 @@ KviCString & KviCString::insert(int idx,const char *data) if(idx <= m_len){ int len = (int)strlen(data); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+len+1); - kvi_memmove(m_ptr+idx+len,m_ptr+idx,(m_len - idx)+1); - kvi_fastmove(m_ptr+idx,data,len); + KviMemory::move(m_ptr+idx+len,m_ptr+idx,(m_len - idx)+1); + KviMemory::copy(m_ptr+idx,data,len); m_len+=len; } return (*this); @@ -1944,7 +1944,7 @@ KviCString & KviCString::insert(int idx,char c) { if(idx <= m_len){ m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+2); - kvi_memmove(m_ptr+idx+1,m_ptr+idx,(m_len - idx)+1); + KviMemory::move(m_ptr+idx+1,m_ptr+idx,(m_len - idx)+1); m_len++; *(m_ptr + idx) = c; } @@ -1967,7 +1967,7 @@ KviCString & KviCString::hexEncodeWithTable(const unsigned char table[256]) { int len = aux - begin; n = (char *)KviMemory::reallocate(n,curSize + len + 3); - kvi_memmove(n + curSize,begin,len); + KviMemory::move(n + curSize,begin,len); curSize += len; n[curSize] = '%'; @@ -1985,7 +1985,7 @@ KviCString & KviCString::hexEncodeWithTable(const unsigned char table[256]) int len = aux - begin; n = (char *)KviMemory::reallocate(n,curSize + len + 1); - kvi_memmove(n + curSize,begin,len); + KviMemory::move(n + curSize,begin,len); curSize += len; n[curSize] = '\0'; @@ -2070,7 +2070,7 @@ KviCString & KviCString::hexDecode(const char * pFrom) // move last block int len = aux - begin; n = (char *)KviMemory::reallocate(n,curSize + len + 1); - kvi_memmove(n + curSize,begin,len); + KviMemory::move(n + curSize,begin,len); curSize += len; // get the hex code @@ -2104,7 +2104,7 @@ KviCString & KviCString::hexDecode(const char * pFrom) int len = aux - begin; n = (char *)KviMemory::reallocate(n,curSize + len + 2); - kvi_memmove(n + curSize,begin,len); + KviMemory::move(n + curSize,begin,len); curSize += len; n[curSize] = '\0'; @@ -2129,7 +2129,7 @@ KviCString & KviCString::replaceAll(const char c,const char *str) // Now copy m_len = tmp.m_len; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_fastmove(m_ptr,tmp.m_ptr,m_len+1); + KviMemory::copy(m_ptr,tmp.m_ptr,m_len+1); return (*this); } @@ -2149,7 +2149,7 @@ KviCString & KviCString::replaceAll(const char *toFind,const char *str,bool bCas // Now copy m_len = tmp.m_len; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); - kvi_fastmove(m_ptr,tmp.m_ptr,m_len+1); + KviMemory::copy(m_ptr,tmp.m_ptr,m_len+1); return (*this); } @@ -2485,7 +2485,7 @@ KviCString & KviCString::cutLeft(int len) KVI_ASSERT(len >= 0); if(len <= m_len){ m_len -= len; - kvi_memmove(m_ptr,m_ptr+len,m_len+1); + KviMemory::move(m_ptr,m_ptr+len,m_len+1); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); } else { m_ptr = (char *)KviMemory::reallocate(m_ptr,1); @@ -2523,7 +2523,7 @@ KviCString & KviCString::cut(int idx,int len) char * p1 = m_ptr+idx; if(len + idx > m_len)len = m_len - idx; char * p2 = p1+len; - kvi_memmove(p1,p2,(m_len - (len+idx)) +1); + KviMemory::move(p1,p2,(m_len - (len+idx)) +1); m_len -= len; m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); } @@ -2618,7 +2618,7 @@ KviCString & KviCString::stripLeftWhiteSpace() register char *p=m_ptr; while(isspace(*p))p++; m_len -= (p-m_ptr); - kvi_memmove(m_ptr,p,m_len+1); + KviMemory::move(m_ptr,p,m_len+1); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); return (*this); } @@ -2629,7 +2629,7 @@ KviCString & KviCString::stripLeft(char c) register char *p=m_ptr; while(*p == c)p++; m_len -= (p-m_ptr); - kvi_memmove(m_ptr,p,m_len+1); + KviMemory::move(m_ptr,p,m_len+1); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); return (*this); } @@ -2646,7 +2646,7 @@ bool KviCString::getToken(KviCString & str,char sep) //^ ^ str.m_len = p-m_ptr; str.m_ptr = (char *)KviMemory::reallocate(str.m_ptr,str.m_len+1); - kvi_fastmove(str.m_ptr,m_ptr,str.m_len); + KviMemory::copy(str.m_ptr,m_ptr,str.m_len); *(str.m_ptr + str.m_len)='\0'; while(*p && (*p == sep))p++; cutLeft(p-m_ptr); @@ -2666,7 +2666,7 @@ bool KviCString::getLine(KviCString &str) //^ ^ str.m_len = p-m_ptr; str.m_ptr = (char *)KviMemory::reallocate(str.m_ptr,str.m_len+1); - kvi_fastmove(str.m_ptr,m_ptr,str.m_len); + KviMemory::copy(str.m_ptr,m_ptr,str.m_len); *(str.m_ptr + str.m_len)='\0'; p++; cutLeft(p-m_ptr); @@ -2933,7 +2933,7 @@ KviCString & KviCString::trimmed() // ^ ^ // left right m_len = (right - left)+1; - kvi_memmove(m_ptr,left,m_len); + KviMemory::move(m_ptr,left,m_len); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); *(m_ptr+m_len)='\0'; } else { @@ -2997,7 +2997,7 @@ KviCString & KviCString::stripSpace() // ^ ^ // left right m_len = (right - left)+1; - kvi_memmove(m_ptr,left,m_len); + KviMemory::move(m_ptr,left,m_len); m_ptr = (char *)KviMemory::reallocate(m_ptr,m_len+1); *(m_ptr+m_len)='\0'; } else { diff --git a/src/kvilib/core/KviMemory.cpp b/src/kvilib/core/KviMemory.cpp index 9e0429468..e4fc98f59 100644 --- a/src/kvilib/core/KviMemory.cpp +++ b/src/kvilib/core/KviMemory.cpp @@ -34,6 +34,10 @@ #include <stdio.h> +#ifdef COMPILE_MEMORY_PROFILE + #include "KviPointerList.h" +#endif //COMPILE_MEMORY_PROFILE + namespace KviMemory { @@ -45,8 +49,6 @@ namespace KviMemory // Used to find memory leaks etc... // - #include "kvi_pointerlist.h" - typedef struct _KviMallocEntry { struct _KviMallocEntry * prev; void * pointer; @@ -198,4 +200,202 @@ namespace KviMemory #endif //!COMPILE_MEMORY_PROFILE + +#if 0 + + // The code below is unused and remains here only for historical reasons. + // At the time KVIrc was first written there were some platforms with weak + // memmove and memcpy implementations. + // + // Modern compilers coupled with decent C library implementations we have these days + // can do better than plain assembler. The glibc memcpy implementation, for instance, + // can copy entire pages of memory at very low cost by using virtual address manipulation + // tricks. 64bit architectures can move bytes in larger chunks too. + + + #ifdef COMPILE_ix86_ASM + + // WE WANT repnz; movsq\n"!!! + + inline void copy(void * dst_ptr,const void *src_ptr,int len) + { + __asm__ __volatile__( + " cld\n" + " shr $1,%0\n" + " jnc 1f\n" + " movsb\n" + "1:\n" + " shr $1,%0\n" + " jnc 2f\n" + " movsw\n" + "2:\n" + " repnz; movsl\n" + : "=c" (len), "=&S" (src_ptr), "=&D" (dst_ptr) + : "0" (len), "1" (src_ptr), "2" (dst_ptr) + ); + } + + inline void copy(void * dst_ptr,const void *src_ptr,int len) + { + __asm__ __volatile__( + " cld\n" + " shr $2,%0\n" + " jnc 1f\n" + " movsw\n" + "1:\n" + " repnz; movsl\n" + : "=c" (len), "=&S" (src_ptr), "=&D" (dst_ptr) + : "0" (len), "1" (src_ptr), "2" (dst_ptr) + ); + } + + void * move(void * dst_ptr,const void *src_ptr,int len) + { + KVI_ASSERT(dst_ptr); + KVI_ASSERT(src_ptr); + KVI_ASSERT(len >= 0); + // Save pointer registers + asm(" pushl %esi"); // save %esi + asm(" pushl %edi"); // save %edi + // Load arguments + asm(" movl 16(%ebp),%ecx"); // %ecx = len + asm(" movl 12(%ebp),%esi"); // %esi = src + asm(" movl 8(%ebp),%edi"); // %edi = dst + // Compare src and dest + asm(" cmpl %esi,%edi"); // %edi - %esi + asm(" jbe move_from_bottom_to_top"); // if(%edi < %esi) jump to move_from_bottom_to_top + // dst_ptr > src_ptr + asm(" addl %ecx,%esi"); // %esi += %ecx (src_ptr += len); + asm(" addl %ecx,%edi"); // %edi += %ecx (dst_ptr += len); + asm(" decl %esi"); // %esi--; (src_ptr--); + asm(" decl %edi"); // %edi--; (dst_ptr--); + asm(" std"); // set direction flag (decrement esi and edi in movsb) + // Optimization : check for non-odd len (1,3,5,7...) + asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF + asm(" jnc move_two_bytes_top_to_bottom_directly"); // if !carry (CF == 0) skip this move + // Move the first byte (non-odd) + asm(" movsb %ds:(%esi),%es:(%edi)"); // *dst-- = *src-- if DF else *dst++ = *src++ + asm("move_two_bytes_top_to_bottom_directly:"); + asm(" decl %esi"); // %esi--; (src_ptr--); + asm(" decl %edi"); // %edi--; (dst_ptr--); + asm("move_two_bytes_top_to_bottom:"); + asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF + asm(" jnc move_the_rest_top_to_bottom_directly"); // if !carry (CF == 0) skip this move + // Move the next two bytes + asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ + asm("move_the_rest_top_to_bottom_directly:"); + asm(" subl $2,%esi"); // %esi-=2; (src-=2); + asm(" subl $2,%edi"); // %edi-=2; (dst-=2); + asm(" jmp move_the_rest"); // call last repnz movsl + // dst_ptr <= src_ptr + asm("move_from_bottom_to_top:"); + asm(" cld"); // clear direction flag (increment esi and edi in movsb) + // Optimization : check for non-odd len (1,3,5,7...) + asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF + asm(" jnc move_two_bytes"); // if !carry (CF == 0) skip this move + // Move the first byte (non-odd) + asm(" movsb %ds:(%esi),%es:(%edi)"); // *dst-- = *src-- if DF else *dst++ = *src++ + // Optimization : pass 2, check for %2 and %3 + asm("move_two_bytes:"); + asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF + asm(" jnc move_the_rest"); // if !carry (CF == 0) skip this move + // Move the next two bytes + asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ + // Main move remaining part + asm("move_the_rest:"); + asm(" repnz; movsl %ds:(%esi),%es:(%edi)"); // loop moving 4 bytes at once (increment or decrement as above) + // Restore pointer registers + asm(" popl %edi"); // restore %edi + asm(" popl %esi"); // restore %esi + return dst_ptr; //asm(" movl 8(%ebp),%eax"); <-- gcc will put that (AFTER THE OPTIMISATION PASS!) + } + + void * move(void * dst_ptr,const void *src_ptr,int len) + { + KVI_ASSERT(dst_ptr); + KVI_ASSERT(src_ptr); + KVI_ASSERT(len >= 0); + // Save pointer registers + asm(" pushl %esi"); // save %esi + asm(" pushl %edi"); // save %edi + // Load arguments + asm(" movl 16(%ebp),%ecx"); // %ecx = len + asm(" movl 12(%ebp),%esi"); // %esi = src + asm(" movl 8(%ebp),%edi"); // %edi = dst + // Compare src and dest + asm(" cmpl %esi,%edi"); // %edi - %esi + asm(" jbe xmove_from_bottom_to_top"); // if(%edi < %esi) jump to move_from_bottom_to_top + // dst_ptr > src_ptr + asm(" addl %ecx,%esi"); // %esi += %ecx (src_ptr += len); + asm(" addl %ecx,%edi"); // %edi += %ecx (dst_ptr += len); + asm(" std"); // set direction flag (decrement esi and edi in movsb) + // start moving + asm(" shr $2,%ecx"); // %ecx >> 2, last shifted bit -> CF + asm(" jnc xmove_the_rest_top_to_bottom_directly"); // if !carry (CF == 0) skip this move + // Move the next two bytes + asm(" subl $2,%esi"); // %esi-=2; (src_ptr-=2); + asm(" subl $2,%edi"); // %edi-=2; (dst_ptr-=2); + asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ + asm(" subl $2,%esi"); // %esi-=2; (src_ptr-=2); + asm(" subl $2,%edi"); // %edi-=2; (dst_ptr-=2); + asm(" jmp xmove_the_rest"); + asm("xmove_the_rest_top_to_bottom_directly:"); + asm(" subl $4,%esi"); // %esi-=4; (src-=4); + asm(" subl $4,%edi"); // %edi-=4; (dst-=4); + asm(" jmp xmove_the_rest"); // call last repnz movsl + // dst_ptr <= src_ptr + asm("xmove_from_bottom_to_top:"); + asm(" cld"); // clear direction flag (increment esi and edi in movsb) + // move it + asm(" shr $2,%ecx"); // %ecx >> 2, last shifted bit -> CF + asm(" jnc xmove_the_rest"); // if !carry (CF == 0) skip this move + // Move the next two bytes + asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ + // Main move remaining part + asm("xmove_the_rest:"); + asm(" repnz; movsl %ds:(%esi),%es:(%edi)"); // loop moving 4 bytes at once (increment or decrement as above) + // Restore pointer registers + asm(" popl %edi"); // restore %edi + asm(" popl %esi"); // restore %esi + return dst_ptr; //asm(" movl 8(%ebp),%eax"); <-- gcc will put that (AFTER THE OPTIMISATION PASS!) + } + + #endif COMPILE_ix86_ASM + + // The next 4 functions could be optimized with the & and shift technique + // used in the assembly implementations but the compilers usually + // will not translate the carry bit trick producing code + // that works slower on short block of memory (really near the average case) + + // The trick would be: + // + // if(len & 1) // the length is even + // *dst-- = *src--; // move one byte + // len >> 1; // drop the last bit (thus divide by 2) + // if(len & 1) // the length is still even + // *((short *)dst)-- = *((short *)src)--; // move two bytes + // len >> 1; // again drop the last bit (thus divide by 2) + // while(len--)*((int *)dst)-- = *((int *)src)--; // move four bytes at a time + + void * move(void *dst_ptr,const void *src_ptr,int len) + { + KVI_ASSERT(dst_ptr); + KVI_ASSERT(src_ptr); + KVI_ASSERT(len >= 0); + register char *dst; + register const char *src; + if(dst_ptr > src_ptr){ + dst = (char *)dst_ptr + len - 1; + src = (const char *)src_ptr + len - 1; + while(len--)*dst-- = *src--; + } else { //it is valid even if dst_ptr == src_ptr + dst = (char *)dst_ptr; + src = (const char *)src_ptr; + while(len--)*dst++ = *src++; + } + return dst_ptr; + } + +#endif //0 + } diff --git a/src/kvilib/core/KviMemory.h b/src/kvilib/core/KviMemory.h index d3515a5ec..f81df5aba 100644 --- a/src/kvilib/core/KviMemory.h +++ b/src/kvilib/core/KviMemory.h @@ -32,6 +32,7 @@ #include "kvi_settings.h" #include <stdlib.h> +#include <string.h> /** * \file KviMemory.h @@ -94,7 +95,7 @@ namespace KviMemory inline void * allocate(int size) { - void * ptr = malloc(size); + void * ptr = ::malloc(size); if(!ptr) outOfMemory(); return ptr; @@ -102,7 +103,7 @@ namespace KviMemory inline void * reallocate(void * ptr,int size) { - ptr = realloc(ptr,size); + ptr = ::realloc(ptr,size); if(!ptr) outOfMemory(); return ptr; @@ -128,6 +129,46 @@ namespace KviMemory ::free(ptr); } + /** + * \brief Moves len bytes from src_ptr to dst_ptr + * + * \param dst_ptr The destination memory pointer + * \param src_ptr The source memory pointer + * \param len the number of bytes to move + * \return void * + */ + inline void move(void *dst_ptr,const void *src_ptr,int len) + { + memmove(dst_ptr,src_ptr,len); + } + + /** + * \brief Initializes len bytes of memory starting from dst_ptr to c + * + * \param dst_ptr The destination memory pointer + * \param c The character that will fill the memory + * \param len the number of bytes to initialize + * \return void * + */ + inline void set(void *dst_ptr,char c,int len) + { + memset(dst_ptr,c,len); + } + + /** + * \brief Moves len bytes from src_ptr to dst_ptr + * + * \param dst_ptr The destination memory pointer + * \param src_ptr The source memory pointer + * \param len the number of bytes to move + * \return void * + * \warning In fastmove the src and dst may not overlap + */ + inline void copy(void *dst_ptr,const void *src_ptr,int len) + { + memcpy(dst_ptr,src_ptr,len); + } + #endif //!COMPILE_MEMORY_PROFILE } // namespace KviMemory diff --git a/src/kvilib/core/KviPointerHashTable.h b/src/kvilib/core/KviPointerHashTable.h index 30a4155c5..04750db39 100644 --- a/src/kvilib/core/KviPointerHashTable.h +++ b/src/kvilib/core/KviPointerHashTable.h @@ -35,7 +35,7 @@ #include "KviCString.h" #include "KviQString.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_debug.h" #include <ctype.h> @@ -111,7 +111,7 @@ inline void kvi_hash_key_copy(const char * const &szFrom,const char * &szTo,bool int len = kvi_strLen(szFrom); #endif char * dst = (char *)KviMemory::allocate(len+1); - kvi_fastmove(dst,szFrom,len+1); + KviMemory::copy(dst,szFrom,len+1); szTo = dst; } else { szTo = szFrom; // we never modify it anyway diff --git a/src/kvilib/core/kvi_memmove.cpp b/src/kvilib/core/kvi_memmove.cpp deleted file mode 100644 index d7c179fbd..000000000 --- a/src/kvilib/core/kvi_memmove.cpp +++ /dev/null @@ -1,252 +0,0 @@ -//============================================================================= -// -// File : kvi_memmove.cpp -// Creation date : Sun Jun 18 2000 18:27:50 CEST by Szymon Stefanek -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - - -#define _KVI_DEBUG_CHECK_RANGE_ -#include "kvi_debug.h" - -#define _KVI_MEMMOVE_CPP_ -#include "kvi_memmove.h" - -// FIXME: #warning "With system memmove could be guessed by configure" - -#ifndef COMPILE_WITH_SYSTEM_MEMMOVE - - #ifdef COMPILE_ix86_ASM - - - void *kvi_memmove(void * dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - // Save pointer registers - asm(" pushl %esi"); // save %esi - asm(" pushl %edi"); // save %edi - // Load arguments - asm(" movl 16(%ebp),%ecx"); // %ecx = len - asm(" movl 12(%ebp),%esi"); // %esi = src - asm(" movl 8(%ebp),%edi"); // %edi = dst - // Compare src and dest - asm(" cmpl %esi,%edi"); // %edi - %esi - asm(" jbe move_from_bottom_to_top"); // if(%edi < %esi) jump to move_from_bottom_to_top - // dst_ptr > src_ptr - asm(" addl %ecx,%esi"); // %esi += %ecx (src_ptr += len); - asm(" addl %ecx,%edi"); // %edi += %ecx (dst_ptr += len); - asm(" decl %esi"); // %esi--; (src_ptr--); - asm(" decl %edi"); // %edi--; (dst_ptr--); - asm(" std"); // set direction flag (decrement esi and edi in movsb) - // Optimization : check for non-odd len (1,3,5,7...) - asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF - asm(" jnc move_two_bytes_top_to_bottom_directly"); // if !carry (CF == 0) skip this move - // Move the first byte (non-odd) - asm(" movsb %ds:(%esi),%es:(%edi)"); // *dst-- = *src-- if DF else *dst++ = *src++ - asm("move_two_bytes_top_to_bottom_directly:"); - asm(" decl %esi"); // %esi--; (src_ptr--); - asm(" decl %edi"); // %edi--; (dst_ptr--); - asm("move_two_bytes_top_to_bottom:"); - asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF - asm(" jnc move_the_rest_top_to_bottom_directly"); // if !carry (CF == 0) skip this move - // Move the next two bytes - asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ - asm("move_the_rest_top_to_bottom_directly:"); - asm(" subl $2,%esi"); // %esi-=2; (src-=2); - asm(" subl $2,%edi"); // %edi-=2; (dst-=2); - asm(" jmp move_the_rest"); // call last repnz movsl - // dst_ptr <= src_ptr - asm("move_from_bottom_to_top:"); - asm(" cld"); // clear direction flag (increment esi and edi in movsb) - // Optimization : check for non-odd len (1,3,5,7...) - asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF - asm(" jnc move_two_bytes"); // if !carry (CF == 0) skip this move - // Move the first byte (non-odd) - asm(" movsb %ds:(%esi),%es:(%edi)"); // *dst-- = *src-- if DF else *dst++ = *src++ - // Optimization : pass 2, check for %2 and %3 - asm("move_two_bytes:"); - asm(" shr $1,%ecx"); // %ecx >> 1, shifted bit -> CF - asm(" jnc move_the_rest"); // if !carry (CF == 0) skip this move - // Move the next two bytes - asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ - // Main move remaining part - asm("move_the_rest:"); - asm(" repnz; movsl %ds:(%esi),%es:(%edi)"); // loop moving 4 bytes at once (increment or decrement as above) - // Restore pointer registers - asm(" popl %edi"); // restore %edi - asm(" popl %esi"); // restore %esi - return dst_ptr; //asm(" movl 8(%ebp),%eax"); <-- gcc will put that (AFTER THE OPTIMISATION PASS!) - } - - void *kvi_memmoveodd(void * dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - // Save pointer registers - asm(" pushl %esi"); // save %esi - asm(" pushl %edi"); // save %edi - // Load arguments - asm(" movl 16(%ebp),%ecx"); // %ecx = len - asm(" movl 12(%ebp),%esi"); // %esi = src - asm(" movl 8(%ebp),%edi"); // %edi = dst - // Compare src and dest - asm(" cmpl %esi,%edi"); // %edi - %esi - asm(" jbe xmove_from_bottom_to_top"); // if(%edi < %esi) jump to move_from_bottom_to_top - // dst_ptr > src_ptr - asm(" addl %ecx,%esi"); // %esi += %ecx (src_ptr += len); - asm(" addl %ecx,%edi"); // %edi += %ecx (dst_ptr += len); - asm(" std"); // set direction flag (decrement esi and edi in movsb) - // start moving - asm(" shr $2,%ecx"); // %ecx >> 2, last shifted bit -> CF - asm(" jnc xmove_the_rest_top_to_bottom_directly"); // if !carry (CF == 0) skip this move - // Move the next two bytes - asm(" subl $2,%esi"); // %esi-=2; (src_ptr-=2); - asm(" subl $2,%edi"); // %edi-=2; (dst_ptr-=2); - asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ - asm(" subl $2,%esi"); // %esi-=2; (src_ptr-=2); - asm(" subl $2,%edi"); // %edi-=2; (dst_ptr-=2); - asm(" jmp xmove_the_rest"); - asm("xmove_the_rest_top_to_bottom_directly:"); - asm(" subl $4,%esi"); // %esi-=4; (src-=4); - asm(" subl $4,%edi"); // %edi-=4; (dst-=4); - asm(" jmp xmove_the_rest"); // call last repnz movsl - // dst_ptr <= src_ptr - asm("xmove_from_bottom_to_top:"); - asm(" cld"); // clear direction flag (increment esi and edi in movsb) - // move it - asm(" shr $2,%ecx"); // %ecx >> 2, last shifted bit -> CF - asm(" jnc xmove_the_rest"); // if !carry (CF == 0) skip this move - // Move the next two bytes - asm(" movsw %ds:(%esi),%es:(%edi)"); // *((word *)dst)-- = *((word)src)-- if DF else *((word *)dst)++ = *((word)src)++ - // Main move remaining part - asm("xmove_the_rest:"); - asm(" repnz; movsl %ds:(%esi),%es:(%edi)"); // loop moving 4 bytes at once (increment or decrement as above) - // Restore pointer registers - asm(" popl %edi"); // restore %edi - asm(" popl %esi"); // restore %esi - return dst_ptr; //asm(" movl 8(%ebp),%eax"); <-- gcc will put that (AFTER THE OPTIMISATION PASS!) - } - - #else // ndef COMPILE_ix86_ASM - - - - // The next 4 functions could be optimized with the & and shift technique - // used in the assembly implementations but the compilers usually - // will not translate the carry bit trick producing code - // that works slower on short block of memory (really near the average case) - - // The trick would be: - // - // if(len & 1) // the length is even - // *dst-- = *src--; // move one byte - // len >> 1; // drop the last bit (thus divide by 2) - // if(len & 1) // the length is still even - // *((short *)dst)-- = *((short *)src)--; // move two bytes - // len >> 1; // again drop the last bit (thus divide by 2) - // while(len--)*((int *)dst)-- = *((int *)src)--; // move four bytes at a time - // - // - - void *kvi_memmove(void *dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - register char *dst; - register const char *src; - if(dst_ptr > src_ptr){ - dst = (char *)dst_ptr + len - 1; - src = (const char *)src_ptr + len - 1; - while(len--)*dst-- = *src--; - } else { //it is valid even if dst_ptr == src_ptr - dst = (char *)dst_ptr; - src = (const char *)src_ptr; - while(len--)*dst++ = *src++; - } - return dst_ptr; - } - - void *kvi_memmoveodd(void *dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - KVI_ASSERT((len & 1) == 0); - register short *dst; - register const short *src; - if(dst_ptr > src_ptr){ - dst = (short *) (((char *)dst_ptr) + len - 2); - src = (const short *) (((const char *)src_ptr) + len - 2); - while(len > 0) - { - *dst-- = *src--; - len -= 2; - } - } else { //it is valid even if dst_ptr == src_ptr - dst = (short *)dst_ptr; - src = (const short *)src_ptr; - while(len > 0) - { - *dst++ = *src++; - len -= 2; - } - } - return dst_ptr; - } - - void kvi_fastmove(void *dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - register const char *src = (const char *)src_ptr; - register char *dst = (char *)dst_ptr; - while(len--)*dst++ = *src++; - } - - void kvi_fastmoveodd(void *dst_ptr,const void *src_ptr,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(src_ptr); - KVI_ASSERT(len >= 0); - KVI_ASSERT((len & 1) == 0); - register const short *src = (const short *)src_ptr; - register short *dst = (short *)dst_ptr; - while(len > 0){ - *dst++ = *src++; - len -= 2; - } - } - - #endif // !COMPILE_ix86_ASM - - void kvi_memset(void *dst_ptr,char c,int len) - { - KVI_ASSERT(dst_ptr); - KVI_ASSERT(len >= 0); - register char *dst = (char *)dst_ptr; - while(len--)*dst++ = c; - } - -#endif // !COMPILE_WITH_SYSTEM_MEMMOVE diff --git a/src/kvilib/core/kvi_memmove.h b/src/kvilib/core/kvi_memmove.h deleted file mode 100644 index 7a5703ee1..000000000 --- a/src/kvilib/core/kvi_memmove.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef _KVI_MEMMOVE_H_ -#define _KVI_MEMMOVE_H_ - -//============================================================================= -// -// File : kvi_memmove.h -// Creation date : Fri Mar 19 1999 03:15:21 CEST by Szymon Stefanek -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -//============================================================================= - -/** -* \file kvi_memmove.h -* \author Szymon Stefanek -* \brief This file contains an internal implementation of the memove/memcpy functions -* -* If COMPILE_WITH_SYSTEM_MEMMOVE is disabled, kvirc will use its internal implementation -* of the memmove/memcpy family of functions. If COMPILE_ix86_ASM is enabled, the implementation -* is based on x86 (32-bit only) asm. -*/ - -#include "kvi_settings.h" - -#ifndef _KVI_MEMMOVE_CPP_ - - #ifdef COMPILE_WITH_SYSTEM_MEMMOVE - - #include <string.h> - - #define kvi_memmove memmove - #define kvi_memmoveodd memmove - #define kvi_memset memset - #define kvi_fastmove memcpy - #define kvi_fastmoveodd memcpy - - #else - - #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - #error "This stuff should be never compiled on Windows" - #endif - - /** - * \brief Moves len bytes from src_ptr to dst_ptr - * - * \param dst_ptr The destination memory pointer - * \param src_ptr The source memory pointer - * \param len the number of bytes to move - * \return void * - */ - extern void *kvi_memmove(void *dst_ptr,const void *src_ptr,int len); - - /** - * \brief Moves an odd number of bytes (specified in len) from src_ptr to dst_ptr - * - * \param dst_ptr The destination memory pointer - * \param src_ptr The source memory pointer - * \param len the number of bytes to move; has to be odd - * \return void * - */ - extern void *kvi_memmoveodd(void *dst_ptr,const void *src_ptr,int len); - - /** - * \brief Initializes len bytes of memory starting from dst_ptr to c - * - * \param dst_ptr The destination memory pointer - * \param c The character that will fill the memory - * \param len the number of bytes to initialize - * \return void * - */ - extern void *kvi_memset(void *dst_ptr,char c,int len); - - #ifdef COMPILE_ix86_ASM - - // WE WANT repnz; movsq\n"!!! - - inline void kvi_fastmove(void * dst_ptr,const void *src_ptr,int len) - { - __asm__ __volatile__( - " cld\n" - " shr $1,%0\n" - " jnc 1f\n" - " movsb\n" - "1:\n" - " shr $1,%0\n" - " jnc 2f\n" - " movsw\n" - "2:\n" - " repnz; movsl\n" - : "=c" (len), "=&S" (src_ptr), "=&D" (dst_ptr) - : "0" (len), "1" (src_ptr), "2" (dst_ptr) - ); - } - - inline void kvi_fastmoveodd(void * dst_ptr,const void *src_ptr,int len) - { - __asm__ __volatile__( - " cld\n" - " shr $2,%0\n" - " jnc 1f\n" - " movsw\n" - "1:\n" - " repnz; movsl\n" - : "=c" (len), "=&S" (src_ptr), "=&D" (dst_ptr) - : "0" (len), "1" (src_ptr), "2" (dst_ptr) - ); - } - - #else // ! COMPILE_ix86_ASM - - /** - * \brief Moves len bytes from src_ptr to dst_ptr - * - * \param dst_ptr The destination memory pointer - * \param src_ptr The source memory pointer - * \param len the number of bytes to move - * \return void * - * \warning In fastmove the src and dst may not overlap - */ - extern void kvi_fastmove(void *dst_ptr,const void *src_ptr,int len); - - /** - * \brief Moves an odd number of bytes (specified in len) from src_ptr to dst_ptr - * - * \param dst_ptr The destination memory pointer - * \param src_ptr The source memory pointer - * \param len the number of bytes to move; has to be odd - * \return void * - * \warning In fastmove the src and dst may not overlap - */ - extern void kvi_fastmoveodd(void *dst_ptr,const void *src_ptr,int len); - - #endif // !COMPILE_ix86_ASM - - #endif // COMPILE_WITH_SYSTEM_MEMMOVE - -#endif // _KVI_MEMMOVE_CPP_ - -#endif // !_KVI_MEMMOVE_H_ diff --git a/src/kvilib/ext/KviConfigurationFile.cpp b/src/kvilib/ext/KviConfigurationFile.cpp index ef30f93e5..47b80378f 100644 --- a/src/kvilib/ext/KviConfigurationFile.cpp +++ b/src/kvilib/ext/KviConfigurationFile.cpp @@ -28,7 +28,7 @@ #include "KviPixmap.h" #include "KviMessageTypeSettings.h" #include "KviStringConversion.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMemory.h" #include "KviFile.h" @@ -344,7 +344,7 @@ bool KviConfigurationFile::load() remainingLen = endp-begin; if(buffer != begin) { - kvi_memmove(buffer,begin,remainingLen); + KviMemory::move(buffer,begin,remainingLen); p = buffer + remainingLen; } // else p remains where it is } else { diff --git a/src/kvilib/ext/KviDataBuffer.cpp b/src/kvilib/ext/KviDataBuffer.cpp index e47fe9c19..37247fe46 100644 --- a/src/kvilib/ext/KviDataBuffer.cpp +++ b/src/kvilib/ext/KviDataBuffer.cpp @@ -29,7 +29,7 @@ #include "KviDataBuffer.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" // FIXME: this could resize in chunks!...this would be damn faster :) @@ -38,7 +38,7 @@ KviDataBuffer::KviDataBuffer(int uSize,const unsigned char * data) KVI_ASSERT(uSize > 0); m_uSize = uSize; m_pData = (unsigned char *)KviMemory::allocate(sizeof(unsigned char) * uSize); - if(data)kvi_memmove(m_pData,data,uSize); + if(data)KviMemory::move(m_pData,data,uSize); } KviDataBuffer::KviDataBuffer() @@ -106,7 +106,7 @@ void KviDataBuffer::remove(int uSize) if(m_uSize > 0) { - kvi_memmove(m_pData,m_pData + uSize,m_uSize); + KviMemory::move(m_pData,m_pData + uSize,m_uSize); m_pData = (unsigned char *)KviMemory::reallocate(m_pData,m_uSize * sizeof(unsigned char)); } else { KviMemory::free(m_pData); @@ -130,6 +130,6 @@ void KviDataBuffer::resize(int uSize) void KviDataBuffer::append(const unsigned char * data,int uSize) { m_pData = (unsigned char *)KviMemory::reallocate(m_pData,m_uSize + uSize); - kvi_memmove(m_pData + m_uSize,data,uSize); + KviMemory::move(m_pData + m_uSize,data,uSize); m_uSize += uSize; } diff --git a/src/kvilib/irc/KviIrcMask.cpp b/src/kvilib/irc/KviIrcMask.cpp index d76168afe..33e34b16c 100644 --- a/src/kvilib/irc/KviIrcMask.cpp +++ b/src/kvilib/irc/KviIrcMask.cpp @@ -103,11 +103,11 @@ const char * KviIrcMask::setMask(const char *szMask,char c) int len = p - szMask; if(len > 0){ m_nick_ptr = (char *)KviMemory::reallocate(m_nick_ptr,len+1); - kvi_memmove((void *)m_nick_ptr,(void *)szMask,len); + KviMemory::move((void *)m_nick_ptr,(void *)szMask,len); } else { //Empty nick...set it to "*" len = 1; m_nick_ptr = (char *)KviMemory::reallocate(m_nick_ptr,len+1); - kvi_memmove((void *)m_nick_ptr,(void *)"*",len); + KviMemory::move((void *)m_nick_ptr,(void *)"*",len); } *(m_nick_ptr+len) = '\0'; //With zero length nick it will be just an empty-string if(!(*p)){ @@ -121,11 +121,11 @@ const char * KviIrcMask::setMask(const char *szMask,char c) len = p - szMask; if(len > 0){ m_user_ptr = (char *)KviMemory::reallocate(m_user_ptr,len+1); - kvi_memmove((void *)m_user_ptr,(void *)szMask,len); + KviMemory::move((void *)m_user_ptr,(void *)szMask,len); } else { len = 1; m_user_ptr = (char *)KviMemory::reallocate(m_user_ptr,len+1); - kvi_memmove((void *)m_user_ptr,(void *)"*",len); + KviMemory::move((void *)m_user_ptr,(void *)"*",len); } *(m_user_ptr+len) = '\0'; if(!(*p)){ @@ -138,11 +138,11 @@ const char * KviIrcMask::setMask(const char *szMask,char c) len = p - szMask; if(len > 0){ m_host_ptr = (char *)KviMemory::reallocate(m_host_ptr,len+1); - kvi_memmove((void *)m_host_ptr,(void *)szMask,len); + KviMemory::move((void *)m_host_ptr,(void *)szMask,len); } else { len = 1; m_host_ptr = (char *)KviMemory::reallocate(m_host_ptr,len+1); - kvi_memmove((void *)m_host_ptr,(void *)"*",len); + KviMemory::move((void *)m_host_ptr,(void *)"*",len); } *(m_host_ptr+len) = '\0'; return p; @@ -160,11 +160,11 @@ const char * KviIrcMask::setUserhostMask(const char *szMask) int len = p - szMask; if(len > 0){ m_nick_ptr = (char *)KviMemory::reallocate(m_nick_ptr,len+1); - kvi_memmove((void *)m_nick_ptr,(void *)szMask,len); + KviMemory::move((void *)m_nick_ptr,(void *)szMask,len); } else { //Empty nick...set it to "*" len = 1; m_nick_ptr = (char *)KviMemory::reallocate(m_nick_ptr,len+1); - kvi_memmove((void *)m_nick_ptr,(void *)"*",len); + KviMemory::move((void *)m_nick_ptr,(void *)"*",len); } *(m_nick_ptr+len) = '\0'; //With zero length nick it will be just an empty-string // now skip all the flags @@ -184,11 +184,11 @@ const char * KviIrcMask::setUserhostMask(const char *szMask) len = p - szMask; if(len > 0){ m_user_ptr = (char *)KviMemory::reallocate(m_user_ptr,len+1); - kvi_memmove((void *)m_user_ptr,(void *)szMask,len); + KviMemory::move((void *)m_user_ptr,(void *)szMask,len); } else { len = 1; m_user_ptr = (char *)KviMemory::reallocate(m_user_ptr,len+1); - kvi_memmove((void *)m_user_ptr,(void *)"*",len); + KviMemory::move((void *)m_user_ptr,(void *)"*",len); } *(m_user_ptr+len) = '\0'; @@ -204,11 +204,11 @@ const char * KviIrcMask::setUserhostMask(const char *szMask) len = p - szMask; if(len > 0){ m_host_ptr = (char *)KviMemory::reallocate(m_host_ptr,len+1); - kvi_memmove((void *)m_host_ptr,(void *)szMask,len); + KviMemory::move((void *)m_host_ptr,(void *)szMask,len); } else { len = 1; m_host_ptr = (char *)KviMemory::reallocate(m_host_ptr,len+1); - kvi_memmove((void *)m_host_ptr,(void *)"*",len); + KviMemory::move((void *)m_host_ptr,(void *)"*",len); } *(m_host_ptr+len) = '\0'; while(*p && isspace(*p))p++; diff --git a/src/kvilib/net/KviNetUtils.cpp b/src/kvilib/net/KviNetUtils.cpp index 4e4edcfa2..35d1308c4 100644 --- a/src/kvilib/net/KviNetUtils.cpp +++ b/src/kvilib/net/KviNetUtils.cpp @@ -31,7 +31,7 @@ #endif #include "KviNetUtils.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include <QStringList> @@ -582,7 +582,7 @@ namespace KviNetUtils int len = szInterfaceName.length(); if(len > (IFNAMSIZ - 1))return false; // invalid interface anyway - kvi_memmove(ifr.ifr_name,KviQString::toUtf8(szInterfaceName).data(),len + 1); + KviMemory::move(ifr.ifr_name,KviQString::toUtf8(szInterfaceName).data(),len + 1); int fd = socket(AF_INET,SOCK_STREAM,0); if(fd < 0)return false; @@ -686,7 +686,7 @@ bool kvi_getLocalHostAddress(QString &buffer) KviSockaddr::KviSockaddr(const char * szIpAddress,kvi_u32_t uPort,bool bIPv6,bool bUdp) { struct addrinfo hints; - kvi_memset((void *)&hints,0,sizeof(hints)); + KviMemory::set((void *)&hints,0,sizeof(hints)); hints.ai_flags = AI_NUMERICHOST; #ifdef COMPILE_IPV6_SUPPORT hints.ai_family = bIPv6 ? PF_INET6 : PF_INET; @@ -706,7 +706,7 @@ KviSockaddr::KviSockaddr(kvi_u32_t uPort,bool bIPv6,bool bUdp) // passive sockad { struct addrinfo hints; - kvi_memset((void *)&hints,0,sizeof(hints)); + KviMemory::set((void *)&hints,0,sizeof(hints)); hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE; #ifdef COMPILE_IPV6_SUPPORT hints.ai_family = bIPv6 ? PF_INET6 : PF_INET; diff --git a/src/kvilib/net/KviSSL.cpp b/src/kvilib/net/KviSSL.cpp index dedc70632..9f6ced8c1 100644 --- a/src/kvilib/net/KviSSL.cpp +++ b/src/kvilib/net/KviSSL.cpp @@ -30,7 +30,7 @@ #ifdef COMPILE_SSL_SUPPORT #include "KviThread.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMemory.h" #include <openssl/asn1.h> @@ -378,7 +378,7 @@ static int cb(char *buf, int size, int, void *u) KviCString * p = (KviCString *)u; int len = p->len(); if(len >= size)return 0; - kvi_memmove(buf,p->ptr(),len + 1); + KviMemory::move(buf,p->ptr(),len + 1); // qDebug("PASS REQYESTED: %s",p->ptr()); return len; } @@ -574,7 +574,7 @@ const char * KviSSLCertificate::getX509Base64() PEM_write_bio_X509(mem, m_pX509); int iLen = BIO_get_mem_data(mem, &bptr); char * szTmp = (char *) KviMemory::allocate(iLen+1); - kvi_fastmove(szTmp, bptr, iLen); + KviMemory::copy(szTmp, bptr, iLen); *(szTmp+iLen) = '\0'; BIO_free_all(mem); return szTmp; diff --git a/src/kvilib/system/KviEnvironment.cpp b/src/kvilib/system/KviEnvironment.cpp index 0e80a3940..38883376c 100644 --- a/src/kvilib/system/KviEnvironment.cpp +++ b/src/kvilib/system/KviEnvironment.cpp @@ -27,7 +27,7 @@ #include "KviEnvironment.h" #include "KviCString.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" namespace KviEnvironment { @@ -45,9 +45,9 @@ bool setVariable(const char * name,const char * value) int iLen1 = kvi_strLen(name); int iLen2 = kvi_strLen(value); char * buf = (char *)KviMemory::allocate(iLen1 + iLen2 + 2); - kvi_memmove(buf,name,iLen1); + KviMemory::move(buf,name,iLen1); *(buf + iLen1) = '='; - kvi_memmove(buf + iLen1 + 1,value,iLen2); + KviMemory::move(buf + iLen1 + 1,value,iLen2); *(buf + iLen1 + iLen2 + 1) = '\0'; int iRet = putenv(buf); if(iRet != 0) @@ -75,7 +75,7 @@ void unsetVariable(const char * name) { int iLen1 = kvi_strLen(name); char * buf = (char *)KviMemory::allocate(iLen1 + 1); - kvi_memmove(buf,name,iLen1); + KviMemory::move(buf,name,iLen1); *(buf + iLen1) = '\0'; int iRet = putenv(buf); if(iRet != 0) diff --git a/src/kvirc/kernel/kvi_ipc.cpp b/src/kvirc/kernel/kvi_ipc.cpp index b4f59b491..01dc8cf87 100644 --- a/src/kvirc/kernel/kvi_ipc.cpp +++ b/src/kvirc/kernel/kvi_ipc.cpp @@ -30,7 +30,7 @@ #ifndef COMPILE_NO_IPC - #include "kvi_memmove.h" + #include "KviMemory.h" #include "kvi_app.h" #include "KviQString.h" @@ -165,7 +165,7 @@ kvi_ipcSetRemoteCommand(sentinel,message); XEvent e; - kvi_memset(&e,0,sizeof(XEvent)); + KviMemory::set(&e,0,sizeof(XEvent)); e.type = ClientMessage; e.xclient.display = kvi_ipc_get_xdisplay(); e.xclient.window = sentinel; diff --git a/src/kvirc/kernel/kvi_ircconnection.cpp b/src/kvirc/kernel/kvi_ircconnection.cpp index 958902b46..12a007f9a 100644 --- a/src/kvirc/kernel/kvi_ircconnection.cpp +++ b/src/kvirc/kernel/kvi_ircconnection.cpp @@ -50,7 +50,7 @@ #include "kvi_frame.h" #include "kvi_mexlinkfilter.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_debug.h" #include "kvi_channel.h" #include "kvi_query.h" @@ -786,7 +786,7 @@ bool KviIrcConnection::sendData(const char * pcBuffer, int iBuflen) } KviDataBuffer * pData = new KviDataBuffer(iBuflen + 2); - kvi_memmove(pData->data(),pcBuffer,iBuflen); + KviMemory::move(pData->data(),pcBuffer,iBuflen); *(pData->data() + iBuflen) = '\r'; *(pData->data() + iBuflen + 1) = '\n'; diff --git a/src/kvirc/kernel/kvi_ircconnectiontargetresolver.cpp b/src/kvirc/kernel/kvi_ircconnectiontargetresolver.cpp index 0bde7324b..8185436d7 100644 --- a/src/kvirc/kernel/kvi_ircconnectiontargetresolver.cpp +++ b/src/kvirc/kernel/kvi_ircconnectiontargetresolver.cpp @@ -40,7 +40,7 @@ #include "kvi_mexlinkfilter.h" //#include "kvi_garbage.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_debug.h" #include "kvi_ircconnection.h" #include "kvi_ircconnectiontarget.h" diff --git a/src/kvirc/kernel/kvi_irclink.cpp b/src/kvirc/kernel/kvi_irclink.cpp index e9d5ad11f..331b2cc12 100644 --- a/src/kvirc/kernel/kvi_irclink.cpp +++ b/src/kvirc/kernel/kvi_irclink.cpp @@ -39,7 +39,7 @@ #include "kvi_mexlinkfilter.h" //#include "kvi_garbage.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_ircconnection.h" #include "kvi_ircconnectiontarget.h" #include "kvi_ircconnectiontargetresolver.h" @@ -241,8 +241,8 @@ void KviIrcLink::processData(char * buffer, int iLen) { KVI_ASSERT(m_pReadBuffer); cMessageBuffer = (char *)KviMemory::reallocate(cMessageBuffer,iBufLen + m_uReadBufferLen + 1); - kvi_memmove(cMessageBuffer,m_pReadBuffer,m_uReadBufferLen); - kvi_memmove((void *)(cMessageBuffer + m_uReadBufferLen),cBeginOfCurData,iBufLen); + KviMemory::move(cMessageBuffer,m_pReadBuffer,m_uReadBufferLen); + KviMemory::move((void *)(cMessageBuffer + m_uReadBufferLen),cBeginOfCurData,iBufLen); *(cMessageBuffer + iBufLen + m_uReadBufferLen) = '\0'; m_uReadBufferLen = 0; KviMemory::free(m_pReadBuffer); @@ -250,7 +250,7 @@ void KviIrcLink::processData(char * buffer, int iLen) } else { KVI_ASSERT(!m_pReadBuffer); cMessageBuffer = (char *)KviMemory::reallocate(cMessageBuffer,iBufLen + 1); - kvi_memmove(cMessageBuffer,cBeginOfCurData,iBufLen); + KviMemory::move(cMessageBuffer,cBeginOfCurData,iBufLen); *(cMessageBuffer + iBufLen) = '\0'; } m_uReadPackets++; @@ -302,14 +302,14 @@ void KviIrcLink::processData(char * buffer, int iLen) //and there was more stuff saved... (really slow connection) KVI_ASSERT(m_pReadBuffer); m_pReadBuffer =(char *)KviMemory::reallocate(m_pReadBuffer,m_uReadBufferLen + iBufLen); - kvi_memmove((void *)(m_pReadBuffer+m_uReadBufferLen),cBeginOfCurData,iBufLen); + KviMemory::move((void *)(m_pReadBuffer+m_uReadBufferLen),cBeginOfCurData,iBufLen); m_uReadBufferLen += iBufLen; } else { // KVI_ASSERT(!m_pReadBuffer); m_uReadBufferLen = iBufLen; m_pReadBuffer =(char *)KviMemory::allocate(m_uReadBufferLen); - kvi_memmove(m_pReadBuffer,cBeginOfCurData,m_uReadBufferLen); + KviMemory::move(m_pReadBuffer,cBeginOfCurData,m_uReadBufferLen); } //The m_pReadBuffer contains at max 1 irc message... //that can not be longer than 510 bytes (the message is not CRLF terminated) diff --git a/src/kvirc/kernel/kvi_ircsocket.cpp b/src/kvirc/kernel/kvi_ircsocket.cpp index 9803316d9..7e42e2f71 100644 --- a/src/kvirc/kernel/kvi_ircsocket.cpp +++ b/src/kvirc/kernel/kvi_ircsocket.cpp @@ -34,7 +34,7 @@ #include "kvi_debug.h" #include "KviCString.h" #include "kvi_options.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_socket.h" #include "kvi_console.h" #include "kvi_out.h" @@ -744,7 +744,7 @@ void KviIrcSocket::proxyLoginV4() pcBufToSend[1] = (unsigned char)1; //Connect quint16 port = (quint16)htons(m_pIrcServer->port()); - kvi_memmove((void *)(pcBufToSend + 2),(void *)&port,2); + KviMemory::move((void *)(pcBufToSend + 2),(void *)&port,2); struct in_addr ircInAddr; @@ -752,8 +752,8 @@ void KviIrcSocket::proxyLoginV4() qDebug("SOCKET INTERNAL ERROR IN IPV4 (SOCKS4) ADDR CONVERSION"); quint32 host = (quint32)ircInAddr.s_addr; - kvi_memmove((void *)(pcBufToSend + 4),(void *)&host,4); - kvi_memmove((void *)(pcBufToSend + 8),(void *)(szUserAndPass.ptr()),szUserAndPass.len()); + KviMemory::move((void *)(pcBufToSend + 4),(void *)&host,4); + KviMemory::move((void *)(pcBufToSend + 8),(void *)(szUserAndPass.ptr()),szUserAndPass.len()); pcBufToSend[iLen-1] = 0; //NULL @@ -875,11 +875,11 @@ void KviIrcSocket::proxyAuthUserPassV5() pcBufToSend[1] = (unsigned char)uUser; //username - kvi_memmove((void *)(pcBufToSend + 2),(void *)m_pProxy->user().toUtf8().data(),uUser); + KviMemory::move((void *)(pcBufToSend + 2),(void *)m_pProxy->user().toUtf8().data(),uUser); //length of the password pcBufToSend[2 + uUser] = (unsigned char)uPass; - kvi_memmove((void *)(pcBufToSend + 3 + uUser),(void *)m_pProxy->pass().toUtf8().data(),uPass); + KviMemory::move((void *)(pcBufToSend + 3 + uUser),(void *)m_pProxy->pass().toUtf8().data(),uPass); // spit out the buffer and wait setState(ProxyUserPassV5); @@ -970,20 +970,20 @@ void KviIrcSocket::proxySendTargetDataV5() if(bRemoteDns) { - kvi_memmove((void *)(pcBufToSend + 5), + KviMemory::move((void *)(pcBufToSend + 5), (void *)(m_pIrcServer->hostName().toUtf8().data()), m_pIrcServer->hostName().toUtf8().length()); quint16 port = (quint16)htons(m_pIrcServer->port()); - kvi_memmove((void *)(pcBufToSend + 4 + 1 + m_pIrcServer->hostName().toUtf8().length()),(void *)&port,2); + KviMemory::move((void *)(pcBufToSend + 4 + 1 + m_pIrcServer->hostName().toUtf8().length()),(void *)&port,2); } else if(m_pIrcServer->isIPv6()) { #ifdef COMPILE_IPV6_SUPPORT struct in6_addr ircInAddr; if(!KviNetUtils::stringIpToBinaryIp_V6(m_pIrcServer->ip(),&ircInAddr)) qDebug("SOCKET INTERNAL ERROR IN IPV6 ADDR CONVERSION"); - kvi_memmove((void *)(pcBufToSend + 4),(void *)(&ircInAddr),4); + KviMemory::move((void *)(pcBufToSend + 4),(void *)(&ircInAddr),4); quint16 port = (quint16)htons(m_pIrcServer->port()); - kvi_memmove((void *)(pcBufToSend + 20),(void *)&port,2); + KviMemory::move((void *)(pcBufToSend + 20),(void *)&port,2); #endif } else { struct in_addr ircInAddr; @@ -991,9 +991,9 @@ void KviIrcSocket::proxySendTargetDataV5() if(!KviNetUtils::stringIpToBinaryIp(m_pIrcServer->ip(),&ircInAddr)) qDebug("SOCKET INTERNAL ERROR IN IPV4 ADDR CONVERSION"); quint32 host = (quint32)ircInAddr.s_addr; - kvi_memmove((void *)(pcBufToSend + 4),(void *)&host,4); + KviMemory::move((void *)(pcBufToSend + 4),(void *)&host,4); quint16 port = (quint16)htons(m_pIrcServer->port()); - kvi_memmove((void *)(pcBufToSend + 8),(void *)&port,2); + KviMemory::move((void *)(pcBufToSend + 8),(void *)&port,2); } // send it into hyperspace... @@ -1537,8 +1537,8 @@ void KviIrcSocket::processData(char * buffer,int) if(m_uReadBufferLen > 0){ KVI_ASSERT(m_pReadBuffer); messageBuffer = (char *)KviMemory::reallocate(messageBuffer,bufLen + m_uReadBufferLen + 1); - kvi_memmove(messageBuffer,m_pReadBuffer,m_uReadBufferLen); - kvi_memmove((void *)(messageBuffer + m_uReadBufferLen),beginOfCurData,bufLen); + KviMemory::move(messageBuffer,m_pReadBuffer,m_uReadBufferLen); + KviMemory::move((void *)(messageBuffer + m_uReadBufferLen),beginOfCurData,bufLen); *(messageBuffer + bufLen + m_uReadBufferLen) = '\0'; m_uReadBufferLen = 0; KviMemory::free(m_pReadBuffer); @@ -1546,7 +1546,7 @@ void KviIrcSocket::processData(char * buffer,int) } else { __range_invalid(m_pReadBuffer); messageBuffer = (char *)KviMemory::reallocate(messageBuffer,bufLen + 1); - kvi_memmove(messageBuffer,beginOfCurData,bufLen); + KviMemory::move(messageBuffer,beginOfCurData,bufLen); *(messageBuffer + bufLen) = '\0'; } m_uReadPackets++; @@ -1598,14 +1598,14 @@ void KviIrcSocket::processData(char * buffer,int) //and there was more stuff saved... (really slow connection) KVI_ASSERT(m_pReadBuffer); m_pReadBuffer =(char *)KviMemory::reallocate(m_pReadBuffer,m_uReadBufferLen + bufLen); - kvi_memmove((void *)(m_pReadBuffer+m_uReadBufferLen),beginOfCurData,bufLen); + KviMemory::move((void *)(m_pReadBuffer+m_uReadBufferLen),beginOfCurData,bufLen); m_uReadBufferLen += bufLen; } else { // __range_invalid(m_pReadBuffer); m_uReadBufferLen = bufLen; m_pReadBuffer =(char *)KviMemory::allocate(m_uReadBufferLen); - kvi_memmove(m_pReadBuffer,beginOfCurData,m_uReadBufferLen); + KviMemory::move(m_pReadBuffer,beginOfCurData,m_uReadBufferLen); } //The m_pReadBuffer contains at max 1 irc message... //that can not be longer than 510 bytes (the message is not CRLF terminated) @@ -1966,7 +1966,7 @@ bool KviIrcSocket::sendData(const char *buffer,int buflen) outputSocketWarning(__tr2qs("Socket message truncated to 512 bytes.")); } ptr->pData = new KviDataBuffer(buflen + 2); - kvi_memmove(ptr->pData->data(),buffer,buflen); + KviMemory::move(ptr->pData->data(),buffer,buflen); *(ptr->pData->data()+buflen)='\r'; *(ptr->pData->data()+buflen+1)='\n'; @@ -1985,7 +1985,7 @@ bool KviIrcSocket::sendRawData(const char * pcBuffer, int iBuflen) KviIrcSocketMsgEntry * pEntry = (KviIrcSocketMsgEntry *)KviMemory::allocate(sizeof(KviIrcSocketMsgEntry)); pEntry->pData = new KviDataBuffer(iBuflen); - kvi_memmove(pEntry->pData->data(),pcBuffer,iBuflen); + KviMemory::move(pEntry->pData->data(),pcBuffer,iBuflen); queue_insertMessage(pEntry); if(!m_bInProcessData) diff --git a/src/kvirc/ui/kvi_cryptcontroller.cpp b/src/kvirc/ui/kvi_cryptcontroller.cpp index ffcc67c44..617a5b965 100644 --- a/src/kvirc/ui/kvi_cryptcontroller.cpp +++ b/src/kvirc/ui/kvi_cryptcontroller.cpp @@ -35,7 +35,7 @@ #include "kvi_modulemanager.h" #include "kvi_module.h" #include "KviMemory.h" - #include "kvi_memmove.h" + #include "KviMemory.h" #include "kvi_toolwindows_container.h" #include "KviPointerHashTable.h" @@ -307,12 +307,12 @@ if(iEncKeyLen > 0) { pcEncKey = (char *)KviMemory::allocate(iEncKeyLen); - kvi_memmove(pcEncKey,pcTmpKey,iEncKeyLen); + KviMemory::move(pcEncKey,pcTmpKey,iEncKeyLen); KviCString::freeBuffer(pcTmpKey); } } else { pcEncKey = (char *)KviMemory::allocate(szEncryptKey.len()); - kvi_memmove(pcEncKey,szEncryptKey.ptr(),szEncryptKey.len()); + KviMemory::move(pcEncKey,szEncryptKey.ptr(),szEncryptKey.len()); iEncKeyLen = szEncryptKey.len(); } } @@ -327,12 +327,12 @@ if(iDecKeyLen > 0) { pcDecKey = (char *)KviMemory::allocate(iDecKeyLen); - kvi_memmove(pcDecKey,pcTmpKey,iDecKeyLen); + KviMemory::move(pcDecKey,pcTmpKey,iDecKeyLen); KviCString::freeBuffer(pcTmpKey); } } else { pcDecKey = (char *)KviMemory::allocate(szDecryptKey.len()); - kvi_memmove(pcDecKey,szDecryptKey.ptr(),szDecryptKey.len()); + KviMemory::move(pcDecKey,szDecryptKey.ptr(),szDecryptKey.len()); iDecKeyLen = szDecryptKey.len(); } } diff --git a/src/kvirc/ui/kvi_ircview_gettextline.cpp b/src/kvirc/ui/kvi_ircview_gettextline.cpp index 0b5ab10ce..820fe891f 100644 --- a/src/kvirc/ui/kvi_ircview_gettextline.cpp +++ b/src/kvirc/ui/kvi_ircview_gettextline.cpp @@ -32,7 +32,7 @@ #include "kvi_ircviewprivate.h" #include "kvi_kvs_eventtriggers.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMircCntrl.h" #include "kvi_options.h" #include "kvi_out.h" @@ -44,7 +44,7 @@ // FIXME: Get rid of this!!!!!!!!! #define WSTRINGCONFIG_SAFE_TO_MEMCPY_QCHAR -#define _WSTRING_WMEMCPY(_dst,_src,_len) kvi_fastmoveodd((void *)(_dst),(const void *)(_src),sizeof(kvi_wchar_t) * (_len)) +#define _WSTRING_WMEMCPY(_dst,_src,_len) KviMemory::copy((void *)(_dst),(const void *)(_src),sizeof(kvi_wchar_t) * (_len)) void kvi_appendWCharToQStringWithLength(QString * qstrptr,const kvi_wchar_t * ptr,kvi_wslen_t len) { @@ -565,7 +565,7 @@ found_command_escape: blockLen = (next_cr - p); line_ptr->pChunks[iCurChunk].szPayload = (kvi_wchar_t *)KviMemory::allocate(((next_cr - p) + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd((void *)(line_ptr->pChunks[iCurChunk].szPayload),p,blockLen * sizeof(kvi_wchar_t)); + KviMemory::copy((void *)(line_ptr->pChunks[iCurChunk].szPayload),p,blockLen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szPayload[blockLen] = 0; @@ -658,7 +658,7 @@ found_icon_escape: APPEND_LAST_TEXT_BLOCK(data_ptr,beginPtr - data_ptr) NEW_LINE_CHUNK(KVI_TEXT_ICON) line_ptr->pChunks[iCurChunk].szPayload = (kvi_wchar_t *)KviMemory::allocate((datalen + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd((void *)(line_ptr->pChunks[iCurChunk].szPayload),icon_name,datalen * sizeof(kvi_wchar_t)); + KviMemory::copy((void *)(line_ptr->pChunks[iCurChunk].szPayload),icon_name,datalen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szPayload[datalen] = 0; line_ptr->pChunks[iCurChunk].szSmileId=line_ptr->pChunks[iCurChunk].szPayload; @@ -1038,11 +1038,11 @@ check_emoticon_char: int reallen=item2 ? 3 : 2; line_ptr->pChunks[iCurChunk].szPayload = (kvi_wchar_t *)KviMemory::allocate((emolen + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd(line_ptr->pChunks[iCurChunk].szPayload,begin,emolen * sizeof(kvi_wchar_t)); + KviMemory::copy(line_ptr->pChunks[iCurChunk].szPayload,begin,emolen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szPayload[emolen] = 0; line_ptr->pChunks[iCurChunk].szSmileId = (kvi_wchar_t *)KviMemory::allocate((reallen + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd(line_ptr->pChunks[iCurChunk].szSmileId,ng,reallen * sizeof(kvi_wchar_t)); + KviMemory::copy(line_ptr->pChunks[iCurChunk].szSmileId,ng,reallen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szSmileId[reallen] = 0; APPEND_LAST_TEXT_BLOCK_HIDDEN_FROM_NOW(begin,emolen) @@ -1053,11 +1053,11 @@ check_emoticon_char: { NEW_LINE_CHUNK(KVI_TEXT_ICON) line_ptr->pChunks[iCurChunk].szPayload = (kvi_wchar_t *)KviMemory::allocate((emolen + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd(line_ptr->pChunks[iCurChunk].szPayload,begin,emolen * sizeof(kvi_wchar_t)); + KviMemory::copy(line_ptr->pChunks[iCurChunk].szPayload,begin,emolen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szPayload[emolen] = 0; line_ptr->pChunks[iCurChunk].szSmileId = (kvi_wchar_t *)KviMemory::allocate((reallen + 1) * sizeof(kvi_wchar_t)); - kvi_fastmoveodd(line_ptr->pChunks[iCurChunk].szSmileId,ng,reallen * sizeof(kvi_wchar_t)); + KviMemory::copy(line_ptr->pChunks[iCurChunk].szSmileId,ng,reallen * sizeof(kvi_wchar_t)); line_ptr->pChunks[iCurChunk].szSmileId[reallen] = 0; APPEND_ZERO_LENGTH_BLOCK(data_ptr) diff --git a/src/kvirc/ui/kvi_ircviewtools.cpp b/src/kvirc/ui/kvi_ircviewtools.cpp index bcf8a22cf..95980d413 100644 --- a/src/kvirc/ui/kvi_ircviewtools.cpp +++ b/src/kvirc/ui/kvi_ircviewtools.cpp @@ -33,7 +33,7 @@ #include "kvi_msgbox.h" #include "kvi_filedialog.h" #include "kvi_app.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_shortcuts.h" #include "kvi_window.h" @@ -249,7 +249,7 @@ void KviIrcViewToolWidget::filterLoad() if(f.open(QIODevice::ReadOnly)) { char cBuffer[KVI_NUM_MSGTYPE_OPTIONS]; - kvi_memset(cBuffer,0,KVI_NUM_MSGTYPE_OPTIONS); + KviMemory::set(cBuffer,0,KVI_NUM_MSGTYPE_OPTIONS); f.read(cBuffer,KVI_NUM_MSGTYPE_OPTIONS); f.close(); for(int i=0; i < KVI_NUM_MSGTYPE_OPTIONS; i++) diff --git a/src/modules/dcc/canvas.cpp b/src/modules/dcc/canvas.cpp index 01bbf8e3b..4beb89436 100644 --- a/src/modules/dcc/canvas.cpp +++ b/src/modules/dcc/canvas.cpp @@ -45,7 +45,7 @@ #include "kvi_console.h" #include "kvi_frame.h" #include "KviMemory.h" - #include "kvi_memmove.h" + #include "KviMemory.h" #include "KviThread.h" #include "kvi_ircsocket.h" #include "kvi_settings.h" diff --git a/src/modules/dcc/chat.cpp b/src/modules/dcc/chat.cpp index 6ac90a686..f34a45579 100644 --- a/src/modules/dcc/chat.cpp +++ b/src/modules/dcc/chat.cpp @@ -43,7 +43,7 @@ #include "kvi_console.h" #include "kvi_frame.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviThread.h" #include "kvi_ircsocket.h" #include "kvi_settings.h" @@ -751,7 +751,7 @@ bool KviDccChatThread::handleIncomingData(KviDccThreadIncomingData * data,bool b { // memmove the remaining part to the beginning // aux points after \n or \0 - kvi_memmove(data->buffer,aux,data->iLen); + KviMemory::move(data->buffer,aux,data->iLen); data->buffer = (char *)KviMemory::reallocate(data->buffer,data->iLen); end = data->buffer + data->iLen; aux = data->buffer; diff --git a/src/modules/dcc/marshal.cpp b/src/modules/dcc/marshal.cpp index 8464c94a7..843eb1d83 100644 --- a/src/modules/dcc/marshal.cpp +++ b/src/modules/dcc/marshal.cpp @@ -29,7 +29,7 @@ #include "kvi_error.h" #include "kvi_options.h" #include "KviLocale.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_socket.h" #include "KviFileUtils.h" diff --git a/src/modules/dcc/send.cpp b/src/modules/dcc/send.cpp index bbad7d198..9aa155b74 100644 --- a/src/modules/dcc/send.cpp +++ b/src/modules/dcc/send.cpp @@ -42,7 +42,7 @@ #include "kvi_console.h" #include "kvi_frame.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviThread.h" #include "kvi_ircsocket.h" #include "KviMediaType.h" diff --git a/src/modules/dcc/thread.cpp b/src/modules/dcc/thread.cpp index 09f0b49dc..61cb2f1eb 100644 --- a/src/modules/dcc/thread.cpp +++ b/src/modules/dcc/thread.cpp @@ -27,7 +27,7 @@ #include "kvi_debug.h" #include "kvi_window.h" #include "kvi_error.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMemory.h" #include "KviNetUtils.h" #include "kvi_socket.h" diff --git a/src/modules/dcc/video.cpp b/src/modules/dcc/video.cpp index 896d7b98b..d7cb7e65b 100644 --- a/src/modules/dcc/video.cpp +++ b/src/modules/dcc/video.cpp @@ -266,7 +266,7 @@ bool KviDccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool { // memmove the remaining part to the beginning // aux points after \n or \0 - kvi_memmove(data->buffer,aux,data->iLen); + KviMemory::move(data->buffer,aux,data->iLen); data->buffer = (char *)KviMemory::reallocate(data->buffer,data->iLen); end = data->buffer + data->iLen; aux = data->buffer; diff --git a/src/modules/lamerizer/libkvilamerizer.cpp b/src/modules/lamerizer/libkvilamerizer.cpp index 3b40d625a..53ad9bda2 100644 --- a/src/modules/lamerizer/libkvilamerizer.cpp +++ b/src/modules/lamerizer/libkvilamerizer.cpp @@ -47,7 +47,7 @@ #ifdef COMPILE_CRYPT_SUPPORT - #include "kvi_memmove.h" + #include "KviMemory.h" #include "KviMemory.h" #include "KviPointerList.h" diff --git a/src/modules/objects/class_socket.cpp b/src/modules/objects/class_socket.cpp index a22082902..6ef5cf3ea 100644 --- a/src/modules/objects/class_socket.cpp +++ b/src/modules/objects/class_socket.cpp @@ -41,7 +41,7 @@ #include "kvi_error.h" #include "kvi_socket.h" #include "KviMemory.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviDataBuffer.h" #include <QByteArray> @@ -417,7 +417,7 @@ KVSO_CLASS_FUNCTION(socket,read) QByteArray *pBuffer=((KviKvsObject_memorybuffer *)pObject)->pBuffer(); int oldsize=pBuffer->size(); pBuffer->resize(oldsize+uLen); - kvi_memmove(pBuffer->data()+oldsize,m_pInBuffer,uLen); + KviMemory::move(pBuffer->data()+oldsize,m_pInBuffer,uLen); } else if(pObject->inheritsClass("file")) { @@ -1171,7 +1171,7 @@ void KviKvsObject_socket::eatInData(unsigned int uLen) if(m_uInDataLen > 0) { - kvi_memmove(m_pInBuffer,m_pInBuffer + uLen,m_uInDataLen); + KviMemory::move(m_pInBuffer,m_pInBuffer + uLen,m_uInDataLen); } unsigned int uSpace = m_uInBufferLen - m_uInDataLen; diff --git a/src/modules/rijndael/ablowfish.cpp b/src/modules/rijndael/ablowfish.cpp index 91820baf3..1c829f3b0 100644 --- a/src/modules/rijndael/ablowfish.cpp +++ b/src/modules/rijndael/ablowfish.cpp @@ -23,7 +23,7 @@ //============================================================================= #include "ablowfish.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #ifdef COMPILE_CRYPT_SUPPORT @@ -318,11 +318,11 @@ BlowFish::BlowFish(unsigned char* ucKey, unsigned int keysize, const SBlock& roC keysize = 56; unsigned char aucLocalKey[56]; unsigned int i, j; - kvi_fastmove(aucLocalKey, ucKey, keysize); + KviMemory::copy(aucLocalKey, ucKey, keysize); //Reflexive Initialization of the Blowfish. //Generating the Subkeys from the Key flood P and S boxes with PI - kvi_fastmove(m_auiP, scm_auiInitP, sizeof(m_auiP)); - kvi_fastmove(m_auiS, scm_auiInitS, sizeof(m_auiS)); + KviMemory::copy(m_auiP, scm_auiInitP, sizeof(m_auiP)); + KviMemory::copy(m_auiS, scm_auiInitS, sizeof(m_auiS)); //Load P boxes with key bytes const unsigned char* p = aucLocalKey; unsigned int x=0; diff --git a/src/modules/rijndael/libkvirijndael.cpp b/src/modules/rijndael/libkvirijndael.cpp index 3a9013c2d..14fa267a2 100644 --- a/src/modules/rijndael/libkvirijndael.cpp +++ b/src/modules/rijndael/libkvirijndael.cpp @@ -62,7 +62,7 @@ #if defined(COMPILE_CRYPT_SUPPORT) || defined(Q_MOC_RUN) - #include "kvi_memmove.h" + #include "KviMemory.h" #include "KviMemory.h" #include "KviPointerList.h" @@ -123,12 +123,12 @@ char * decryptKey = (char *)KviMemory::allocate(defLen); if(encKeyLen > defLen)encKeyLen = defLen; - kvi_memmove(encryptKey,encKey,encKeyLen); - if(encKeyLen < defLen)kvi_memset(encryptKey + encKeyLen,'0',defLen - encKeyLen); + KviMemory::move(encryptKey,encKey,encKeyLen); + if(encKeyLen < defLen)KviMemory::set(encryptKey + encKeyLen,'0',defLen - encKeyLen); if(decKeyLen > defLen)decKeyLen = defLen; - kvi_memmove(decryptKey,decKey,decKeyLen); - if(decKeyLen < defLen)kvi_memset(decryptKey + decKeyLen,'0',defLen - decKeyLen); + KviMemory::move(decryptKey,decKey,decKeyLen); + if(decKeyLen < defLen)KviMemory::set(decryptKey + decKeyLen,'0',defLen - decKeyLen); m_pEncryptCipher = new Rijndael(); int retVal = m_pEncryptCipher->init(Rijndael::CBC,Rijndael::Encrypt,(unsigned char *)encryptKey,getKeyLenId()); @@ -277,7 +277,7 @@ if(len > 0) { *outBuffer = (char *)KviMemory::allocate(*len); - kvi_memmove(*outBuffer,tmpBuf,*len); + KviMemory::move(*outBuffer,tmpBuf,*len); KviCString::freeBuffer(tmpBuf); } } @@ -303,7 +303,7 @@ if(len > 0) { *outBuffer = (char *)KviMemory::allocate(*len); - kvi_memmove(*outBuffer,tmpBuf,*len); + KviMemory::move(*outBuffer,tmpBuf,*len); KviCString::freeBuffer(tmpBuf); } } @@ -633,7 +633,7 @@ for(int i=0;i<8;i++)in[i] = (unsigned char)(rand() % 256); - kvi_fastmove(in+8,plain.ptr(),plain.len()); + KviMemory::copy(in+8,plain.ptr(),plain.len()); // encrypt unsigned char * out = (unsigned char *)KviMemory::allocate(ll); diff --git a/src/modules/rijndael/rijndael.cpp b/src/modules/rijndael/rijndael.cpp index 9546f4cfa..def26034f 100644 --- a/src/modules/rijndael/rijndael.cpp +++ b/src/modules/rijndael/rijndael.cpp @@ -59,7 +59,7 @@ #include "rijndael.h" -#include "kvi_memmove.h" +#include "KviMemory.h" //#include <stdio.h> //#include <stdlib.h> @@ -1103,7 +1103,7 @@ int Rijndael::blockEncrypt(const UINT8 *input,int inputLen,UINT8 *outBuffer) break; case CFB1: #if STRICT_ALIGN - kvi_memmove(iv,m_initVector,16); + KviMemory::move(iv,m_initVector,16); #else /* !STRICT_ALIGN */ *((UINT32*)iv[0]) = *((UINT32*)(m_initVector )); *((UINT32*)iv[1]) = *((UINT32*)(m_initVector + 4)); @@ -1170,8 +1170,8 @@ int Rijndael::padEncrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer) } padLen = 16 - (inputOctets - 16*numBlocks); // assert(padLen > 0 && padLen <= 16); - kvi_memmove(block, input, 16 - padLen); - kvi_memset(block + 16 - padLen, padLen, padLen); + KviMemory::move(block, input, 16 - padLen); + KviMemory::set(block + 16 - padLen, padLen, padLen); encrypt(block,outBuffer); break; case CBC: @@ -1229,7 +1229,7 @@ int Rijndael::blockDecrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer) break; case CBC: #if STRICT_ALIGN - kvi_memmove(iv,m_initVector,16); + KviMemory::move(iv,m_initVector,16); #else *((UINT32*)iv[0]) = *((UINT32*)(m_initVector )); *((UINT32*)iv[1]) = *((UINT32*)(m_initVector+ 4)); @@ -1244,8 +1244,8 @@ int Rijndael::blockDecrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer) ((UINT32*)block)[2] ^= *((UINT32*)iv[2]); ((UINT32*)block)[3] ^= *((UINT32*)iv[3]); #if STRICT_ALIGN - kvi_memmove(iv, input, 16); - kvi_memmove(outBuf, block, 16); + KviMemory::move(iv, input, 16); + KviMemory::move(outBuf, block, 16); #else *((UINT32*)iv[0]) = ((UINT32*)input)[0]; ((UINT32*)outBuffer)[0] = ((UINT32*)block)[0]; *((UINT32*)iv[1]) = ((UINT32*)input)[1]; ((UINT32*)outBuffer)[1] = ((UINT32*)block)[1]; @@ -1258,7 +1258,7 @@ int Rijndael::blockDecrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer) break; case CFB1: #if STRICT_ALIGN - kvi_memmove(iv, m_initVector, 16); + KviMemory::move(iv, m_initVector, 16); #else *((UINT32*)iv[0]) = *((UINT32*)(m_initVector)); *((UINT32*)iv[1]) = *((UINT32*)(m_initVector+ 4)); @@ -1333,10 +1333,10 @@ int Rijndael::padDecrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer) { if(block[i] != padLen)return RIJNDAEL_CORRUPTED_DATA; } - kvi_memmove(outBuffer, block, 16 - padLen); + KviMemory::move(outBuffer, block, 16 - padLen); break; case CBC: - kvi_memmove(iv, m_initVector, 16); + KviMemory::move(iv, m_initVector, 16); /* all blocks but last */ for (i = numBlocks - 1; i > 0; i--) { @@ -1345,8 +1345,8 @@ int Rijndael::padDecrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer) ((UINT32*)block)[1] ^= iv[1]; ((UINT32*)block)[2] ^= iv[2]; ((UINT32*)block)[3] ^= iv[3]; - kvi_memmove(iv, input, 16); - kvi_memmove(outBuffer, block, 16); + KviMemory::move(iv, input, 16); + KviMemory::move(outBuffer, block, 16); input += 16; outBuffer += 16; } @@ -1362,7 +1362,7 @@ int Rijndael::padDecrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer) { if(block[i] != padLen)return RIJNDAEL_CORRUPTED_DATA; } - kvi_memmove(outBuffer, block, 16 - padLen); + KviMemory::move(outBuffer, block, 16 - padLen); break; default: diff --git a/src/modules/rot13/libkvirot13.cpp b/src/modules/rot13/libkvirot13.cpp index 556ef957d..6929223eb 100644 --- a/src/modules/rot13/libkvirot13.cpp +++ b/src/modules/rot13/libkvirot13.cpp @@ -47,7 +47,7 @@ #ifdef COMPILE_CRYPT_SUPPORT - #include "kvi_memmove.h" + #include "KviMemory.h" #include "KviMemory.h" #include "KviPointerList.h" diff --git a/src/modules/trayicon/libkvitrayicon.cpp b/src/modules/trayicon/libkvitrayicon.cpp index c11d6bda8..aa2e68b5c 100644 --- a/src/modules/trayicon/libkvitrayicon.cpp +++ b/src/modules/trayicon/libkvitrayicon.cpp @@ -30,7 +30,7 @@ #include "kvi_app.h" #include "kvi_module.h" #include "KviLocale.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "kvi_windowlist.h" #include "kvi_window.h" #include "kvi_dynamictooltip.h" diff --git a/src/modules/window/libkviwindow.cpp b/src/modules/window/libkviwindow.cpp index 0a585fb01..5b7bf103c 100644 --- a/src/modules/window/libkviwindow.cpp +++ b/src/modules/window/libkviwindow.cpp @@ -36,7 +36,7 @@ #include "kvi_input.h" #include "kvi_iconmanager.h" #include "kvi_modulemanager.h" -#include "kvi_memmove.h" +#include "KviMemory.h" #include "KviMemory.h" #include "kvi_mdichild.h" #include "kvi_channel.h" @@ -1494,7 +1494,7 @@ static bool initializeCryptEngine(KviCryptEngine * eng,KviCString &szEncryptKey, if(encKeyLen > 0) { encKey = (char *)KviMemory::allocate(encKeyLen); - kvi_memmove(encKey,tmpKey,encKeyLen); + KviMemory::move(encKey,tmpKey,encKeyLen); KviCString::freeBuffer(tmpKey); } else { szError = __tr2qs("The encrypt key wasn't a valid hexadecimal string"); @@ -1508,7 +1508,7 @@ static bool initializeCryptEngine(KviCryptEngine * eng,KviCString &szEncryptKey, if(decKeyLen > 0) { decKey = (char *)KviMemory::allocate(decKeyLen); - kvi_memmove(decKey,tmpKey,decKeyLen); + KviMemory::move(decKey,tmpKey,decKeyLen); KviCString::freeBuffer(tmpKey); } else { szError = __tr2qs("The decrypt key wasn't a valid hexadecimal string"); |
