cinvoke-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-svn] r52 - in trunk/cinvoke: . bindings/lua lib test


From: will
Subject: [cinvoke-svn] r52 - in trunk/cinvoke: . bindings/lua lib test
Date: 27 Jun 2006 18:57:47 -0400

Author: will
Date: 2006-06-27 18:57:46 -0400 (Tue, 27 Jun 2006)
New Revision: 52

Modified:
   trunk/cinvoke/TODO.txt
   trunk/cinvoke/bindings/lua/cinvoke_lua.c
   trunk/cinvoke/lib/cinvoke.c
   trunk/cinvoke/lib/cinvoke.h
   trunk/cinvoke/lib/hashtable.h
   trunk/cinvoke/test/runtests.c
Log:
bugfixes


Modified: trunk/cinvoke/TODO.txt
===================================================================
--- trunk/cinvoke/TODO.txt      2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/TODO.txt      2006-06-27 22:57:46 UTC (rev 52)
@@ -1,6 +1,5 @@
-test lua structs/callbacks
+lua documentation
+style website
 finish amd64 port
 ppc port
 java binding
-lua documentation
-style website

Modified: trunk/cinvoke/bindings/lua/cinvoke_lua.c
===================================================================
--- trunk/cinvoke/bindings/lua/cinvoke_lua.c    2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/bindings/lua/cinvoke_lua.c    2006-06-27 22:57:46 UTC (rev 52)
@@ -115,7 +115,7 @@
        
        lib = cinv_library_create(ctx, tostring(l, 1));
        if (lib == NULL) {
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(ctx));
                cinv_context_delete(ctx);
                lua_error(l);
        }
@@ -131,7 +131,7 @@
        st->ctx = ctx;
        st->lib = lib;
        st->cc = cc;
-       
+
        lua_newtable(l); // metatable for userdata
        lua_getglobal(l, "clibrary");
        lua_getfield(l, -1, "dispose");
@@ -252,7 +252,7 @@
        
        st = cinv_structure_create(ctx);
        if (!st) {
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(ctx));
                cinv_context_delete(ctx);
                lua_error(l);
        }
@@ -283,7 +283,7 @@
                } else if (!strcmp(family, "string")) {
                        if (!cinv_structure_addmember_value(ctx, st,
                                tostring(l, i + 1), CINV_T_PTR)) {
-                               lua_pushstring(l, 
cinv_context_get_errormsg(ctx));
+                               lua_pushstring(l, 
cinv_context_geterrormsg(ctx));
                                goto error;
                        }
                } else if (!strcmp(family, "struct")) {
@@ -292,7 +292,7 @@
                        mem = touserdata(l, -1);
                        if (!cinv_structure_addmember_struct(ctx, st,
                                tostring(l, i + 1), mem->st)) {
-                               lua_pushstring(l, 
cinv_context_get_errormsg(ctx));
+                               lua_pushstring(l, 
cinv_context_geterrormsg(ctx));
                                goto error;
                        }
                        lua_pop(l, 1);
@@ -302,7 +302,7 @@
                        id = tointeger(l, -1);
                        if (!cinv_structure_addmember_value(ctx, st,
                                tostring(l, i + 1), (cinv_type_t)id)) {
-                               lua_pushstring(l, 
cinv_context_get_errormsg(ctx));
+                               lua_pushstring(l, 
cinv_context_geterrormsg(ctx));
                                goto error;
                        }
                        lua_pop(l, 1);
@@ -314,7 +314,7 @@
        } 
 
        if (!cinv_structure_finish(ctx, st)) {
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(ctx));
                goto error;
        }
 
@@ -332,7 +332,7 @@
        lua_setfield(l, -2, "members");
 
        if (!cinv_structure_getsize(ctx, st, &size)) {
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(ctx));
                goto error;
        }
        lua_pushinteger(l, size);
@@ -450,6 +450,7 @@
                        lua_error(l);
                }
                family = tostring(l, -1);
