Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Serhiy Storchaka
22.01.14 07:13, Nikolaus Rath написав(ла): To me this version looks shorter and clearer. Is there really an advantage in defining the clinic argument as a custom struct rather than object? To me too. ___ Python-Dev mailing list Python-Dev@python.org

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Nikolaus Rath
Larry Hastings writes: > All is not lost! What follows is rough pseudo-C code, hopefully you > can take it from here. > >typedef struct { > int set; > time_t when; >} clinic_time_t; > >#define DEFAULT_CLINIC_TIME_T {0, 0} > >static int >parse_clinic_time_t_arg(PyOb

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Larry Hastings
Yes, I meant in the definition of the convertor class.  You can fix c_default in converter_init. On Jan 21, 2014 7:19 PM, Nikolaus Rath wrote: > > Larry Hastings writes: > > A comment on your approach so far: I'm very much against giving > > "default" a default value in the constructor. > > You

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Nikolaus Rath
Larry Hastings writes: > A comment on your approach so far: I'm very much against giving > "default" a default value in the constructor. You mean in the definition of the custom converter class? > I realize that hack saves you having to say "= NULL" in a lot of > places. But explicit is better

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Larry Hastings
On 01/21/2014 12:59 AM, Serhiy Storchaka wrote: 21.01.14 04:44, Nikolaus Rath написав(ла): Serhiy Storchaka writes: 20.01.14 06:19, Nikolaus Rath написав(ла): This works if the user calls time.gmtime(None), but it fails for time.gmtime(). It seems that in that case my C converter function is

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-21 Thread Serhiy Storchaka
21.01.14 04:44, Nikolaus Rath написав(ла): Serhiy Storchaka writes: 20.01.14 06:19, Nikolaus Rath написав(ла): This works if the user calls time.gmtime(None), but it fails for time.gmtime(). It seems that in that case my C converter function is never called. What's the trick that I'm missing?

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-20 Thread Larry Hastings
On 01/20/2014 06:44 PM, Nikolaus Rath wrote: All in all, I'm still not sure how I'm supposed to proceed. I see the following options (and I'm fine with all of them): 1. Use the option group with a custom converter. This means a time(NULL) call even if the caller passed a parameter. 2. Decla

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-20 Thread Nikolaus Rath
Serhiy Storchaka writes: > 20.01.14 06:19, Nikolaus Rath написав(ла): >> This works if the user calls time.gmtime(None), but it fails for >> time.gmtime(). It seems that in that case my C converter function is >> never called. >> >> What's the trick that I'm missing? > > /*[clinic input] > time.gm

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-20 Thread Nikolaus Rath
Ryan Smith-Roberts writes: > The trick you're missing is that *any time* you have an optional argument > with a custom converter[1], PyArg_ParseTuple *only* calls the converter > function in the case that the user *actually supplies some value*. This is > a basic property of an optional argument.

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-20 Thread Ryan Smith-Roberts
The trick you're missing is that *any time* you have an optional argument with a custom converter[1], PyArg_ParseTuple *only* calls the converter function in the case that the user *actually supplies some value*. This is a basic property of an optional argument. Another property is that the c_defau

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-20 Thread Serhiy Storchaka
20.01.14 06:19, Nikolaus Rath написав(ла): This works if the user calls time.gmtime(None), but it fails for time.gmtime(). It seems that in that case my C converter function is never called. What's the trick that I'm missing? /*[clinic input] time.gmtime [ seconds: time_t ] /

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-19 Thread Nikolaus Rath
Larry Hastings writes: > On 01/18/2014 09:52 PM, Ryan Smith-Roberts wrote: >> >> I still advise you not to use this solution. time() is a system call >> on many operating systems, and so it can be a heavier operation than >> you'd think. Best to avoid it unless it's needed (on FreeBSD it >> seems

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-19 Thread Nikolaus Rath
Larry Hastings writes: > On 01/18/2014 09:52 PM, Ryan Smith-Roberts wrote: >> >> I still advise you not to use this solution. time() is a system call >> on many operating systems, and so it can be a heavier operation than >> you'd think. Best to avoid it unless it's needed (on FreeBSD it >> seems

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-19 Thread Ryan Smith-Roberts
On Sun, Jan 19, 2014 at 2:38 AM, Larry Hastings wrote: > According to the issue tracker, " rmsr" has only ever filed one issue. > I just fixed (and closed) it. > The two issues were "custom converter with converter and default raises exception" and "custom converter with py_default and c_defaul

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-19 Thread Larry Hastings
On 01/18/2014 09:52 PM, Ryan Smith-Roberts wrote: I still advise you not to use this solution. time() is a system call on many operating systems, and so it can be a heavier operation than you'd think. Best to avoid it unless it's needed (on FreeBSD it seems to add about 15% overhead to local

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-18 Thread Ryan Smith-Roberts
Ah yes, my apologies, I was thrown off by the first converter declaration in your class and didn't spot the second, so didn't realize what you were up to. I still advise you not to use this solution. time() is a system call on many operating systems, and so it can be a heavier operation than you'd

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-18 Thread Nikolaus Rath
Hi Ryan, Ryan Smith-Roberts writes: > Hi Nikolaus. I also started a conversion of timemodule, but dropped it when > I saw in the issue that you had taken over that conversion. I also tried to > turn parse_time_t_args into a converter. However, it won't work. The > problem is that parse_time_t_ar

Re: [Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-18 Thread Ryan Smith-Roberts
Hi Nikolaus. I also started a conversion of timemodule, but dropped it when I saw in the issue that you had taken over that conversion. I also tried to turn parse_time_t_args into a converter. However, it won't work. The problem is that parse_time_t_args must be called whether or not the user suppl

[Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

2014-01-18 Thread Nikolaus Rath
Hello, I'm trying to convert functions using parse_time_t_args() (from timemodule.c) for argument parsing to argument clinic. The function is defined as: , | static int | parse_time_t_args(PyObject *args, char *format, time_t *pwhen) | { | PyObject *ot = NULL; | time_t whent; | |