celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject celix git commit: CELIX-237: dyn_interface now parses types and methods sections
Date Tue, 14 Jul 2015 19:57:03 GMT
Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-237_rsa-ffi 723d5aed0 -> f1252e248


CELIX-237: dyn_interface now parses types and methods sections


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/f1252e24
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/f1252e24
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/f1252e24

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: f1252e248bb100e04412c836b2bdf84d5fd3673a
Parents: 723d5ae
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Tue Jul 14 21:56:18 2015 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Tue Jul 14 21:56:18 2015 +0200

----------------------------------------------------------------------
 .../descriptors/example1.descriptor             |  11 +-
 .../dynamic_function_interface/dyn_common.c     |  26 ++-
 .../dynamic_function_interface/dyn_common.h     |   3 +
 .../dynamic_function_interface/dyn_function.c   |  27 ++-
 .../dynamic_function_interface/dyn_function.h   |   4 +-
 .../dynamic_function_interface/dyn_interface.c  | 229 ++++++++++++++-----
 .../dynamic_function_interface/dyn_interface.h  |  31 ++-
 .../dynamic_function_interface/dyn_type.c       |  39 ++--
 .../dynamic_function_interface/dyn_type.h       |  18 +-
 .../tst/dyn_closure_tests.cpp                   |   4 +
 .../tst/dyn_interface_tests.cpp                 |   8 +-
 11 files changed, 277 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/descriptors/example1.descriptor
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/descriptors/example1.descriptor b/remote_services/dynamic_function_interface/descriptors/example1.descriptor
index 251219a..a0eacfa 100644
--- a/remote_services/dynamic_function_interface/descriptors/example1.descriptor
+++ b/remote_services/dynamic_function_interface/descriptors/example1.descriptor
@@ -5,10 +5,9 @@ major_version=1
 minor_version=0
 micro_version=0
 :types
