예제 #1
0
void test_o_exceptions_nested()
{
	try
	{
		int check = 0;
		try
		{
			internal_safe_exception();
			check = 1;
			internal_exception();
			fail("Error this code must not be executed after exception throw");
		}
		catch(struct o_exception ,ex)
		{
			if (check == 0)
				fail("Exception scaled up before");
			assert_true(strcmp(o_exception_message(ex), EXCEPTION_MESSAGE) == 0, "Exception message not match");
			assert_true(o_exception_code(ex) == 20, "Exception error code not match");
			o_exception_free(ex);
		}
		end_try;
	}
	catch(struct o_exception ,ex)
	{
		o_exception_free(ex);
		fail("Error on catch invoke");
	}
	end_try;
}
예제 #2
0
파일: pf_items.c 프로젝트: gitpan/ponie
static void
cvt_num12_num8_be(unsigned char *dest, unsigned char *src)
{
    cvt_num12_num8(dest, src);
    /* TODO endianize */
    internal_exception(1, "TODO cvt_num12_num8_be\n");
}
예제 #3
0
파일: chartype.c 프로젝트: gitpan/ponie
static UINTVAL
chartype_from_unicode_cparray(const CHARTYPE *from, const CHARTYPE *to,
                              UINTVAL c)
{
    const struct chartype_unicode_map_t *map = to->unicode_map;

    if (c < map->n1) {
        return c;
    }
    else {
        UINTVAL i;
        if (map->cparray) {
            for (i = 0; i < 256 - map->n1; i++) {
                if (map->cparray[i] == (INTVAL)c)
                    return i + map->n1;
            }
        }
        if (map->cparray2) {
            for (i = 0; i < 128*256; i++) {
                if (map->cparray2[i] == (INTVAL)c)
                    return i + 128*256;
            }
        }
        internal_exception(INVALID_CHARACTER,
                           "Invalid character <%X> for chartype\n",c);
        return 0;
    }
}
예제 #4
0
    static void handle_run_simulation(button *b)
    {
        simulation_tab *stab = dynamic_cast<simulation_tab *>(b->get_parent());
        if (!stab)
            throw internal_exception(__FILE__, __LINE__, L"Run Simulation button is not correctly parented.");

        // create new simulation if necessary
        config_record *sim_rec = stab->current_sim_record;
        if (!sim_rec)
        {
            string fname = get_temp_sim_fname();
            if (file::exists(fname))
                file::remove(fname);

            // initialize file
            {
                file f(fname);
                smart_pointer<ft_stream> s(f.open_text(io::FILE_OPEN_WRITE));
                *s << L"<simulation name=\"Running Simulation\"></simulation>";
            }

            sim_rec = new config_record(fname);
        }

        // insert time node if necessary
        config_record & time_param = sim_rec->get_child(L"start_time");
        if (time_param.get_text().is_empty())
        {
            time_param.get_text() = string::format(L"%f", stab->get_time_box()->get_jdn());
        }

        // insert view node if necessary
        config_record & view_param = sim_rec->get_child(L"viewpoint");
        if (view_param.get_text().is_empty())
        {
            node *n = reinterpret_cast<node *>(stab->get_view_box()->get_scenery_box()->get_selected_node()->get_user_data());
            assert(n);

            view_param[L"parent"] = n->get_name();
        }

        // save simulation record, and run
        string fname = sim_rec->get_file().get_full_path();
        sim_rec->save();
        delete sim_rec;
        sim_rec = 0;

        periapsis_app *app = dynamic_cast<periapsis_app *>(application::global_instance());
        if (app)
        {
            app->load_and_run_simulation(fname, app->get_sim_context(), app->get_draw_context());
        }
        else
        {
            throw runtime_exception(L"You cannot run a Periapsis simulation within a different application!");
        }
    } // handle_run_simulation()
예제 #5
0
 int directory::compare(const comparable & d) const
 {
     const directory *dp = dynamic_cast<const directory *>(&d);
     if (dp)
     {
         return full_path.compare(dp->full_path);
     }
     else
     {
         throw internal_exception(__FILE__, __LINE__, L"Comparing different types.");
     }
 } // directory::compare()
