Skip unnecessary conversion. Fixes
In processing a type conversion, the extractArrayFromPointer step can result in fromType and toType being the same. So we should check them for equality again, and skip the conversion if they are equal.
@@ -486,8 +486,6 @@ func CastExpr(p *program.Program, expr goast.Expr, cFromType, cToType string) (
}, nil
}
- p.AddImport("github.com/elliotchance/c2go/noarch")
-
if strings.HasPrefix(toType, "[]") && strings.HasPrefix(fromType, "*") && isArrayToPointerExpr(expr) {
expr = extractArrayFromPointer(expr)
fromType = "[]" + fromType[1:]
@@ -508,6 +506,13 @@ func CastExpr(p *program.Program, expr goast.Expr, cFromType, cToType string) (
return expr, nil
}
+ if toType == fromType {
+ return expr, nil
+ }
+
+ p.AddImport("github.com/elliotchance/c2go/noarch")
+ p.AddImport("unsafe")
+
exportedLeftName := util.GetExportedName(leftName)
exportedRightName := util.GetExportedName(rightName)
functionName := fmt.Sprintf("noarch.%sTo%s",
