[Python-Dev] Re: sre warnings

Martin v. Loewis martin at v.loewis.de
Fri Jan 9 16:47:18 EST 2004


Gustavo Niemeyer wrote:

>>The changes to re are still throwing off signed/unsigned warnings.  Can
>>you please get that fixed up?
> 
> 
> My changes to sre have nothing to do with these warnings.

This is not true. I get

Modules/_sre.c:811: warning: comparison between signed and unsigned

Now, line 811 is

     DATA_ALLOC(SRE_MATCH_CONTEXT, ctx);

This expands to

     alloc_pos = state->data_stack_base; \
     TRACE(("allocating %s in %d (%d)\n", \
            SFY(type), alloc_pos, sizeof(type))); \
     if (state->data_stack_size < alloc_pos+sizeof(type)) { \
         int j = data_stack_grow(state, sizeof(type)); \
         if (j < 0) return j; \
         if (ctx_pos != -1) \
             DATA_STACK_LOOKUP_AT(state, SRE_MATCH_CONTEXT, ctx, ctx_pos); \
     } \
     ptr = (type*)(state->data_stack+alloc_pos); \
     state->data_stack_base += sizeof(type); \
} while (0)

The culprit is the line

     if (state->data_stack_size < alloc_pos+sizeof(type)) { \

because data_stack_size is signed, and sizeof(type) is
size_t. This line is yours

2.101        (niemeyer 17-Oct-03):     if (state->data_stack_size < 
alloc_pos+sizeof (type)) {

Changing the type of data_stack_size to unsigned makes the
warning go away.

Please change all uses of sizes/positions to "size_t", and
change the special -1 marker to (size_t)-1.

Regards,
Martin





More information about the Python-Dev mailing list