Skip to content

Commit 62b962a

Browse files
committed
Allow ARRAY[ANY] to be applied to pointers
1 parent 15fd4a9 commit 62b962a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

Source/Modules/fortran.cxx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,32 @@ int fix_fortran_dims(Node *n, const char *tmap_name, String *typemap) {
136136
if (!is_checkdims)
137137
return SWIG_OK;
138138

139-
SwigType* t = Getattr(n, "type");
140-
ASSERT_OR_PRINT_NODE(SwigType_isarray(t), n);
141-
int ndim = SwigType_array_ndim(t);
142-
for (int i = 0; i < ndim; i++) {
143-
String *dim = SwigType_array_getdim(t, i);
144-
if (dim && Len(dim) > 0 && !is_fortran_intexpr(dim)) {
145-
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number,
146-
"Array dimension expression '%s' is incompatible with Fortran\n",
147-
dim);
139+
SwigType *t = Getattr(n, "type");
140+
141+
if (SwigType_isarray(t)) {
142+
int ndim = SwigType_array_ndim(t);
143+
for (int i = 0; i < ndim; i++) {
144+
String *dim = SwigType_array_getdim(t, i);
145+
if (dim && Len(dim) > 0 && !is_fortran_intexpr(dim)) {
146+
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Array dimension expression '%s' is incompatible with Fortran\n", dim);
147+
Delete(dim);
148+
return SWIG_ERROR;
149+
}
148150
Delete(dim);
149-
return SWIG_ERROR;
150151
}
151-
Delete(dim);
152-
}
153152

154-
// Replace empty dimensions with assumed-size dimension
155-
Replaceall(typemap, "dimension()", "dimension(*)");
156-
Replaceall(typemap, ",)", ",*)");
153+
// Replace empty dimensions with assumed-size dimension
154+
Replaceall(typemap, "dimension()", "dimension(*)");
155+
Replaceall(typemap, ",)", ",*)");
156+
} else if (SwigType_ispointer(t)) {
157+
// Note that we use `imname` instead of `lname` since it was temporarily changed for typemap matching for ftype. Pointers should only have a single
158+
// dimension, so we replace with deferred size.
159+
String *dimname = NewStringf("%s_dim0", Getattr(n, "imname"));
160+
Replaceall(typemap, dimname, "*");
161+
Delete(dimname);
162+
} else {
163+
ASSERT_OR_PRINT_NODE(false, n);
164+
}
157165

158166
return SWIG_OK;
159167
}

0 commit comments

Comments
 (0)