[Vala] Posix.strerror_r and immutable Vala strings
- From: Van de Bugger <van de bugger gmail com>
- To: vala-list gnome org
- Subject: [Vala] Posix.strerror_r and immutable Vala strings
- Date: Wed, 04 Dec 2019 00:50:12 +0300
Hi all,
I am studying Vala because I am going to use it in a small GTK-based
project. In the code, I need to convert errno value to user-friendly
error message. Since my application is multithreaded, I think that
thread-safe strerror_r would be better choice rather than traditional
strerror. Ok, let's look into posix.vapi:
public int* strerror_r (int errnum, string strerrbuf, size_t buflen);
The first problem: There are two flavours of strerror_r in Linux: GNU
version returns char*, XSI-compliant returns int. Linux man page says
that XSI version provided if (_POSIX_C_SOURCE >= 200112L) &&
! _GNU_SOURCE, otherwise GNU version is provided. But Vala function
returns int*. What does it mean? Is it GNU or XSI?
The second problem: I just finished reading the Vala Tutorial
<https://wiki.gnome.org/Projects/Vala/Tutorial>:
Strings
The data type for strings is string. Vala strings are UTF-8 encoded
and *immutable*.
Both GNI and XSI strerror_r functions expect a buffer to write the
error message to:
strerror_r(int errnum, char *buf, size_t buflen);
But Vala strings are immutable. How will strerror_r modify an
*immutable* string?
It was a great surprise to me, but in the string class documentation <
https://valadoc.org/glib-2.0/string.html> I found a few methods which
modify strings: _chomp, _chug, _delimit, _strip. Are strings actually
mutable? Why does the Vala Tutorial say they aren't?
In the glib-2.0.vapi I see:
[Compact]
[Immutable]
[GIR (name = "utf8")]
[CCode <...skipped...>]
public class string {
What does [Immutable] attribute mean? The Vala Tutorial says nothing
about it. The Vala Reference Manual <
https://www.vala-project.org/doc/vala/Attributes.html#CCode_Attribute>
does not say a word about [Immutable] too. It is very confusing.
I still do not understand how to call strerror_r from Vala code.
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]