예제 #6
0
파일: events.c 프로젝트: gitpan/ponie
void
Parrot_schedule_broadcast_qentry(QUEUE_ENTRY* entry)
{
    Parrot_Interp interp;
    parrot_event* event;
    size_t i;

    event = entry->data;
    switch (event->type) {
        case EVENT_TYPE_SIGNAL:
            edebug((stderr, "broadcast signal\n"));
            /*
             * we don't have special signal handlers in usercode yet
             * e.g.:
             * install handler like exception handler *and*
             * set a interpreter flag, that a handler exists
             * we then could examine that flag (after LOCKing it)
             * and dispatch the exception to all interpreters that
             * handle it
             * Finally, we send the first (main) interpreter that signal
             *
             * For now just send to all.
             *
             */
            switch(event->u.signal) {
                case SIGINT:
                    if (n_interpreters) {
                        LOCK(interpreter_array_mutex);
                        for (i = 1; i < n_interpreters; ++i) {
                            edebug((stderr, "deliver SIGINT to %d\n", i));
                            interp = interpreter_array[i];
                            if (interp)
                                Parrot_schedule_interp_qentry(interp,
                                        dup_entry(entry));
                        }
                        UNLOCK(interpreter_array_mutex);
                    }
                    interp = interpreter_array[0];
                    Parrot_schedule_interp_qentry(interp, entry);
                    edebug((stderr, "deliver SIGINT to 0\n"));
                    break;
                default:
                    mem_sys_free(entry);
                    mem_sys_free(event);
            }
            break;
        default:
            mem_sys_free(entry);
            mem_sys_free(event);
            internal_exception(1, "Unknown event to broadcast");
            break;
    }
}
예제 #7
0
파일: events.c 프로젝트: gitpan/ponie
static void*
event_thread(void *data)
{
    QUEUE* event_q = (QUEUE*) data;
    parrot_event* event;
    QUEUE_ENTRY *entry;
    int running = 1;

    LOCK(event_q->queue_mutex);
    /*
     * we might already have an event in the queue
     */
    if (peek_entry(event_q))
        running = process_events(event_q);
    while (running) {
        entry = peek_entry(event_q);
        if (!entry) {
            /* wait infinite until entry arrives */
            queue_wait(event_q);
        }
        else if (entry->type == QUEUE_ENTRY_TYPE_TIMED_EVENT) {
            /* do a_timedwait for entry */
            struct timespec abs_time;
            FLOATVAL when;
            event = (parrot_event* )entry->data;
            when = event->u.timer_event.abs_time;
            abs_time.tv_sec = (time_t) when;
            abs_time.tv_nsec = (when - abs_time.tv_sec) *
                (1000L*1000L*1000L);
            queue_timedwait(event_q, &abs_time);
        }
        else {
            /* we shouldn't get here probably
             */
            internal_exception(1, "Spurious event");

        }
        /*
         * one or more entries arrived - we hold the mutex again
         * so we have to use the nonsync_pop_entry to pop off event entries
         */
        running = process_events(event_q);
    } /* event loop */
    /*
     * the main interpreter is dying
     * TODO empty the queue
     */
    UNLOCK(event_q->queue_mutex);
    queue_destroy(event_q);
    stop_io_thread();
    edebug((stderr, "event thread stopped\n"));
    return NULL;
}
예제 #8
0
 void shader_program::bind() const
 {
     // use shader
     if (opengl_id)
     {
         glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);                                                             CHECK_GL_ERRORS();
         glUseProgram(opengl_id);                                                                            CHECK_GL_ERRORS();
     }
     else
     {
         throw internal_exception(__FILE__, __LINE__, L"Unable to use shader program.");
     }
 } // shader_program::bind()
