Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use exception where appropriate instead of integer return
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 14 Apr 2008 16:18:34 +0000 (16:18 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 14 Apr 2008 16:18:34 +0000 (16:18 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5341 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/java/jmsg.c
src/xbt/xbt_context.c
src/xbt/xbt_context_java.c
src/xbt/xbt_context_private.h
src/xbt/xbt_context_sysv.c
src/xbt/xbt_context_thread.c

index e74aec4..61fef1c 100644 (file)
@@ -988,17 +988,26 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) {
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
 {
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
 {
-       int rv;
+   char *errmsg=NULL;
+   xbt_ex_t e;
        
        
-       /* get the C string from the java string*/
-       const char* name = (*env)->GetStringUTFChars(env, jname, 0);
-
-       rv = xbt_context_select_factory(name);
-               
+   /* get the C string from the java string*/
+   const char* name = (*env)->GetStringUTFChars(env, jname, 0);
+
+   TRY {
+      xbt_context_select_factory(name);
+   } CATCH(e) {
+      errmsg = xbt_strdup(e.msg);
+      xbt_ex_free(e);
+   }
+   
        (*env)->ReleaseStringUTFChars(env, jname, name);
        
        (*env)->ReleaseStringUTFChars(env, jname, name);
        
-       if(rv)
-               jxbt_throw_native(env, xbt_strdup("xbt_select_context_factory() failed"));       
+   if(errmsg) {
+      char *thrown = bprintf("xbt_select_context_factory() failed: %s",errmsg);
+      free(errmsg);
+      jxbt_throw_native(env, thrown);
+   }   
 }
 
 JNIEXPORT void JNICALL 
 }
 
 JNIEXPORT void JNICALL 
index ea50160..712d7c3 100644 (file)
@@ -277,26 +277,20 @@ xbt_context_select_factory(const char* name)
        return 0;       \r
 }\r
 \r
        return 0;       \r
 }\r
 \r
-int\r
+void\r
 xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name)\r
 {\r
        if(!strcmp(name,"java"))\r
 xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name)\r
 {\r
        if(!strcmp(name,"java"))\r
-       {\r
-               return xbt_ctx_java_factory_init(factory);      \r
-       }\r
+               xbt_ctx_java_factory_init(factory);     \r
        #ifdef CONTEXT_THREADS\r
        else if(!strcmp(name,"thread")) \r
        #ifdef CONTEXT_THREADS\r
        else if(!strcmp(name,"thread")) \r
-       {\r
-               return xbt_ctx_thread_factory_init(factory);    \r
-       }\r
+               xbt_ctx_thread_factory_init(factory);   \r
        #elif !defined(WIN32)\r
        else if(!strcmp(name,"sysv"))\r
        #elif !defined(WIN32)\r
        else if(!strcmp(name,"sysv"))\r
-       {\r
-               return xbt_ctx_sysv_factory_init(factory);      \r
-       }\r
+               xbt_ctx_sysv_factory_init(factory);     \r
        #endif\r
        #endif\r
-       \r
-       return EINVAL;\r
+\r
+   THROW1(not_found_error, 0,"Factory '%s' does not exist",name);\r
 }\r
 \r
 /** Garbage collection\r
 }\r
 \r
 /** Garbage collection\r
index bf75e6d..156fba3 100644 (file)
@@ -73,7 +73,7 @@ xbt_ctx_java_ex_terminate(xbt_ex_t *e)
        abort();\r
 }\r
 \r
        abort();\r
 }\r
 \r
-int\r
+void\r
 xbt_ctx_java_factory_init(xbt_context_factory_t* factory)\r
 {\r
        /* context exception handlers */\r
 xbt_ctx_java_factory_init(xbt_context_factory_t* factory)\r
 {\r
        /* context exception handlers */\r
@@ -87,8 +87,6 @@ xbt_ctx_java_factory_init(xbt_context_factory_t* factory)
        (*factory)->finalize = xbt_ctx_java_factory_finalize;\r
        (*factory)->create_maestro_context = xbt_ctx_java_factory_create_maestro_context;\r
        (*factory)->name = "ctx_java_factory";\r
        (*factory)->finalize = xbt_ctx_java_factory_finalize;\r
        (*factory)->create_maestro_context = xbt_ctx_java_factory_create_maestro_context;\r
        (*factory)->name = "ctx_java_factory";\r
-       \r
-       return 0;\r
 }\r
 \r
 static int \r
 }\r
 \r
 static int \r
