Пример #1
1
/* This is where execution begins [windowed apps] */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
{
    char **argv;
    int argc;
    char *cmdline;
    char *bufp;
    size_t nLen;

    /* Grab the command line */
    bufp = GetCommandLine();
    nLen = SDL_strlen(bufp) + 1;
    cmdline = SDL_stack_alloc(char, nLen);
    if (cmdline == NULL) {
        return OutOfMemory();
    }
    SDL_strlcpy(cmdline, bufp, nLen);

    /* Parse it into argv and argc */
    argc = ParseCommandLine(cmdline, NULL);
    argv = SDL_stack_alloc(char *, argc + 1);
    if (argv == NULL) {
        return OutOfMemory();
    }
    ParseCommandLine(cmdline, argv);

    /* Run the main program */
    console_main(argc, argv);

    /* Hush little compiler, don't you cry... */
    return 0;
}
Пример #2
0
//
// WinMain function
//
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
   char **argv;
   int    argc;
   char  *cmdline;

   // grab the command lien
   char *text = GetCommandLineA();
   cmdline = mystrdup(text);

   if(!cmdline)
   {
      OutOfMemory();
      return 0;
   }

   // parse into argv, argc
   argc = Win32_parseCommandLine(cmdline, NULL);
   argv = (char **)(calloc(argc + 1, sizeof(char *)));
   if(!argv)
   {
      OutOfMemory();
      return 0;
   }
   Win32_parseCommandLine(cmdline, argv);

   // run application main program
   Jag68k_main(argc, argv);

   free(argv);
   free(cmdline);

   return 0;
}
Пример #3
0
int WINAPI G3D_WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {
    char **argv;
    int argc;
    int status;
    char *cmdline;
#   ifdef _WIN32_WCE
        wchar_t *bufp;
        int nLen;
#   else
        char *bufp;
        size_t nLen;
#   endif
    (void)sw;
    (void)szCmdLine;
    (void)hInst;
    (void)hPrev;

#ifdef _WIN32_WCE
#error WinCE not supported
    /*
    nLen = wcslen(szCmdLine) + 128 + 1;
    bufp = SDL_stack_alloc(wchar_t, nLen * 2);
    wcscpy(bufp, TEXT("\""));
    GetModuleFileName(NULL, bufp + 1, 128 - 3);
    wcscpy(bufp + wcslen(bufp), TEXT("\" "));
    wcsncpy(bufp + wcslen(bufp), szCmdLine, nLen - wcslen(bufp));
    nLen = wcslen(bufp) + 1;
    cmdline = SDL_stack_alloc(char, nLen);
    if (cmdline == NULL) {
        return OutOfMemory();
    }
    WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
    */
#else
    /* Grab the command line */
    bufp = GetCommandLineA();
    nLen = strlen(bufp) + 1;
    cmdline = (char*)malloc(sizeof(char) * nLen);
    if (cmdline == NULL) {
        return OutOfMemory();
    }
    strncpy(cmdline, bufp, nLen);
#endif

    /* Parse it into argv and argc */
    argc = ParseCommandLine(cmdline, NULL);
    argv = (char**)malloc(sizeof(char*) * (argc + 1));
    if (argv == NULL) {
        return OutOfMemory();
    }
    ParseCommandLine(cmdline, argv);

    /* Run the main program */
    status = main(argc, (const char**)argv);
    free(argv);
    free(cmdline);

    return status;
}
Пример #4
0
static void PrepareData(void){

  TCHAR sTmp[5];

  if (NumberOfAirspaces==0) return;

  sNameFilter[0] =_T('\0');
  AirspaceSelectInfo = (AirspaceSelectInfo_t*)
    malloc(sizeof(AirspaceSelectInfo_t) * NumberOfAirspaces);

  if (AirspaceSelectInfo==NULL) {
	OutOfMemory(_T(__FILE__),__LINE__);
	return;
  }

  StrIndex = (int*)malloc(sizeof(int)*(NumberOfAirspaces+1));
  if (StrIndex==NULL) {
        OutOfMemory(_T(__FILE__),__LINE__);

        return;
  }

  int index=0;
  double bearing;
  double distance;
  CAirspaceList Airspaces = CAirspaceManager::Instance().GetAllAirspaces();
  CAirspaceList::const_iterator it;
  for (it=Airspaces.begin(); it != Airspaces.end(); ++it) {
    AirspaceSelectInfo[index].airspace = *it;

	distance = DISTANCEMODIFY * (*it)->Range(Longitude, Latitude, bearing);
	if (distance<0) distance=0;
    AirspaceSelectInfo[index].Distance = distance;
	AirspaceSelectInfo[index].Direction = bearing;

    LK_tcsncpy(sTmp, (*it)->Name(), 4);
    CharUpper(sTmp);

    AirspaceSelectInfo[index].FourChars =
                    (((unsigned)sTmp[0] & 0xff) << 24)
                  + (((unsigned)sTmp[1] & 0xff) << 16)
                  + (((unsigned)sTmp[2] & 0xff) << 8)
                  + (((unsigned)sTmp[3] & 0xff) );

    AirspaceSelectInfo[index].Type = (*it)->Type();

    index++;
  }

  qsort(AirspaceSelectInfo, UpLimit,
      sizeof(AirspaceSelectInfo_t), AirspaceNameCompare);

}
Пример #5
0
    void GlobalExceptionHandler::newHandler()