+               lua_pop(l, 1);
                if (!strcmp("void", family)) {
                        // only put up with void if it is the first and only 
parameter
                        if (i == numparms && i == (startarg + 2)) {
@@ -472,7 +473,7 @@
        ret = cinv_function_create(ctx, cc, retfmt, parmfmt);
        if (!ret) {
                free(parmfmt);
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(ctx));
                lua_error(l);
        }
 
@@ -590,7 +591,7 @@
 void marshal_struct(lua_State *l, void *ret, int typeindex, int argindex) {
        struct StrStruct *st;
        int members;
-
+       
        if (lua_isnil(l, argindex)) {
                lua_pushstring(l, "structs cannot be nil");
                lua_error(l);
@@ -626,7 +627,7 @@
                if (!cinv_structure_instance_setvalue(st->ctx, st->st,
                        ret, key, val)) {
                        free(val);
-                       lua_pushstring(l, cinv_context_get_errormsg(st->ctx));
+                       lua_pushstring(l, cinv_context_geterrormsg(st->ctx));
                        lua_error(l);
                }
                free(val);
@@ -771,7 +772,7 @@
                void *val = cinv_structure_instance_getvalue(st->ctx, st->st,
                        instance, key);
                if (val == NULL) {
-                       lua_pushstring(l, cinv_context_get_errormsg(st->ctx));
+                       lua_pushstring(l, cinv_context_geterrormsg(st->ctx));
                        lua_error(l);
                }
 
@@ -819,7 +820,7 @@
        lua_pushinteger(l, cb->key);
        lua_pushnil(l);
        lua_settable(l, LUA_GLOBALSINDEX);
-       
+
        if (cb->cb) {
                cinv_callback_delete(cb->ctx, cb->cb);
                cb->cb = NULL;
@@ -865,11 +866,13 @@
        lua_remove(cb->l, pindex);
 
        lua_call(cb->l, numargs, 1);
+       retindex = lua_gettop(cb->l);
 
-       retindex = lua_gettop(cb->l);
        lua_getfield(cb->l, usertable, "return");
        index = lua_gettop(cb->l);
-       marshal_basic(cb->l, returnout, index, retindex);
+       if (!isvoid(cb->l, index)) {
+               marshal_basic(cb->l, returnout, index, retindex);
+       }
        lua_remove(cb->l, index);
 
        lua_pop(cb->l, 2); // return value and usertable
@@ -879,9 +882,9 @@
        struct CBStruct *cbs;
        struct LibStruct *lib;
        CInvFunction *func;
-       CInvContext *ctx;
        CInvCallback *cb;
        int i;
+       void *ep;
        int retval;
        int numargs = lua_gettop(l);
        if (numargs < 3) {
@@ -900,12 +903,12 @@
 
        cbs = lua_newuserdata(l, sizeof(struct CBStruct));
        cbs->func = func;
-       cbs->ctx = ctx;
+       cbs->ctx = lib->ctx;
        cbs->l = l;
        
-       cb = cinv_callback_create(ctx, func, cbs, _ccallback_invoked);
+       cb = cinv_callback_create(lib->ctx, func, cbs, _ccallback_invoked);
        if (!cb) {
-               lua_pushstring(l, cinv_context_get_errormsg(ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(lib->ctx));
                cinv_function_delete(lib->ctx, func);
                lua_error(l);
        }
@@ -926,14 +929,22 @@
                lua_settable(l, LUA_GLOBALSINDEX);
                break;
        }
-       
+
        lua_newtable(l);
        lua_pushcfunction(l, _ccallback_gc);
        lua_setfield(l, -2, "__gc");
        lua_setmetatable(l, -2);
        lua_setfield(l, -2, "ud");
 
-       lua_pushvalue(l, 1);
+       ep = cinv_callback_getentrypoint(lib->ctx, cb);
+       if (!ep) {
+               lua_pushstring(l, cinv_context_geterrormsg(lib->ctx));
+               lua_error(l);
+       }
+       lua_pushlightuserdata(l, ep);
+       lua_setfield(l, -2, "ep");
+
+       lua_pushvalue(l, 2);
        lua_setfield(l, -2, "return");
        
        lua_newtable(l);
@@ -1093,7 +1104,7 @@
 
        ep = cinv_library_load_entrypoint(lib->ctx, lib->lib, tostring(l, 3));
        if (!ep) {
-               lua_pushstring(l, cinv_context_get_errormsg(lib->ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(lib->ctx));
                cinv_function_delete(lib->ctx, func);
                lua_error(l);
        }
@@ -1173,7 +1184,7 @@
 
        ep = cinv_library_load_entrypoint(lib->ctx, lib->lib, tostring(l, 3));
        if (!ep) {
-               lua_pushstring(l, cinv_context_get_errormsg(lib->ctx));
+               lua_pushstring(l, cinv_context_geterrormsg(lib->ctx));
                lua_error(l);
        }
        

Modified: trunk/cinvoke/lib/cinvoke.c
===================================================================
--- trunk/cinvoke/lib/cinvoke.c 2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/lib/cinvoke.c 2006-06-27 22:57:46 UTC (rev 52)
@@ -67,10 +67,10 @@
        return CINV_SUCCESS;
 }
 
-const char *cinv_context_get_errormsg(CInvContext *context) {
+const char *cinv_context_geterrormsg(CInvContext *context) {
        return context->errormsg;
 }
-cinv_int32_t cinv_context_get_errorcode(CInvContext *context) {
+cinv_int32_t cinv_context_geterrorcode(CInvContext *context) {
        return context->errorcode;
 }
 

Modified: trunk/cinvoke/lib/cinvoke.h
===================================================================
--- trunk/cinvoke/lib/cinvoke.h 2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/lib/cinvoke.h 2006-06-27 22:57:46 UTC (rev 52)
@@ -175,14 +175,14 @@
 * \param[in] context A C/Invoke context.
 * \return An error message.
 */
-const char *cinv_context_get_errormsg(CInvContext *context);
+const char *cinv_context_geterrormsg(CInvContext *context);
 /** Gets the error code corresponding to the error which occurred when
 * a C/Invoke function fails, or 0 if the last call succeeded.
 * The code returned will be platform-specific.
 * \param[in] context A C/Invoke context.
 * \return An error code, or 0 if no error occurred.
 */
-cinv_int32_t cinv_context_get_errorcode(CInvContext *context);
+cinv_int32_t cinv_context_geterrorcode(CInvContext *context);
 /** Deletes a C/Invoke context
 * \param[in] context A C/Invoke context.
 * \return A standard C/Invoke status code.

Modified: trunk/cinvoke/lib/hashtable.h
===================================================================
--- trunk/cinvoke/lib/hashtable.h       2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/lib/hashtable.h       2006-06-27 22:57:46 UTC (rev 52)
@@ -234,8 +234,8 @@
 */
 
 /*****************************************************************************/
-#define freekey(X) free(X)
-/*define freekey(X) ; */
+//#define freekey(X) free(X)
+#define freekey(X) ;
 
 
 /*****************************************************************************/

Modified: trunk/cinvoke/test/runtests.c
===================================================================
--- trunk/cinvoke/test/runtests.c       2006-06-27 03:37:15 UTC (rev 51)
+++ trunk/cinvoke/test/runtests.c       2006-06-27 22:57:46 UTC (rev 52)
@@ -31,8 +31,8 @@
 void *getep(CInvContext *ctx, CInvLibrary *lib, const char *name) {
        void *ep = cinv_library_load_entrypoint(ctx, lib, name);
        if (!ep)
-               fprintf(stderr, "%s cinv_library_get_entrypoint: %s\n", name,
-                       cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "%s cinv_library_load_entrypoint: %s\n", name,
+                       cinv_context_geterrormsg(ctx));
        return ep;
 }
 
@@ -42,14 +42,14 @@
                paramsig);
        if (!f)
                fprintf(stderr, "%s cinv_function_create: %s\n", name,
-                       cinv_context_get_errormsg(ctx));
+                       cinv_context_geterrormsg(ctx));
        return f;
 }
 
 int test1(CInvContext *ctx, CInvLibrary *lib, void *ep,
        CInvFunction *f) {
        if (!cinv_function_invoke(ctx, f, ep, NULL, NULL)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
        return 1;
@@ -62,7 +62,7 @@
        void *args[1] = { &arg1 };
 
        if (!cinv_function_invoke(ctx, f, ep, &retval, args)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
 
@@ -78,7 +78,7 @@
        void *retval;
 
        if (!cinv_function_invoke(ctx, f, ep, &retval, NULL)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
 
@@ -94,7 +94,7 @@
        float retval;
 
        if (!cinv_function_invoke(ctx, f, ep, &retval, NULL)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
 
@@ -110,7 +110,7 @@
        double retval;
 
        if (!cinv_function_invoke(ctx, f, ep, &retval, NULL)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
 
@@ -134,7 +134,7 @@
        void *args[5] = { &arg1, &arg2, &arg3, &arg4, &arg5 };
 
        if (!cinv_function_invoke(ctx, f, ep, &retval, args)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
        
@@ -282,7 +282,7 @@
        void *args[1] = { &e };
 
        if (!cinv_function_invoke(ctx, f, ep, NULL, args)) {
-               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_get_errormsg(ctx));
+               fprintf(stderr, "invoke failed: %s\n", 
cinv_context_geterrormsg(ctx));
                return 0;
        }
 
@@ -335,7 +335,7 @@
        lib = cinv_library_create(ctx, "./lib." LIBSUFFIX);
        if (!lib) {
                fprintf(stderr, "Cannot load library: %s\n",
-                       cinv_context_get_errormsg(ctx));
+                       cinv_context_geterrormsg(ctx));
                return 1;
        }
 
@@ -351,12 +351,12 @@
        
        if (!cinv_library_delete(ctx, lib)) {
                fprintf(stderr, "Error deleting library: %s\n",
-                       cinv_context_get_errormsg(ctx));
+                       cinv_context_geterrormsg(ctx));
                return 1;
        }
        if (!cinv_context_delete(ctx)) {
                fprintf(stderr, "Error deleting context: %s\n",
-                       cinv_context_get_errormsg(ctx));
+                       cinv_context_geterrormsg(ctx));
                return 1;
        }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]