applied patch #1611866 - Fix MMapFile::release(void *pView, int size)

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4843 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2006-12-09 15:17:24 +00:00
parent 4ca1f6d04b
commit ae3373311e
4 changed files with 14 additions and 13 deletions

View file

@ -41,8 +41,7 @@ public:
int offset2 = rand() % BUF_SIZE; int offset2 = rand() % BUF_SIZE;
int size2 = rand() % (BUF_SIZE - offset2); int size2 = rand() % (BUF_SIZE - offset2);
int size2forrelease = size2; char *p2 = (char *) mmap.getmore(offset2, size2);
char *p2 = (char *) mmap.getmore(offset2, &size2forrelease);
int minsize = min(size1, size2); int minsize = min(size1, size2);
for (size_t j = 0; j < minsize; j++) { for (size_t j = 0; j < minsize; j++) {
@ -50,7 +49,7 @@ public:
} }
mmap.release(); mmap.release();
mmap.release(p2, size2forrelease); mmap.release(p2, size2);
} }
} }

View file

@ -614,13 +614,12 @@ int CEXEBuild::datablock_optimize(int start_offset, int first_int)
while (left > 0) while (left > 0)
{ {
int l = min(left, build_filebuflen); int l = min(left, build_filebuflen);
int la = l;
void *newstuff = db->get(start_offset + this_len - left, 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); int res = memcmp(newstuff, oldstuff, l);
db->release(oldstuff, la); db->release(oldstuff, l);
db->release(); db->release();
if (res) if (res)

View file

@ -290,7 +290,7 @@ void *MMapFile::get(int offset, int *sizep) const
return (void *)((char *)m_pView + offset - alignedoffset); 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 *pView;
void *pViewBackup = m_pView; void *pViewBackup = m_pView;
@ -324,6 +324,9 @@ void MMapFile::release(void *pView, int size)
if (!pView) if (!pView)
return; return;
unsigned int alignment = ((unsigned int)pView) % m_iAllocationGranularity;
pView = (char *)pView - alignment;
size += alignment;
#ifdef _WIN32 #ifdef _WIN32
UnmapViewOfFile(pView); UnmapViewOfFile(pView);
#else #else
@ -374,7 +377,7 @@ void *MMapFake::get(int offset, int *size) const
return (void *)(m_pMem + offset); 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); return get(offset, size);
} }
@ -477,7 +480,7 @@ void *MMapBuf::get(int offset, int size) const
return (void *) ((char *) m_gb.get() + offset); 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) if (m_gb_u)
return m_fm.getmore(offset, size); return m_fm.getmore(offset, size);

View file

@ -31,7 +31,7 @@ class IMMap
virtual int getsize() const=0; 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 *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()=0;
virtual void release(void *view, int size)=0; virtual void release(void *view, int size)=0;
virtual void clear()=0; virtual void clear()=0;
@ -61,7 +61,7 @@ class MMapFile : public IMMap
int getsize() const; int getsize() const;
void *get(int offset, int size) const; void *get(int offset, int size) const;
void *get(int offset, int *sizep) 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 release(void *pView, int size); void release(void *pView, int size);
void flush(int num); void flush(int num);
@ -94,7 +94,7 @@ class MMapFake : public IMMap
int getsize() const; int getsize() const;
void *get(int offset, int size) const; void *get(int offset, int size) 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 resize(int n);
void release(); void release();
@ -126,7 +126,7 @@ class MMapBuf : public IGrowBuf, public IMMap
void *get() const; void *get() const;
void *get(int offset, int *sizep) const; void *get(int offset, int *sizep) 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 release(); void release();
void release(void *pView, int size); void release(void *pView, int size);
void clear(); void clear();