#ifndef OPENMS_COMPILER_MSVC
    throw(OutOfMemory)
#endif
    {
      throw OutOfMemory(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
Пример #6
0
void* FMallocTBB::Malloc( SIZE_T Size, uint32 Alignment )
{
	IncrementTotalMallocCalls();

	MEM_TIME(MemTime -= FPlatformTime::Seconds());

	void* NewPtr = NULL;
	if( Alignment != DEFAULT_ALIGNMENT )
	{
		Alignment = FMath::Max(Size >= 16 ? (uint32)16 : (uint32)8, Alignment);
		NewPtr = scalable_aligned_malloc( Size, Alignment );
	}
	else
	{
		NewPtr = scalable_malloc( Size );
	}

	if( !NewPtr && Size )
	{
		OutOfMemory(Size, Alignment);
	}
#if UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT
	else if (Size)
	{
		FMemory::Memset(NewPtr, DEBUG_FILL_NEW, Size); 
	}
#endif
	MEM_TIME(MemTime += FPlatformTime::Seconds());
	return NewPtr;
}
Пример #7
0
void PAWN::promote(PIECETYPE promoteType)
  {
    switch (promoteType)
      {
      case TYPEQUEEN:
        promotePiece = new QUEEN(whatColor());
        break;

      case TYPEROOK:
        promotePiece = new ROOK(whatColor());
        break;

      case TYPEBISHOP:
        promotePiece = new BISHOP(whatColor());
        break;

      case TYPEKNIGHT:
        promotePiece = new KNIGHT(whatColor());
        break;
      }

    if (!promotePiece)
      OutOfMemory();

    return;
  }
Пример #8
0
/* X=Trans*X : computes IN PLACE the transformation X=Trans*X.  X: nxT, Trans: nxn */
void Transform(double *X, double *Trans, int n, int T)
{
	double *Tx; /* buffer for a column vector */
	int i, s, t;
	int Xind, Xstart, Xstop;
	double sum;

	Tx = (double *)calloc(n, sizeof(double));
	if (Tx == NULL) OutOfMemory();

	for (t = 0; t<T; t++)
	{
		Xstart = t * n;
		Xstop = Xstart + n;

		/* stores in Tx the t-th colum of X transformed by Trans */
		for (i = 0; i<n; i++) {
			sum = 0.0;
			for (s = i, Xind = Xstart; Xind<Xstop; s += n, Xind++)
				sum += Trans[s] * X[Xind];
			Tx[i] = sum;
		}

		/* plugs the transformed vector back in the orignal matrix */
		for (i = 0, Xind = Xstart; i< n; i++, Xind++)
			X[Xind] = Tx[i];
	}
	free(Tx);
}
Пример #9
0
void* PTHeapImpl::allocate(size_t size)
{
    void * p = allocate_(size);
    if(!p)
        throw OutOfMemory();
    return p;
}
/* W = sqrt(inv(cov(X)))  */
void ComputeWhitener (double *W, double *X, int n, int T)  
{//ok
  double threshold_W  = RELATIVE_W_THRESHOLD /  sqrt((double) T) ;
  double *Cov  = (double *) calloc(n*n,     sizeof(double)) ; 
  double rescale ;
  int i,j ;

  if (Cov == NULL) OutOfMemory() ;

  EstCovMat (Cov, X, n, T) ; 

  printf ("covmat\n");
  PrintMat (Cov, n, n) ;
  printf ("\n");

  Diago (Cov, W, n, threshold_W)  ;

  printf ("diago\n");
  PrintMat (Cov, n, n) ;
  printf ("\n");

  for (i=0; i<n; i++) {
    rescale= 1.0 / sqrt (Cov[i+i*n]) ;
    for (j=0; j< n ; j++) 
      W[i*n+j] = rescale * W[i*n+j] ;
  }
  free(Cov);//done
}
Пример #11
0
void *AllocBufmemR (ULONG size, globaldata *g)
{
  ULONG *buffer;

	while (!(buffer = AllocBufmem (size, g)))
		OutOfMemory (g);

	return buffer;
}
Пример #12
0
/*
 * Retrying AllocVec
 */
VOID *AllocMemR (ULONG size, ULONG flags, globaldata *g)
{
 UBYTE *buffer;

	while (!(buffer=AllocVec (size, flags)))
	{
		OutOfMemory (g);
	}

	return buffer;
}
Пример #13
0
Channel* ChannelRegistry::add(const std::string& channelName) {
	ND_DEBUG("[ChannelRegistry] Request to add new Channel named %s.\n", channelName.c_str());

	if ( exists(channelName) ) throw AlreadyExists(AlreadyExists::msg("channel", channelName));

	Channel* channelPtr = new Channel(channelName);
	if ( !channelPtr ) throw OutOfMemory("ChannelRegistry::autoLoad: Unable to allocate memory for new Channel.");
	_channels[channelName] = channelPtr;

	return (channelPtr);
}
Пример #14
0
//
// strdup polyfill
//
static char *mystrdup(const char *instr)
{
   size_t  len = strlen(instr) + 1;
   char   *buf = malloc(len);
   if(!buf)
   {
      OutOfMemory();
      return NULL;
   }
   return strncpy(buf, instr, len);
}
Пример #15
0
void TypeIndexMap::Reset( const uint count )
/******************************************/
{
    try {
        _mappingTable.ClearAndReset( count );
        Init(count);
    }
    // temporary internal testing code.
    catch (...) {
        throw OutOfMemory( DEF_ARRAY_SIZE * sizeof(int) );
    }
}
Пример #16
0
ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
{
    // Allocate client side handles.
    const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
    if (client == HandleRangeAllocator::kInvalidHandle)
        return OutOfMemory() << "Failed to allocate path handle range.";

    const auto &paths = factory->createPaths(range);
    if (paths.empty())
    {
        mHandleAllocator.releaseRange(client, range);
        return OutOfMemory() << "Failed to allocate path objects.";
    }

    for (GLsizei i = 0; i < range; ++i)
    {
        const auto impl = paths[static_cast<unsigned>(i)];
        const auto id   = client + i;
        mPaths.assign(id, new Path(impl));
    }
    return client;
}
Пример #17
0
/* This is where execution begins [windowed apps] */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
	HINSTANCE handle;
	char **argv;
	int argc;
	char *cmdline;
	char *bufp;

	/* AllocConsole(); */

	/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
	   keep them open.  This is a hack.. hopefully it will be fixed 
	   someday.  DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
	 */
	handle = LoadLibrary(TEXT("DDRAW.DLL"));
	if ( handle != NULL ) {
		FreeLibrary(handle);
	}

	/* Grab the command line (use alloca() on Windows) */
	bufp = GetCommandLine();
	cmdline = (char *)alloca(strlen(bufp)+1);
	if ( cmdline == NULL ) {
		return OutOfMemory();
	}
	strcpy(cmdline, bufp);

	/* Parse it into argv and argc */
	argc = ParseCommandLine(cmdline, NULL);
	argv = (char **)alloca((argc+1)*(sizeof *argv));
	if ( argv == NULL ) {
		return OutOfMemory();
	}
	ParseCommandLine(cmdline, argv);

	/* Run the main program (after a little SDL initialization) */
	return(console_main(argc, argv));
}
Пример #18
0
void *BasicAlloc(size_t size) {
    void *newBlock;
    newBlock = malloc(size);
    if (newBlock == NULL) if (size != 0) {
        // We are fried.
        OutOfMemory();
    }
    if (size != 0) {
        g_memUsed += _msize(newBlock);
    }
    g_maxMemUsage = __max(g_maxMemUsage, g_memUsed);
    g_numAllocCalls++;
    return newBlock;
}
Пример #19
0
void Jade(
	    /* Input.  Number of samples  */
	double *B, /* Output. Separating matrix. nbc*nbc */
	double *X, /* Input.  Data set nbc x nbs */
	int nbc,   /* Input.  Number of sensors  */
	int nbs
	)
{
	double threshold_JD = RELATIVE_JD_THRESHOLD / sqrt((double)nbs);
	int rots = 1;
	int i;
	double *Transf = (double *)calloc(nbc*nbc, sizeof(double));
	double *CumTens = (double *)calloc(nbc*nbc*nbc*nbc, sizeof(double));
	if (Transf == NULL || CumTens == NULL) OutOfMemory();
	/*
	printf("teste \n");
	for (i = 0; i < nbc*nbs; i++){
		if (X[i] == X[i]){
			printf("teste %lf", X[i]);
		}
	}*/
	/* Init */
	Message0(2, "Init...\n");
	Identity(B, nbc);

	MeanRemoval(X, nbc, nbs);

	Message0(2, "Whitening...\n");
	ComputeWhitener(Transf, X, nbc, nbs);
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	Message0(2, "Estimating the cumulant tensor...\n");
	EstCumTens(CumTens, X, nbc, nbs);

	Message0(2, "Joint diagonalization...\n");
	rots = JointDiago(CumTens, Transf, nbc, nbc*nbc, threshold_JD);
	MessageI(3, "Total number of plane rotations: %6i.\n", rots);
	MessageF(3, "Size of the total rotation: %10.7e\n", NonIdentity(Transf, nbc));

	Message0(2, "Updating...\n");
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	

	free(Transf);
	free(CumTens);
}
Пример #20
0
/* This is where execution begins [windowed apps] */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
    char **argv;
    int argc;
    char *cmdline;

    /* Grab the command line */
    TCHAR *text = GetCommandLine();
#if UNICODE
    cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));
