Пример #1
0
int main (int argc, char *argv[])
{
    int i, j, b;

    bdescr *a[ARRSIZE];

    srand(SEED);

    hs_init(&argc, &argv);

   // repeatedly sweep though the array, allocating new random-sized
   // objects and deallocating the old ones.
   for (i=0; i < LOOPS; i++)
   {
       for (j=0; j < ARRSIZE; j++)
       {
           if (i > 0)
           {
               IF_DEBUG(block_alloc, debugBelch("A%d: freeing %p, %d blocks @ %p\n", j, a[j], a[j]->blocks, a[j]->start));
               freeGroup_lock(a[j]);
               DEBUG_ONLY(checkFreeListSanity());
           }
           b = (rand() % MAXALLOC) + 1;
           a[j] = allocGroup_lock(b);
           IF_DEBUG(block_alloc, debugBelch("A%d: allocated %p, %d blocks @ %p\n", j, a[j], b, a[j]->start));
           // allocating zero blocks isn't allowed
           DEBUG_ONLY(checkFreeListSanity());
       }
   }

   for (j=0; j < ARRSIZE; j++)
   {
       freeGroup_lock(a[j]);
   }
    
    // this time, sweep forwards allocating new blocks, and then
    // backwards deallocating them.
    for (i=0; i < LOOPS; i++)
    {
        for (j=0; j < ARRSIZE; j++)
        {
            b = (rand() % MAXALLOC) + 1;
            a[j] = allocGroup_lock(b);
            IF_DEBUG(block_alloc, debugBelch("B%d,%d: allocated %p, %d blocks @ %p\n", i, j, a[j], b, a[j]->start));
            DEBUG_ONLY(checkFreeListSanity());
        }
        for (j=ARRSIZE-1; j >= 0; j--)
        {
            IF_DEBUG(block_alloc, debugBelch("B%d,%d: freeing %p, %d blocks @ %p\n", i, j, a[j], a[j]->blocks, a[j]->start));
            freeGroup_lock(a[j]);
            DEBUG_ONLY(checkFreeListSanity());
        }
    }
    
    DEBUG_ONLY(checkFreeListSanity());

    hs_exit(); // will do a memory leak test

    exit(0);
}
Пример #2
0
int SDL_main(int argc, char *argv[])
{
  int i;
 
#ifdef __APPLE__
  void * pool = objc_msgSend((id)objc_lookUpClass("NSAutoreleasePool"), sel_getUid("alloc"));
  objc_msgSend(pool, sel_getUid("init"));
#endif
 
  hs_init(&argc, &argv);

#ifdef __GLASGOW_HASKELL__
  hs_add_root(__stginit_RectanglesMain);
#endif
 
  rectangles_main();
 
  hs_exit();

#ifdef __APPLE__
  objc_msgSend(pool, sel_getUid("release"));
#endif
  
  return 0;
}
int c_main(void) {
  hs_init(0, 0);
  hsMain();
  hs_exit();

  return 0;
}
Пример #4
0
int main(int argc, char *argv[]) {
    hs_init(&argc,&argv);

    // load test input
    int n1 = 5;
    TPoint proto[5] = {{0,0},{0.5,0},{1,0},{1,1},{0,1}};
    
    int n2 = 4;
    TPoint target[4] = {{1.1,0.1},{1.1,0.9},{-0.1,0.9},{-0.1,0.1}};
    
    // output
    int m;
    TPoint *res;
    double h[3][3];

    hfun(n1,proto,n2,target,&m,&res,h);
        
    printf("%d\n", m);
    int k;
    for (k=0; k<m; k++) {
        printf("px=%f  py=%f\n",res[k].x,res[k].y);
    }
    int j;
    for (j=0; j<3; j++) {
        for (k=0; k<3; k++) {
            printf("%f\n",h[j][k]);
         }
    }
    free(res);
    
    hs_exit();
    return 0;
}
Пример #5
0
int main (int argc, char *argv[])
{
    hs_init(&argc,&argv);

    // check that we can call hs_thread_done() without having made any
    // Haskell calls:
    hs_thread_done();

    // check that we can call hs_thread_done() and then make another Haskell
    // call:
    int i;
    for (i=0; i < 1000; i++) {
        f(3);
        hs_thread_done();
    }

    // check that we can call hs_thread_done() twice:
    hs_thread_done();
    hs_thread_done();

    // check that hs_thread_done() from child threads works:
    pthread_t pid;
    for (i=0; i < 1000; i++) {
        pthread_create(&pid, NULL, thread, NULL);
        pthread_join(pid, NULL);
    }

    hs_exit();
    exit(0);
}
Пример #6
0
int main(int argc, char *argv[])
{
        hs_init(&argc, &argv);
        test_fixture_start();
        run_test(basic_test);
        run_test(foreignptr_test);
        test_fixture_end();
        hs_exit();
        return 0;
}
Пример #7
0
int
main(int argc, char *argv[])
{
        hs_init(&argc,&argv);
        if (jhc_setjmp(&jhc_uncaught))
                jhc_error("Uncaught Exception");
        else
                _amain();
        hs_exit();
        return 0;
}
Пример #8
0
int main(int argc, char *argv[])
{
  int *p;
  hs_init(&argc, &argv);
  p = hs_eval_i("show $ case 1 + 2 in{-wrong-} x -> x");
  if (p == NULL)
	  printf("failed!\n");
  else
	  printf("%d\n",*p);
  hs_exit();
  return 0;
}
Пример #9
0
int main(int argc, char *argv[])
{
  char *p;
  hs_init(&argc, &argv);
  p = hs_eval_s("show $ let fibs = 1:1:zipWith (+) fibs (tail fibs) in fibs !! 20");
  if (p == NULL)
  	  printf("failed!\n");
  else
	  printf("%s\n",p);
  hs_exit();
  return 0;
}
Пример #10
0
int main(int argc, char *argv[])
{
  hs_init(&argc, &argv);
#ifdef __GLASGOW_HASKELL__
  hs_add_root(__stginit_SDLWrapper);
#endif

  haskell_main();

  hs_exit();
  return 0;
}
Пример #11
0
int main(int argc, char *argv[])
{
  int *p;
  hs_init(&argc, &argv);
  p = hs_eval_i("\"an ill-typed string\"");
  if (p == NULL)
	  printf("failed!\n");
  else
	  printf("%d\n",*p);
  hs_exit();
  return 0;
}
Пример #12
0
int
main(int argc, char *argv[])
{
	int i;

	hs_init(&argc, &argv);

	for (i = 0; i < 5; i++) {
		printf("%d\n", foo(2500));
	}

	hs_exit();
	return 0;
}
Пример #13
0
int main(int argc, char *argv[])
{
    int i;
    hs_init(&argc, &argv);
#ifdef __GLASGOW_HASKELL__
    hs_add_root(__stginit_Safe);
#endif

    printf("Main thread: %d\n", (int)pthread_self());
    
    i = fibonacci_hs(42);
    printf("Fibonacci: %d\n", i);

    print_numcaps();
    
    hs_exit();
    return 0;
}
Пример #14
0
int main(int argc, char *argv[])
{
    hs_init(&argc,&argv);
    f(500000);
#if mingw32_HOST_OS
    Sleep(100);
#else
    usleep(100000);
#endif
    printf("exiting...\n");
    hs_exit();
    printf("exited.\n");
#if mingw32_HOST_OS
    Sleep(1000);
#else
    usleep(1000000);
#endif
    exit(0);
}
Пример #15
0
int main(int argc, char *argv[]) {
    hs_init(&argc, &argv);
    hs_add_root(__stginit_HaskelineExport);

    // TODO: block signals at certain points of this program 
    // in order to avoid race conditions.
    hdata = initialize_input();

    signal(SIGINT, catch_signal);

    char* str1 = get_input_line(hdata,"first:");
    char* str2 = get_input_line(hdata,"second:");

    if (str1!=NULL && str2 != NULL) {
        printf("The strings were:\n%s\n%s\n",str1,str2);
    }

    close_input(hdata);

    hs_exit();
    return 0;
}
Пример #16
0
int main (int argc, char *argv[])
{
    testfun *f;
    int i, r;

    RtsConfig conf = defaultRtsConfig;
    conf.rts_opts_enabled = RtsOptsAll;
    hs_init_ghc(&argc, &argv, conf);

    initLinker_(0);

    loadPackages();

    for (i=0; i < ITERATIONS; i++) {
        r = loadObj(OBJPATH);
        if (!r) {
            errorBelch("loadObj(%s) failed", OBJPATH);
            exit(1);
        }
        r = resolveObjs();
        if (!r) {
            errorBelch("resolveObjs failed");
            exit(1);
        }
#if LEADING_UNDERSCORE
        f = lookupSymbol("_f");
#else
        f = lookupSymbol("f");
#endif
        if (!f) {
            errorBelch("lookupSymbol failed");
            exit(1);
        }
        r = f(3);
        if (r != 4) {
            errorBelch("call failed; %d", r);
            exit(1);
        }
        unloadObj(OBJPATH);
        performMajorGC();
        printf("%d ", i);
        fflush(stdout);
    }

    for (i=0; i < ITERATIONS; i++) {
        r = loadObj(OBJPATH);
        if (!r) {
            errorBelch("loadObj(%s) failed", OBJPATH);
            exit(1);
        }
        r = resolveObjs();
        if (!r) {
            errorBelch("resolveObjs failed");
            exit(1);
        }
#if LEADING_UNDERSCORE
        f = lookupSymbol("_f");
#else
        f = lookupSymbol("f");
#endif
        if (!f) {
            errorBelch("lookupSymbol failed");
            exit(1);
        }
        r = f(3);
        if (r != 4) {
            errorBelch("call failed; %d", r);
            exit(1);
        }
        // check that we can purge first, then unload
        purgeObj(OBJPATH);
        performMajorGC();
        unloadObj(OBJPATH);
        performMajorGC();
        printf("%d ", i);
        fflush(stdout);
    }

    hs_exit();
    exit(0);
}
Пример #17
0
static int doChildExit(void *data) {
  fprintf(stderr, "mod_ghc finalizer; pid=%d\n", getpid());
  hs_exit();
  fprintf(stderr, "mod_ghc finalizer done; pid=%d\n", getpid());
  return OK;
}
Пример #18
0
static void my_exit(void)
{
  hs_exit();
}
Пример #19
0
static void Destroy_factorial(void) // never called.
{
  hs_exit();
}
Пример #20
0
int main(int argc, char **argv)
{
    glfwSetErrorCallback(error_callback);

    /* Initialize the library */
    if (!glfwInit()){
        fprintf(stderr, "Initialization failed.\n");
        return 1;
    }

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(width, height, "Hello World", NULL, NULL);
    if (!window) {
        glfwTerminate();
        fprintf(stderr, "Error creating window.\n");
        return 1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);
    glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, 1);
    glfwSetKeyCallback(window, key_callback);
    glfwSetMouseButtonCallback(window, mouse_button_callback);
    glfwSetCursorPosCallback(window, cursor_pos_callback);

    //**************************** generowanie przykładowych piksli
    hs_init(&argc, &argv);
    initOctTree();
    hs_exit();
    float *piksele = malloc(height*width*3*sizeof(*piksele));

    printf("sizeof(OctTreeNode)=%d\n", (int)sizeof(OctTreeNode));

    //****************************

    init_cl();
    turnCamera(0.f,0.f,0.f); // Calculates initial camera direction
    fflush(stderr);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        for (int i = 0; i < height * width * 3; i++)
            piksele[i] = 0.0;

        clock_t start = clock();
        captureOctTree(camera_pos, camera_target, up, width, height, piksele);
        clock_t end = clock();

        // show render time in window title
        char title[16];
        snprintf(title, 16, "%d ms", (int)((end - start) / (CLOCKS_PER_SEC / 1000)));
        glfwSetWindowTitle(window, title);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    if (num_platforms > 0) {
        clReleaseMemObject(mainOctCL);
        clReleaseMemObject(image);
        clReleaseKernel(kernel);
        clReleaseCommandQueue(queue);
    }
    glfwDestroyWindow(window);

    glfwTerminate();
    return 0;
}
Пример #21
0
void
end(void)
{
	hs_exit();
}
Пример #22
0
static void library_exit(void)
{
    hs_exit();
}
Пример #23
0
//void __attribute__ ((dllexport))
void __cdecl
	HsEnd()
{
	hs_exit();
}
Пример #24
0
void catch_signal(int signo) {
    cancel_input(hdata);
    hs_exit();
    exit(0);
}
Пример #25
0
void
mylib_end(void)
{
	hs_exit();
}
Пример #26
0
void pandoc_exit()
{
  hs_exit();
}
Пример #27
0
int main (int argc, char *argv[])
{
    int i, j, b;

    bdescr *a[ARRSIZE];

    srand(SEED);

    hs_init(&argc, &argv);

    memset(a, 0, ARRSIZE * sizeof(bdescr*));

    for (i=0; i < LOOPS; i++)
    {
        j = rand() % ARRSIZE;
        if (a[j]) { freeGroup_lock(a[j]); }
        a[j] = allocGroup_lock(rand() % MAXALLOC + 1);
    }

#ifdef DEBUG
    {
        void *p;
        i = 0;
        for (p = getFirstMBlock(); p != NULL; p = getNextMBlock(p))
        {
            if (!HEAP_ALLOCED(p)) barf("%p",p);
            i++;
        }
        printf("%d\n", i);
    }
#endif

    {
        void *p, *base;

        j = 0;
        base = RtsFlags.GcFlags.heapBase;
        
        for (i=0; i < LOOPS*2000; i++)
        {
            // this is for testing: generate random addresses anywhere
            // in the address space.
            //
            // 48 bits is: 0x800000000000 - 0x7fffffffffff
            // so ((StgInt)rand() >> 4) varies between -2^27 and 2^27-1.
            // and << 20 of this is a random signed 48-bit megablock address
            //
            // p = (void*)((StgWord)((StgInt)rand() >> 4) << 20);

            // this is for benchmarking: roughly half of these
            // addresses will be in the heap.
            p = base + (((StgWord)rand() << 10) % 
                        ((StgWord)ARRSIZE * MAXALLOC * BLOCK_SIZE));

            if (HEAP_ALLOCED(p)) {
                // printf("%p\n",p);
                j++;
            }
        }
        printf("%d\n", j);
    }

    printf("misses: %ld, %ld%%\n", mpc_misses, mpc_misses / (LOOPS*20));

    for (i=0; i < ARRSIZE; i++)
    {
        if (a[i]) { freeGroup_lock(a[i]); }
    }

    hs_exit(); // will do a memory leak test

    exit(0);
}
Пример #28
0
AppDelegate::~AppDelegate() 
{
    hs_exit();
}
Пример #29
0
EQ_API void eq_end_runtime()
    { hs_exit(); }
Пример #30
0
static void library_exit(void)
{
    printf("Unloading library OfxPlugin\n ");
    hs_exit();
}