ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.73 by root, Wed Apr 2 11:13:53 2008 UTC vs.
Revision 1.74 by root, Fri Apr 11 21:09:52 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
37#include <material.h> 37#include <material.h>
38 38
39#include <glib.h> 39#include <glib.h>
40 40
41refcnt_base::refcnt_t refcnt_dummy; 41refcnt_base::refcnt_t refcnt_dummy;
42size_t slice_alloc; 42ssize_t slice_alloc;
43rand_gen rndm; 43rand_gen rndm;
44 44
45void 45void
46tausworthe_random_generator::seed (uint32_t seed) 46tausworthe_random_generator::seed (uint32_t seed)
47{ 47{
48 state [0] = seed * 69069U; if (state [0] < 2U) state [0] += 2U; 48 state [0] = seed * 69069U; if (state [0] < 2U) state [0] += 2U;
49 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; 49 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U;
50 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; 50 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U;
51 state [3] = state [2] * 69069U; if (state [0] < 128) state [0] += 128U; 51 state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U;
52 52
53 for (int i = 11; --i; ) 53 for (int i = 11; --i; )
54 operator ()(); 54 operator ()();
55} 55}
56 56
469 LOG (llevError, "fork abort: %s\n", msg); 469 LOG (llevError, "fork abort: %s\n", msg);
470} 470}
471 471
472void *salloc_ (int n) throw (std::bad_alloc) 472void *salloc_ (int n) throw (std::bad_alloc)
473{ 473{
474#if PREFER_MALLOC
475 void *ptr = malloc (n);
476#else
477 slice_alloc += n;
478 void *ptr = g_slice_alloc (n); 474 void *ptr = g_slice_alloc (n);
479#endif
480 475
481 if (!ptr) 476 if (!ptr)
482 throw std::bad_alloc (); 477 throw std::bad_alloc ();
483 478
479 slice_alloc += n;
484 return ptr; 480 return ptr;
485} 481}
486 482
487void *salloc_ (int n, void *src) throw (std::bad_alloc) 483void *salloc_ (int n, void *src) throw (std::bad_alloc)
488{ 484{
515 return memset (g_slice_alloc (size), 0, size); 511 return memset (g_slice_alloc (size), 0, size);
516} 512}
517 513
518void g_slice_free1 (unsigned long size, void *ptr) 514void g_slice_free1 (unsigned long size, void *ptr)
519{ 515{
516 //fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D
520 if (expect_true (ptr)) 517 if (expect_true (ptr))
521 { 518 {
522 //fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D
523 unsigned long *p = (unsigned long *)ptr; 519 unsigned long *p = (unsigned long *)ptr;
524 unsigned long s = *--p ^ MAGIC; 520 unsigned long s = *--p ^ MAGIC;
525 521
526 if (size != (unsigned long)(*p ^ MAGIC)) 522 if (size != (unsigned long)(*p ^ MAGIC))
523 {
527 LOG (logBacktrace | llevError, "slice free size (%lx) doesn't match alloc size (%lx)\n", size, s); 524 LOG (logBacktrace | llevError, "slice free size (%lx) doesn't match alloc size (%lx)\n", size, s);
525 abort ();
526 }
528 527
529 *p = MAGIC; 528 *p = MAGIC;
530 529
531 (g_slice_free1)(s + sizeof (unsigned long), p); 530 (g_slice_free1)(s + sizeof (unsigned long), p);
532 } 531 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines