FFI niti: fix extern methods in generic classes
[nit.git] / src / interpreter / dynamic_loading_ffi / on_demand_compiler.nit
index 265ec7f..85deec6 100644 (file)
@@ -30,8 +30,17 @@ redef class AMethPropdef
        fun supported_by_dynamic_ffi: Bool
        do
                var n_extern_code_block = n_extern_code_block
-               return n_extern_calls == null and n_extern_code_block != null and
-                          n_extern_code_block.is_c
+               if not (n_extern_calls == null and n_extern_code_block != null and
+                       n_extern_code_block.is_c) then return false
+
+               for mparam in mpropdef.msignature.mparameters do
+                       var mtype = mparam.mtype
+                       if not mtype.is_cprimitive then
+                               return false
+                       end
+               end
+
+               return true
        end
 end
 
@@ -66,7 +75,7 @@ redef class AModule
                var compile_dir = v.compile_dir
                var foreign_code_lib_path = v.foreign_code_lib_path(mmodule)
 
-               compile_dir.mkdir
+               if not compile_dir.file_exists then compile_dir.mkdir
 
                # Compile the common FFI part
                ensure_compile_ffi_wrapper
@@ -84,6 +93,11 @@ redef class AModule
                var srcs = [for file in ccu.files do new ExternCFile(file, ""): ExternFile]
                srcs.add_all mmodule.ffi_files
 
+               if mmodule.pkgconfigs.not_empty then
+                       fatal(v, "NOT YET IMPLEMENTED annotation `pkgconfig`")
+                       return false
+               end
+
                var ldflags = mmodule.ldflags[""].join(" ")
                # TODO pkgconfig
 
@@ -95,7 +109,7 @@ redef class AModule
 
                # Link everything in a shared library
                # TODO customize the compiler
-               var cmd = "{v.c_compiler} -Wall -shared -Wl,-soname,{mmodule.name}.so -g -o {foreign_code_lib_path} {object_files.join(" ")} {ldflags}"
+               var cmd = "{v.c_compiler} -Wall -shared -o {foreign_code_lib_path} {object_files.join(" ")} {ldflags}"
                if sys.system(cmd) != 0 then
                        v.fatal "FFI Error: Failed to link native code using `{cmd}`"
                        return false
@@ -129,6 +143,11 @@ typedef union nit_call_arg {
        int value_Bool;
        uint32_t value_Char;
        uint8_t value_Byte;
+       int8_t value_Int8;
+       int16_t value_Int16;
+       uint16_t value_UInt16;
+       int32_t value_Int32;
+       uint32_t value_UInt32;
        double value_Float;
        void* value_Pointer;
 } nit_call_arg;
@@ -243,7 +262,7 @@ redef class MMethodDef
                for param in msignature.mparameters do params.add param.mtype.cname_blind
 
                # Declare the implementation function as extern
-               var impl_cname = mproperty.build_cname(mclassdef.mclass.mclass_type,
+               var impl_cname = mproperty.build_cname(mclassdef.bound_mtype,
                        mclassdef.mmodule, "___impl", long_signature)
                ecc.body_decl.add "extern {c_return_type} {impl_cname}({params.join(", ")});\n"