andrew@fgh.fgh.oz (Andrew Buchanan) (06/14/90)
In article <8348@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >It's easy to write a glue routine because it's preprocessed from definitions >like: > > CASE int flushok > I WINDOW* win > I bool boolf > END > >In fact, I've even got a script that scans manual pages and spits out >definitions like that above based on the synopsis, presuming it is >reasonably well formed. This sounds wonderful. We hacked our own interface for use with our DBMS, but it will be nice not to have to worry whether the next patch will break it. From the synopsis above, though, it looks like the C functions won't be able to return arrays. We acheive this by returning values via a function that adds the values one at a time to the return stack, and can return numbers or strings depending on say the type of the database column passed as an argument. The C functions also know whether they are in an array context or not. Of course, these are custom functions, which call the underlying DBMS routines. If no support is given for arrays, we can rewrite the functions in perl accessing the glued DBMS routines. Even without array returns it will be a boon. Once we glue in our screen-handling stuff, we can ditch C-programming altogether :-). -- Andrew Buchanan | andrew@fgh.fgh.oz.au FGH Decision Support Systems Pty Ltd | ..!uunet!fgh.fgh.oz.au!andrew
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/15/90)
In article <190@fgh.fgh.oz> andrew@fgh.UUCP (Andrew Buchanan) writes: : From the synopsis above, though, it looks like the C functions won't be : able to return arrays. We acheive this by returning values via a : function that adds the values one at a time to the return stack, and : can return numbers or strings depending on say the type of the database : column passed as an argument. The C functions also know whether they : are in an array context or not. Of course, these are custom functions, : which call the underlying DBMS routines. If no support is given for : arrays, we can rewrite the functions in perl accessing the glued DBMS : routines. You can return arrays, but you just have to write that particular case of the glue routine by hand. I've already done one--it's not too difficult, modulo the usual difficulties of making sure the stack is long enough. The wantarray variable is also available. Here's what a handwritten case to return an array value looks like: case US_dts_errlist: if (!wantarray) { str_numset(st[0], (double) dts_nerr); return sp; } astore(stack, sp + dts_nerr, Nullstr); /* extend stack */ st = stack->ary_array + sp; /* possibly realloced */ for (i = 0; i < dts_nerr; i++) { tmps = dts_errlist[i]; st[i] = str_2static(str_make(tmps,strlen(tmps))); } return sp + dts_nerr - 1; Not too hard, as you see. Larry