~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to camel/providers/imapx/camel-imapx-exception.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
#include <stdarg.h>
 
5
 
 
6
#include <glib.h>
 
7
 
 
8
#include "camel-imapx-exception.h"
 
9
 
 
10
#include <pthread.h>
 
11
 
 
12
static pthread_key_t handler_key = 0;
 
13
 
 
14
void camel_exception_setup(void)
 
15
{
 
16
        pthread_key_create(&handler_key, NULL);
 
17
}
 
18
 
 
19
void
 
20
camel_exception_try(struct _CamelExceptionEnv *env)
 
21
{
 
22
        struct _CamelExceptionEnv *handler;
 
23
 
 
24
        handler = pthread_getspecific(handler_key);
 
25
        env->parent = handler;
 
26
        handler = env;
 
27
        env->ex = NULL;
 
28
 
 
29
        pthread_setspecific(handler_key, handler);
 
30
}
 
31
 
 
32
void
 
33
camel_exception_throw_ex(CamelException *ex)
 
34
{
 
35
        struct _CamelExceptionEnv *env;
 
36
 
 
37
        printf("throwing exception '%s'\n", ex->desc);
 
38
 
 
39
        env = pthread_getspecific(handler_key);
 
40
        if (env != NULL) {
 
41
                env->ex = ex;
 
42
                pthread_setspecific(handler_key, env->parent);
 
43
                longjmp(env->env, ex->id);
 
44
        } else {
 
45
                fprintf(stderr, "\nUncaught exception: %s\n", ex->desc);
 
46
                /* we just crash and burn, this is a code problem */
 
47
                /* we dont use g_assert_not_reached() since its not a noreturn function */
 
48
                abort();
 
49
        }
 
50
}
 
51
 
 
52
void
 
53
camel_exception_throw(gint id, gchar *fmt, ...)
 
54
{
 
55
        CamelException *ex;
 
56
        va_list ap;
 
57
 
 
58
        ex = camel_exception_new();
 
59
        ex->id = id;
 
60
        va_start(ap, fmt);
 
61
        ex->desc = g_strdup_vprintf(fmt, ap);
 
62
        va_end(ap);
 
63
 
 
64
        camel_exception_throw_ex(ex);
 
65
}
 
66
 
 
67
void
 
68
camel_exception_drop(struct _CamelExceptionEnv *env)
 
69
{
 
70
        pthread_setspecific(handler_key, env->parent);
 
71
}
 
72
 
 
73
void
 
74
camel_exception_done(struct _CamelExceptionEnv *env)
 
75
{
 
76
        pthread_setspecific(handler_key, env->parent);
 
77
        if (env->ex != NULL) {
 
78
                camel_exception_free(env->ex);
 
79
        }
 
80
}