#else
    cmdline = SDL_strdup(text);
#endif
    if (cmdline == NULL) {
        return OutOfMemory();
    }

    /* Parse it into argv and argc */
    argc = ParseCommandLine(cmdline, NULL);
    argv = SDL_stack_alloc(char *, argc + 1);
    if (argv == NULL) {
        return OutOfMemory();
    }
    ParseCommandLine(cmdline, argv);

    /* Run the main program */
    console_main(argc, argv);

    SDL_stack_free(argv);

    SDL_free(cmdline);

    /* Hush little compiler, don't you cry... */
    return 0;
}
Пример #21
0
/* This is where execution begins [console apps] */
int console_main(int argc, char *argv[])
{
	int n;
	char *bufp, *appname;

	/* Get the class name from argv[0] */
	appname = argv[0];
	if ( (bufp=strrchr(argv[0], '\\')) != NULL ) {
		appname = bufp+1;
	} else
	if ( (bufp=strrchr(argv[0], '/')) != NULL ) {
		appname = bufp+1;
	}

	if ( (bufp=strrchr(appname, '.')) == NULL )
		n = strlen(appname);
	else
		n = (bufp-appname);

	bufp = (char *)alloca(n+1);
	if ( bufp == NULL ) {
		return OutOfMemory();
	}
	strncpy(bufp, appname, n);
	bufp[n] = '\0';
	appname = bufp;

	/* Load SDL dynamic link library */
	if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
		ShowError("WinMain() error", SDL_GetError());
		return(FALSE);
	}
	atexit(cleanup_output);
	atexit(SDL_Quit);

