Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > Problem returni...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9350 of 9628
Post > Topic >>

Problem returning strings with pgsql 8.3.x

by eggyknap@[EMAIL PROTECTED] ("Josh Tolley") May 12, 2008 at 11:23 PM

Having posted this to -general [1] per -hackers list instructions [2]
to try elsewhere first, and waited (not very long, I admit) in vain
for a response, I'm posting this to -hackers now. My apologies if my
impatience in that regard annoys.

While developing PL/LOLCODE, I've found something wrong with returning
strings from LOLCODE functions using 8.3.0 or greater. Using 8.4beta
from a few days ago, for instance, a function that should return "test
string" returns
"\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F" in
pgsql (sometimes the number of \x7F characters varies). In 8.2.4 it
works fine.

Here's the code involved, from pl_lolcode_call_handler, the call
handler function for PL/LOLCODE. First, the bit that finds the
FmgrInfo structure and typioparam for the result type:

        procTup = SearchSysCache(PROCOID,
ObjectIdGetDatum(fcinfo->flinfo->fn_oid), 0, 0, 0);
        if (!HeapTupleIsValid(procTup)) elog(ERROR, "Cache lookup
failed for procedure %u", fcinfo->flinfo->fn_oid);
        procStruct = (Form_pg_proc) GETSTRUCT(procTup);

        typeTup = SearchSysCache(TYPEOID,
ObjectIdGetDatum(procStruct->prorettype), 0, 0, 0);
        if (!HeapTupleIsValid(typeTup)) elog(ERROR, "Cache lookup
failed for type %u", procStruct->prorettype);
        typeStruct = (Form_pg_type) GETSTRUCT(typeTup);

        resultTypeIOParam = getTypeIOParam(typeTup);
        fmgr_info_cxt(typeStruct->typinput, &flinfo,
TopMemoryContext); /*CurTransactionContext); */
        ReleaseSysCache(typeTup);

Here's the code that converts the return value into a Datum later on
in the function:

        if (returnTypeOID != VOIDOID) {
                if (returnVal != NULL) {
                        if (returnVal->type == ident_NOOB)
                                fcinfo->isnull = true;
                        else  {
                                SPI_push();
                                if (returnTypeOID == BOOLOID)
                                        retval =
InputFunctionCall(&flinfo, lolVarGetTroof(returnVal) == lolWIN ?
"TRUE" : "FALSE", resultTypeIOParam, -1);
                                else {
                                        /* elog(NOTICE,
lolVarGetString(returnVal, true)); */
                                        retval =
InputFunctionCall(&flinfo, lolVarGetString(returnVal, true),
 resultTypeIOParam, -1);
                                }
                                SPI_pop();
                        }
                }
                else {
                        fcinfo->isnull = true;
                }
        }

        SPI_finish();
        /* elog(NOTICE, "PL/LOLCODE ending"); */

        return retval;

returnVal is an instance of the struct PL/LOLCODE uses to store its
variables. The key line in this case is the one after the
commented-out call to elog. retval is a Datum type. lolVarGetString()
returns the string value the returnVal struct represents -- I'm
certain of that thanks to gdb and other testing. All other data types
PL/LOLCODE knows about internally seem to return just fine. I'm fairly
certain I'm screwing up memory somewhere, but I can't see what I've
done wrong.

I'm glad to provide further details, but those included above are all
the ones I thought were relevant. Thanks in advance for any help you
can provide.

 - Josh / eggyknap

[1] http://archives.postgresql.org/pgsql-general/2008-05/msg00311.php
[2] http://archives.postgresql.org/pgsql-hackers/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers




 3 Posts in Topic:
Problem returning strings with pgsql 8.3.x
eggyknap@[EMAIL PROTECTED  2008-05-12 23:23:17 
Re: Problem returning strings with pgsql 8.3.x
kleptog@[EMAIL PROTECTED]  2008-05-13 08:33:01 
Re: Problem returning strings with pgsql 8.3.x
tgl@[EMAIL PROTECTED] (T  2008-05-13 10:01:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Fri Jul 4 9:16:16 CDT 2008.