Issue 595026: Support for masks in getargs.c (original) (raw)

Created on 2002-08-14 12:26 by gvanrossum, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_getargs2.py theller,2003-04-17 15:41 Test for integer PyArg_ParseTuple format codes.
getargs.patch theller,2003-04-17 15:43 Patch to several core files
getargs.c.diff theller,2003-04-17 17:02 Missing patch for getargs.c
getargs-2.patch theller,2003-04-17 17:21 Complete (hopefully) with decrefs fixed. test_getargs2.py not included.
Messages (20)
msg11944 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-08-14 12:26
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).
msg11945 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-18 19:18
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.
msg11946 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-02-18 19:50
Logged In: YES user_id=6380 Thomas: that would be great! (As long it isn't killed by bw compat. :-)
msg11947 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-18 20:16
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
msg11948 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-02-18 20:18
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.
msg11949 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-18 20:33
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.
msg11950 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-18 20:59
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)?
msg11951 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2003-02-18 22:08
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.
msg11952 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-20 20:45
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?
msg11953 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-02-21 12:58
Logged In: YES user_id=6380 I suggest writing on python-dev or python-list.
msg11954 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-02-21 18:36
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.
msg11955 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 15:47
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.
msg11956 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 15:49
Logged In: YES user_id=11105 I forgot to say: kpatch.diff is obsolete, please ignore. Hm, I'll better delete it.
msg11957 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-17 16:36
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]$
msg11958 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 17:02
Logged In: YES user_id=11105 Oops, sorry: getargs.c.diff
msg11959 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 17:09
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.
msg11960 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 17:21
Logged In: YES user_id=11105 getargs-2.patch, hopefully complete, but test_getargs2.py not included.
msg11961 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-17 18:06
Logged In: YES user_id=6380 Good enough; check it in, with docs and NEWS. But please fix these: - the 'h' opcode comments and error messages still refer to it as "signed short" while it is now clearly an *unsigned* short. (Hm... maybe 'h' should remain a signed short after all, for backwards compatibility?) - there's still an unused definition of AddSym in testcapi.
msg11962 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 18:56
Logged In: YES user_id=11105 Checked in with the changes you requested. I left the 'h' opcode unchanged, if needed this can be fixed later. Will do the docs on tuesday, NEWS today, if time permits.
msg11963 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-17 19:03
Logged In: YES user_id=6380 Thanks!
History
Date User Action Args
2022-04-10 16:05:35 admin set github: 37029
2002-08-14 12:26:55 gvanrossum create