Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: API : constness ?

Reply
Thread Tools

RE: API : constness ?

 
 
Delaney, Timothy C (Timothy)
Guest
Posts: n/a
 
      05-31-2004
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

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Beno=EEt_Dejean?=
Guest
Posts: n/a
 
      05-31-2004
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

 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      06-01-2004
Benoît Dejean <(E-Mail Removed)> 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, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
=?iso-8859-1?q?Beno=EEt_Dejean?=
Guest
Posts: n/a
 
      06-01-2004
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

 
Reply With Quote
 
Isaac To
Guest
Posts: n/a
 
      06-01-2004
>>>>> "Tim" == Tim Roberts <(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrea Griffini
Guest
Posts: n/a
 
      06-12-2004
Isaac To <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Constness of the container of shared_ptr and the constness of it elements PengYu.UT@gmail.com C++ 14 04-04-2006 01:57 AM
RE: API : constness ? Tim Peters Python 12 06-02-2004 03:35 AM
API : constness ? =?iso-8859-1?q?Beno=EEt_Dejean?= Python 0 05-30-2004 10:51 AM
Constness with pointers to pointers etc. Richard Hayden C++ 1 11-23-2003 01:20 PM
Casting away constness Martin Magnusson C++ 1 11-17-2003 01:30 PM



Advertisments