#ifndef DISABLE_VIDEO
	SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif /* !DISABLE_VIDEO */

	/* Run the application main() code */
	SDL_main(argc, argv);

	/* Exit cleanly, calling atexit() functions */
	exit(0);

	/* Hush little compiler, don't you cry... */
	return(0);
}
Пример #22
0
//=============================================================================
void *  MemRealloc (void * ptr, size_t bytes, const char file[], int line) {
#ifdef USE_MALLOC
    if (void * result = _realloc_dbg(ptr, bytes, _NORMAL_BLOCK, file, line))
        return result;
#else
    REF(file);
    REF(line);
    if (!s_heap)
        s_heap = GetProcessHeap();

    if (void * result = HeapReAlloc(s_heap, 0, ptr, bytes))
        return result;
#endif
    OutOfMemory();
    return NULL;
}
Пример #23
0
void* MemoryPoolManager::allocate()
{
	int address = 0;

	if(this->head != nullptr)
	{
		address = (int)this->head;
		this->head = (void*) ((Chunk*)this->head)->next; //remove the head from the free list
	}
	else
	{
		OutOfMemory();
	}

	return (void*) ((Chunk*)address)->getData();
}
Пример #24
0
// ------------------------------------------------------------------------- //
//  * GetTraceMonitor( void )
// ------------------------------------------------------------------------- //
TNewtonTraceMonitor*
TNewtonTraceMonitor::GetTraceMonitor( unsigned int inMode )
{
	TNewtonTraceMonitor* theResult = (TNewtonTraceMonitor*) GetObject( kName );

	if (theResult == nil)
	{
		// CrŽation de l'objet.
		theResult = new TNewtonTraceMonitor( inMode );
		
		if (theResult == nil)
			OutOfMemory();
		
		// Enregistrement.
		(void) CreateObject( theResult, kName );
	}
	
	return theResult;
}
Пример #25
0
/* W = sqrt(inv(cov(X)))  */
void ComputeWhitener(double *W, double *X, int n, int T)
{
	double threshold_W = RELATIVE_W_THRESHOLD / sqrt((double)T);
	double *Cov = (double *)calloc(n*n, sizeof(double));
	double rescale;
	int i, j;

	if (Cov == NULL) OutOfMemory();

	EstCovMat(Cov, X, n, T);

	Diago(Cov, W, n, threshold_W);

	for (i = 0; i<n; i++) {
		rescale = 1.0 / sqrt(Cov[i + i*n]);
		for (j = 0; j< n; j++)
			W[i + j*n] = rescale * W[i + j*n];
	}
	free(Cov);
}
Пример #26
0
void Shibbs(double *B, /* Output. Separating matrix. nbc*nbc */
	double *X, /* Input.  Data set nbc x nbs */
	int nbc,   /* Input.  Number of sensors  */
	int nbs    /* Input.  Number of samples  */
	)
{
	double threshold_JD = RELATIVE_JD_THRESHOLD / sqrt((double)nbs);

	int rots = 1;

	double *Transf = (double *)calloc(nbc*nbc, sizeof(double));
	double *CumMats = (double *)calloc(nbc*nbc*nbc, sizeof(double));
	if (Transf == NULL || CumMats == NULL) OutOfMemory();

	/* Init */
	Message0(2, "Init...\n");
	Identity(B, nbc);
	MeanRemoval(X, nbc, nbs);

	Message0(2, "Whitening...\n");
	ComputeWhitener(Transf, X, nbc, nbs);
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	while (rots>0)
	{
		Message0(2, "Computing cumulant matrices...\n");
		EstCumMats(CumMats, X, nbc, nbs);

		Message0(2, "Joint diagonalization...\n");
		rots = JointDiago(CumMats, Transf, nbc, nbc, threshold_JD);
		MessageI(3, "Total number of plane rotations: %6i.\n", rots);
		MessageF(3, "Size of the total rotation: %10.7e\n", NonIdentity(Transf, nbc));

		Message0(2, "Updating...\n");
		Transform(X, Transf, nbc, nbs);
		Transform(B, Transf, nbc, nbc);
	}
	free(Transf);
	free(CumMats);
}
Пример #27
0
int substr(const char *str1, const char *str2, Bool StripAnsi)
	{
	char *tmp1, *tmp2;
	int toreturn;

	tmp1 = strdup(str1);
	tmp2 = strdup(str2);

	if (tmp1 == NULL || tmp2 == NULL)
		{
		delete [] tmp1;
		delete [] tmp2;

		OutOfMemory(6);
		return (CERROR);
		}

	strlwr(tmp1);
	strlwr(tmp2);

	if (StripAnsi)
		{
		stripansi(tmp1);
		stripansi(tmp2);
		}

	const char *result = strstr(tmp1, tmp2);
	if (result == NULL)
		{
		toreturn = CERROR;
		}
	else
		{
		toreturn = (int) (result - tmp1);
		}

	delete [] tmp1;
	delete [] tmp2;

	return (toreturn);
	}