index bf01c28..54155e9 100644 (file)
@@ -88,17 +88,16 @@ xbt_context_select_factory(const char* name);
 /**\r
  * This function initialize a context factory from the name specified by the parameter\r
  * name.\r
 /**\r
  * This function initialize a context factory from the name specified by the parameter\r
  * name.\r
- * If successful the factory specified by the parameter factory is initialized and the\r
- * function returns 0. Otherwise the function returns the error code.\r
+ * If the factory cannot be found, an exception is raised.\r
  */\r
  */\r
-int\r
+void\r
 xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name);\r
 \r
 \r
 /* All factories init */\r
 xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name);\r
 \r
 \r
 /* All factories init */\r
-int xbt_ctx_thread_factory_init(xbt_context_factory_t* factory);\r
-int xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory);\r
-int xbt_ctx_java_factory_init(xbt_context_factory_t* factory);\r
+void xbt_ctx_thread_factory_init(xbt_context_factory_t* factory);\r
+void xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory);\r
+void xbt_ctx_java_factory_init(xbt_context_factory_t* factory);\r
 \r
 \r
 \r
 \r
 \r
 \r
index 9295621..2a36b6e 100644 (file)
@@ -83,7 +83,7 @@ xbt_ctx_sysv_ex_terminate(xbt_ex_t *e)
 }\r
 \r
 \r
 }\r
 \r
 \r
-int\r
+void\r
 xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory)\r
 {\r
        /* context exception */\r
 xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory)\r
 {\r
        /* context exception */\r
@@ -97,8 +97,6 @@ xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory)
        /* context exception handlers */\r
        __xbt_ex_ctx       = xbt_ctx_sysv_ex_ctx;\r
     __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;    \r
        /* context exception handlers */\r
        __xbt_ex_ctx       = xbt_ctx_sysv_ex_ctx;\r
     __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;    \r
-    \r
-       return 0;\r
 }\r
 \r
 static int \r
 }\r
 \r
 static int \r
index e39ff91..ae325cf 100644 (file)
@@ -60,7 +60,7 @@ xbt_ctx_thread_resume(xbt_context_t context);
 static void* \r
 xbt_ctx_thread_wrapper(void* param);\r
 \r
 static void* \r
 xbt_ctx_thread_wrapper(void* param);\r
 \r
-int\r
+void\r
 xbt_ctx_thread_factory_init(xbt_context_factory_t* factory)\r
 {\r
        *factory = xbt_new0(s_xbt_context_factory_t,1);\r
 xbt_ctx_thread_factory_init(xbt_context_factory_t* factory)\r
 {\r
        *factory = xbt_new0(s_xbt_context_factory_t,1);\r
@@ -69,8 +69,6 @@ xbt_ctx_thread_factory_init(xbt_context_factory_t* factory)
        (*factory)->finalize = xbt_ctx_thread_factory_finalize;\r
        (*factory)->create_maestro_context = xbt_ctx_thread_factory_create_master_context;\r
        (*factory)->name = "ctx_thread_factory";\r
        (*factory)->finalize = xbt_ctx_thread_factory_finalize;\r
        (*factory)->create_maestro_context = xbt_ctx_thread_factory_create_master_context;\r
        (*factory)->name = "ctx_thread_factory";\r
-\r
-       return 0;\r
 }\r
 \r
 static int\r
 }\r
 \r
 static int\r