[tz] [libc-coord] thread-safe localtime() for an arbitrary timezone

Guy Harris gharris at sonic.net
Wed Jun 21 20:08:40 UTC 2023


On Jun 21, 2023, at 12:50 PM, enh <enh at google.com> wrote:

> On Wed, Jun 21, 2023 at 12:54 AM Guy Harris <gharris at sonic.net> wrote:
> 
>> Is there some particular reason to make timezone_t an API/ABI structure, rather than a pointer to an opaque structure?
> 
> no, my preference would be for timezone_t to be more like DIR...
> 
> typedef struct DIR DIR;

Like DIR, which, at least in macOS (and thus probably in most *BSDs), is fully defined in <dirent.>, or like pcap_t, which is "defined" as an opaque structure in <pcap/pcap.h> and only defined fully in a header internal to libpcap?  (And, yes, pcap_t's contents are subject to change over time, have been changed over time, and will continue to change over time.

> means you need to write the * in signatures, but that std::unique_ptr-style safe usage "just works" without having to talk about the underlying struct or use std::remove_pointer.

Does that work if the structure is opaque outside the routines that process tz files?

> Presumably if it's a structure, "tzalloc()" really means "given a tzid, fill in a structure as appropriate for that tzid, and return that structure", not "allocate a structure, fill it in as appropriate for the tzid, and return a pointer to that structure", and "tzfree()" means "free up anything pointed to by the structure whose value was passed to it" rather than "free everything pointed to by the structure pointed to by the argument and then free the structure".  If you want to do that, perhaps names that don't imply that they allocate and free a timezone_t should be chosen.

I.e., it would be

	timezone_t *tzalloc(const char *tzid);

and

	void tzfree(timezone_t *);


More information about the tz mailing list