[Python-bugs-list] [ python-Bugs-595026 ] Support for masks in getargs.c

SourceForge.net noreply@sourceforge.net
Thu, 17 Apr 2003 10:21:44 -0700


Bugs item #595026, was opened at 2002-08-14 14:26
Message generated for change (Comment added) made by theller
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595026&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 7
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Thomas Heller (theller)
Summary: Support for masks in getargs.c

Initial Comment:
We need this implemented:

> How about the following counterproposal.  This also
changes some of
> the other format codes to be a little more regular.
>
> Code    C type          	Range check
>
> b	unsigned char		0..UCHAR_MAX
> B	unsigned char		none **
> h	unsigned short		0..USHRT_MAX
> H	unsigned short		none **
> i	int
		INT_MIN..INT_MAX
> I *	unsigned int		0..UINT_MAX
> l	long
		LONG_MIN..LONG_MAX
> k *	unsigned long		none
> L	long long		LLONG_MIN..LLONG_MAX
> K *	unsigned long long	none
>
> Notes:
>
> * New format codes.
>
> ** Changed from previous "range-and-a-half" to
"none"; the
>    range-and-a-half checking wasn't particularly useful.

Plus a C API or two, e.g. PyInt_AsLongMask() ->
unsigned long and PyInt_AsLongLongMask() -> unsigned
long long (if that exists).

----------------------------------------------------------------------

>Comment By: Thomas Heller (theller)
Date: 2003-04-17 19:21

Message:
Logged In: YES 
user_id=11105

getargs-2.patch, hopefully complete, but test_getargs2.py
not included.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-17 19:09

Message:
Logged In: YES 
user_id=11105

But wait: I'll fix the missing decrefs, and create a new,
complete patch. Takes a couple of minutes, though.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-17 19:02

Message:
Logged In: YES 
user_id=11105

Oops, sorry: getargs.c.diff

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-04-17 18:36

Message:
Logged In: YES 
user_id=6380

Review comments:

- Where's the patch to getargs.c???

- There's a missing DECREF(io) in
PyInt_AsUnsignedLong[Long]Mask() in the block with the
"nb_int should return int object" error return. (This is
also missing from the template you used, PyInt_AsLong()!)

- I get a failure in _testcapi:

[guido@odiug linux]$ ./python ../Lib/test/test_capi.py
internal test_L_code
internal test_config
internal test_dict_iteration
internal test_k_code
Traceback (most recent call last):
  File "../Lib/test/test_capi.py", line 16, in ?
    raise test_support.TestFailed, sys.exc_info()[1]
test.test_support.TestFailed: test_k_code: k code returned
wrong value for long -0xFFF..000042
[guido@odiug linux]$ 


----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-17 17:49

Message:
Logged In: YES 
user_id=11105

I forgot to say: kpatch.diff is obsolete, please ignore.
Hm, I'll better delete it.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-17 17:47

Message:
Logged In: YES 
user_id=11105

Patch is ready for review (although NEWS and docs are
missing, I will add them later if the patch is accepted).

getargs.patch contains a context diff for several files,
including Modules/_testcapimodule.c.
test_getargs2.py should go into Lib/test, and tests the changes.
It also documents the new behaviour.

In the complete test-suite, test_array is crashing now as a
consequence.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-21 19:36

Message:
Logged In: YES 
user_id=11105

Uploading patch whcih implements the 'k' format code.  Any
comments? Is this what is needed?
I know, docs are missing, and 'K' is missing.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-21 13:58

Message:
Logged In: YES 
user_id=6380

I suggest writing on python-dev or python-list.


----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-20 21:45

Message:
Logged In: YES 
user_id=11105

I've implemented the 'k' getargs code, and
PyInt_AsUnsignedLongMask and PyLong_AsUnsignedLongMask
functions.  Is there any facility which would help me to
test this new code?

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2003-02-18 23:08

Message:
Logged In: YES 
user_id=45365

Guido,
I would be happy with the no-rangecheck unsigned long formatcode. One request, though: if this is implemented can it be done ASAP after 2.3a2, so there's still some time to shake out the bugs before 2.3b1 comes out? Especially the hand-written code will have to be examined to see where l needs to be turned into k.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-18 21:59

Message:
Logged In: YES 
user_id=11105

Currently the h code means signed short
(SHRT_MIN..SHRT_MAX), do you really want to change that to
unsigned short (0..USHRT_MAX)?

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-18 21:33

Message:
Logged In: YES 
user_id=11105

Ok, I'll use your codes.

Here is my suggestion for the C api functions:

int PyInt_AsLongMask(PyObject *v, unsigned long *pval);
int PyInt_AsLongLongMask(PyObject *v, unsigned LONG_LONG *pval);

return -1 and set exception on error, return 0 otherwise and
store the result in pval. This saves the PyErr_Occurred() in
case the value is -1.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-18 21:18

Message:
Logged In: YES 
user_id=6380

A few days is fine (this doesn't need to make it into 2.3a2).

But the proposal here is not backwards compatible, is it?
Those codes already mean something different now.

I think we'll need to invent new format codes, or a new
modifier.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-18 21:16

Message:
Logged In: YES 
user_id=11105

But it would probably take a few days.

What about these changes to the format codes, they are now
more in sync with the struct module (I hope the formatting
is kept):

Code    C type          	Range check

b	unsigned char		0..UCHAR_MAX
B	unsigned char		none **
h	unsigned short		0..USHRT_MAX
H	unsigned short		none **
i	int			INT_MIN..INT_MAX
I *	unsigned int		0..UINT_MAX
l	long			LONG_MIN..LONG_MAX
L *	unsigned long		none
q	long long		LLONG_MIN..LLONG_MAX
Q *	unsigned long long	none


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-18 20:50

Message:
Logged In: YES 
user_id=6380

Thomas: that would be great! (As long it isn't killed by bw
compat. :-)


----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-02-18 20:18

Message:
Logged In: YES 
user_id=11105

If nobody else comes up, I can do this. I also had similar
checks for the struct module, but Tim killed it because of
backward compatibility.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595026&group_id=5470