[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sig2str and str2sig use in C++

From: Daniel J Sebald
Subject: Re: sig2str and str2sig use in C++
Date: Wed, 05 Jun 2013 11:57:47 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 06/05/2013 02:17 AM, Thien-Thi Nguyen wrote:
() Daniel J Sebald<address@hidden>
() Tue, 04 Jun 2013 12:35:00 -0500

    >  I seem to recall a paper several years back that argued against
    >  this approach based on ldso issues.  Drat, can't dredge the
    >  details...

    I tried searching the Internet for such issues, but couldn't find
    any. What do you recall as being the loader problem?  The "extern"
    part?  Or use of a null string for termination?

OK, found it.  "How to Write Shared Libraries" by Ulrich Drepper,
version 4.0, section 2.4.3 "Arrays of Data Pointers".  See also the
programs in Appendix B.

I think the problem is (relatively) high constant ldso overhead for a
rarely-used facility.  However, i'm not sure if those concerns are
relevant in this context.  If not, sorry for the noise!

Thanks for the reference. Lots of good info there. Yes, that is Ulrich's point, but it seems to depend a bit on the programming and storage method, i.e., using pointers versus array. Note that in one of Ulrich's examples

static const char msgstr[] =
  "message for err1\0"
  "message for err2\0"
  "message for err3";

static const size_t msgidx[] = {
  sizeof ("message for err1"),
  sizeof ("message for err1")
  + sizeof ("message for err2")

const char *errstr (int nr) {
  return msgstr + msgidx[nr];

is pretty much the same as what Paul described. The one thing I don't like about Ulrich's example is the repeated use of the same expression (could use definitions for the repeated expressions I suppose).

Well, taking this all into consideration, perhaps the easiest thing to do is construct a table at runtime on the heap:

static char *strings_table = 0;

if (! strings_table)
    bytes = compute_amount_of_memory_based_on_numname ();
    strings_table = malloc (bytes);
    construct_table_from_numname (strings_table);

return pointer_to_strings_table (strings_table, signal_number);

That wouldn't create excessive load overhead, nor would it require some complex pre-processing macros. But how would one make that safe in a multithreaded environment? If there are two instances of calling the above at the same time there would be multiple mallocs and a potential memory leak.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]