src: cleanup importations
[nit.git] / src / global_compiler.nit
index 60b1c50..9a82243 100644 (file)
@@ -244,6 +244,7 @@ class GlobalCompiler
                v.add("{res}->classid = {self.classid(mtype)};")
 
                self.generate_init_attr(v, res, mtype)
+               v.set_finalizer res
                v.add("return {res};")
                v.add("\}")
        end
@@ -356,7 +357,7 @@ class GlobalCompilerVisitor
                        return
                else if pname == "copy_to" then
                        var recv1 = "((struct {arguments[1].mcasttype.c_name}*){arguments[1]})->values"
-                       self.add("memcpy({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
+                       self.add("memmove({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
                        return
                end
        end
@@ -400,7 +401,7 @@ class GlobalCompilerVisitor
                        if res != null then self.assign(res, res2.as(not null))
                        return res
                end
-               var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_other.value or m.name == "==" or m.name == "!="
+               var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_null.value or m.name == "==" or m.name == "!="
                if args.first.mcasttype isa MNullableType or args.first.mcasttype isa MNullType and consider_null then
                        # The reciever is potentially null, so we have to 3 cases: ==, != or NullPointerException
                        self.add("if ({args.first} == NULL) \{ /* Special null case */")
@@ -479,7 +480,8 @@ class GlobalCompilerVisitor
        do
                check_valid_reciever(recvtype)
                #debug("call {m} on {recvtype} on {args.first}:{args.first.mtype}")
-               if m.mclassdef.mclass.name == "Object" and recvtype.ctype == "val*" then
+               if m.mproperty.is_toplevel then
+                       # Do not customize top-level methods
                        recvtype = m.mclassdef.bound_mtype
                end
                return recvtype