]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - forb-idl/forb-idl-c-skels.c
forb: Split forb_port_destroy() to stop and destroy phases
[frescor/forb.git] / forb-idl / forb-idl-c-skels.c
index d3348dca7e1b47908fe719f95e6cfa26a65c79f9..1d353381e186063ebbb45c5c500effff1a711774 100644 (file)
@@ -226,11 +226,27 @@ static void free_memory_if_needed(IDL_tree type_spec, const char *name, int n, O
     break;
   case IDLN_TYPE_ARRAY:
     break;
-  case IDLN_TYPE_SEQUENCE:
-    fprintf(ci->fh, "    ");
-    fprintf(ci->fh, "if (CORBA_sequence_get_release(%s%s)) { forb_free(%s%s_buffer); }\n",
-           n==2?"":"&",name, name, n==2?"->":".");
+  case IDLN_TYPE_SEQUENCE: {
+    char *dot = n==2?"->":".";
+    IDL_tree simple_type = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(type_spec).simple_type_spec);
+
+    fprintf(ci->fh, "    if (CORBA_sequence_get_release(%s%s)) {\n",
+           n==2?"":"&",name);
+    if (IDLN_NATIVE == IDL_NODE_TYPE(simple_type)) {
+      fprintf(ci->fh, "      int i;\n"
+                     "      for (i=0; i<%s%s_length; i++)\n"
+                     "          %s_free(%s%s_buffer[i]);\n",
+             name, dot, forb_cbe_get_typespec_str(IDL_NATIVE(type_spec).ident),
+             name, dot);
+    }
+    fprintf(ci->fh, "      forb_free(%s%s_buffer);\n"
+                   "    }\n", name, dot);
+    if (n==2) {
+           fprintf(ci->fh, "    ");
+           fprintf(ci->fh, "forb_free(%s);\n", name);
+    }
     break;
+  }
   case IDLN_NATIVE:
     fprintf(ci->fh, "    ");
     fprintf(ci->fh, "%s_free(%s);\n",
@@ -252,6 +268,7 @@ static void ck_output_op_skel(IDL_tree op, char *intf_id, OIDL_Run_Info *rinfo,
        char *id, *id_plain;
        IDL_tree sub;
        gboolean  has_retval, has_args;
+       const char *const seq_init = " = {0,0,NULL}";
 
        has_retval = IDL_OP_DCL (op).op_type_spec != NULL;
        has_args   = IDL_OP_DCL (op).parameter_dcls != NULL;
@@ -259,7 +276,7 @@ static void ck_output_op_skel(IDL_tree op, char *intf_id, OIDL_Run_Info *rinfo,
        id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(op).ident), "_", 0);
        id_plain = IDL_IDENT(IDL_OP_DCL(op).ident).str;
        fprintf(ci->fh, "static void\n"
-               "forb_skel_%s(CDR_Codec *cin, CDR_Codec *cout, %s _obj, struct forb_env *env)\n"
+               "forb_skel_%s(FORB_CDR_Codec *cin, FORB_CDR_Codec *cout, %s _obj, struct forb_env *env)\n"
                "{\n",
                id, intf_id);
 /*     fprintf(ci->fh, "  if (_obj->interface != %s_interface) {\n", intf_id); */
@@ -281,12 +298,15 @@ static void ck_output_op_skel(IDL_tree op, char *intf_id, OIDL_Run_Info *rinfo,
 
                fprintf(ci->fh, "    ");
                forb_cbe_write_typespec(ci->fh, IDL_PARAM_DCL(parm).param_type_spec);
-               fprintf(ci->fh, " %s%s;\n", n == 2 ? "*":"", name);
+               fprintf(ci->fh, " %s%s%s;\n",
+                       n == 2 ? "*":"",
+                       name,
+                       (n < 2 && IDL_NODE_TYPE(ts) == IDLN_TYPE_SEQUENCE)?seq_init : "");
        }
        if (has_retval) {
                fprintf (ci->fh, "    ");
                forb_cbe_write_param_typespec (ci->fh, op);
-               fprintf (ci->fh, " _forb_ret;\n");
+               fprintf (ci->fh, " _forb_ret;\n"); /* TODO: seq_init */
        }
 
        /* Deserialize in parameters */
@@ -296,14 +316,10 @@ static void ck_output_op_skel(IDL_tree op, char *intf_id, OIDL_Run_Info *rinfo,
                role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
                if (role == DATA_IN || role == DATA_INOUT) {
                        char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
-                       fprintf(ci->fh, /* "  r = " */ "    ");
+                       fprintf(ci->fh, "    if (!");
                        forb_cbe_write_typespec(ci->fh, IDL_PARAM_DCL(parm).param_type_spec);
-                       if (IDL_NODE_TYPE(forb_cbe_get_typespec(parm)) == IDLN_INTERFACE) {
-                         fprintf(ci->fh, "_deserialize(cin, &%s, _obj->orb);\n", name);
-                       } else {
-                         fprintf(ci->fh, "_deserialize(cin, &%s);\n", name);
-                       }
-/*                     fprintf(ci->fh, "    if (!r) { ev->major = FORB_EX_IMP_LIMIT; goto exception; }\n"); */
+                       fprintf(ci->fh, "_deserialize(cin, &%s)) {\n", name);
+                       fprintf(ci->fh, "      env->major = FORB_EX_MARSHAL; goto exception;\n    }\n");
                }
        }
 
@@ -327,7 +343,7 @@ static void ck_output_op_skel(IDL_tree op, char *intf_id, OIDL_Run_Info *rinfo,
        }
        fprintf(ci->fh, "env);\n");
        fprintf(ci->fh,
-               "    if (forb_exception_occured(env)) goto exception;\n");
+               "    if (forb_exception_occurred(env)) goto exception;\n");
        if (has_retval) {
          fprintf(ci->fh, "    ");
          forb_cbe_write_typespec(ci->fh, IDL_OP_DCL(op).op_type_spec);