[Scummvm-cvs-logs] CVS: scummvm/backends/PalmOS/Src/missing _stdlib.cpp,1.3,1.4 stdlib.h,1.2,1.3

Chris Apers chrilith at users.sourceforge.net
Sun Jun 8 02:29:14 CEST 2003


Update of /cvsroot/scummvm/scummvm/backends/PalmOS/Src/missing
In directory sc8-pr-cvs1:/tmp/cvs-serv28498/missing

Modified Files:
	_stdlib.cpp stdlib.h 
Log Message:
Cleanup, add qsort function

Index: _stdlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/PalmOS/Src/missing/_stdlib.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- _stdlib.cpp	19 May 2003 11:06:16 -0000	1.3
+++ _stdlib.cpp	8 Jun 2003 09:28:18 -0000	1.4
@@ -21,12 +21,6 @@
  */
 
 #include "stdlib.h"
-#include "MemGlue.h"
-///////////////////////////////////////////////////////////////////////////////
-/*void qsort(void *base, UInt32 nmemb, UInt32 size, ComparF *compar) {
-	
-	SysQSort(base, nmemb, size, compar);
-}*/
 ///////////////////////////////////////////////////////////////////////////////
 void *bsearch(const void *key, const void *base, UInt32 nmemb, 
 				UInt32 size, int (*compar)(const void *, const void *)) {
@@ -38,136 +32,10 @@
 	return NULL;
 }
 ///////////////////////////////////////////////////////////////////////////////
