should xlog_outdesc modify its argument? - Mailing list pgsql-hackers

From Mark Dilger
Subject should xlog_outdesc modify its argument?
Date
Msg-id 05C5599B-138F-433C-9EFC-7A1B0DF72DC2@gmail.com
Whole thread Raw
Responses Re: should xlog_outdesc modify its argument?
List pgsql-hackers
The function

  static void xlog_outdesc(StringInfo buf, XLogReaderState *record);

in src/backend/access/transam/xlog.c is called by XLogInsertRecord,
and after returning a string describing an XLogRecord, it clears the
state data in its XLogReaderState argument.  That mixes the read-only
semantics of "give me a string that describes this argument" and the
read-write semantics of "clear out the value in this argument".  That
seems ok, except that xlog_outdesc is also called by the function

  static void rm_redo_error_callback(const void *arg);

also in xlog.c, which appears to only want the string description of the
argument, and not the side effect of clearing out the value.  Now,
perhaps under exceptional conditions it won't matter one way or the
other if the xlog record gets modified; perhaps it's going to be discarded
anyway.  I didn't look far enough to find out.  But this is the only function
of all the (void)(void *arg) callback functions in the entire postgresql
source tree that modifies its argument.  I discovered this while trying
to convert all the callback function signatures to (void)(const void *),
and this was the only monkey-wrench in the works.

Is this a bug?  Do I just have to live with the unfortunate lack of
orthogonality in the callback mechanisms?  At the very least, there
should perhaps be some documentation about how all this is intended
to work.

Thanks, please find my work-in-progress attempt and constify-ing
these functions attached.

Mark Dilger







Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: LLVM Address Sanitizer (ASAN) and valgrind support
Next
From: Mark Dilger
Date:
Subject: casting away const in comparators