Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Free markets select for winning solutions." -- Eric S. Raymond


devel / comp.lang.c / Libraries using longjmp for error handling (was: Re: More on NNTP testing)

SubjectAuthor
* Libraries using longjmp for error handling (was: Re: More on NNTPBlue-Maned_Hawk
+* Re: Libraries using longjmp for error handling (was: Re: More on NNTPJohann 'Myrkraverk' Oskarsson
|`* Re: Libraries using longjmp for error handlingBen Bacarisse
| +* Re: Libraries using longjmp for error handlingBlue-Maned_Hawk
| |`* Re: Libraries using longjmp for error handlingScott Lurndal
| | +* Re: Libraries using longjmp for error handlingAnton Shepelev
| | |`- Re: Libraries using longjmp for error handlingScott Lurndal
| | `* Re: Libraries using longjmp for error handlingKeith Thompson
| |  `- Re: Libraries using longjmp for error handlingDavid Brown
| `* Re: Libraries using longjmp for error handlingTim Rentsch
|  `* Re: Libraries using longjmp for error handlingBen Bacarisse
|   `* Re: Libraries using longjmp for error handlingTim Rentsch
|    +* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |`* Re: Libraries using longjmp for error handlingTim Rentsch
|    | `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |  `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |   +- Re: Libraries using longjmp for error handlingAnton Shepelev
|    |   `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |    `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |     `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |      `* Re: Libraries using longjmp for error handlingTim Rentsch
|    |       `* Re: Libraries using longjmp for error handlingBen Bacarisse
|    |        `- Re: Libraries using longjmp for error handlingTim Rentsch
|    `* Re: Libraries using longjmp for error handlingAnton Shepelev
|     `* Re: Libraries using longjmp for error handlingTim Rentsch
|      `- Re: Libraries using longjmp for error handlingAnton Shepelev
+- Re: Libraries using longjmp for error handlingBen Bacarisse
+* Re: Libraries using longjmp for error handling (was: Re: More onKaz Kylheku
|`- Re: Libraries using longjmp for error handling (was: Re: More onKaz Kylheku
+* Re: Libraries using longjmp for error handling (was: Re: More onAnton Shepelev
|`* Re: Libraries using longjmp for error handlingBen Bacarisse
| `* Re: Libraries using longjmp for error handlingAnton Shepelev
|  +* Re: Libraries using longjmp for error handlingKaz Kylheku
|  |+* Re: Libraries using longjmp for error handlingScott Lurndal
|  ||+- Re: Libraries using longjmp for error handlingKaz Kylheku
|  ||`- Re: Libraries using longjmp for error handlingBen Bacarisse
|  |`* Re: Libraries using longjmp for error handlingTim Rentsch
|  | +* Re: Libraries using longjmp for error handlingKaz Kylheku
|  | |`- Re: Libraries using longjmp for error handlingTim Rentsch
|  | `* Re: Libraries using longjmp for error handlingKeith Thompson
|  |  +* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |  |`- Re: Libraries using longjmp for error handlingKaz Kylheku
|  |  `* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   +* Re: Libraries using longjmp for error handlingSpiros Bousbouras
|  |   |+* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   ||+* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |   |||+- Re: Libraries using longjmp for error handlingTim Rentsch
|  |   |||`- Re: Libraries using longjmp for error handlingKenny McCormack
|  |   ||`- Re: Libraries using longjmp for error handlingKaz Kylheku
|  |   |`* Re: Libraries using longjmp for error handlingAnton Shepelev
|  |   | `* Re: Libraries using longjmp for error handlingTim Rentsch
|  |   |  `- Re: Libraries using longjmp for error handlingKeith Thompson
|  |   `- Re: Libraries using longjmp for error handlingKaz Kylheku
|  +* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |`* Re: Libraries using longjmp for error handlingKaz Kylheku
|  | `* Re: Libraries using longjmp for error handlingBen Bacarisse
|  |  +- Re: Libraries using longjmp for error handlingTim Rentsch
|  |  `* Re: Libraries using longjmp for error handlingKaz Kylheku
|  |   `* Re: Libraries using longjmp for error handlingAnton Shepelev
|  |    `- Re: Libraries using longjmp for error handlingTim Rentsch
|  `- Re: Libraries using longjmp for error handlingDavid Brown
`- Re: Libraries using longjmp for error handlingRichard Kettlewell

Pages:123
Libraries using longjmp for error handling (was: Re: More on NNTP testing)

<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29344&group=comp.lang.c#29344

  copy link   Newsgroups: news.software.nntp comp.lang.c
Followup: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: news.software.nntp,comp.lang.c
Subject: Libraries using longjmp for error handling (was: Re: More on NNTP
testing)
Followup-To: comp.lang.c
Date: Wed, 27 Sep 2023 22:52:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Sep 2023 22:52:59 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="2130bf3c74c20cbf06e8b31893e9df54";
logging-data="3495454"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Iys1nkcsKOyUrvUrc2S0L1L63GRKgU+E="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:OQANcn/gOf9zbtXJAZnpDa7qS3U=
X-Face: Llanfair­pwllgwyngyllÃ
ƒ‚Ã
ƒƒ‚­gogery­chwyrnÃ
ƒƒ
? ?‚­drobwll­llan
Ã
? ?ƒƒ‚­tysilio­go
g
o­goch
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
 by: Blue-Maned_Hawk - Wed, 27 Sep 2023 22:52 UTC

Richard Kettlewell wrote:

> It’s more than 20 years since I last had to integrate a C library which
> reported errors via longjmp() and I’m still bitter about it.

I have never encountered a library which does that. Which library was
that?

> As a matter of API design, I’d rather C library communicated errors via
> return values (and pointer parameters, where more complex error
> information is required).

Personally, i think that, at least for a library, an error should _only_
be communicated by return value. If more complex information is required,
then the return value can be made more complex. I don't think i've ever
used a library that communicates information via a pointer parameter.

One thing i've experienced in multiple libraries is a system a bit like
what errno.h offers, but done via a pair of subroutines that retrieve and
assign to some hidden global variable. I don't like this for the same
reason i don't like subroutines that use errno (unless they're syscall
wrappers), but in at least two of the cases the library has also come with
a way to set a callback subroutine to automatically deal with errors
instead. This is nice, since it means that the code doesn't get all
obfuscated with error checking after every subroutine call, but it's
annoying that each library needs to come with its own unique subroutine
for this, and i do worry about it being overly general in treating all
errors lethally.

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr. bluemanedhawk.github.io
Warning: Low flying owls. Lost chihuahua.

Re: Libraries using longjmp for error handling (was: Re: More on NNTP testing)

<AE3RM.402236$kCld.195109@fx08.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29351&group=comp.lang.c#29351

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx08.ams4.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Subject: Re: Libraries using longjmp for error handling (was: Re: More on NNTP
testing)
Content-Language: en-US
Newsgroups: comp.lang.c
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
From: joh...@myrkraverk.invalid (Johann 'Myrkraverk' Oskarsson)
In-Reply-To: <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 51
Message-ID: <AE3RM.402236$kCld.195109@fx08.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 28 Sep 2023 08:19:41 +0800
X-Received-Bytes: 3566
 by: Johann 'Myrkrav - Thu, 28 Sep 2023 00:19 UTC

On 9/28/2023 6:52 AM, Blue-Maned_Hawk wrote:
> Richard Kettlewell wrote:
>
>> It’s more than 20 years since I last had to integrate a C library which
>> reported errors via longjmp() and I’m still bitter about it.

I am not surprised.

> I have never encountered a library which does that. Which library was
> that?
>
>> As a matter of API design, I’d rather C library communicated errors via
>> return values (and pointer parameters, where more complex error
>> information is required).
>
> Personally, i think that, at least for a library, an error should _only_
> be communicated by return value. If more complex information is required,
> then the return value can be made more complex. I don't think i've ever
> used a library that communicates information via a pointer parameter.
>
> One thing i've experienced in multiple libraries is a system a bit like
> what errno.h offers, but done via a pair of subroutines that retrieve and
> assign to some hidden global variable. I don't like this for the same
> reason i don't like subroutines that use errno (unless they're syscall
> wrappers), but in at least two of the cases the library has also come with
> a way to set a callback subroutine to automatically deal with errors
> instead. This is nice, since it means that the code doesn't get all
> obfuscated with error checking after every subroutine call, but it's
> annoying that each library needs to come with its own unique subroutine
> for this, and i do worry about it being overly general in treating all
> errors lethally.

Error handling in libraries is a thorny subject, and I could go on a
long rant on it. The short summary is simply this: error handling is
rife with incompetence, and incompetent designs. Even in languages that
ostensibly provide better mechanisms than C, the details are usually
poorly documented and under-specified [1].

Rest assured that my error handling strategy is /sane/, though for now
I'm not explaining my code, nor design.

[1] Like in Common Lisp, when you're given a handler that supposedly
can handle it in-situ, but then the handler doesn't get enough arguments
to do much more than log a generic error, or -- this was a personal
favorite -- you have to read the source code to figure out what the
error handler gets.

--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk

Re: Libraries using longjmp for error handling

<877cobf7ht.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29353&group=comp.lang.c#29353

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 01:48:14 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <877cobf7ht.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="3537546"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197pTYt5WNhc91b3lErRhEpoN15BWcTE6M="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:h2l5SqLGb6Yx+7FLPTvihdutN/M=
sha1:5hpg7zf9cJjgwR3VsT+3rWI2gPk=
X-BSB-Auth: 1.b249d92a185c3fe661a0.20230928014814BST.877cobf7ht.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 00:48 UTC

Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:

> Richard Kettlewell wrote:
>
>> It’s more than 20 years since I last had to integrate a C library which
>> reported errors via longjmp() and I’m still bitter about it.
>
> I have never encountered a library which does that. Which library was
> that?
>
>> As a matter of API design, I’d rather C library communicated errors via
>> return values (and pointer parameters, where more complex error
>> information is required).
>
> Personally, i think that, at least for a library, an error should _only_
> be communicated by return value. If more complex information is required,
> then the return value can be made more complex. I don't think i've ever
> used a library that communicates information via a pointer parameter.

Well you almost certainly have used such a library because some of the
functions in the C standard library use this technique. For example,
the failure to find a convertible sequence is signalled by strtod by
what is placed in the pointer pointed to by the second argument.

--
Ben.

Re: Libraries using longjmp for error handling

<871qejf62x.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29356&group=comp.lang.c#29356

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 02:18:46 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <871qejf62x.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="3545684"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MW6hK/+c7LWqF/ivQvGxKIvAwhr/TSIc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:UpppGmWUXp6VdOhaz2SxW59+FtY=
sha1:pMJ07jqAGnN698erKv05pYXTt4Y=
X-BSB-Auth: 1.756a7937c890ab94bb31.20230928021846BST.871qejf62x.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 01:18 UTC

Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> writes:

> On 9/28/2023 6:52 AM, Blue-Maned_Hawk wrote:
>> Personally, i think that, at least for a library, an error should _only_
>> be communicated by return value. If more complex information is required,
>> then the return value can be made more complex.
....
> Error handling in libraries is a thorny subject, and I could go on a
> long rant on it. The short summary is simply this: error handling is
> rife with incompetence, and incompetent designs. Even in languages that
> ostensibly provide better mechanisms than C, the details are usually
> poorly documented and under-specified [1].

If it's done well, the result is not even "error handling" -- it's just
what the function returns. For example, a lookup in a table of integers
in Haskell returns a type that is, in effect "maybe an integer" The
return will be either "Nothing" or something like "Just 42".

Haskell does not always get it right (particularly some of the older
APIs) but the trend is to provide return type rich enough to include
either a correct result or an explanation of the fault.

--
Ben.

Re: Libraries using longjmp for error handling (was: Re: More on NNTP testing)

<20230927213652.767@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29357&group=comp.lang.c#29357

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling (was: Re: More on
NNTP testing)
Date: Thu, 28 Sep 2023 05:11:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <20230927213652.767@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Sep 2023 05:11:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b3f31f8706362ec3eacce961c3d2318";
logging-data="3732950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Gvf483t2nWMnFTVPwabtAT+58bNByMHw="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:sNiEPvrq2x6TZwmFAX+Ik5bVw58=
 by: Kaz Kylheku - Thu, 28 Sep 2023 05:11 UTC

On 2023-09-27, Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> wrote:
> Richard Kettlewell wrote:
>
>> It’s more than 20 years since I last had to integrate a C library which
>> reported errors via longjmp() and I’m still bitter about it.
>
> I have never encountered a library which does that. Which library was
> that?

libpng is one example. Given a png handle you can call png_setjmp(png)
to get a jmp_buf * pointer. You setjmp on it, and libpng will longjmp to
it. There is a png_longjmp(png, <val>) function you can tall to test it.

I seem to recall that there is at least one more "famous" library which
similarly uses longjmp, but I cannot remember which.

Supporting this kind of library in the TXR Lisp FFI has been on my
TODO list. Seeing this thread gave me the sudden impetus to get it
working, and I got it done.

This works:

(let ((jb (jmp-buf)))
(setjmp jb result
(progn (put-line "setjmp")
(longjmp jb 42))
(put-line `result @result`)))

There is a jmp-buf function that allocates and returns a blank
object suitable as a jump buffer. There is a setjmp macro
which saves the context and evaluates a form. That form can longjmp,
in which case zero or more longjmp cleanup forms are evaluated
in scope of a variable which is bound to the integer longjmp
value.

I didn't have to add any special operator; setjmp expands to
a call to a run-time support function, where the expression
arguments are shored up into lambda functions.

In the test case file, in addition to the above trivial test,
I detect whether the system has libpng installed. If so,
a FFI test with libpng is conducted:

;; needed by png-set-longjmp-fn API
(defvarl libc (dlopen nil))
(defvarl longjmp-addr (dlsym libc "longjmp"))

(typedef png-structp (cptr png))

(with-dyn-lib "libpng.so"
(deffi png-get-header-ver "png_get_header_ver" str (png-structp))
(deffi png-create-read-struct "png_create_read_struct" png-structp (str cptr cptr cptr))
(deffi png-set-longjmp-fn "png_set_longjmp_fn" (carray uchar) (png-structp (cptr dlsym) size-t))
(deffi png-longjmp "png_longjmp" void (png-structp int)))

(defvar png-ver (png-get-header-ver cptr-null))

;; In the png.h header, png_setjmp is a macro only; you cannot
;; #undef it to get to a function. So we write the macro in
;; the same way as a Lisp macro, in terms of png-set-longjmp-fn,
;; whereby we pass the longjmp function, and sizeof (jmp_buf).
(defmacro png-setjmp (png-ptr)
(let ((jmpbuf-size (load-time (len (jmp-buf)))))
^(png-set-longjmp-fn ,png-ptr longjmp-addr ,jmpbuf-size)))

;;; Test

;; get png handle
(defvar png (png-create-read-struct png-ver cptr-null cptr-null cptr-null))

With that we can get the jmp-buf out of png, setjmp on it,
and then invoke it via png_longjmp, as if the library generated
an error:

;; get jmp_buf from png handle, setjmp it, longjmp to it.
(setjmp (png-setjmp png) err
(progn (put-line "libpng longjmp")
(png-longjmp png 42))
(put-line `libpng error @err`))

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Libraries using longjmp for error handling (was: Re: More on NNTP testing)

<20230927232455.602@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29358&group=comp.lang.c#29358

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling (was: Re: More on
NNTP testing)
Date: Thu, 28 Sep 2023 06:26:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <20230927232455.602@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230927213652.767@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Sep 2023 06:26:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b3f31f8706362ec3eacce961c3d2318";
logging-data="3752769"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e3BgbL8al6zx0x/8RzcToUqMjhVP4JVI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:jaL5moqKiCj1zvYXmOMuOc8+KD8=
 by: Kaz Kylheku - Thu, 28 Sep 2023 06:26 UTC

On 2023-09-28, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> On 2023-09-27, Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> wrote:
>> Richard Kettlewell wrote:
>>
>>> It’s more than 20 years since I last had to integrate a C library which
>>> reported errors via longjmp() and I’m still bitter about it.
>>
>> I have never encountered a library which does that. Which library was
>> that?
>
> libpng is one example. Given a png handle you can call png_setjmp(png)
> to get a jmp_buf * pointer. You setjmp on it, and libpng will longjmp to
> it. There is a png_longjmp(png, <val>) function you can tall to test it.

Found another one: netpbm. With netpbm, you allocate the jmp_buf, save
context with setjmp and pass the jmp_buf to pm_setjmpbuf.

It will then longjmp through it in an error situation.

Re: Libraries using longjmp for error handling (was: Re: More on NNTP testing)

<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29365&group=comp.lang.c#29365

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling (was: Re: More on
NNTP testing)
Date: Thu, 28 Sep 2023 16:02:37 +0300
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="1b7f12a7256bc6dc3a67c8ba303db56b";
logging-data="3888160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18azQsmDG3aCAKoAps4/pwn/8ms23CIMB4="
Cancel-Lock: sha1:Zdl8MsAvN2bjdp63xfNRqvaEVK4=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Thu, 28 Sep 2023 13:02 UTC

Blue-Maned_Hawk:

> Personally, i think that, at least for a library, an error
> should _only_ be communicated by return value. If more
> complex information is required, then the return value can
> be made more complex. I don't think i've ever used a
> library that communicates information via a pointer
> parameter.

The failure to captrue the return value and to test it for
an error is a classic code smell, which is possible because
the return value can be ignored. If the error be signalled
via an output parameter[1], however, it is much harder to
ignore it, becuase the programmer is forced to declare a
local variable to hold the error information and pass it to
the invocation. This frees the return value for the actual
function result, and then again the programmer cannot ignore
it but must use somehow, lest the invocation be pointess.
The above seems to suggest that the unusual practice of
signalling an error via an output parameter is preferable
from at lest the viewpoint of encouraging the programmer to
handle errors...

Furthermore, it is rather annoying in a language with a
single return value, to have that primary ouput channel used
to signal errors, forcing the programmer to resort the
auxiliary channel of ouput parameters to return actual
results. Yes, I do it all the time, and your post may
prompt me to try the alternative.
____________________
1. In C, this would be a pointer, but I am using higher-
level terminology.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<87jzsae7jm.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29368&group=comp.lang.c#29368

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 14:44:45 +0100
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <87jzsae7jm.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="3902442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19foihmCgOGE9I+yui//8M7VAdUQXKd/Tg="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:Yxl6LwEcA9zYk22qhRBw6bfv51o=
sha1:lgJSdBM1QWGSghpn+buALt+9y3M=
X-BSB-Auth: 1.58982044cf8fd5d7df8f.20230928144445BST.87jzsae7jm.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 13:44 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Blue-Maned_Hawk:
>
>> Personally, i think that, at least for a library, an error
>> should _only_ be communicated by return value. If more
>> complex information is required, then the return value can
>> be made more complex. I don't think i've ever used a
>> library that communicates information via a pointer
>> parameter.
>
> The failure to captrue the return value and to test it for
> an error is a classic code smell, which is possible because
> the return value can be ignored. If the error be signalled
> via an output parameter[1], however, it is much harder to
> ignore it, becuase the programmer is forced to declare a
> local variable to hold the error information and pass it to
> the invocation.

To nit-pick a bit, in C, there is no need to declare anything if you
want to ignore an "output parameter". Taking strtod as a (poor)
example:

double d = strtod(str, &(char *){0});

Of course strtod allows you to pass a null pointer here anyway, but
that's not the point. One can always pass a temporary object.

> This frees the return value for the actual
> function result, and then again the programmer cannot ignore
> it but must use somehow, lest the invocation be pointess.
> The above seems to suggest that the unusual practice of
> signalling an error via an output parameter is preferable
> from at lest the viewpoint of encouraging the programmer to
> handle errors...

This may be the case in C (where tagged union return values would be a
pain in the neck), but in other languages I'd say it's backwards. If
the error is a valid but alternate return value the programmer /can't/
ignore it.

> Furthermore, it is rather annoying in a language with a
> single return value, to have that primary ouput channel used
> to signal errors, forcing the programmer to resort the
> auxiliary channel of ouput parameters to return actual
> results. Yes, I do it all the time, and your post may
> prompt me to try the alternative.

One solution, in other languages, is to provide a simple way to use that
primary channel for both. Every call would have to code to handle the
options, even if that ended up being explict "ignore everything but the
successful return" code.

--
Ben.

Re: Libraries using longjmp for error handling

<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29373&group=comp.lang.c#29373

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 18:31:29 +0300
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="1b7f12a7256bc6dc3a67c8ba303db56b";
logging-data="3942200"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WqSF6+10leY0QUAaK9Moxp06fevQClrk="
Cancel-Lock: sha1:IdCKgoQwpwMm1Lz4KF+tSMlos4M=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Thu, 28 Sep 2023 15:31 UTC

Ben Bacarisse to Anton Shepelev:

> To nit-pick a bit, in C, there is no need to declare
> anything if you want to ignore an "output parameter".
> Taking strtod as a (poor) example:
>
> double d = strtod(str, &(char *){0});

Ah, but this is one of the strangest and craziest
innovations of post-modern C -- the ability to pass a
pointer (as it were) to a literal, rather than to a proper
variable. I say post-modern, because the adjective has just
the right connotations of surrealism, abstract art. I
hadn't even thought of doing that. Programming languages
seem obsessed with letting the programmer do as much as
possible in place and inline: treating everyting as an
expression, the comma operator, the ternary conditional
operator, lambdas, anonymous functions and types, and
now -- anonymous variables or literals -- to the detriment
of the academic approach of giving every thing its own
identifer.

> > The above seems to suggest that the unusual practice of
> > signalling an error via an output parameter is
> > preferable from at lest the viewpoint of encouraging the
> > programmer to handle errors...
>
> This may be the case in C (where tagged union return
> values would be a pain in the neck), but in other
> languages I'd say it's backwards. If the error is a valid
> but alternate return value the programmer /can't/ ignore
> it.

He can still work with the tagged union as if the error-
member did not exist. He can still treat the return value
as if it always contained the result of a successful
invocation. With the output parameter, ignoring an error
requires some effort, and that effort is visible in the
code, e.g. as a dummy variable whose value is never used.

> > Furthermore, it is rather annoying in a language with a
> > single return value, to have that primary ouput channel
> > used to signal errors, forcing the programmer to resort
> > the auxiliary channel of ouput parameters to return
> > actual results. Yes, I do it all the time, and your
> > post may prompt me to try the alternative.
>
> One solution, in other languages, is to provide a simple
> way to use that primary channel for both. Every call
> would have to code to handle the options, even if that
> ended up being explict "ignore everything but the
> successful return" code.

Am I right that implementing that "simple" method is a major
difficulty in compiler design?

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<20230928093424.111@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29375&group=comp.lang.c#29375

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 16:43:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20230928093424.111@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
Injection-Date: Thu, 28 Sep 2023 16:43:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b3f31f8706362ec3eacce961c3d2318";
logging-data="3967226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AYEHKFDyWng3w/qX9dL1lE59row+0JbI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:sRaPXEjPx9k+4vXBz7opEsVYgOk=
 by: Kaz Kylheku - Thu, 28 Sep 2023 16:43 UTC

On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
> Ben Bacarisse to Anton Shepelev:
>
>> To nit-pick a bit, in C, there is no need to declare
>> anything if you want to ignore an "output parameter".
>> Taking strtod as a (poor) example:
>>
>> double d = strtod(str, &(char *){0});
>
> Ah, but this is one of the strangest and craziest
> innovations of post-modern C -- the ability to pass a
> pointer (as it were) to a literal, rather than to a proper
> variable.

Two things:

Firstly, it's not a true literal because it is a mutable object in
automatic storage.

Each time control flow enters the scope where "double d" is defined, a
new object is created.

A plausible translation scheme for the &(char *){0} object in
the above situation is to emit a hidden variable, like this:

char *__hidden_1234 = 0;
double d = strtod(str, &__hidden_1234);

The only literal in sight is the 0 constant.

(Rather it is C++ that has the weird design of being able to bind const
references to literals that are of a type whose values don't have
reference semantics.)

Secondly, we have had pointers to literals for over seventy years,
ever since Lisp:

(function '(1 2 3)) ;; literal list passed to function

Quoted lists are bona fide literals in Lisp. Common Lisp makes
it undefined behavior to try to modify them; they can be burned
into ROM or mapped into read-only VM pages and such.
Quoted lists with identical suffixes can be merged together (sound
familiar?), and since they are constants, they can be subject to
constant folding so that they partially or entirely disappear. E.g.(cdr
'(1 2 3)) can compile into '(2 3).

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Libraries using longjmp for error handling

<cjiRM.52588$wO91.11826@fx39.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29377&group=comp.lang.c#29377

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx39.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Libraries using longjmp for error handling
Newsgroups: comp.lang.c
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com>
Lines: 33
Message-ID: <cjiRM.52588$wO91.11826@fx39.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 28 Sep 2023 17:00:56 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 28 Sep 2023 17:00:56 GMT
X-Received-Bytes: 1953
 by: Scott Lurndal - Thu, 28 Sep 2023 17:00 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
>On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>> Ben Bacarisse to Anton Shepelev:
>>
>>> To nit-pick a bit, in C, there is no need to declare
>>> anything if you want to ignore an "output parameter".
>>> Taking strtod as a (poor) example:
>>>
>>> double d = strtod(str, &(char *){0});
>>
>> Ah, but this is one of the strangest and craziest
>> innovations of post-modern C -- the ability to pass a
>> pointer (as it were) to a literal, rather than to a proper
>> variable.
>
>Two things:
>
>Firstly, it's not a true literal because it is a mutable object in
>automatic storage.

Perhaps Ben should have written it as

double d= strtod(str, NULL);

RETURN VALUE
These functions return the converted value, if any.

If endptr is not NULL, a pointer to the character after the last char-
acter used in the conversion is stored in the location referenced by
endptr.

This will just push a zero to the stack (or argument register) before calling
strtod. No need to allocate storage anywhere.

Re: Libraries using longjmp for error handling

<20230928101336.603@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29379&group=comp.lang.c#29379

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 17:16:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <20230928101336.603@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <cjiRM.52588$wO91.11826@fx39.iad>
Injection-Date: Thu, 28 Sep 2023 17:16:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b3f31f8706362ec3eacce961c3d2318";
logging-data="3981185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PVmZdhv0kYST8G/OmExf2ZCrOiccvVK8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:hTmoOUJPLY/ENVVXhg7CSM8WAm4=
 by: Kaz Kylheku - Thu, 28 Sep 2023 17:16 UTC

On 2023-09-28, Scott Lurndal <scott@slp53.sl.home> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>> Ben Bacarisse to Anton Shepelev:
>>>
>>>> To nit-pick a bit, in C, there is no need to declare
>>>> anything if you want to ignore an "output parameter".
>>>> Taking strtod as a (poor) example:
>>>>
>>>> double d = strtod(str, &(char *){0});
>>>
>>> Ah, but this is one of the strangest and craziest
>>> innovations of post-modern C -- the ability to pass a
>>> pointer (as it were) to a literal, rather than to a proper
>>> variable.
>>
>>Two things:
>>
>>Firstly, it's not a true literal because it is a mutable object in
>>automatic storage.
>
> Perhaps Ben should have written it as
>
> double d= strtod(str, NULL);

Check Ben's original post. That was mentioned from the start, but set
aside for the sake of illustrating how you can ignore an "output
parameter" which doesn't have such a NULL opt-out mechanism, and
to do it in a self-contained way, without the clutter of separately
declaring temporary objects.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Libraries using longjmp for error handling

<878r8qdufu.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29380&group=comp.lang.c#29380

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 19:27:49 +0100
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <878r8qdufu.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="4007497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oJwMpOuE/cvPqYP7O29k2nBBebEmt1GA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:piAHznTXnAAE8ADEF+3vsNDnMlg=
sha1:sTzUxAJkQ4bs+hXiLyezYQhGzCI=
X-BSB-Auth: 1.35b75adedec9d769db06.20230928192749BST.878r8qdufu.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 18:27 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Ben Bacarisse to Anton Shepelev:
>
>> To nit-pick a bit, in C, there is no need to declare
>> anything if you want to ignore an "output parameter".
>> Taking strtod as a (poor) example:
>>
>> double d = strtod(str, &(char *){0});
>
> Ah, but this is one of the strangest and craziest
> innovations of post-modern C -- the ability to pass a
> pointer (as it were) to a literal, rather than to a proper
> variable.

The C term is an object -- a region on memory that can hold values of
some type or other. A variable is a named object (though C does not
define the term variable), whereas a compound literal denotes an
anonymous object.

Why do you consider anonymous objects to be strange and crazy?

> I say post-modern, because the adjective has just
> the right connotations of surrealism, abstract art.

Neither surrealism not abstract art have much to do with postmodernism
as it is now understood. (A few early abstract artists called
themselves postmodernists, but they did not mean what we mean by the
term.)

Outside of the field, the term "postmodernism" has come to mean little
more that "everything that makes me uncomfortable about the humanities",
but that's a very lazy way to use the term.

Anyway, what is "postmodern" about anonymous objects?

> I
> hadn't even thought of doing that. Programming languages
> seem obsessed with letting the programmer do as much as
> possible in place and inline: treating everyting as an
> expression, the comma operator, the ternary conditional
> operator, lambdas, anonymous functions and types, and
> now -- anonymous variables or literals -- to the detriment
> of the academic approach of giving every thing its own
> identifer.

Why do you associate the term academic with naming everything? What's
the connection?

Mind you, the term is most often used (again rather lazily) to mean
"everything I don't like about modern programming" which would usually
include the functional approach you are criticising here, so it's
refreshing to see it used favourably.

>> > The above seems to suggest that the unusual practice of
>> > signalling an error via an output parameter is
>> > preferable from at lest the viewpoint of encouraging the
>> > programmer to handle errors...
>>
>> This may be the case in C (where tagged union return
>> values would be a pain in the neck), but in other
>> languages I'd say it's backwards. If the error is a valid
>> but alternate return value the programmer /can't/ ignore
>> it.
>
> He can still work with the tagged union as if the error-
> member did not exist. He can still treat the return value
> as if it always contained the result of a successful
> invocation. With the output parameter, ignoring an error
> requires some effort, and that effort is visible in the
> code, e.g. as a dummy variable whose value is never used.

I can't see how you come to this conclusion. Is it only about C or are
you considering other more strongly-typed languages?

Example: in Haskell a table lookup can fail (the key may not exist in
the map) so the return type of lookup on a map if integers is "Maybe
Integer". The (polymorphic) Maybe type is like a tagged union. It's
values are either "Nothing" or "Just x" where x is an integer. You
can't ignore this fact; the code must explicitly handle this return
type. (Of course in Haskell there is no alternative. Without
modifiable variables one can't implement an "output parameter".)

Can you give an example of what you mean in C? I could come up with an
example, but then it might be tailored to backing up my point of view!

>> > Furthermore, it is rather annoying in a language with a
>> > single return value, to have that primary ouput channel
>> > used to signal errors, forcing the programmer to resort
>> > the auxiliary channel of ouput parameters to return
>> > actual results. Yes, I do it all the time, and your
>> > post may prompt me to try the alternative.
>>
>> One solution, in other languages, is to provide a simple
>> way to use that primary channel for both. Every call
>> would have to code to handle the options, even if that
>> ended up being explict "ignore everything but the
>> successful return" code.
>
> Am I right that implementing that "simple" method is a major
> difficulty in compiler design?

I would not have thought so. I've implemented a version in a functional
language, but that was not a traditional compiler. Where is the
difficulty you see?

The problem in C would be the cost (larger return values) combined with
the fact that C has no clean way to handle tagged unions so the code
would be a mess.

--
Ben.

Re: Libraries using longjmp for error handling

<8734yydtyg.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29381&group=comp.lang.c#29381

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 19:38:15 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <8734yydtyg.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <cjiRM.52588$wO91.11826@fx39.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="4007497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GlcXlT6FRvP1r7TVtq4XuXIUbOTdlLsc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:TMGQn+OVCgfWTn+qoSvgd2S4XKc=
sha1:tFOhiiqJOLv+xil6LXQPrzfAA5A=
X-BSB-Auth: 1.f1c446b0359ed05c7f5d.20230928193815BST.8734yydtyg.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 18:38 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>> Ben Bacarisse to Anton Shepelev:
>>>
>>>> To nit-pick a bit, in C, there is no need to declare
>>>> anything if you want to ignore an "output parameter".
>>>> Taking strtod as a (poor) example:
>>>>
>>>> double d = strtod(str, &(char *){0});
>>>
>>> Ah, but this is one of the strangest and craziest
>>> innovations of post-modern C -- the ability to pass a
>>> pointer (as it were) to a literal, rather than to a proper
>>> variable.
>>
>>Two things:
>>
>>Firstly, it's not a true literal because it is a mutable object in
>>automatic storage.
>
> Perhaps Ben should have written it as
>
> double d= strtod(str, NULL);

No, for reasons I gave! The point was that one can always do at least
this so there is never a need for a declared variable when the
information is going to be ignored.

--
Ben.

Re: Libraries using longjmp for error handling

<uf4lqe$3r5qi$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29383&group=comp.lang.c#29383

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 21:57:02 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uf4lqe$3r5qi$2@dont-email.me>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Sep 2023 19:57:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="17289fe600f3ba4b8e2925c9cee58389";
logging-data="4036434"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19C1rnzaNBsroffPcipBsRa0EOkxHfaIAE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:NLkY0f9qO5EZwIbf/zKZIGukbLg=
In-Reply-To: <20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
Content-Language: en-GB
 by: David Brown - Thu, 28 Sep 2023 19:57 UTC

On 28/09/2023 17:31, Anton Shepelev wrote:
> Ben Bacarisse to Anton Shepelev:
>
>> To nit-pick a bit, in C, there is no need to declare
>> anything if you want to ignore an "output parameter".
>> Taking strtod as a (poor) example:
>>
>> double d = strtod(str, &(char *){0});
>
> Ah, but this is one of the strangest and craziest
> innovations of post-modern C -- the ability to pass a
> pointer (as it were) to a literal, rather than to a proper
> variable.

That is not what is happening at all. There is a compound literal used
to initialise a temporary object of type char* with the value 0, and a
pointer to this temporary object is passed to the function.

> I say post-modern, because the adjective has just
> the right connotations of surrealism, abstract art.

Compound literals arrived with C99 (or gcc extensions a few years before
that) - long before modern C, which is C17/C18. "Post-modern C" would
be C23.

> I
> hadn't even thought of doing that.

If you don't want to do that, don't do it.

>>
>> One solution, in other languages, is to provide a simple
>> way to use that primary channel for both. Every call
>> would have to code to handle the options, even if that
>> ended up being explict "ignore everything but the
>> successful return" code.
>
> Am I right that implementing that "simple" method is a major
> difficulty in compiler design?
>

Well, it is certainly fine to do this in C++ (which supports optional
types in the standard library, as well as structured binding, std::tie
and tuples to make it easy to use multiple return values. I don't
believe anyone has claimed C++ is a language that is easy for compiler
design - but I doubt if this is a major reason.

Re: Libraries using longjmp for error handling

<20230928130843.804@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29384&group=comp.lang.c#29384

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 20:24:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20230928130843.804@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<878r8qdufu.fsf@bsb.me.uk>
Injection-Date: Thu, 28 Sep 2023 20:24:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9b3f31f8706362ec3eacce961c3d2318";
logging-data="4048904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1871VkIU2TVVEyBRFwAOcl4Bqnuz87uOlo="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:bsbDVXjlGPF6GUO3nzjRyrD1gqU=
 by: Kaz Kylheku - Thu, 28 Sep 2023 20:24 UTC

On 2023-09-28, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Anton Shepelev <anton.txt@gmail.moc> writes:
>
>> Ben Bacarisse to Anton Shepelev:
>>
>>> To nit-pick a bit, in C, there is no need to declare
>>> anything if you want to ignore an "output parameter".
>>> Taking strtod as a (poor) example:
>>>
>>> double d = strtod(str, &(char *){0});
>>
>> Ah, but this is one of the strangest and craziest
>> innovations of post-modern C -- the ability to pass a
>> pointer (as it were) to a literal, rather than to a proper
>> variable.
>
> The C term is an object -- a region on memory that can hold values of
> some type or other. A variable is a named object (though C does not
> define the term variable), whereas a compound literal denotes an
> anonymous object.
>
> Why do you consider anonymous objects to be strange and crazy?

By the way, here is an approach using only C90 syntax:

#include <stdlib.h>
#include <stdio.h>

struct ptr {
char *ptr[1];
};

struct ptr tmp(void)
{ struct ptr tmp = { 0 };
return tmp;
}

int main(int argc, char **argv)
{ if (argv[1]) {
double d = strtod(argv[1], tmp().ptr); /* i.e. &tmp().ptr[0] */
printf("d = %f\n", d);
}

return 0;
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Libraries using longjmp for error handling

<87il7uc7q4.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29387&group=comp.lang.c#29387

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 22:23:47 +0100
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <87il7uc7q4.fsf@bsb.me.uk>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<878r8qdufu.fsf@bsb.me.uk> <20230928130843.804@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="4069705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Eltx3IJbfTQE8n9XaTy2eRbYgdyKwKuU="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:elGHFrejdVdPmHgUBy8kWEjqWyM=
sha1:SMUx/0qPl805Al52uWhfApbRWi8=
X-BSB-Auth: 1.0b6a65ac060621eabb47.20230928222347BST.87il7uc7q4.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 21:23 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-28, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> Anton Shepelev <anton.txt@gmail.moc> writes:
>>
>>> Ben Bacarisse to Anton Shepelev:
>>>
>>>> To nit-pick a bit, in C, there is no need to declare
>>>> anything if you want to ignore an "output parameter".
>>>> Taking strtod as a (poor) example:
>>>>
>>>> double d = strtod(str, &(char *){0});
>>>
>>> Ah, but this is one of the strangest and craziest
>>> innovations of post-modern C -- the ability to pass a
>>> pointer (as it were) to a literal, rather than to a proper
>>> variable.
>>
>> The C term is an object -- a region on memory that can hold values of
>> some type or other. A variable is a named object (though C does not
>> define the term variable), whereas a compound literal denotes an
>> anonymous object.
>>
>> Why do you consider anonymous objects to be strange and crazy?
>
> By the way, here is an approach using only C90 syntax:
>
> #include <stdlib.h>
> #include <stdio.h>
>
> struct ptr {
> char *ptr[1];
> };
>
> struct ptr tmp(void)
> {
> struct ptr tmp = { 0 };
> return tmp;
> }
>
> int main(int argc, char **argv)
> {
> if (argv[1]) {
> double d = strtod(argv[1], tmp().ptr); /* i.e. &tmp().ptr[0] */
> printf("d = %f\n", d);
> }
>
> return 0;
> }

Two points... This is C90 syntax but not C90 semantics. A C90 function
call is not an lvalue, so neither is the member access expression.
What's more in C99, it's not permitted to modify the returned object
which I assume is the whole point here. I think it's OK in C11 and
later.

Second point... The context was not declaring a variable in order to
pass an object address to a function that needs it. So instead of
declaring a variable you declare a struct type, a function and a local
variable within it!

OK, I see the point -- the ptr member in the returned value is sort of
an anonymous object -- but in my opinion it's a stretch.

--
Ben.

Re: Libraries using longjmp for error handling

<pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29390&group=comp.lang.c#29390

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 22:30:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Sep 2023 22:30:41 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="af1baa55adaa8773158c5f095f958003";
logging-data="4080519"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HK4/S7YxyoFgqq5JMpxqT6VFr+LgEt7Q="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:8oxO6lMnuw8zn0ZWblbgMMdwWGw=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Llanfair­pwllgwyngyllÃ
ƒ‚Ã
ƒƒ‚­gogery­chwyrnÃ
ƒƒ
? ?‚­drobwll­llan
Ã
? ?ƒƒ‚­tysilio­go
g
o­goch
 by: Blue-Maned_Hawk - Thu, 28 Sep 2023 22:30 UTC

[This article is a resend because my first try seems to not have worked;
if this is duplicated, that's the explanation.]

Ben Bacarisse wrote:

> Haskell does not always get it right (particularly some of the older
> APIs) but the trend is to provide return type rich enough to include
> either a correct result or an explanation of the fault.

Things like that are pretty much what i was referring to earlier when i
referred to making the return type more complex to handle more complex
situations. Obviously, it would have to be done differently in C, since C
doesn't support tagged unions (at least not natively—i know of a couple
libraries that use macro magic to implement them).

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr. bluemanedhawk.github.io
A flamethrower will not interfere with WiFi unless you aim it directly at
the router.

Re: Libraries using longjmp for error handling

<PanRM.9358$Sn81.8479@fx08.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29391&group=comp.lang.c#29391

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Libraries using longjmp for error handling
Newsgroups: comp.lang.c
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk> <pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>
Lines: 19
Message-ID: <PanRM.9358$Sn81.8479@fx08.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 28 Sep 2023 22:33:19 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 28 Sep 2023 22:33:19 GMT
X-Received-Bytes: 1744
 by: Scott Lurndal - Thu, 28 Sep 2023 22:33 UTC

Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
>[This article is a resend because my first try seems to not have worked;
>if this is duplicated, that's the explanation.]
>
>Ben Bacarisse wrote:
>
>> Haskell does not always get it right (particularly some of the older
>> APIs) but the trend is to provide return type rich enough to include
>> either a correct result or an explanation of the fault.
>
>Things like that are pretty much what i was referring to earlier when i
>referred to making the return type more complex to handle more complex
>situations. Obviously, it would have to be done differently in C, since C
>doesn't support tagged unions (at least not natively—i know of a couple
>libraries that use macro magic to implement them).

In C++, a std::pair<bool, return-type> is used in that context. If the sizeof
the return type is 64-bits or less, most modern ABI's will return it in a pair
of registers.

Re: Libraries using longjmp for error handling

<20230929014147.db836fd718d5d67557fc138c@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29392&group=comp.lang.c#29392

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 01:41:47 +0300
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <20230929014147.db836fd718d5d67557fc138c@gmail.moc>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<AE3RM.402236$kCld.195109@fx08.ams4>
<871qejf62x.fsf@bsb.me.uk>
<pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid>
<PanRM.9358$Sn81.8479@fx08.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="06d0112a97a09d1fb944513fc1d528dd";
logging-data="4091817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gcw81c46Ag+T9B9mfyfxPtLMqGCakfOY="
Cancel-Lock: sha1:jcYmEbq6gfI3vQRapJecTqpNTy0=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Thu, 28 Sep 2023 22:41 UTC

Scott Lurndal:

> In C++, a std::pair<bool, return-type> is used in that
> context. If the sizeof the return type is 64-bits or
> less, most modern ABI's will return it in a pair of
> registers.

This groups the error flag and return value, the error
message having to be passed somewhere else. In C, one can
group the error flag, error code, error message plus any
additional error information, in order to return the actual
return value.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Libraries using longjmp for error handling

<86bkdlj4ur.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29393&group=comp.lang.c#29393

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 15:43:56 -0700
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <86bkdlj4ur.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <878r8qdufu.fsf@bsb.me.uk> <20230928130843.804@kylheku.com> <87il7uc7q4.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="4098691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19H0fCtWtx6cOxq48tlR70VAhYkakY2Ur4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:DlL/u29IIPeEA46h847LTOyfbEs=
sha1:+jKNTWsAfWihUnWuBu9YJPBJklg=
 by: Tim Rentsch - Thu, 28 Sep 2023 22:43 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-28, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>>
>>> Anton Shepelev <anton.txt@gmail.moc> writes:
>>>
>>>> Ben Bacarisse to Anton Shepelev:
>>>>
>>>>> To nit-pick a bit, in C, there is no need to declare
>>>>> anything if you want to ignore an "output parameter".
>>>>> Taking strtod as a (poor) example:
>>>>>
>>>>> double d = strtod(str, &(char *){0});
>>>>
>>>> Ah, but this is one of the strangest and craziest
>>>> innovations of post-modern C -- the ability to pass a
>>>> pointer (as it were) to a literal, rather than to a proper
>>>> variable.
>>>
>>> The C term is an object -- a region on memory that can hold values of
>>> some type or other. A variable is a named object (though C does not
>>> define the term variable), whereas a compound literal denotes an
>>> anonymous object.
>>>
>>> Why do you consider anonymous objects to be strange and crazy?
>>
>> By the way, here is an approach using only C90 syntax:
>>
>> #include <stdlib.h>
>> #include <stdio.h>
>>
>> struct ptr {
>> char *ptr[1];
>> };
>>
>> struct ptr tmp(void)
>> {
>> struct ptr tmp = { 0 };
>> return tmp;
>> }
>>
>> int main(int argc, char **argv)
>> {
>> if (argv[1]) {
>> double d = strtod(argv[1], tmp().ptr); /* i.e. &tmp().ptr[0] */
>> printf("d = %f\n", d);
>> }
>>
>> return 0;
>> }
>
> Two points... This is C90 syntax but not C90 semantics. A C90 function
> call is not an lvalue, so neither is the member access expression.
> What's more in C99, it's not permitted to modify the returned object
> which I assume is the whole point here. I think it's OK in C11 and
> later.

Some clarifications.

The result of a function call is not an lvalue in any version of
C (with the disclaimer that I have not checked the C23 draft).

Despite the result of a function call not being an lvalue, it is
legal to use '.' to access a member of a struct value returned by
a function, even in C90. Member access does not require that the
first operand be an lvalue (although it needs to be an lvalue if
the member access expression is used as an lvalue).

In both C90 and C99, it's undefined behavior to use the pointer
value that results from 'tmp().ptr' to attempt an access, either
for writing or for reading. It's possible that this omission is
just an oversight, but the plain text of both of the early C
standards says fairly clearly that undefined behavior results.

In C11, it's okay to use the pointer value from 'tmp().ptr' to
read a value, but attempting to store a value using that pointer
is undefined behavior.

Re: Libraries using longjmp for error handling

<8634yxj3uh.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29396&group=comp.lang.c#29396

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 16:05:42 -0700
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <8634yxj3uh.fsf@linuxsc.com>
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <20230928160237.9796f1896cb0be293bd24b76@gmail.moc> <87jzsae7jm.fsf@bsb.me.uk> <20230928183129.fb386b543c40cd56340ca40f@gmail.moc> <20230928093424.111@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="13636bbb038e3a1f79d11dd50eec8409";
logging-data="4098691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Yh7PiK0vzML7DSL5dHayDuFy6UrgSZV0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Lbn+ffFsgH8sirpxYgrFbpzplVA=
sha1:iX3K1Y3x+BxaGoIyhI1mR/NoZUg=
 by: Tim Rentsch - Thu, 28 Sep 2023 23:05 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>
>> Ben Bacarisse to Anton Shepelev:
>>
>>> To nit-pick a bit, in C, there is no need to declare
>>> anything if you want to ignore an "output parameter".
>>> Taking strtod as a (poor) example:
>>>
>>> double d = strtod(str, &(char *){0});
>>
>> Ah, but this is one of the strangest and craziest
>> innovations of post-modern C -- the ability to pass a
>> pointer (as it were) to a literal, rather than to a proper
>> variable.
>
> Two things:
>
> Firstly, it's not a true literal because it is a mutable object in
> automatic storage.

It most definitely is a literal, both in the original meaning
of the word, and also as used in the ISO C standard.

Re: Libraries using longjmp for error handling

<20230928155123.960@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29397&group=comp.lang.c#29397

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Thu, 28 Sep 2023 23:11:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <20230928155123.960@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<878r8qdufu.fsf@bsb.me.uk> <20230928130843.804@kylheku.com>
<87il7uc7q4.fsf@bsb.me.uk>
Injection-Date: Thu, 28 Sep 2023 23:11:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e2464a16a598f67870a96179f3b3745";
logging-data="4108149"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Jmoac8j6q8ZcrxjPyrhFelWP/GqvwErs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:r+nWa1vR+PVkGaARpw7WBc2VLIY=
 by: Kaz Kylheku - Thu, 28 Sep 2023 23:11 UTC

On 2023-09-28, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>> On 2023-09-28, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>>> Anton Shepelev <anton.txt@gmail.moc> writes:
>>>> Ah, but this is one of the strangest and craziest
>>>> innovations of post-modern C -- the ability to pass a
>>>> pointer (as it were) to a literal, rather than to a proper
>>>> variable.
[...]
>>> Why do you consider anonymous objects to be strange and crazy?
>>
>> By the way, here is an approach using only C90 syntax:
>>
>> #include <stdlib.h>
>> #include <stdio.h>
>>
>> struct ptr {
>> char *ptr[1];
>> };
>>
>> struct ptr tmp(void)
>> {
>> struct ptr tmp = { 0 };
>> return tmp;
>> }
>>
>> int main(int argc, char **argv)
>> {
>> if (argv[1]) {
>> double d = strtod(argv[1], tmp().ptr); /* i.e. &tmp().ptr[0] */
>> printf("d = %f\n", d);
>> }
>>
>> return 0;
>> }
>
> Two points... This is C90 syntax but not C90 semantics.

Exactly; I didn't say that this is something that was possible in C90.

It's not required to work.

But in, fact, it can work, and when it does, it's because of the
semantics that there is an hidden temporary object there.

Things could go wrong; we have no idea what the lifetime is of that
object; when is its storage reused for something else being
evaluated in a neighboring subesxpression.

The program's evil trick uses a hole in the language.

If we just made it

struct ptr {
char ptr;
};

and then

&tmp().ptr

then that violates a constraint: taking the address of a non-lvalue.

That constraint does not apply to the array-to-pointer "decay"
conversion, because that would prevent a non-lvalue array from being
simply accessed. We can't do a[2] without producing a pointer to
a[0] which is displaced and dereferenced.

> A C90 function
> call is not an lvalue, so neither is the member access expression.
> What's more in C99, it's not permitted to modify the returned object
> which I assume is the whole point here. I think it's OK in C11 and
> later.
>
> Second point... The context was not declaring a variable in order to
> pass an object address to a function that needs it. So instead of
> declaring a variable you declare a struct type, a function and a local
> variable within it!

But I only have to do that once; then invoke tmp().ptr any number of
times I want to get a temporary char *. Or, could, if it were documented
as reliable.

> OK, I see the point -- the ptr member in the returned value is sort of
> an anonymous object -- but in my opinion it's a stretch.

I think the point is that Anton should find the existence of all
anoymous temporary objects repugnant, not just the more recently
introduced ones.

That's why I put this under the "strange and crazy innovations in
post-modern C" remarks.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Libraries using longjmp for error handling

<8eoRM.229644$vMO8.204792@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29399&group=comp.lang.c#29399

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Libraries using longjmp for error handling
Newsgroups: comp.lang.c
References: <65SQM.565977$9o89.411905@fx05.ams4> <wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk> <pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid> <AE3RM.402236$kCld.195109@fx08.ams4> <871qejf62x.fsf@bsb.me.uk> <pan$b83bb$766eb4cb$b79b4acf$fdd8021c@invalid.invalid> <PanRM.9358$Sn81.8479@fx08.iad> <20230929014147.db836fd718d5d67557fc138c@gmail.moc>
Lines: 26
Message-ID: <8eoRM.229644$vMO8.204792@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 28 Sep 2023 23:45:08 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 28 Sep 2023 23:45:08 GMT
X-Received-Bytes: 2034
 by: Scott Lurndal - Thu, 28 Sep 2023 23:45 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:
>Scott Lurndal:
>
>> In C++, a std::pair<bool, return-type> is used in that
>> context. If the sizeof the return type is 64-bits or
>> less, most modern ABI's will return it in a pair of
>> registers.
>
>This groups the error flag and return value, the error
>message having to be passed somewhere else. In C, one can
>group the error flag, error code, error message plus any
>additional error information, in order to return the actual
>return value.

In C++ you can group any number of objects into a struct
and return that, if you need to. I wouldn't return a
message from the function, an error code that maps into
a message is often sufficient.

One could take a leaf from the VMS book and replace the bool
with an error code (which maps externally into a locale-specific
string), where "SS$_NORMAL" indicates that the operation was
successful, and the range less than MAX(defined errno) is
reserved for strerror() messages and the range above some
value is reserved to the application.

Re: Libraries using longjmp for error handling

<20230928161154.506@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29400&group=comp.lang.c#29400

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Libraries using longjmp for error handling
Date: Fri, 29 Sep 2023 00:26:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <20230928161154.506@kylheku.com>
References: <65SQM.565977$9o89.411905@fx05.ams4>
<wwvpm23d9fr.fsf@LkoBDZeT.terraraq.uk>
<pan$6f4ce$6edf891e$2b5c40c1$f8f989c1@invalid.invalid>
<20230928160237.9796f1896cb0be293bd24b76@gmail.moc>
<87jzsae7jm.fsf@bsb.me.uk>
<20230928183129.fb386b543c40cd56340ca40f@gmail.moc>
<20230928093424.111@kylheku.com> <8634yxj3uh.fsf@linuxsc.com>
Injection-Date: Fri, 29 Sep 2023 00:26:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e2464a16a598f67870a96179f3b3745";
logging-data="4132375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18X5Mfp7OsLpgcE0CFMNb5v8hkFhAcabcM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:swCEEJzLkEVYr8iNXmL4aw3TUIM=
 by: Kaz Kylheku - Fri, 29 Sep 2023 00:26 UTC

On 2023-09-28, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-28, Anton Shepelev <anton.txt@gmail.moc> wrote:
>>
>>> Ben Bacarisse to Anton Shepelev:
>>>
>>>> To nit-pick a bit, in C, there is no need to declare
>>>> anything if you want to ignore an "output parameter".
>>>> Taking strtod as a (poor) example:
>>>>
>>>> double d = strtod(str, &(char *){0});
>>>
>>> Ah, but this is one of the strangest and craziest
>>> innovations of post-modern C -- the ability to pass a
>>> pointer (as it were) to a literal, rather than to a proper
>>> variable.
>>
>> Two things:
>>
>> Firstly, it's not a true literal because it is a mutable object in
>> automatic storage.
>
> It most definitely is a literal, both in the original meaning

Let's examine our use of the article "a".

#include <stdio.h>

void fun(int c)
{ char x;

if (c > 0) {
printf("%p\n", (void *) &(char *){&x});
fun(c - 1);
}
}

int main(void)
{ fun(5);
return 0;
}

$ ./literal
0xbfd9f4b8
0xbfd9f488
0xbfd9f458
0xbfd9f428
0xbfd9f3f8

This illustrates why I have an issue with using the term "literal" for
this situation.

The object:

1. (by default) is freshly allocated on the fly in automatic storage;

2. consequently, may exhibit multiple addresses concurrently;

3. is destroyed when the scope terminates;

4. is independently mutable in all its multiple instances; and

5. doesn't have literals in its expression, being initialized using &x.

What is literal about it?

C99 said that a compound literal "is an expression that provides access
to an anonymous object".

Why can't we call that expression "anonymous object designator"
or something? If we have "char *p = 0", p is a primary expression which
designates an object, and not a literal.

If we then have (char *){p} we get an anonymous object that is
initialized with a copy of p, and that expression designates it in much
the same way as p designates its object.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor