kernel32: Return an error when unlocking a global with a zero lock count.

Rename GLOBAL_LOCK_MAX to the public GMEM_LOCKCOUNT.
This commit is contained in:
Robert Shearman 2006-01-10 19:59:15 +01:00 committed by Alexandre Julliard
parent ab113d7e59
commit cb7aa0306e
1 changed files with 13 additions and 7 deletions

View File

@ -299,7 +299,6 @@ SIZE_T WINAPI HeapSize( HANDLE heap, DWORD flags, LPVOID ptr )
*/ */
#define MAGIC_GLOBAL_USED 0x5342 #define MAGIC_GLOBAL_USED 0x5342
#define GLOBAL_LOCK_MAX 0xFF
#define HANDLE_TO_INTERN(h) ((PGLOBAL32_INTERN)(((char *)(h))-2)) #define HANDLE_TO_INTERN(h) ((PGLOBAL32_INTERN)(((char *)(h))-2))
#define INTERN_TO_HANDLE(i) ((HGLOBAL) &((i)->Pointer)) #define INTERN_TO_HANDLE(i) ((HGLOBAL) &((i)->Pointer))
#define POINTER_TO_HANDLE(p) (*(((HGLOBAL *)(p))-2)) #define POINTER_TO_HANDLE(p) (*(((HGLOBAL *)(p))-2))
@ -416,7 +415,7 @@ LPVOID WINAPI GlobalLock(
palloc = pintern->Pointer; palloc = pintern->Pointer;
if (!pintern->Pointer) if (!pintern->Pointer)
SetLastError(ERROR_DISCARDED); SetLastError(ERROR_DISCARDED);
else if (pintern->LockCount < GLOBAL_LOCK_MAX) else if (pintern->LockCount < GMEM_LOCKCOUNT)
pintern->LockCount++; pintern->LockCount++;
} }
else else
@ -461,13 +460,20 @@ BOOL WINAPI GlobalUnlock(
pintern=HANDLE_TO_INTERN(hmem); pintern=HANDLE_TO_INTERN(hmem);
if(pintern->Magic==MAGIC_GLOBAL_USED) if(pintern->Magic==MAGIC_GLOBAL_USED)
{ {
if((pintern->LockCount<GLOBAL_LOCK_MAX)&&(pintern->LockCount>0)) if(pintern->LockCount)
{
pintern->LockCount--; pintern->LockCount--;
locked = (pintern->LockCount != 0); locked = (pintern->LockCount != 0);
if (!locked) SetLastError(NO_ERROR); if (!locked) SetLastError(NO_ERROR);
} }
else else
{
WARN("%p not locked\n", hmem);
SetLastError(ERROR_NOT_LOCKED);
locked = FALSE;
}
}
else
{ {
WARN("invalid handle\n"); WARN("invalid handle\n");
SetLastError(ERROR_INVALID_HANDLE); SetLastError(ERROR_INVALID_HANDLE);