static void __pyx_f_16coercearraytoptr_eggs(void) { char __pyx_v_silly[42]; struct __pyx_t_16coercearraytoptr_Grail __pyx_v_grail; /* "/Local/Projects/D/Pyrex/Source/Tests/6/coercearraytoptr.pyx":9 */ spam(__pyx_v_silly); /* "/Local/Projects/D/Pyrex/Source/Tests/6/coercearraytoptr.pyx":10 */ spam(__pyx_v_grail.silly); }
void masterhandler(nick *np, int message, void **args) { char *msg; switch(message) { case LU_KILLED: cmnick=NULL; scheduleoneshot(time(NULL)+1, makenick, NULL); break; case LU_CHANMSG: msg=args[2]; if (!ircd_strncmp(msg, "!spawn ",7)) { spawnclones(strtoul(msg+7,NULL,10)); } if (!ircd_strncmp(msg,"!join ",6)) { join(msg+6); } if (!ircd_strncmp(msg,"!spam ", 6)) { spam(strtoul(msg+6, NULL, 10)); } break; } }
void check_all(struct MP *mp) { struct MPMAP *mpm = &mp->mpm; while(mpm) { volatile unsigned char *c = (unsigned char *)mpm; unsigned int len = mpm->size; spam("checking object %p - size %u\n", mpm, len); while (len--) { c[len]; } mpm=mpm->next; } }
void mpool_free(struct MP *mp, void *ptr) { struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD); unsigned int sbits; if (!ptr) return; #ifdef CL_DEBUG assert(f->magic == MPOOLMAGIC && "Attempt to mpool_free a pointer we did not allocate!"); memset(ptr, FREEPOISON, from_bits(f->u.sbits) - FRAG_OVERHEAD); #endif sbits = f->u.sbits; f->u.next = mp->avail[sbits]; mp->avail[sbits] = f; spam("free @ %p\n", f); }
struct MP *mpool_create() { struct MP mp, *mpool_p; unsigned int sz; memset(&mp, 0, sizeof(mp)); mp.psize = getpagesize(); sz = align_to_pagesize(&mp, MIN_FRAGSIZE); mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP)); mp.mpm.size = sz - align_to_voidptr(sizeof(mp)); if ((mpool_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED) return NULL; #ifdef CL_DEBUG memset(mpool_p, ALLOCPOISON, sz); #endif memcpy(mpool_p, &mp, sizeof(mp)); spam("Map created @ %p->%p - size %u out of %u\n", mpool_p, (char *)mpool_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size); return mpool_p; }
/* Generated by Pyrex 0.4 on Wed Sep 4 19:45:38 2002 */ #include "Python.h" #include "foo.h" static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/ static int __Pyx_EndUnpack(PyObject *, int); /*proto*/ static int __Pyx_PrintItem(PyObject *); /*proto*/ static int __Pyx_PrintNewline(void); /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static void __Pyx_ReRaise(void); /*proto*/ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ static PyObject *__Pyx_GetExcValue(void); /*proto*/ static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, char *name); /*proto*/ static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/ static void __Pyx_WriteUnraisable(char *name); /*proto*/ static void __Pyx_AddTraceback(char *funcname); /*proto*/ static PyObject *__pyx_m; static PyObject *__pyx_b; static char *__pyx_srcfile = "ProjectsA:Python:Pyrex:Tests:(experiments):big_t.pyx"; static int __pyx_lineno; static struct PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; DL_EXPORT(void) initbig_t(void); /*proto*/ DL_EXPORT(void) initbig_t(void) { PyObject *__pyx_1 = 0; long long __pyx_2; __pyx_m = Py_InitModule4("big_t", __pyx_methods, 0, 0, PYTHON_API_VERSION); __pyx_b = PyImport_AddModule("__builtin__"); PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b); /* "ProjectsA:Python:Pyrex:Tests:(experiments):big_t.pyx":1 */ /* "ProjectsA:Python:Pyrex:Tests:(experiments):big_t.pyx":5 */ __pyx_1 = __Pyx_GetName(__pyx_b, "grail"); if (!__pyx_1) {__pyx_lineno = 5; goto __pyx_L1;} __pyx_2 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_lineno = 5; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; spam(__pyx_2); return; __pyx_L1:; Py_XDECREF(__pyx_1); __Pyx_AddTraceback("big_t"); }
void mpool_destroy(struct MP *mp) { struct MPMAP *mpm_next = mp->mpm.next, *mpm; unsigned int mpmsize; while((mpm = mpm_next)) { mpmsize = mpm->size; mpm_next = mpm->next; #ifdef CL_DEBUG memset(mpm, FREEPOISON, mpmsize); #endif munmap((void *)mpm, mpmsize); } mpmsize = mp->mpm.size; #ifdef CL_DEBUG memset(mp, FREEPOISON, mpmsize + align_to_voidptr(sizeof(*mp))); #endif munmap((void *)mp, mpmsize + align_to_voidptr(sizeof(*mp))); spam("Map destroyed @ %p\n", mp); }
void *mpool_realloc(struct MP *mp, void *ptr, size_t size) { struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD); unsigned int csize; void *new_ptr; if (!ptr) return mpool_malloc(mp, size); spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->u.sbits), size); if(!size || !(csize = from_bits(f->u.sbits))) { cli_errmsg("mpool_realloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size); return NULL; } csize -= FRAG_OVERHEAD; if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size)) return ptr; if (!(new_ptr = mpool_malloc(mp, size))) return NULL; memcpy(new_ptr, ptr, csize <= size ? csize : size); mpool_free(mp, ptr); return new_ptr; }
static void __pyx_f_11excvalcheck_eggs(void) { int __pyx_v_i; char *__pyx_v_p; int __pyx_1; char *__pyx_2; /* "/Local/Projects/D/Pyrex/Source/Tests/7/excvalcheck.pyx":8 */ __pyx_1 = spam(); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;} __pyx_v_i = __pyx_1; /* "/Local/Projects/D/Pyrex/Source/Tests/7/excvalcheck.pyx":9 */ grail(); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;} /* "/Local/Projects/D/Pyrex/Source/Tests/7/excvalcheck.pyx":10 */ __pyx_2 = tomato(); if (__pyx_2 == NULL && PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;} __pyx_v_p = __pyx_2; goto __pyx_L0; __pyx_L1:; __Pyx_WriteUnraisable("excvalcheck.eggs"); __pyx_L0:; }
void mpool_flush(struct MP *mp) { size_t used = 0, mused; struct MPMAP *mpm_next = mp->mpm.next, *mpm; while((mpm = mpm_next)) { mpm_next = mpm->next; #ifdef CL_DEBUG memset((char *)mpm + align_to_pagesize(mp, mpm->usize), FREEPOISON, mpm->size - align_to_pagesize(mp, mpm->usize)); #endif munmap((char *)mpm + align_to_pagesize(mp, mpm->usize), mpm->size - align_to_pagesize(mp, mpm->usize)); mpm->size = align_to_pagesize(mp, mpm->usize); used += mpm->size; } mused = align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(*mp))); if (mused < mp->mpm.size) { #ifdef CL_DEBUG memset((char *)&mp->mpm + mused, FREEPOISON, mp->mpm.size - mused); #endif munmap((char *)&mp->mpm + mused, mp->mpm.size - mused); mp->mpm.size = mused; } used += mp->mpm.size; spam("Map flushed @ %p, in use: %lu\n", mp, used); }
Timed::Timed(int ac, char **av) : QCoreApplication(ac, av), peer(NULL) // session_bus_name("timed_not_connected"), // session_bus_address("invalid_address") { spam() ; halted = "" ; // XXX: remove it, as we don't want to halt anymore first_boot_date_adjusted = false; log_debug() ; init_scratchbox_mode() ; log_debug() ; init_unix_signal_handler() ; log_debug() ; QMLOG_IF init_dbus_peer_info() ; log_debug() ; QMLOG_ENDIF ; // init_act_dead() ; // init_dsme_mode() ; log_debug() ; init_configuration() ; log_debug() ; init_customization() ; log_debug() ; init_read_settings() ; log_debug() ; init_create_event_machine() ; log_debug() ; init_device_mode() ; log_debug() ; init_context_objects() ; log_debug() ; init_backup_object() ; log_debug() ; init_main_interface_object() ; log_debug() ; init_backup_dbus_name() ; log_debug() ; init_main_interface_dbus_name() ; log_debug() ; start_voland_watcher(); log_debug() ; init_kernel_notification(); init_first_boot_hwclock_time_adjustment_check(); log_debug() ; init_load_events() ; log_debug() ; #if OFONO init_cellular_services() ; #endif // OFONO log_debug() ; init_network_events() ; log_debug() ; init_dst_checker() ; log_debug("starting event mahine") ; init_start_event_machine() ; log_debug() ; log_debug("applying time zone settings") ; init_apply_tz_settings() ; log_debug() ; log_info("daemon is up and running") ; }
void OctreeTests::byteCountCodingTests() { bool verbose = true; qDebug() << "FIXME: this test is broken and needs to be fixed."; qDebug() << "We're disabling this so that ALL_BUILD works"; return; if (verbose) { qDebug() << "******************************************************************************************"; } qDebug() << "OctreeTests::byteCountCodingTests()"; QByteArray encoded; if (verbose) { qDebug() << "ByteCountCodedUINT zero(0)"; } ByteCountCodedUINT zero(0); encoded = zero.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedZero; decodedZero.decode(encoded); QCOMPARE(decodedZero.data, static_cast<decltype(decodedZero.data)>( 0 )); QCOMPARE(decodedZero, zero); ByteCountCodedUINT decodedZeroB(encoded); QCOMPARE(decodedZeroB.data, (unsigned int) 0); if (verbose) { qDebug() << "ByteCountCodedUINT foo(259)"; } ByteCountCodedUINT foo(259); encoded = foo.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedFoo; decodedFoo.decode(encoded); QCOMPARE(decodedFoo.data, (unsigned int) 259); QCOMPARE(decodedFoo, foo); ByteCountCodedUINT decodedFooB(encoded); QCOMPARE(decodedFooB.data, (unsigned int) 259); if (verbose) { qDebug() << "ByteCountCodedUINT bar(1000000)"; } ByteCountCodedUINT bar(1000000); encoded = bar.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedBar; decodedBar.decode(encoded); QCOMPARE(decodedBar.data, (unsigned int) 1000000); QCOMPARE(decodedBar, bar); if (verbose) { qDebug() << "ByteCountCodedUINT spam(4294967295/2)"; } ByteCountCodedUINT spam(4294967295/2); encoded = spam.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedSpam; decodedSpam.decode(encoded); if (verbose) { qDebug() << "decodedSpam=" << decodedSpam.data; qDebug() << "decodedSpam==spam" << (decodedSpam==spam) << " { expected true } "; } QCOMPARE(decodedSpam.data, (unsigned int) 4294967295/2); QCOMPARE(decodedSpam, spam); if (verbose) { qDebug() << "ByteCountCodedQUINT64 foo64(259)"; } ByteCountCodedQUINT64 foo64(259); encoded = foo64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } if (verbose) { qDebug() << "testing... quint64 foo64POD = foo64;"; } quint64 foo64POD = foo64; if (verbose) { qDebug() << "foo64POD=" << foo64POD; } QCOMPARE(foo64POD, (quint64) 259); if (verbose) { qDebug() << "testing... encoded = foo64;"; } encoded = foo64; if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedFoo64; decodedFoo64 = encoded; if (verbose) { qDebug() << "decodedFoo64=" << decodedFoo64.data; qDebug() << "decodedFoo64==foo64" << (decodedFoo64==foo64) << " { expected true } "; } QCOMPARE(decodedFoo.data, (unsigned int) 259); QCOMPARE(decodedFoo64, foo64); if (verbose) { qDebug() << "ByteCountCodedQUINT64 bar64(1000000)"; } ByteCountCodedQUINT64 bar64(1000000); encoded = bar64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedBar64; decodedBar64.decode(encoded); QCOMPARE(decodedBar64.data, static_cast<decltype(decodedBar.data)>( 1000000 )); QCOMPARE(decodedBar64, bar64); if (verbose) { qDebug() << "ByteCountCodedQUINT64 spam64(4294967295/2)"; } ByteCountCodedQUINT64 spam64(4294967295/2); encoded = spam64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedSpam64; decodedSpam64.decode(encoded); QCOMPARE(decodedSpam64.data, static_cast<decltype(decodedSpam64.data)>( 4294967295/2 )); QCOMPARE(decodedSpam64, spam64); if (verbose) { qDebug() << "testing encoded << spam64"; } encoded.clear(); encoded << spam64; if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } if (verbose) { qDebug() << "testing encoded >> decodedSpam64"; } encoded >> decodedSpam64; QCOMPARE(decodedSpam64, spam64); if (verbose) { qDebug() << "NOW..."; } quint64 now = usecTimestampNow(); ByteCountCodedQUINT64 nowCoded = now; QByteArray nowEncoded = nowCoded; ByteCountCodedQUINT64 decodedNow = nowEncoded; QCOMPARE(decodedNow.data, static_cast<decltype(decodedNow.data)>( now )); if (verbose) { qDebug() << "******************************************************************************************"; } if (verbose) { qDebug() << "******************************************************************************************"; } }
void OctreeTests::byteCountCodingTests(bool verbose) { int testsTaken = 0; int testsPassed = 0; int testsFailed = 0; if (verbose) { qDebug() << "******************************************************************************************"; } qDebug() << "OctreeTests::byteCountCodingTests()"; QByteArray encoded; if (verbose) { qDebug() << "ByteCountCodedUINT zero(0)"; } ByteCountCodedUINT zero(0); encoded = zero.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedZero; decodedZero.decode(encoded); if (verbose) { qDebug() << "decodedZero=" << decodedZero.data; qDebug() << "decodedZero==zero" << (decodedZero == zero) << " { expected true } "; } testsTaken++; bool result1 = (decodedZero.data == 0); bool expected1 = true; if (result1 == expected1) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 1: ByteCountCodedUINT zero(0) decodedZero.data == 0"; } testsTaken++; bool result2 = (decodedZero == zero); bool expected2 = true; if (result2 == expected2) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 2: ByteCountCodedUINT zero(0) (decodedZero == zero)"; } ByteCountCodedUINT decodedZeroB(encoded); if (verbose) { qDebug() << "decodedZeroB=" << decodedZeroB.data; } testsTaken++; bool result3 = (decodedZeroB.data == 0); bool expected3 = true; if (result3 == expected3) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 3: (decodedZeroB.data == 0)"; } if (verbose) { qDebug() << "ByteCountCodedUINT foo(259)"; } ByteCountCodedUINT foo(259); encoded = foo.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedFoo; decodedFoo.decode(encoded); if (verbose) { qDebug() << "decodedFoo=" << decodedFoo.data; qDebug() << "decodedFoo==foo" << (decodedFoo == foo) << " { expected true } "; } testsTaken++; bool result4 = (decodedFoo.data == 259); bool expected4 = true; if (result4 == expected4) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 4: ByteCountCodedUINT zero(0) (decodedFoo.data == 259)"; } testsTaken++; bool result5 = (decodedFoo == foo); bool expected5 = true; if (result5 == expected5) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 5: (decodedFoo == foo)"; } ByteCountCodedUINT decodedFooB(encoded); if (verbose) { qDebug() << "decodedFooB=" << decodedFooB.data; } testsTaken++; bool result6 = (decodedFooB.data == 259); bool expected6 = true; if (result6 == expected6) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 6: (decodedFooB.data == 259)"; } if (verbose) { qDebug() << "ByteCountCodedUINT bar(1000000)"; } ByteCountCodedUINT bar(1000000); encoded = bar.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedBar; decodedBar.decode(encoded); if (verbose) { qDebug() << "decodedBar=" << decodedBar.data; qDebug() << "decodedBar==bar" << (decodedBar == bar) << " { expected true } "; } testsTaken++; bool result7 = (decodedBar.data == 1000000); bool expected7 = true; if (result7 == expected7) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 7: ByteCountCodedUINT zero(0) (decodedBar.data == 1000000)"; } testsTaken++; bool result8 = (decodedBar == bar); bool expected8 = true; if (result8 == expected8) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 8: (decodedBar == bar)"; } if (verbose) { qDebug() << "ByteCountCodedUINT spam(4294967295/2)"; } ByteCountCodedUINT spam(4294967295/2); encoded = spam.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedUINT decodedSpam; decodedSpam.decode(encoded); if (verbose) { qDebug() << "decodedSpam=" << decodedSpam.data; qDebug() << "decodedSpam==spam" << (decodedSpam==spam) << " { expected true } "; } testsTaken++; bool result9 = (decodedSpam.data == 4294967295/2); bool expected9 = true; if (result9 == expected9) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 9: (decodedSpam.data == 4294967295/2)"; } testsTaken++; bool result10 = (decodedSpam == spam); bool expected10 = true; if (result10 == expected10) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 10: (decodedSpam == spam)"; } if (verbose) { qDebug() << "ByteCountCodedQUINT64 foo64(259)"; } ByteCountCodedQUINT64 foo64(259); encoded = foo64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } if (verbose) { qDebug() << "testing... quint64 foo64POD = foo64;"; } quint64 foo64POD = foo64; if (verbose) { qDebug() << "foo64POD=" << foo64POD; } testsTaken++; bool result11 = (foo64POD == 259); bool expected11 = true; if (result11 == expected11) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 11: quint64 foo64POD = foo64"; } if (verbose) { qDebug() << "testing... encoded = foo64;"; } encoded = foo64; if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedFoo64; decodedFoo64 = encoded; if (verbose) { qDebug() << "decodedFoo64=" << decodedFoo64.data; qDebug() << "decodedFoo64==foo64" << (decodedFoo64==foo64) << " { expected true } "; } testsTaken++; bool result12 = (decodedFoo64.data == 259); bool expected12 = true; if (result12 == expected12) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 12: decodedFoo64.data == 259"; } testsTaken++; bool result13 = (decodedFoo64==foo64); bool expected13 = true; if (result13 == expected13) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 13: decodedFoo64==foo64"; } if (verbose) { qDebug() << "ByteCountCodedQUINT64 bar64(1000000)"; } ByteCountCodedQUINT64 bar64(1000000); encoded = bar64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedBar64; decodedBar64.decode(encoded); if (verbose) { qDebug() << "decodedBar64=" << decodedBar64.data; qDebug() << "decodedBar64==bar64" << (decodedBar64==bar64) << " { expected true } "; } testsTaken++; bool result14 = (decodedBar64.data == 1000000); bool expected14 = true; if (result14 == expected14) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 14: decodedBar64.data == 1000000"; } testsTaken++; bool result15 = (decodedBar64==bar64); bool expected15 = true; if (result15 == expected15) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 15: decodedBar64==bar64"; } if (verbose) { qDebug() << "ByteCountCodedQUINT64 spam64(4294967295/2)"; } ByteCountCodedQUINT64 spam64(4294967295/2); encoded = spam64.encode(); if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } ByteCountCodedQUINT64 decodedSpam64; decodedSpam64.decode(encoded); if (verbose) { qDebug() << "decodedSpam64=" << decodedSpam64.data; qDebug() << "decodedSpam64==spam64" << (decodedSpam64==spam64) << " { expected true } "; } testsTaken++; bool result16 = (decodedSpam64.data == 4294967295/2); bool expected16 = true; if (result16 == expected16) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 16: decodedSpam64.data == 4294967295/2"; } testsTaken++; bool result17 = (decodedSpam64==spam64); bool expected17 = true; if (result17 == expected17) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 17: decodedSpam64==spam64"; } if (verbose) { qDebug() << "testing encoded << spam64"; } encoded.clear(); encoded << spam64; if (verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } if (verbose) { qDebug() << "testing encoded >> decodedSpam64"; } encoded >> decodedSpam64; if (verbose) { qDebug() << "decodedSpam64=" << decodedSpam64.data; } testsTaken++; bool result18 = (decodedSpam64==spam64); bool expected18 = true; if (result18 == expected18) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 18: decodedSpam64==spam64"; } //ByteCountCodedINT shouldFail(-100); if (verbose) { qDebug() << "NOW..."; } quint64 now = usecTimestampNow(); ByteCountCodedQUINT64 nowCoded = now; QByteArray nowEncoded = nowCoded; if (verbose) { outputBufferBits((const unsigned char*)nowEncoded.constData(), nowEncoded.size()); } ByteCountCodedQUINT64 decodedNow = nowEncoded; testsTaken++; bool result19 = (decodedNow.data==now); bool expected19 = true; if (result19 == expected19) { testsPassed++; } else { testsFailed++; qDebug() << "FAILED - Test 19: now test..."; } if (verbose) { qDebug() << "******************************************************************************************"; } qDebug() << " tests passed:" << testsPassed << "out of" << testsTaken; if (verbose) { qDebug() << "******************************************************************************************"; } }
void *mpool_malloc(struct MP *mp, size_t size) { unsigned int i, needed = align_to_voidptr(size + FRAG_OVERHEAD); const unsigned int sbits = to_bits(needed); struct FRAG *f = NULL; struct MPMAP *mpm = &mp->mpm; /* check_all(mp); */ if (!size || sbits == FRAGSBITS) { cli_errmsg("mpool_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size); return NULL; } /* Case 1: We have a free'd frag */ if((f = mp->avail[sbits])) { spam("malloc %p size %u (freed)\n", f, mpool_roundup(size)); mp->avail[sbits] = f->u.next; f->u.sbits = sbits; #ifdef CL_DEBUG f->magic = MPOOLMAGIC; memset(&f->fake, ALLOCPOISON, size); #endif return &f->fake; } if (!(needed = from_bits(sbits))) { cli_errmsg("mpool_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size); return NULL; } /* Case 2: We have nuff room available for this frag already */ while(mpm) { if(mpm->size - mpm->usize >= needed) { f = (struct FRAG *)((char *)mpm + mpm->usize); spam("malloc %p size %u (hole)\n", f, mpool_roundup(size)); mpm->usize += needed; f->u.sbits = sbits; #ifdef CL_DEBUG f->magic = MPOOLMAGIC; memset(&f->fake, ALLOCPOISON, size); #endif return &f->fake; } mpm = mpm->next; } /* Case 3: We allocate more */ if (needed + align_to_voidptr(sizeof(*mpm)) > MIN_FRAGSIZE) i = align_to_pagesize(mp, needed + align_to_voidptr(sizeof(*mpm))); else i = align_to_pagesize(mp, MIN_FRAGSIZE); if ((mpm = (struct MPMAP *)mmap(NULL, i, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED) { cli_errmsg("mpool_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)i); spam("failed to alloc %u bytes (%u requested)\n", i, size); return NULL; } #ifdef CL_DEBUG memset(mpm, ALLOCPOISON, i); #endif mpm->size = i; mpm->usize = needed + align_to_voidptr(sizeof(*mpm)); mpm->next = mp->mpm.next; mp->mpm.next = mpm; f = (struct FRAG *)((char *)mpm + align_to_voidptr(sizeof(*mpm))); spam("malloc %p size %u (new map)\n", f, mpool_roundup(size)); f->u.sbits = sbits; #ifdef CL_DEBUG f->magic = MPOOLMAGIC; #endif return &f->fake; }