-StatResult={DDD[D average min max input}
+StatsResult={DDD[D average min max input}
 :methods
-add(PDD*D)N
-sub(PDD*D)N
-sqrt(PD*D)N
-stats(P[D*LStatsResult;)N
-
+add(DD)D=add(PDD*D)N
+sub(DD)D=sub(PDD*D)N
+sqrt(D)D=sqrt(PD*D)N
+stats([D)LStatsResult;=stats(P[D*LStatsResult;)N

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_common.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_common.c b/remote_services/dynamic_function_interface/dyn_common.c
index 05844ef..5ee1a5a 100644
--- a/remote_services/dynamic_function_interface/dyn_common.c
+++ b/remote_services/dynamic_function_interface/dyn_common.c
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <stdbool.h>
 
 #if defined(BSD) || defined(__APPLE__) 
 #include "open_memstream.h"
@@ -17,7 +18,13 @@ static const int ERROR = 1;
 
 DFI_SETUP_LOG(dynCommon)
 
+static bool dynCommon_charIn(int c, const char *acceptedChars);
+
 int dynCommon_parseName(FILE *stream, char **result) {
+    return dynCommon_parseNameAlsoAccept(stream, NULL, result);
+}
+
+int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result)
{
     int status = OK;
 
     char *buf = NULL;
@@ -27,7 +34,7 @@ int dynCommon_parseName(FILE *stream, char **result) {
 
     if (name != NULL) { 
         int c = getc(stream);
-        while (isalnum(c) || c == '_') {
+        while (isalnum(c) || c == '_' || dynCommon_charIn(c, acceptedChars)) {
             fputc(c, name); 
             c = getc(stream);
             strLen += 1;
@@ -83,7 +90,7 @@ int dynCommon_parseNameValue(FILE *stream, char **outName, char **outValue)
{
     return status;
 }
 
-int dynCommon_eatChar(FILE *stream, int expected) {
+inline int dynCommon_eatChar(FILE *stream, int expected) {
     int status = OK;
     int c = fgetc(stream);
     if (c != expected) {
@@ -92,3 +99,18 @@ int dynCommon_eatChar(FILE *stream, int expected) {
     }
     return status;
 }
+
+static bool dynCommon_charIn(int c, const char *acceptedChars) {
+    bool status = false;
+    if (acceptedChars != NULL) {
+        int i;
+        for (i = 0; acceptedChars[i] != '\0'; i += 1) {
+            if (c == acceptedChars[i]) {
+                status = true;
+                break;
+            }
+        }
+    }
+
+    return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_common.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_common.h b/remote_services/dynamic_function_interface/dyn_common.h
index 16df6e2..163bafc 100644
--- a/remote_services/dynamic_function_interface/dyn_common.h
+++ b/remote_services/dynamic_function_interface/dyn_common.h
@@ -14,6 +14,7 @@
 //logging
 DFI_SETUP_LOG_HEADER(dynCommon);
 
+/*
 typedef struct _dyn_annotation_list_type annotation_list_type;
 TAILQ_HEAD(_dyn_annotation_list_type, _dyn_annotation_type);
 
@@ -22,8 +23,10 @@ struct _dyn_annotation_type {
     char *name;
     char *value;
 };
+*/
 
 int dynCommon_parseName(FILE *stream, char **result);
+int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, char **result);
 int dynCommon_parseNameValue(FILE *stream, char **name, char **value);
 int dynCommon_eatChar(FILE *stream, int c);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_function.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_function.c b/remote_services/dynamic_function_interface/dyn_function.c
index 75aa1ae..68c3a11 100644
--- a/remote_services/dynamic_function_interface/dyn_function.c
+++ b/remote_services/dynamic_function_interface/dyn_function.c
@@ -19,7 +19,7 @@ DFI_SETUP_LOG(dynFunction)
 
 struct _dyn_function_type {
     char *name;
-    dyn_type_list_type *refTypes; //NOTE not owned
+    struct reference_types_head *refTypes; //NOTE not owned
     TAILQ_HEAD(,_dyn_function_argument_type) arguments;
     ffi_type **ffiArguments;
     dyn_type *funcReturn;
@@ -43,12 +43,13 @@ struct _dyn_function_argument_type {
 static const int OK = 0;
 static const int MEM_ERROR = 1;
 static const int PARSE_ERROR = 2;
+static const int ERROR = 2;
 
 static int dynFunction_initCif(dyn_function_type *dynFunc);
 static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor);
 static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData); 
 
-int dynFunction_parse(FILE *descriptor, dyn_type_list_type *typeReferences, dyn_function_type
**out) {
+int dynFunction_parse(FILE *descriptor, struct reference_types_head *refTypes, dyn_function_type
**out) {
     int status = OK;
     dyn_function_type *dynFunc = NULL;
     LOG_DEBUG("Creating dyn function", descriptor);
@@ -57,11 +58,14 @@ int dynFunction_parse(FILE *descriptor, dyn_type_list_type *typeReferences,
dyn_
 
     if (dynFunc != NULL) {
         TAILQ_INIT(&dynFunc->arguments);
-        dynFunc->refTypes = typeReferences;
+        dynFunc->refTypes = refTypes;
         status = dynFunction_parseDescriptor(dynFunc, descriptor);
         if (status == 0) {
             int rc = dynFunction_initCif(dynFunc);
-            status = rc != 0 ? rc : 0;
+            if (rc != 0) {
+                LOG_ERROR("Error initializing cif");
+                status = ERROR;
+            }
         }
     } else {
         LOG_ERROR("Error allocationg memory for dyn functipn\n");
@@ -70,21 +74,16 @@ int dynFunction_parse(FILE *descriptor, dyn_type_list_type *typeReferences,
dyn_
     
     if (status == 0) {
         *out = dynFunc;
-    } else {
-        if (status == 1) {
-            LOG_ERROR("Cannot parse func descriptor '%s'\n", descriptor);
-        } else {
-            LOG_ERROR("Cannot allocate memory for dyn function\n");
-        }
-    }
+    }     
+    
     return status;
 }
 
-int dynFunction_parseWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
dyn_function_type **out)  {
+int dynFunction_parseWithStr(const char *descriptor, struct reference_types_head *refTypes,
dyn_function_type **out)  {
     int status = OK;
     FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
     if (stream != NULL) {
-        status = dynFunction_parse(stream, typeReferences, out);
+        status = dynFunction_parse(stream, refTypes, out);
         fclose(stream);
     } else {
         status = MEM_ERROR;
@@ -231,7 +230,7 @@ int dynFunction_createClosure(dyn_function_type *dynFunc, void (*bind)(void
*, v
     return status;
 }
 
-int dynClosure_getFnPointer(dyn_function_type *dynFunc, void (**fn)(void)) {
+int dynFunction_getFnPointer(dyn_function_type *dynFunc, void (**fn)(void)) {
     int status = 0;
     if (dynFunc != NULL && dynFunc->fn != NULL) {
         (*fn) = dynFunc->fn;

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_function.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_function.h b/remote_services/dynamic_function_interface/dyn_function.h
index 3747656..098c76e 100644
--- a/remote_services/dynamic_function_interface/dyn_function.h
+++ b/remote_services/dynamic_function_interface/dyn_function.h
@@ -19,8 +19,8 @@ typedef struct _dyn_closure_type dyn_closure_type;
 
 DFI_SETUP_LOG_HEADER(dynFunction);
 
-int dynFunction_parse(FILE *descriptorStream, dyn_type_list_type *typeReferences, dyn_function_type
**dynFunc);
-int dynFunction_parseWithStr(const char *descriptor, dyn_type_list_type *typeReferences,
dyn_function_type **dynFunc);
+int dynFunction_parse(FILE *descriptorStream, struct reference_types_head *refTypes, dyn_function_type
**dynFunc);
+int dynFunction_parseWithStr(const char *descriptor, struct reference_types_head *refTypes,
dyn_function_type **dynFunc);
 
 void dynFunction_destroy(dyn_function_type *dynFunc);
 int dynFunction_call(dyn_function_type *dynFunc, void(*fn)(void), void *returnValue, void
**argValues);

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_interface.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_interface.c b/remote_services/dynamic_function_interface/dyn_interface.c
index a563eab..bc07a47 100644
--- a/remote_services/dynamic_function_interface/dyn_interface.c
+++ b/remote_services/dynamic_function_interface/dyn_interface.c
@@ -15,6 +15,7 @@ DFI_SETUP_LOG(dynInterface);
 const int OK = 0;
 const int ERROR = 1;
 
+static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream);
 static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream);
 static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream);
 static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream);
@@ -28,12 +29,19 @@ int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) {
         TAILQ_INIT(&intf->types);
         TAILQ_INIT(&intf->methods);
 
-        status = dynInterface_parseAnnotations(intf, descriptor);
-        if (status == OK) {
-            status =dynInterface_parseTypes(intf, descriptor);
+        char peek = fgetc(descriptor);
+        while (peek == ':') {
+            ungetc(peek, descriptor);
+            status = dynInterface_parseSection(intf, descriptor);
+            if (status == OK) {
+                peek = fgetc(descriptor);
+            } else {
+                break;
+            }
         }
+
         if (status == OK) {
-            status = dynInterface_parseMethods(intf, descriptor);
+            status = dynCommon_eatChar(descriptor, EOF);
         }
     } else {
         status = ERROR;
@@ -48,7 +56,7 @@ int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) {
     return status;
 }
 
-static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream) {
+static int dynInterface_parseSection(dyn_interface_type *intf, FILE *stream) {
     int status = OK;
     char *sectionName = NULL;
 
@@ -63,72 +71,187 @@ static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE
*stream)
     }
 
     if (status == OK) {
-        if (strcmp("annotations", sectionName) == 0) {
-            LOG_DEBUG("Parsed annotations section header");
+        if (strcmp("annotations", sectionName) ==0) {
+                status = dynInterface_parseAnnotations(intf, stream);
+        } else if (strcmp("types", sectionName) == 0) {
+                status =dynInterface_parseTypes(intf, stream);
+        } else if (strcmp("methods", sectionName) == 0) {
+                status =dynInterface_parseMethods(intf, stream);
         } else {
             status = ERROR;
-            LOG_ERROR("Expected annotations section, got '%s'", sectionName);
+            LOG_ERROR("unsupported section '%s'", sectionName);
         }
     }
 
-    if (status == OK) {
-        int peek = fgetc(stream);
-        while (peek != ':' && peek != EOF) {
-            ungetc(peek, stream);
+    return status;
+}
+
+static int dynInterface_parseAnnotations(dyn_interface_type *intf, FILE *stream) {
+    int status = OK;
 
-            char *name;
-            char *value;
-            status = dynCommon_parseNameValue(stream, &name, &value);
+    int peek = fgetc(stream);
+    while (peek != ':' && peek != EOF) {
+        ungetc(peek, stream);
 
-            if (status == OK) {
-                status = dynCommon_eatChar(stream, '\n');
+        char *name;
+        char *value;
+        status = dynCommon_parseNameValue(stream, &name, &value);
+
+        if (status == OK) {
+            status = dynCommon_eatChar(stream, '\n');
+        }
+
+        struct namval_entry *entry = NULL;
+        if (status == OK) {
+            entry = calloc(1, sizeof(*entry));
+            if (entry != NULL) {
+                entry->name = name;
+                entry->value = value;
+                TAILQ_INSERT_TAIL(&intf->annotations, entry, entries);
+            } else {
+                status = ERROR;
+                LOG_ERROR("Error allocating memory for namval entry");
             }
+        }
 
-            if (status == OK) {
-                interface_namval_type *entry = calloc(1, sizeof(*entry));
-                if (entry != NULL) {
-                    entry->name = name;
-                    entry->value = value;
-                    TAILQ_INSERT_TAIL(&intf->annotations, entry, entries);
-                } else {
-                    status = ERROR;
-                    LOG_ERROR("Error allocating memory for namval entry");
-                }
-            }
-
-            if (status != OK) {
-                if (name != NULL) {
-                    free(name);
-                }
-                if (value != NULL) {
-                    free(value);
-                }
-                break;
+        if (status != OK) {
+            if (name != NULL) {
+                free(name);
+            }
+            if (value != NULL) {
+                free(value);
             }
-            peek = fgetc(stream);
+            if (entry != NULL) {
+                free(entry);
+            }
+            break;
         }
-        ungetc(peek, stream);
+        peek = fgetc(stream);
     }
+    ungetc(peek, stream);
     
     return status;
 }
 
 static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream) {
     int status = OK;
-    //TODO implement -> extract section parse part  from parseAnnotations first?
+
+    //expected input (Name)=<Type>\n
+    int peek = fgetc(stream);
+    while (peek != ':' && peek != EOF) {
+        ungetc(peek, stream);
+
+        char *name;
+        status = dynCommon_parseName(stream, &name);
+
+        if (status == OK) {
+            status = dynCommon_eatChar(stream, '=');
+        }
+
+        dyn_type *type = NULL;
+        if (status == OK) {
+            dynType_parse(stream, name, &intf->types, &type);
+        }
+        if (name != NULL) {
+            free(name);
+        }
+
+        if (status == OK) {
+            status = dynCommon_eatChar(stream, '\n');
+        }
+
+        struct type_entry *entry = NULL;
+        if (status == OK) {
+            entry = calloc(1, sizeof(*entry));
+            if (entry != NULL) {
+                entry->type = type;
+                TAILQ_INSERT_TAIL(&intf->types, entry, entries);
+            } else {
+                status = ERROR;
+                LOG_ERROR("Error allocating memory for type entry");
+            }
+        }
+
+        if (status != OK) {
+            if (type != NULL) {
+                dynType_destroy(type);
+            }
+            if (entry != NULL) {
+                free(entry);
+            }
+            break;
+        }
+        peek = fgetc(stream);
+    }
+    ungetc(peek, stream);
+
     return status;
 }
 
 static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
     int status = OK;
-    //TODO refactor
+
+    //expected input (Name)=<Method>\n
+    int peek = fgetc(stream);
+    int index = 0;
+    while (peek != ':' && peek != EOF) {
+        ungetc(peek, stream);
+
+        char *id;
+        status = dynCommon_parseNameAlsoAccept(stream, "();[{}", &id);
+
+        if (status == OK) {
+            status = dynCommon_eatChar(stream, '=');
+        }
+
+
+        dyn_function_type *func = NULL;
+        if (status == OK) {
+            status = dynFunction_parse(stream, &intf->types, &func);
+        }
+
+        if (status == OK) {
+            status = dynCommon_eatChar(stream, '\n');
+        }
+
+        struct method_entry *entry = NULL;
+        if (status == OK) {
+            entry = calloc(1, sizeof(*entry));
+            if (entry != NULL) {
+                entry->index = index++;
+                entry->id = id;
+                entry->dynFunc = func;
+                TAILQ_INSERT_TAIL(&intf->methods, entry, entries);
+            } else {
+                status = ERROR;
+                LOG_ERROR("Error allocating memory for method entry");
+            }
+        }
+
+        if (status != OK) {
+            if (id != NULL) {
+                free(id);
+            }
+            if (func != NULL) {
+                dynFunction_destroy(func);
+                //TODO free strIdentier, name
+            }
+            if (entry != NULL) {
+                free(entry);
+            }
+            break;
+        }
+        peek = fgetc(stream);
+    }
+    ungetc(peek, stream);
+
     return status;
 }
 
 void dynInterface_destroy(dyn_interface_type *intf) {
     if (intf != NULL) {
-        interface_namval_type *nTmp = NULL;
-        interface_namval_type *nEntry = TAILQ_FIRST(&intf->annotations);
+        struct namval_entry *nTmp = NULL;
+        struct namval_entry *nEntry = TAILQ_FIRST(&intf->annotations);
         while (nEntry != NULL) {
             nTmp = nEntry;
             nEntry = TAILQ_NEXT(nEntry, entries);
@@ -141,27 +264,23 @@ void dynInterface_destroy(dyn_interface_type *intf) {
             free(nTmp);
         }
 
-        interface_type_type *tmp = NULL;
-        interface_type_type *tInfo = TAILQ_FIRST(&intf->types);
+        struct type_entry *tmp = NULL;
+        struct type_entry *tInfo = TAILQ_FIRST(&intf->types);
         while (tInfo != NULL) {
             tmp = tInfo;
             tInfo = TAILQ_NEXT(tInfo, entries);
-
-            if (tmp->name != NULL) {
-                free(tmp->name);
-            }
-
+            dynType_destroy(tmp->type);
             free(tmp);
         }
 
-        interface_method_type *mTmp = NULL;
-        interface_method_type *mInfo = TAILQ_FIRST(&intf->methods);
+        struct method_entry *mTmp = NULL;
+        struct method_entry *mInfo = TAILQ_FIRST(&intf->methods);
         while (mInfo != NULL) {
             mTmp = mInfo;
             mInfo = TAILQ_NEXT(mInfo, entries);
             
-            if (mTmp->strIdentifier != NULL) {
-                free(mTmp->strIdentifier);
+            if (mTmp->id != NULL) {
+                free(mTmp->id);
             }
             if (mTmp->name != NULL) {
                 free(mTmp->name);
@@ -180,7 +299,7 @@ void dynInterface_destroy(dyn_interface_type *intf) {
 int dynInterface_getName(dyn_interface_type *intf, char **out) {
     int status = OK;
     char *name = NULL;
-    interface_namval_type *entry = NULL;
+    struct namval_entry *entry = NULL;
     TAILQ_FOREACH(entry, &intf->annotations, entries) {
         if (strcmp("name", entry->name) == 0) {
             name = entry->value;

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_interface.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_interface.h b/remote_services/dynamic_function_interface/dyn_interface.h
index a574496..84badc4 100644
--- a/remote_services/dynamic_function_interface/dyn_interface.h
+++ b/remote_services/dynamic_function_interface/dyn_interface.h
@@ -20,36 +20,33 @@ DFI_SETUP_LOG_HEADER(dynInterface);
  * expected sections: header, types & mehods
  */
 
+TAILQ_HEAD(namvals_head, namval_entry);
+TAILQ_HEAD(methods_head, method_entry);
+//struct reference_types_head in dyn_type.h
+
 typedef struct _dyn_interface_type dyn_interface_type;
 
 struct _dyn_interface_type {
-    TAILQ_HEAD(, _interface_namval_type) annotations;
-    TAILQ_HEAD(, _interface_type_type) types;
-    TAILQ_HEAD(, _interface_method_type) methods;
+    struct namvals_head annotations;
+    struct reference_types_head types;
+    struct methods_head methods;
 };
 
-typedef struct _interface_namval_type interface_namval_type;
-struct _interface_namval_type {
+//TODO move to dynCommon
+struct namval_entry {
     char *name;
     char *value;
-    TAILQ_ENTRY(_interface_namval_type) entries;
+    TAILQ_ENTRY(namval_entry) entries;
 };
 
-typedef struct _interface_method_type interface_method_type;
-struct _interface_method_type {
-    int identifier;
-    char *strIdentifier;
+struct method_entry {
+    int index;
+    char *id;
     char *name;
 
     dyn_function_type *dynFunc;
 
-    TAILQ_ENTRY(_interface_method_type) entries; 
-};
-
-typedef struct _interface_type_type interface_type_type;
-struct _interface_type_type {
-    char *name;
-    TAILQ_ENTRY(_interface_type_type) entries;
+    TAILQ_ENTRY(method_entry) entries; 
 };
 
 int dynInterface_parse(FILE *descriptor, dyn_interface_type **out);

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_type.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_type.c b/remote_services/dynamic_function_interface/dyn_type.c
index 2915093..720f929 100644
--- a/remote_services/dynamic_function_interface/dyn_type.c
+++ b/remote_services/dynamic_function_interface/dyn_type.c
@@ -17,7 +17,7 @@
 
 DFI_SETUP_LOG(dynType)
 
-static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, dyn_type_list_type
*typeReferences, dyn_type **result);
+static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct
reference_types_head *refTypes, dyn_type **result);
 static void dynType_clear(dyn_type *type);
 static void dynType_clearComplex(dyn_type *type);
 static void dynType_clearSequence(dyn_type *type);
@@ -58,15 +58,15 @@ static const int DT_ERROR = 1;
 static const int DT_MEM_ERROR = 2;
 static const int DT_PARSE_ERROR = 3;
 
-int dynType_parse(FILE *descriptorStream, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type) {
-    return dynType_parseWithStream(descriptorStream, name, NULL, typeReferences, type);
+int dynType_parse(FILE *descriptorStream, const char *name, struct reference_types_head *refTypes,
dyn_type **type) {
+    return dynType_parseWithStream(descriptorStream, name, NULL, refTypes, type);
 }
 
-int dynType_parseWithStr(const char *descriptor, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type) {
+int dynType_parseWithStr(const char *descriptor, const char *name, struct reference_types_head
*refTypes, dyn_type **type) {
     int status = DT_OK;
     FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r");
     if (stream != NULL) {
-        status = dynType_parseWithStream(stream, name, NULL, typeReferences, type);
+        status = dynType_parseWithStream(stream, name, NULL, refTypes, type);
         if (status == DT_OK) {
             int c = fgetc(stream);
             if (c != '\0' && c != EOF) {
@@ -82,13 +82,13 @@ int dynType_parseWithStr(const char *descriptor, const char *name, dyn_type_list
     return status;
 }
 
-static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, dyn_type_list_type
*typeReferences, dyn_type **result) {
+static int dynType_parseWithStream(FILE *stream, const char *name, dyn_type *parent, struct
reference_types_head *refTypes, dyn_type **result) {
     int status = DT_OK;
     dyn_type *type = calloc(1, sizeof(*type));
     if (type != NULL) {
         type->parent = parent;
         type->type = DYN_TYPE_INVALID;
-        type->typeReferences = typeReferences;
+        type->referenceTypes = refTypes;
         TAILQ_INIT(&type->nestedTypesHead);
         if (name != NULL) {
             type->name = strdup(name);
@@ -295,13 +295,13 @@ static int dynType_parseRefByValue(FILE *stream, dyn_type *type) {
     status = dynCommon_parseName(stream, &name);
     if (status == DT_OK) {
         dyn_type *ref = dynType_findType(type, name);
-        free(name);
         if (ref != NULL) {
             type->ref.ref = ref;
         } else {
             status = DT_PARSE_ERROR;
             LOG_ERROR("Error cannot find type '%s'", name);
         }
+        free(name);
     } 
 
     if (status == DT_OK) {
@@ -594,21 +594,26 @@ static ffi_type * dynType_ffiTypeFor(int c) {
 
 static dyn_type * dynType_findType(dyn_type *type, char *name) {
     dyn_type *result = NULL;
-    struct nested_entry *entry = NULL;
 
-    if (type->typeReferences != NULL) {
-        TAILQ_FOREACH(entry, type->typeReferences, entries) {
-            if (strcmp(name, entry->type.name) == 0) {
-                result = &entry->type;
+    struct type_entry *entry = NULL;
+    if (type->referenceTypes != NULL) {
+        TAILQ_FOREACH(entry, type->referenceTypes, entries) {
+            LOG_DEBUG("checking ref type '%s' with name '%s'", entry->type->name, name);
+            if (strcmp(name, entry->type->name) == 0) {
+                result = entry->type;
                 break;
             }
         }
     }
 
-    TAILQ_FOREACH(entry, &type->nestedTypesHead, entries) {
-        if (strcmp(name, entry->type.name) == 0) {
-            result = &entry->type;
-            break;
+    if (result == NULL) {
+        struct nested_entry *nEntry = NULL;
+        TAILQ_FOREACH(nEntry, &type->nestedTypesHead, entries) {
+            LOG_DEBUG("checking nested type '%s' with name '%s'", nEntry->type.name, name);
+            if (strcmp(name, nEntry->type.name) == 0) {
+                result = &nEntry->type;
+                break;
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/dyn_type.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_type.h b/remote_services/dynamic_function_interface/dyn_type.h
index bc19836..b1d2c9f 100644
--- a/remote_services/dynamic_function_interface/dyn_type.h
+++ b/remote_services/dynamic_function_interface/dyn_type.h
@@ -79,8 +79,8 @@
 
 typedef struct _dyn_type dyn_type;
 
-TAILQ_HEAD(_dyn_type_list_type, nested_entry); 
-typedef struct _dyn_type_list_type dyn_type_list_type;
+TAILQ_HEAD(reference_types_head, type_entry); 
+TAILQ_HEAD(nested_types_head, nested_entry); 
 
 struct _dyn_type {
     char *name;
@@ -88,8 +88,8 @@ struct _dyn_type {
     int type;
     ffi_type *ffiType;
     dyn_type *parent;
-    dyn_type_list_type *typeReferences; //NOTE: not owned
-    dyn_type_list_type  nestedTypesHead;
+    struct reference_types_head *referenceTypes; //NOTE: not owned
+    struct nested_types_head  nestedTypesHead;
     union {
         struct {
             TAILQ_HEAD(, complex_type_entry) entriesHead;
@@ -115,18 +115,22 @@ struct complex_type_entry {
     TAILQ_ENTRY(complex_type_entry) entries;
 };
 
+struct type_entry {
+    dyn_type *type;
+    TAILQ_ENTRY(type_entry) entries;
+};
+
 struct nested_entry {
     dyn_type type;
     TAILQ_ENTRY(nested_entry) entries;
 };
 
-
 //logging
 DFI_SETUP_LOG_HEADER(dynType);
 
 //generic
-int dynType_parse(FILE *descriptorStream, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type);
-int dynType_parseWithStr(const char *descriptor, const char *name, dyn_type_list_type *typeReferences,
dyn_type **type);
+int dynType_parse(FILE *descriptorStream, const char *name, struct reference_types_head *refTypes,
dyn_type **type);
+int dynType_parseWithStr(const char *descriptor, const char *name, struct reference_types_head
*refTypes, dyn_type **type);
 void dynType_destroy(dyn_type *type);
 
 int dynType_alloc(dyn_type *type, void **bufLoc);

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
index d01b22e..b2b11d7 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
@@ -93,11 +93,15 @@ static void tests() {
 
     {
         double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
+        double (*func2)(int32_t a, struct example2_arg2 b, int32_t c) = NULL;
         dynFunction = NULL;
         rc = dynFunction_parseWithStr(EXAMPLE2_DESCRIPTOR, NULL, &dynFunction);
         CHECK_EQUAL(0, rc);
         rc = dynFunction_createClosure(dynFunction, example2_binding, NULL, (void(**)(void))&func);
         CHECK_EQUAL(0, rc);
+        rc = dynFunction_getFnPointer(dynFunction, (void(**)(void))&func2);
+        CHECK_EQUAL(0, rc);
+        CHECK(func == func2);
         struct example2_arg2 b;
         b.val1 = 1.0;
         b.val2 = 1.5;

http://git-wip-us.apache.org/repos/asf/celix/blob/f1252e24/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
index 68dae7a..f22c540 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
@@ -50,9 +50,11 @@ extern "C" {
 
 TEST_GROUP(DynInterfaceTests) {
     void setup() {
-        dynCommon_logSetup(stdLog, NULL, 4);
-        dynType_logSetup(stdLog, NULL, 4);
-        dynFunction_logSetup(stdLog, NULL, 4);
+        int level = 3;
+        dynCommon_logSetup(stdLog, NULL, level);
+        dynType_logSetup(stdLog, NULL, level);
+        dynFunction_logSetup(stdLog, NULL, level);
+        dynInterface_logSetup(stdLog, NULL, level);
     }
 };
 


Mime
View raw message