Пример #28
0
void* FMallocTBB::Realloc( void* Ptr, SIZE_T NewSize, uint32 Alignment )
{
	IncrementTotalReallocCalls();

	MEM_TIME(MemTime -= FPlatformTime::Seconds())
#if UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT
	SIZE_T OldSize = 0;
	if (Ptr)
	{
		OldSize = scalable_msize(Ptr);
		if (NewSize < OldSize)
		{
			FMemory::Memset((uint8*)Ptr + NewSize, DEBUG_FILL_FREED, OldSize - NewSize); 
		}
	}
#endif
	void* NewPtr = NULL;
	if (Alignment != DEFAULT_ALIGNMENT)
	{
		Alignment = FMath::Max(NewSize >= 16 ? (uint32)16 : (uint32)8, Alignment);
		NewPtr = scalable_aligned_realloc(Ptr, NewSize, Alignment);
	}
	else
	{
		NewPtr = scalable_realloc(Ptr, NewSize);
	}
#if UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT
	if (NewPtr && NewSize > OldSize )
	{
		FMemory::Memset((uint8*)NewPtr + OldSize, DEBUG_FILL_NEW, NewSize - OldSize); 
	}
#endif
	if( !NewPtr && NewSize )
	{
		OutOfMemory(NewSize, Alignment);
	}
	MEM_TIME(MemTime += FPlatformTime::Seconds())
	return NewPtr;
}
Пример #29
0
    unsigned long
    Bzip2Compressor::compressBlock(char* dst, unsigned long dst_len, char* src, unsigned long src_len)
    {
      // Get proper compression level.
      int plevel = level();
      if (plevel < 1)
        plevel = 1;

      unsigned compressed_length = dst_len;
      int rv = BZ2_bzBuffToBuffCompress(dst, &compressed_length, src, src_len, plevel, 0, 0);

      if (rv == BZ_OK)
        return compressed_length;

      if (rv == BZ_MEM_ERROR)
        throw OutOfMemory();

      if (rv == BZ_OUTBUFF_FULL)
        throw BufferTooShort(dst_len);

      return 0;
    }
Пример #30
0
// put all the pieces for one color at their starting positions on
// the board
LOCAL void setupPieces
  (
    PIECE *board[][NUMCOLS],
    PIECECOLOR color,
    // column in which the non-pawn pieces go
    int backCol,
    // column in which the pawns go
    int pawnCol
  )
  {
    BOOL f = TRUE;
    int row;

    #define NEWPIECE(P, ROWOFFSET, COLOFFSET) \
      f = f && \
          ((board[ROWOFFSET][COLOFFSET] = new P) != (PIECE *) 0);

    NEWPIECE(ROOK(color), 0, backCol);
    NEWPIECE(KNIGHT(color), 1, backCol);
    NEWPIECE(BISHOP(color), 2, backCol);
    NEWPIECE(QUEEN(color), 3, backCol);
    NEWPIECE(KING(color), 4, backCol);
    NEWPIECE(BISHOP(color), 5, backCol);
    NEWPIECE(KNIGHT(color), 6, backCol);
    NEWPIECE(ROOK(color), 7, backCol);

    for (row = 0; row < NUMROWS; row++)
      NEWPIECE(PAWN(color), row, pawnCol);

    if (!f)
      OutOfMemory();

    return;

    #undef NEWPIECE
  }