Compiler warning when subclassing InputStream
When subclassing GLib.InputStream the c compiler gives an incompatible-pointer-types warning as the signature of the implemented abstract methods read/close do not match. The buffer parameter is internally of type void *
, the vapi presents it as uint8[]
, which is accurate, but an incompatible type. Just adding [CCode (type = "void*")]
to the buffer
parameter in vapi or vala code did not resolve this issue. Other methods in InputStream
and OutputStream
are affected as well. I also noted that .metadata
cannot be used to add such type annotation to parameters.
Sample code:
public class NotSupportedInputStream : InputStream {
public override ssize_t read(uint8[] buffer, Cancellable? cancellable = null) throws IOError {
throw new IOError.NOT_SUPPORTED("NotSupportedInputStream doesn't support read()");
}
public override bool close(Cancellable? cancellable = null) throws IOError {
throw new IOError.NOT_SUPPORTED("NotSupportedInputStream doesn't support close()");
}
}
Warning message:
subclass-inputstream.vala.c: In function ‘not_supported_input_stream_class_init’:
subclass-inputstream.vala.c:115:41: warning: assignment to ‘gssize (*)(GInputStream *, void *, gsize, GCancellable *, GError **)’ {aka ‘long int (*)(struct _GInputStream *, void *, long unsigned int, struct _GCancellable *, struct _GError **)’} from incompatible pointer type ‘gssize (*)(GInputStream *, guint8 *, gsize, GCancellable *, GError **)’ {aka ‘long int (*)(struct _GInputStream *, unsigned char *, long unsigned int, struct _GCancellable *, struct _GError **)’} [-Wincompatible-pointer-types]
115 | ((GInputStreamClass *) klass)->read_fn = (gssize (*) (GInputStream*, guint8*, gsize, GCancellable*, GError**)) not_supported_input_stream_real_read;
Edited by Marvin W