RE: API : constness ?

Discussion in 'Python' started by Delaney, Timothy C (Timothy), May 31, 2004.

  1. Benoît Dejean wrote:

    > it's also for a simple reason, eg using PyArg_ParseTupleAndKeywords
    >
    > using const helps gcc to move these data to the text segment
    >
    > static const char * const kwlist[] = { "uri", "open_mode",
    > "exclusive", "perm", NULL };


    Does this give any performance or size improvement?

    > or a better (but tricky) storage could be used to avoid relocation
    >
    > bust casting again again like this
    >
    > PyArg_ParseTupleAndKeywords(args, kwargs, "should be const char *",
    > (char**)kwlist, ...
    >
    > is quite ugly ...


    If it will simplify calling code, I don't see any reason not to do it. However, there is a general policy of not doing large chunks of boilerplate fixing - instead it is encouraged to make these changes in code that is being actively worked on for some other reason. Small patches are good.

    Perhaps you should choose a few cases that bug you the most (e.g. PyArg_ParseTupleAndKeywords) and submit a patch just for those.

    Additionally, if you can show a performance improvement as a result (and importantly, no loss of performance on Windows ...) it's more likely to be reviewed kindly ... ;)

    Tim Delaney
    Delaney, Timothy C (Timothy), May 31, 2004
    #1
    1. Advertising

  2. Le Mon, 31 May 2004 11:56:57 +1000, Delaney, Timothy C (Timothy) a
    écrit :

    > Benoît Dejean wrote:


    >> static const char * const kwlist[] = { "uri", "open_mode", "exclusive",
    >> "perm", NULL };

    >
    > Does this give any performance or size improvement?


    of course, it avoids a lot of relocation, reduces load time, and manque
    the compiler to make further informations because data will be in a
    readonly segment. it is safe to apply this kind of change to static data.

    >
    > If it will simplify calling code, I don't see any reason not to do it.
    > However, there is a general policy of not doing large chunks of
    > boilerplate fixing - instead it is encouraged to make these changes in
    > code that is being actively worked on for some other reason. Small
    > patches are good.
    >
    > Perhaps you should choose a few cases that bug you the most (e.g.
    > PyArg_ParseTupleAndKeywords) and submit a patch just for those.


    you're right. i should first work on printf/scanf like functions

    > Additionally, if you can show a performance improvement as a result (and
    > importantly, no loss of performance on Windows ...) it's more likely to
    > be reviewed kindly ... ;)


    my first goal is const correctness, i don't know if i can show something.
    it will just remove warnings and move data to the text segment, etc
    =?iso-8859-1?q?Beno=EEt_Dejean?=, May 31, 2004
    #2
    1. Advertising

  3. Delaney, Timothy C (Timothy)

    Tim Roberts Guest

    Benoît Dejean <> wrote:

    >Le Mon, 31 May 2004 11:56:57 +1000, Delaney, Timothy C (Timothy) a
    >écrit :
    >
    >> Benoît Dejean wrote:

    >
    >>> static const char * const kwlist[] = { "uri", "open_mode", "exclusive",
    >>> "perm", NULL };

    >>
    >> Does this give any performance or size improvement?

    >
    >of course, it avoids a lot of relocation, reduces load time, and manque
    >the compiler to make further informations because data will be in a
    >readonly segment.


    The data MAY be in a read-only segment, but even assuming that it is, that
    doesn't do anything to reduce relocation or load time.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
    Tim Roberts, Jun 1, 2004
    #3
  4. Le Mon, 31 May 2004 17:40:16 -0700, Tim Roberts a écrit :

    >
    > The data MAY be in a read-only segment, but even assuming that it is, that
    > doesn't do anything to reduce relocation or load time.


    i don't agree, but btw constness is more important to me
    =?iso-8859-1?q?Beno=EEt_Dejean?=, Jun 1, 2004
    #4
  5. Delaney, Timothy C (Timothy)

    Isaac To Guest

    >>>>> "Tim" == Tim Roberts <> writes:

    >>>> static const char * const kwlist[] = { "uri", "open_mode",
    >>>> "exclusive", "perm", NULL };
    >>> Does this give any performance or size improvement?


    Tim> The data MAY be in a read-only segment,

    The strings like "uri", "open_mode", etc., are in read-only segment anyway,
    whether you add the "const" or not. On the other hand, kwlist cannot be in
    read-only segment, no matter you add "const" or not, since they are
    initialized not when you compile the module, but instead when you load the
    module (see below). Initialization at load time means modification of the
    memory location. Since the memory need to be modified (once, at load time),
    they cannot be mapped to memory from file directly, and accordingly they
    cannot be in read-only memory.

    Tim> but even assuming that it is, that doesn't do anything to reduce
    Tim> relocation or load time.

    This is absolutely correct. It is simply impossible to make relocations
    unnecessary, because the char* pointers stored in kwlist must point to the
    absolute addresses of the static strings, which cannot be determined until
    the python program actually loads the module (because, until then, we won't
    be able to tell what part of the address space is available).

    Regards,
    Isaac.
    Isaac To, Jun 1, 2004
    #5
  6. Isaac To <> wrote in message news:<>...

    > This is absolutely correct. It is simply impossible to make relocations
    > unnecessary, because the char* pointers stored in kwlist must point to the
    > absolute addresses of the static strings, which cannot be determined until
    > the python program actually loads the module (because, until then, we won't
    > be able to tell what part of the address space is available).


    And, supposing the pointers are declared constant, that can't be solved
    by the loader using relocation entries ?

    There are no architectures on which python runs in which executable
    modules require fixups by the loader ?

    Andrea
    Andrea Griffini, Jun 12, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Magnusson

    Casting away constness

    Martin Magnusson, Nov 17, 2003, in forum: C++
    Replies:
    1
    Views:
    384
    tom_usenet
    Nov 17, 2003
  2. Richard Hayden
    Replies:
    1
    Views:
    742
    Rob Williscroft
    Nov 23, 2003
  3. =?iso-8859-1?q?Beno=EEt_Dejean?=

    API : constness ?

    =?iso-8859-1?q?Beno=EEt_Dejean?=, May 30, 2004, in forum: Python
    Replies:
    0
    Views:
    312
    =?iso-8859-1?q?Beno=EEt_Dejean?=
    May 30, 2004
  4. Tim Peters

    RE: API : constness ?

    Tim Peters, May 30, 2004, in forum: Python
    Replies:
    12
    Views:
    585
    Isaac To
    Jun 2, 2004
  5. Replies:
    14
    Views:
    827
    Ian Collins
    Apr 4, 2006
Loading...

Share This Page