Skip to content

Commit b33df16

Browse files
committed
Merge: FFI: Fix extern methods in generic classes with the interpreter, and complex types with nith
A kind of resolve was missing so the name of the generated C function was different between the call and its implementation. Fix #1899. Pull-Request: #1902 Reviewed-by: Jean Privat <jean@pryen.org>
2 parents 825d239 + c063f7f commit b33df16

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/interpreter/dynamic_loading_ffi/on_demand_compiler.nit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ redef class MMethodDef
262262
for param in msignature.mparameters do params.add param.mtype.cname_blind
263263

264264
# Declare the implementation function as extern
265-
var impl_cname = mproperty.build_cname(mclassdef.mclass.mclass_type,
265+
var impl_cname = mproperty.build_cname(mclassdef.bound_mtype,
266266
mclassdef.mmodule, "___impl", long_signature)
267267
ecc.body_decl.add "extern {c_return_type} {impl_cname}({params.join(", ")});\n"
268268

src/nitni/nitni_base.nit

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ redef class MType
6767
# Representation of this type in pure C on the FFI extern side
6868
# Object -> Object
6969
# Pointer -> void*
70-
fun cname: String is abstract
70+
fun cname: String do return cname_normal_class
7171

7272
# Representation of this type in C for the internal of the system
7373
# Hides extern types.
@@ -83,6 +83,9 @@ redef class MType
8383
# type Object is_primitive? false
8484
# type Pointer is_primitive? true
8585
fun is_cprimitive: Bool do return false
86+
87+
# Name of this type in C for normal classes (not extern and not primitive)
88+
protected fun cname_normal_class: String do return mangled_cname
8689
end
8790

8891
redef class MClassType
@@ -125,9 +128,6 @@ redef class MClassType
125128
return super
126129
end
127130

128-
# Name of this type in C for normal classes (not extern and not primitive)
129-
protected fun cname_normal_class: String do return mangled_cname
130-
131131
redef fun mangled_cname do return mclass.name
132132

133133
redef fun is_cprimitive do return mclass.kind == extern_kind or
@@ -136,7 +136,6 @@ redef class MClassType
136136
end
137137

138138
redef class MNullableType
139-
redef fun cname do return mangled_cname
140139
redef fun mangled_cname do return "nullable_{mtype.mangled_cname}"
141140
end
142141

@@ -145,7 +144,6 @@ redef class MFormalType
145144
end
146145

147146
redef class MGenericType
148-
redef fun cname do return mangled_cname
149147
redef fun mangled_cname
150148
do
151149
var base = super

tests/sav/test_ffi_c_generics.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bar
2+
foo

tests/test_ffi_c_generics.nit

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is part of NIT ( http://www.nitlanguage.org ).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
redef class Array[E]
16+
fun bar `{ puts("bar"); `}
17+
end
18+
19+
redef class NativeArray[E]
20+
fun foo `{ puts("foo"); `}
21+
end
22+
23+
var a = new Array[String]
24+
a.bar
25+
26+
var aa = new NativeArray[Int](1)
27+
aa.foo

0 commit comments

Comments
 (0)