diff --git a/Source/Tests/mmap.cpp b/Source/Tests/mmap.cpp index b0a71d69..ddc4bfdd 100644 --- a/Source/Tests/mmap.cpp +++ b/Source/Tests/mmap.cpp @@ -41,8 +41,7 @@ public: int offset2 = rand() % BUF_SIZE; int size2 = rand() % (BUF_SIZE - offset2); - int size2forrelease = size2; - char *p2 = (char *) mmap.getmore(offset2, &size2forrelease); + char *p2 = (char *) mmap.getmore(offset2, size2); int minsize = min(size1, size2); for (size_t j = 0; j < minsize; j++) { @@ -50,7 +49,7 @@ public: } mmap.release(); - mmap.release(p2, size2forrelease); + mmap.release(p2, size2); } } diff --git a/Source/build.cpp b/Source/build.cpp index 126cf362..f1d52017 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -614,13 +614,12 @@ int CEXEBuild::datablock_optimize(int start_offset, int first_int) while (left > 0) { int l = min(left, build_filebuflen); - int la = l; void *newstuff = db->get(start_offset + this_len - left, l); - void *oldstuff = db->getmore(pos + this_len - left, &la); + void *oldstuff = db->getmore(pos + this_len - left, l); int res = memcmp(newstuff, oldstuff, l); - db->release(oldstuff, la); + db->release(oldstuff, l); db->release(); if (res) diff --git a/Source/mmap.cpp b/Source/mmap.cpp index e0fcb23c..930a612e 100644 --- a/Source/mmap.cpp +++ b/Source/mmap.cpp @@ -290,7 +290,7 @@ void *MMapFile::get(int offset, int *sizep) const return (void *)((char *)m_pView + offset - alignedoffset); } -void *MMapFile::getmore(int offset, int *size) const +void *MMapFile::getmore(int offset, int size) const { void *pView; void *pViewBackup = m_pView; @@ -324,6 +324,9 @@ void MMapFile::release(void *pView, int size) if (!pView) return; + unsigned int alignment = ((unsigned int)pView) % m_iAllocationGranularity; + pView = (char *)pView - alignment; + size += alignment; #ifdef _WIN32 UnmapViewOfFile(pView); #else @@ -374,7 +377,7 @@ void *MMapFake::get(int offset, int *size) const return (void *)(m_pMem + offset); } -void *MMapFake::getmore(int offset, int *size) const +void *MMapFake::getmore(int offset, int size) const { return get(offset, size); } @@ -477,7 +480,7 @@ void *MMapBuf::get(int offset, int size) const return (void *) ((char *) m_gb.get() + offset); } -void *MMapBuf::getmore(int offset, int *size) const +void *MMapBuf::getmore(int offset, int size) const { if (m_gb_u) return m_fm.getmore(offset, size); diff --git a/Source/mmap.h b/Source/mmap.h index eb91b856..a72249ae 100644 --- a/Source/mmap.h +++ b/Source/mmap.h @@ -31,7 +31,7 @@ class IMMap virtual int getsize() const=0; virtual void *get(int offset, int size) const=0; virtual void *get(int offset, int *size) const=0; - virtual void *getmore(int offset, int *size) const=0; + virtual void *getmore(int offset, int size) const=0; virtual void release()=0; virtual void release(void *view, int size)=0; virtual void clear()=0; @@ -61,7 +61,7 @@ class MMapFile : public IMMap int getsize() const; void *get(int offset, int size) const; void *get(int offset, int *sizep) const; - void *getmore(int offset, int *size) const; + void *getmore(int offset, int size) const; void release(); void release(void *pView, int size); void flush(int num); @@ -94,7 +94,7 @@ class MMapFake : public IMMap int getsize() const; void *get(int offset, int size) const; void *get(int offset, int *size) const; - void *getmore(int offset, int *size) const; + void *getmore(int offset, int size) const; void resize(int n); void release(); @@ -126,7 +126,7 @@ class MMapBuf : public IGrowBuf, public IMMap void *get() const; void *get(int offset, int *sizep) const; void *get(int offset, int size) const; - void *getmore(int offset, int *size) const; + void *getmore(int offset, int size) const; void release(); void release(void *pView, int size); void clear();