-static DmOpenRef gExtMemory = NULL;
-
-static UInt16 MemFindHeapID(UInt32 size)
-{
-	UInt32  nFree, maxChunk ;
-	UInt16 maxCards = 1;	//MemNumCards(); process only first card for now
-	UInt16 heapID = -1;		// no heap avaliable
-
-	UInt16 cardNo;
-	UInt16 maxHeaps, heapIndex;
-
-	for (cardNo = 0; cardNo < maxCards; cardNo++)
-	{
-		if (MemNumRAMHeaps(cardNo) > 0)
-		{
-			maxHeaps =  MemNumHeaps(cardNo);
-			for (heapIndex = 0; heapIndex < maxHeaps; heapIndex++)
-			{
-				// Obtain the ID of the heap.
-				heapID = MemHeapID(cardNo, heapIndex);
-				
-				if (!(MemHeapFlags(heapID) & memHeapFlagReadOnly))
-				{
-					MemHeapFreeBytes( heapID, &nFree, &maxChunk );
-					if (maxChunk > size)
-						return heapID;
-				}
-			}
-		}
-	}
-
-	return heapID;
-}
-
-void MemExtInit()
-{
-	if (!gExtMemory)
-	{
-		LocalID localID = DmFindDatabase(0, "ScummVM-Memory");
-		if (localID) DmDeleteDatabase(0, localID);
-		
-		if (DmCreateDatabase (0, "ScummVM-Memory", 'ScVM', 'DATA', false) != errNone)
-			return;
-
-		localID = DmFindDatabase(0, "ScummVM-Memory");
-		gExtMemory = DmOpenDatabase(0, localID, dmModeReadWrite|dmModeExclusive);
-	}
-}
-
-void MemExtCleanup()
-{
-	if (gExtMemory) {
-		DmCloseDatabase(gExtMemory);
-		LocalID localID = DmFindDatabase(0, "ScummVM-Memory");
-		if (localID)
-			DmDeleteDatabase(0, localID);
-	}
-}
-//#define USE_EXTENDEDMEM
-#ifdef USE_EXTENDEDMEM
-
-MemPtr calloc(UInt32 nelem, UInt32 elsize)
-{
-	UInt32 size = nelem*elsize;
-	MemPtr newP = NULL;
-	UInt16 heapID = MemFindHeapID(size);
-
-	if (heapID != NO_HEAP_FOUND)
-	{
-		if (MemHeapDynamic(heapID) && size < 65536-8) // 8 = chunk header size
-			newP = MemPtrNew(size);
-		else
-		{
-			SysAppInfoPtr appInfoP;
-			UInt16 ownerID, large, nmovable;
-			UInt16 attr;
-
-			ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID; 
-			large	= ((size > 65536-8) ? memNewChunkFlagAllowLarge : 0);
-			nmovable= (MemHeapDynamic(heapID) ? memNewChunkFlagNonMovable : memNewChunkFlagPreLock);
-			attr	=	ownerID|large|nmovable;
-			
-			//MEMORY_RESERVE_ACCESS
-			newP = MemChunkNew(heapID, size, attr);
-			//MEMORY_RELEASE_ACCESS
-
-			if (newP && MemPtrDataStorage(newP)) {		// if storage heap ?
-				if (!gExtMemory) {						// if memory DB doesn't exist
-					MemChunkFree(newP);
-					return NULL;
-				}
-
-				UInt16 index = dmMaxRecordIndex;	// used for record purpose
-				MemHandle newH = MemPtrRecoverHandle(newP);					// exists
-				if (DmAttachRecord(gExtMemory, &index, newH, NULL) != errNone) // attach to DB
-				{
-					MemChunkFree(newP);	// error
-					return NULL;
-				}
-			}
-		}
-	}
-
-	if (newP)
-		MemSet(newP,size,0);
-
-	return newP;
-}
-
-#else
-
-MemPtr calloc(UInt32 nelem, UInt32 elsize)
-{
+MemPtr calloc(UInt32 nelem, UInt32 elsize) {
+	MemPtr newP;
 	UInt32 size = nelem*elsize;
-	MemPtr newP = NULL;
-
-/*	if (size < 65536-8) 		// 8 = chunk header size
-		newP = MemPtrNew(size);
-	else*/
-/*	{
-		SysAppInfoPtr appInfoP;
-		UInt16 ownerID;
-		UInt16 attr;
 
-		ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID; 
-		attr	=	ownerID|memNewChunkFlagAllowLarge|memNewChunkFlagNonMovable;
-
-		newP = MemChunkNew(0, size, attr);
-	}
-*/
 	newP = MemGluePtrNew(size);
 
 	if (newP)
@@ -175,39 +43,12 @@
 
 	return newP;
 }
-
-#endif
 ///////////////////////////////////////////////////////////////////////////////
-#ifdef USE_EXTENDEDMEM
-Err free(MemPtr memP)
-{
-	Err err = memErrInvalidParam;
-
-	if (!memP)
-		return err;
-
-	if (MemPtrDataStorage(memP)) {		// if storage heap ?
-		if (gExtMemory) {				// if memory DB exists
-			DmOpenRef where;
-			MemHandle newH = MemPtrRecoverHandle(memP);
-			UInt16 index = DmSearchRecord(newH, &where);
-			err = DmRemoveRecord(gExtMemory, index);
-		}
-	}
-	else
-		err = MemChunkFree(memP);
-
-	return err;
-}
-#else
-Err free(MemPtr memP)
-{
+Err free(MemPtr memP) {
 	if (memP)
 		return MemPtrFree(memP);
-	
 	return memErrInvalidParam;
 }
-#endif
 ///////////////////////////////////////////////////////////////////////////////
 MemPtr realloc(MemPtr oldP, UInt32 size)
 {

Index: stdlib.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/PalmOS/Src/missing/stdlib.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- stdlib.h	30 Apr 2003 21:08:44 -0000	1.2
+++ stdlib.h	8 Jun 2003 09:28:18 -0000	1.3
@@ -24,30 +24,18 @@
 #define STDLIB_H
 
 #include <PalmOS.h>
+#include "MemGlue.h"
 #include "mathlib.h"
 
-//#define memNewChunkFlagNonMovable	0x0200 
-#define memNewChunkFlagAllowLarge	0x1000  // this is not in the sdk *g* 
-#define memHeapFlagReadOnly			0x0001
-
-#define	NO_HEAP_FOUND				-1
-
-SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP) 
-							SYS_TRAP(sysTrapSysGetAppInfo); 
-
-
 #define atoi				StrAToI
 #define atol				StrAToI
 #define abs(a)				((a) < 0 ? -(a) : (a))
 //#define abs					fabs
-#define	malloc(a)			calloc(a,1)
+#define	malloc(a)			MemGluePtrNew(a)
 //#define free				MemPtrFree
 #define strtol(a,b,c)		StrAToI(a)
-#define qsort(a,b,c,d)
+#define qsort(a,b,c,d)		SysQSort((a), (b), (c), (CmpFuncPtr)(&d), 0);
 #define rand()				SysRandom(0)
-
-void MemExtInit();
-void MemExtCleanup();
 
 MemPtr realloc(MemPtr oldP, UInt32 size);
 MemPtr calloc(UInt32 nelem, UInt32 elsize);





More information about the Scummvm-git-logs mailing list