Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx4.public.one.com ([10.246.18.24])
	by mail6.local.one.com (Dovecot) with LMTP id W7OtHF9mzFgnHwEAsyOMew
	for <filtered@awaresystems.be>; Fri, 17 Mar 2017 22:50:33 +0000
X-HalOne-ID: 1fe28f7d-0b64-11e7-b4a7-b82a72d0454d
Received: from mail-oi0-f42.google.com (unknown [209.85.218.42])
	by mx4.public.one.com (Halon) with ESMTPS
	id 1fe28f7d-0b64-11e7-b4a7-b82a72d0454d;
	Fri, 17 Mar 2017 22:50:32 +0000 (UTC)
Received: by mail-oi0-f42.google.com with SMTP id a94so2057166oic.2
        for <filtered@awaresystems.be>; Fri, 17 Mar 2017 15:50:32 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-original-authentication-results:x-gm-message-state:delivered-to
         :message-id:date:from:user-agent:mime-version:to:references
         :in-reply-to:subject:precedence:list-id:list-unsubscribe
         :list-archive:list-post:list-help:list-subscribe
         :content-transfer-encoding:sender:errors-to;
        bh=srIYsdlPXFLkmlwKb3CMtDMCWnzCNy+X2mizpqskcF8=;
        b=Mk7qsqExK64MiURUMFC0BiIZR6ImQwvG4c/PNO7tMA4GdbQfUlxgpNhihF0lndQy4J
         dSi8nPaM5GJ8g7UTpkR7PHapIg/XDo0Hfb+1JNrywCZ3BuC+gigSbPrz8Lp2/rD5AAe8
         K8XcahqBtix8p6PihLz9Lyj7yVISgjthWztyxLnn4xla3pXVOYKWCFu4qT/m6jV8tWhQ
         QA5Ywbzowt/V4cRNvh0kK+sRLphQQ/hw5/22LG+GWQji8AOw8ZFU+bs94u48acppkKS4
         0eq6WlmX5ssBZAhp5jBJXkaWgSsaZ8EebTP0jWVnLKAOEH1XWMI0ORetHHDgPzBfevQI
         /baQ==
X-Original-Authentication-Results: mx.google.com;       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
X-Gm-Message-State: AFeK/H3hl/lDvPO8sCD4iZGSHHw89lAssTFipvX7TPKcmsSg7rJ5r04G5ESjzUzg9ze564AdR255OYWMahdc1fwTtPJjYUA=
X-Received: by 10.202.197.73 with SMTP id v70mr8111675oif.125.1489791031420;
        Fri, 17 Mar 2017 15:50:31 -0700 (PDT)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.202.195.2 with SMTP id t2csp507648oif;
        Fri, 17 Mar 2017 15:50:30 -0700 (PDT)
X-Received: by 10.223.135.215 with SMTP id c23mr14705141wrc.135.1489791030469;
        Fri, 17 Mar 2017 15:50:30 -0700 (PDT)
Return-Path: <tiff-bounces@lists.maptools.org>
Received: from lists.maptools.org (ks365428.kimsufi.com. [94.23.4.142])
        by mx.google.com with ESMTP id t3si4950517wmd.79.2017.03.17.15.50.29;
        Fri, 17 Mar 2017 15:50:30 -0700 (PDT)
Received-SPF: neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) client-ip=94.23.4.142;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 96E0735C06F;
	Fri, 17 Mar 2017 17:49:41 -0500 (EST)
Received: from polaris.osa.pri.ee (osa.pri.ee [213.219.84.188])
	by lists.maptools.org (Postfix) with ESMTP id 8967935C06D
	for <tiff@lists.maptools.org>; Fri, 17 Mar 2017 17:41:38 -0500 (EST)
Received: from localhost (localhost [127.0.0.1])
	by polaris.osa.pri.ee (Postfix) with ESMTP id BBEF96E693
	for <tiff@lists.maptools.org>; Sat, 18 Mar 2017 00:38:46 +0200 (EET)
X-Virus-Scanned: amavisd-new at osa.pri.ee
Received: from polaris.osa.pri.ee ([127.0.0.1])
	by localhost (osa.pri.ee [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id w3cV6Sm8H9wp for <tiff@lists.maptools.org>;
	Sat, 18 Mar 2017 00:37:51 +0200 (EET)
Received: from [0.0.0.0] (polaris.osa.pri.ee [213.219.84.188])
	by polaris.osa.pri.ee (Postfix) with ESMTP id 8EE1F6E636
	for <tiff@lists.maptools.org>; Sat, 18 Mar 2017 00:37:50 +0200 (EET)
Message-ID: <58CC65E8.4030709@osa.pri.ee>
Date: Sat, 18 Mar 2017 00:40:40 +0200
From: Paavo Helde <paavo@osa.pri.ee>
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64;
	rv:25.8) Gecko/20151117 FossaMail/25.1.9
MIME-Version: 1.0
To: tiff@lists.maptools.org
References: <CAHcSuBpB46=uPKCS48LuFCqbZ1GeQau6_f8Bbbj5fs6LbJdE+Q@mail.gmail.com>	<alpine.GSO.2.20.1703170947500.4525@scrappy.simplesystems.org>	<CAHcSuBqZQh4kJH_R_9LEkpnjRm=s-CmOE_vcoyRF6fxgwt1B8A@mail.gmail.com>	<alpine.GSO.2.20.1703171154040.4525@scrappy.simplesystems.org>	<18b5b63b7b889c5c3c9f51af1b2651c4@codelibre.net>
	<alpine.GSO.2.20.1703171604260.4525@scrappy.simplesystems.org>
In-Reply-To: <alpine.GSO.2.20.1703171604260.4525@scrappy.simplesystems.org>
Subject: Re: [Tiff] TIFFSetErrorHandler vs TIFFSetErrorHandlerExt
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org


On 17.03.2017 23:08, Bob Friesenhahn wrote:
> On Fri, 17 Mar 2017, rleigh@codelibre.net wrote:
>> Could I suggest a perhaps controversial but useful solution for handling
>> errors, which might be worth your consideration.
>>
>> If the libtiff core were to use a C++ TIFF class reporting errors via
>> exceptions, it would be possible for this to be wrapped by the existing
>> C API calling the C++ code in a try/catch block and reporting any thrown
>> errors via the handlers.  Or direct use by C++ code without any of that
> Unfortunately, throwing C++ exceptions through C code is not portable.
> It would require that the using program to be linked using the C++
> compiler.  The built library would only support one C++ compiler
> (perhaps just one of several C++ dialects supported by the same
> compiler) due to C++ compiler run-time libraries and name mangling.

A C++ library can have an interface defined purely in extern "C" 
functions. This does not help with exceptions (which cannot be passed 
through extern "C" functions (portably)), but it gets rid of the 
problems of compiler versions and name manglings.

I have developed an extern "C" interface for a large C++ library and I 
think this has proved to be quite a success. The error handling is done 
by try-catch in each interface function and storing the exception in 
thread-local storage. There is a special interface function for 
obtaining the last stored error message in the current thread which the 
client code is supposed to use in the case of a failing call.

This does not mean libTIFF should be converted to C++. It's just a 
general remark that a library does not need to be developed in C in 
order to have C interface.

Best
Paavo

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