예제 #9
0
파일: events.c 프로젝트: gitpan/ponie
static void
init_events_first(Parrot_Interp interpreter)
{
    Parrot_thread    ev_handle, io_handle;

    /*
     * be sure all init is done only once
     * we could use pthread_once for that too
     */
    if (event_queue)
        PANIC("event queue already exists - missing parent_interp?");
    /*
     * we need a global mutex to protect the interpreter array
     */
    MUTEX_INIT(interpreter_array_mutex);
    /*
     * create event queue
     */
    event_queue = queue_init(TASK_PRIO);
    /*
     * we use a message pipe to send IO related stuff to the
     * IO thread
     */
#ifndef WIN32
    /*
     * pipes on WIN32 don't support select
     * s. p6i: "event.c - of signals and pipes"
     */
    if (pipe(pipe_fds))
        internal_exception(1, "Couldn't create message pipe");
#endif
    /*
     * now set some sig handlers before any thread is started, so
     * that all threads inherit the signal block mask
     */
#if INSTALL_EVENT_HANDLER
    Parrot_init_signals();
#endif
    /*
     * we start an event_handler thread
     */
    THREAD_CREATE_DETACHED(ev_handle, event_thread, event_queue);
    /*
     * and a signal and IO handler thread
     */
#ifndef WIN32
    THREAD_CREATE_DETACHED(io_handle, io_thread, event_queue);
#endif
}
예제 #10
0
void internal_safe_exception()
{
	try
	{
		internal_exception();
		fail("Error this code must not be executed after exception throw");
	}
	catch(struct o_exception ,ex)
	{
		assert_true(strcmp(o_exception_message(ex), EXCEPTION_MESSAGE) == 0, "Exception message not match");
		assert_true(o_exception_code(ex) == 20, "Exception error code not match");
		o_exception_free(ex);
	}
	end_try;
}
예제 #11
0
파일: events.c 프로젝트: gitpan/ponie
static void
stop_io_thread(void)
{
    int buf[3];
    /*
     * tell IO thread to stop
     */
    buf[0] = 'e';
    buf[1] = -1;
    buf[2] = '\n';
#ifndef WIN32
    if (write(PIPE_WRITE_FD, buf, MSG_SIZE) != MSG_SIZE)
        internal_exception(1, "msg pipe write failed");
#endif
}
예제 #12
0
파일: io_unix.c 프로젝트: gitpan/ponie
static INTVAL
PIO_unix_async(theINTERP, ParrotIOLayer *layer, ParrotIO *io, INTVAL b)
{
    int rflags;
#if defined(linux)
    if((rflags = fcntl(io->fd, F_GETFL, 0)) >= 0) {
        if(b)
            rflags |= O_ASYNC;
        else
            rflags &= ~O_ASYNC;
        return fcntl(io->fd, F_SETFL, rflags);
    }
#else
    internal_exception(PIO_NOT_IMPLEMENTED, "Async support not available");
#endif
    return -1;
}
예제 #13
0
 int display::scoped_buffer::get_gl_type(const primitive_type & pt)
 {
     switch (pt)
     {
     case PRIMITIVE_POINTS:
         return GL_POINTS;
     case PRIMITIVE_LINES:
         return GL_LINES;
     case PRIMITIVE_TRIANGLES:
         return GL_TRIANGLES;
     case PRIMITIVE_TRIANGLE_STRIP:
         return GL_TRIANGLE_STRIP;
     case PRIMITIVE_TRIANGLE_FAN:
         return GL_TRIANGLE_FAN;
     default:
         throw internal_exception(__FILE__, __LINE__, L"Unknown primitive type.");
     }
 } // display::scoped_buffer::get_gl_type()
예제 #14
0
 smart_pointer<T,ARRAY_PTR> & smart_pointer<T,ARRAY_PTR>::operator= (const smart_pointer & sp)
 {
     throw internal_exception(__FILE__, __LINE__, L"Cannot assign a smart pointer.");
 } // smart_pointer<T,ARRAY_PTR>::smart_pointer()
예제 #15
0
        mapped_file::mapped_file(const string & fname, unsigned int io_open_mode, unsigned int create_size)
            : file_handle(0), map_handle(0), map_pointer(0)
        {
#ifdef WIN32
            string full_path = io::file::get_full_path(fname);

            // open file handle
            unsigned int win_open_mode = GENERIC_READ;

            if (io_open_mode & io::FILE_OPEN_WRITE)
                win_open_mode |= GENERIC_WRITE;

            if (file::exists(full_path))
            {
                file_handle = CreateFileW(full_path.w_string(), win_open_mode, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

                if (file_handle != INVALID_HANDLE_VALUE)
                    create_size = GetFileSize(file_handle, 0);
            }
            else
            {
                if (create_size == 0)
                    throw internal_exception(__FILE__, __LINE__, L"Must specify size for creating memory-mapped files.");

                file_handle = CreateFileW(full_path.w_string(), win_open_mode, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                
                if (file_handle != INVALID_HANDLE_VALUE)
                {
                    unsigned char buf = 0;
                    unsigned int written;
                    SetFilePointer(file_handle, create_size-1, 0, FILE_BEGIN);                    
                    WriteFile(file_handle, &buf, 1, (LPDWORD) &written, 0);
                    SetFilePointer(file_handle, 0, 0, FILE_BEGIN);
                }
            }
            
            if (file_handle == INVALID_HANDLE_VALUE)
                throw io_exception(L"Unable to open %ls: %ls", full_path.w_string(), get_windows_error().w_string());

            // create mapping
            string map_name = string::format(L"periapsis_mapped_file_%d", NUM_MAPPED_FILES++);

            if (io_open_mode & io::FILE_OPEN_WRITE)
                win_open_mode = PAGE_READWRITE;
            else
                win_open_mode = PAGE_READONLY;

            map_handle = CreateFileMappingW(file_handle, 0, win_open_mode, 0, create_size, map_name.w_string());

            if (!map_handle)
                throw io_exception(L"Unable to create memory map for %ls: %ls", full_path.w_string(), get_windows_error().w_string());

            // map file
            if (io_open_mode & io::FILE_OPEN_WRITE)
                win_open_mode = FILE_MAP_ALL_ACCESS;
            else
                win_open_mode = FILE_MAP_READ;

            map_pointer = MapViewOfFile(map_handle, win_open_mode, 0, 0, 0);

            if (!map_pointer)
                throw io_exception(L"Unable to create memory map for %ls: %ls", full_path.w_string(), get_windows_error().w_string());

            map_size = create_size;
#else
#error Implement memory-mapped files!
#endif
        } // mapped_file::mapped_file()
예제 #16
0
파일: events.c 프로젝트: gitpan/ponie
static int
process_events(QUEUE* event_q)
{
    FLOATVAL now;
    QUEUE_ENTRY *entry;
    parrot_event* event;

    while (( entry = peek_entry(event_q))) {
        /*
         * one or more entries arrived - we hold the mutex again
         * so we have to use the nonsyc_pop_entry to pop off event entries
         */
        event = NULL;
        switch (entry->type) {
            case QUEUE_ENTRY_TYPE_EVENT:
                entry = nosync_pop_entry(event_q);
                event = entry->data;
                break;
            case QUEUE_ENTRY_TYPE_TIMED_EVENT:
                event = entry->data;
                now = Parrot_floatval_time();
                /*
                 * if the timer_event isn't due yet, ignore the event
                 * (we were signalled on insert of the event)
                 * wait until we get at it again when time has elapsed
                 */
                if (now < event->u.timer_event.abs_time)
                    return 1;
                entry = nosync_pop_entry(event_q);
                /*
                 * if event is repeated dup and reinsert it
                 */
                if (event->u.timer_event.interval) {
                    if (event->u.timer_event.repeat) {
                        if (event->u.timer_event.repeat != -1)
                            event->u.timer_event.repeat--;
                        nosync_insert_entry(event_q,
                                dup_entry_interval(entry, now));
                    }
                }
                break;
            default:
                internal_exception(1, "Unknown queue entry");
        }
        assert(event);
        if (event->type == EVENT_TYPE_NONE) {
            mem_sys_free(entry);
            mem_sys_free(event);
            continue;
        }
        else if (event->type == EVENT_TYPE_EVENT_TERMINATE) {
            mem_sys_free(entry);
            mem_sys_free(event);

            return 0;
        }
        /*
         * now insert entry in interpreter task queue
         */
        if (event->interp) {
            Parrot_schedule_interp_qentry(event->interp, entry);
        }
        else {
            Parrot_schedule_broadcast_qentry(entry);
        }
    } /* while events */
    return 1;
}
예제 #17
0
파일: events.c 프로젝트: gitpan/ponie
static void*
io_thread(void *data)
{
    QUEUE* event_q = (QUEUE*) data;
    fd_set rfds, wfds;
    int n_highest;
    int running = 1;

    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    UNUSED(event_q);
    /*
     * Watch the reader end of the pipe for messages
     */
    FD_SET(PIPE_READ_FD, &rfds);
    n_highest = PIPE_READ_FD + 1;
    /*
     * all signals that we shall handle here have to be unblocked
     * in this and only in this thread
     */
    Parrot_unblock_signal(SIGINT);
    while (running) {
        int retval = select(n_highest, &rfds, &wfds, NULL, NULL);
        switch (retval) {
            case -1:
                if (errno == EINTR) {
                    edebug((stderr, "select EINTR\n"));
                    if (sig_int) {
                        edebug((stderr, "int arrived\n"));
                        sig_int = 0;
                        /*
                         * signal the event thread
                         */
                        schedule_signal_event(SIGINT);
                    }

                }
                break;
            default:
                if (retval > 0) {
                    edebug((stderr, "IO ready\n"));
                    if (FD_ISSET(PIPE_READ_FD, &rfds)) {
                        int buf[3];
                        /*
                         * a command arrived
                         */
                        edebug((stderr, "msg arrived\n"));
                        if (read(PIPE_READ_FD, buf, MSG_SIZE) != MSG_SIZE)
                            internal_exception(1,
                                    "read error from msg pipe");
                        switch (buf[0]) {
                            case 'e':
                                running = 0;
                                break;
                            /* TODO */
                            case 'r':
                                /* insert fd in buf[1] into rfds */
                            case 'w':
                                /* insert fd in buf[1] into wfds */
                            case 'R':
                                /* delete fd in buf[1] from rfds */
                            case 'W':
                                /* delete fd in buf[1] from wfds */
                                break;
                            default:
                                internal_exception(1,
                                        "unhandled msg in pipe");
                                break;
                        }

                    }
                    /* TODO check fds */
                    break;
                }
        }
    }
    edebug((stderr, "IO thread terminated\n"));
    close(PIPE_READ_FD);
    close(PIPE_WRITE_FD);
    return NULL;
}