Thread: Can functions return NULL value?
Can a function, written in C, return a NULL value? I would like write code like this: text * getnull (text * t){ return NULL;} but it doesn't work, the backend terminates abnormally. Thanks a lot -- Andrea Austa - aausta@athena.polito.it Debian GNU/Linux User --
Andrea Austa <aausta@athena.polito.it> writes: > Can a function, written in C, return a NULL value? > I would like write code like this: > text * getnull (text * t) > { > return NULL; > } > but it doesn't work, the backend terminates abnormally. This will be possible in 7.1 with the new function manager interface. Right now, it's not possible. (If your stomach is easily turned, stop reading here.) There is an incredibly ugly hack for single-argument functions; if that's the only kind you need to do this for, you're in luck. A single-argument function implicitly gets a second "bool *" argument, which on entry tells you whether the argument is NULL, and on exit tells whether the result is NULL. So: text * getnull (text * t, bool * isNull) { if (*isNull) { /* passed argument is NULL, do appropriatething */ } else { /* normal case here */ } if (want-to-return-NULL) { *isNull = true; return NULL; } else { *isNull = false; /* necessaryiff arg is NULL */ return appropriate-value; } } Note that you still declare the function to SQL as taking a single argument; the extra arg only appears at the C level. This was only meant to support implementation of IS NULL/IS NOT NULL, which is why it only copes with the single-argument case. 7.1 will replace this crock with a more reasonable design that passes in a separate isNull flag for each argument, and also has an isNull flag the function can set for its result value. See past discussions of function manager redesign in pghackers archives (last thread was in late Oct 99). regards, tom lane
Tom Lane wrote: > > Andrea Austa <aausta@athena.polito.it> writes: > > Can a function, written in C, return a NULL value? > > I would like write code like this: > > > text * getnull (text * t) > > { > > return NULL; > > } > > > but it doesn't work, the backend terminates abnormally. > > This will be possible in 7.1 with the new function manager interface. > Right now, it's not possible. Who is doing the new function manager interface. Is there a preliminary description somewhere ? What is the planned timetable? I ask because friend of mine is working on plpython (and has the basics working) on current code but he is quite turned off by the ugliness of current function manager (and SPI interface). ---------------- Hannu
Hannu Krosing <hannu@tm.ee> writes: >> This will be possible in 7.1 with the new function manager interface. >> Right now, it's not possible. > Who is doing the new function manager interface. Me. > Is there a preliminary description somewhere ? I posted a proposal to pghackers around 20 Oct last year; it's changed a little since then but not much. > What is the planned timetable? 7.1. I have fmgr.c code that compiles (as of late last night) but probably still has bugs. I haven't started on converting any individual functions, nor have I touched the PLfoo modules yet. > I ask because friend of mine is working on plpython (and has the > basics working) on current code but he is quite turned off by the > ugliness of current function manager (and SPI interface). Wasn't planning to touch the SPI interface in this go-round, but if someone else wants to... regards, tom lane
Tom Lane wrote: > > Hannu Krosing <hannu@tm.ee> writes: > >> This will be possible in 7.1 with the new function manager interface. > >> Right now, it's not possible. > > > Who is doing the new function manager interface. > > Me. > > > Is there a preliminary description somewhere ? > > I posted a proposal to pghackers around 20 Oct last year; it's changed a > little since then but not much. Ok, ill' find it. > > What is the planned timetable? > > 7.1. I have fmgr.c code that compiles (as of late last night) but > probably still has bugs. I haven't started on converting any individual > functions, nor have I touched the PLfoo modules yet. When will it be available to the general public (i.e. me ;) ? --------------- Hannu
Hannu Krosing <hannu@tm.ee> writes: >>>> What is the planned timetable? >> >> 7.1. I have fmgr.c code that compiles (as of late last night) but >> probably still has bugs. I haven't started on converting any individual >> functions, nor have I touched the PLfoo modules yet. > When will it be available to the general public (i.e. me ;) ? I'm planning to commit what I have as soon as Marc makes the CVS branch for 7.1. Sounds like that'll be around the end of the month. regards, tom lane
Tom Lane wrote: > > Hannu Krosing <hannu@tm.ee> writes: > >>>> What is the planned timetable? > >> > >> 7.1. I have fmgr.c code that compiles (as of late last night) but > >> probably still has bugs. I haven't started on converting any individual > >> functions, nor have I touched the PLfoo modules yet. > > > When will it be available to the general public (i.e. me ;) ? > > I'm planning to commit what I have as soon as Marc makes the CVS branch > for 7.1. Sounds like that'll be around the end of the month. What will people do the remaining tree weeks ? A well deserved rest perhaps ;) --------------- Hannu