Index: configure.in =================================================================== RCS file: /junk/pgsql/repo/pgsql/configure.in,v retrieving revision 1.132 diff -u -r1.132 configure.in --- configure.in 2001/08/01 23:52:50 1.132 +++ configure.in 2001/08/23 15:18:30 @@ -411,6 +411,21 @@ # +# If Tcl is enabled (above) then check for pltcl_utf +# +AC_MSG_CHECKING([whether to build with PL/Tcl with UTF support]) +if test "$with_tcl" = yes; then + PGAC_ARG_BOOL(enable, pltcl-utf, no, + [ --enable-pltcl-utf build PL/Tcl UTF support (if Tcl is enabled)], + [AC_DEFINE([ENABLE_PLTCL_UTF])]) +else + enable_pltcl_utf=no +fi +AC_MSG_RESULT([$enable_pltcl_utf]) +AC_SUBST([enable_pltcl_utf]) + + +# # Optionally build Perl modules (Pg.pm and PL/Perl) # AC_MSG_CHECKING([whether to build Perl modules]) Index: src/include/config.h.in =================================================================== RCS file: /junk/pgsql/repo/pgsql/src/include/config.h.in,v retrieving revision 1.170 diff -u -r1.170 config.h.in --- src/include/config.h.in 2001/08/01 23:52:50 1.170 +++ src/include/config.h.in 2001/08/23 15:01:41 @@ -84,6 +84,9 @@ /* --enable-pltcl-unknown */ #undef ENABLE_PLTCL_UNKNOWN +/* --enable-pltcl-utf */ +#undef ENABLE_PLTCL_UTF + /* --enable-nls */ #undef ENABLE_NLS Index: src/pl/tcl/pltcl.c =================================================================== RCS file: /junk/pgsql/repo/pgsql/src/pl/tcl/pltcl.c,v retrieving revision 1.38 diff -u -r1.38 pltcl.c --- src/pl/tcl/pltcl.c 2001/08/02 15:45:55 1.38 +++ src/pl/tcl/pltcl.c 2001/08/23 14:41:33 @@ -189,6 +189,9 @@ * Create the dummy hold interpreter to prevent close of * stdout and stderr on DeleteInterp ************************************************************/ +#ifdef ENABLE_PLTCL_UTF + Tcl_FindExecutable("postgres"); +#endif /* ENABLE_PLTCL_UTF */ if ((pltcl_hold_interp = Tcl_CreateInterp()) == NULL) { elog(ERROR, "pltcl: internal error - cannot create 'hold' " @@ -333,7 +336,13 @@ SPI_tuptable->tupdesc, fno); if (part != NULL) { +#ifndef ENABLE_PLTCL_UTF Tcl_DStringAppend(&unknown_src, part, -1); +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString tmp; + Tcl_DStringAppend(&unknown_src, Tcl_ExternalToUtfDString(NULL,part,-1,&tmp), -1); + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ pfree(part); } } @@ -459,7 +468,11 @@ Tcl_DString proc_internal_def; Tcl_DString proc_internal_body; char proc_internal_args[4096]; +#ifndef ENABLE_PLTCL_UTF char *proc_source; +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString proc_source; +#endif /* ENABLE_PLTCL_UTF */ char buf[512]; /************************************************************ @@ -611,10 +624,20 @@ sprintf(buf, "array set %d $__PLTcl_Tup_%d\n", i + 1, i + 1); Tcl_DStringAppend(&proc_internal_body, buf, -1); } +#ifndef ENABLE_PLTCL_UTF proc_source = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(&procStruct->prosrc))); Tcl_DStringAppend(&proc_internal_body, proc_source, -1); pfree(proc_source); +#else /* ENABLE_PLTCL_UTF */ + Tcl_DStringAppend(&proc_internal_body, + Tcl_ExternalToUtfDString(NULL, + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(&procStruct->prosrc))), + -1,&proc_source), + -1); + Tcl_DStringFree(&proc_source); +#endif /* ENABLE_PLTCL_UTF */ Tcl_DStringAppendElement(&proc_internal_def, Tcl_DStringValue(&proc_internal_body)); Tcl_DStringFree(&proc_internal_body); @@ -709,14 +732,29 @@ Tcl_DStringAppendElement(&tcl_cmd, ""); else { +#ifndef ENABLE_PLTCL_UTF char *tmp; +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ +#ifndef ENABLE_PLTCL_UTF tmp = DatumGetCString(FunctionCall3(&prodesc->arg_out_func[i], fcinfo->arg[i], ObjectIdGetDatum(prodesc->arg_out_elem[i]), Int32GetDatum(prodesc->arg_out_len[i]))); Tcl_DStringAppendElement(&tcl_cmd, tmp); pfree(tmp); +#else /* ENABLE_PLTCL_UTF */ + Tcl_DStringAppendElement(&tcl_cmd, + Tcl_ExternalToUtfDString(NULL, + DatumGetCString(FunctionCall3(&prodesc->arg_out_func[i], + fcinfo->arg[i], + ObjectIdGetDatum(prodesc->arg_out_elem[i]), + Int32GetDatum(prodesc->arg_out_len[i]))), + -1,&tmp)); + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ } } } @@ -779,11 +817,24 @@ if (fcinfo->isnull) retval = (Datum) 0; +#ifndef ENABLE_PLTCL_UTF else +#else /* ENABLE_PLTCL_UTF */ + else { + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ retval = FunctionCall3(&prodesc->result_in_func, +#ifndef ENABLE_PLTCL_UTF PointerGetDatum(interp->result), +#else /* ENABLE_PLTCL_UTF */ + PointerGetDatum(Tcl_UtfToExternalDString(NULL,interp->result,-1,&tmp)), +#endif /* ENABLE_PLTCL_UTF */ ObjectIdGetDatum(prodesc->result_in_elem), Int32GetDatum(-1)); +#ifdef ENABLE_PLTCL_UTF + Tcl_DStringFree(&tmp); + }; +#endif /* ENABLE_PLTCL_UTF */ /************************************************************ * Finally we may restore normal error handling. @@ -845,7 +896,11 @@ HeapTuple langTup; Form_pg_proc procStruct; Form_pg_language langStruct; +#ifndef ENABLE_PLTCL_UTF char *proc_source; +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString proc_source; +#endif /* ENABLE_PLTCL_UTF */ /************************************************************ * Allocate a new procedure description block @@ -927,10 +982,20 @@ "}\n" "unset i v\n\n", -1); +#ifndef ENABLE_PLTCL_UTF proc_source = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(&procStruct->prosrc))); Tcl_DStringAppend(&proc_internal_body, proc_source, -1); pfree(proc_source); +#else /* ENABLE_PLTCL_UTF */ + Tcl_DStringAppend(&proc_internal_body, + Tcl_ExternalToUtfDString(NULL, + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(&procStruct->prosrc))), + -1,&proc_source), + -1); + Tcl_DStringFree(&proc_source); +#endif /* ENABLE_PLTCL_UTF */ Tcl_DStringAppendElement(&proc_internal_def, Tcl_DStringValue(&proc_internal_body)); Tcl_DStringFree(&proc_internal_body); @@ -1191,6 +1256,9 @@ Oid typinput; Oid typelem; FmgrInfo finfo; +#ifdef ENABLE_PLTCL_UTF + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ /************************************************************ * Ignore pseudo elements with a dot name @@ -1232,9 +1300,16 @@ fmgr_info(typinput, &finfo); modvalues[attnum - 1] = FunctionCall3(&finfo, +#ifndef ENABLE_PLTCL_UTF CStringGetDatum(ret_values[i++]), +#else /* ENABLE_PLTCL_UTF */ + CStringGetDatum(Tcl_UtfToExternalDString(NULL,ret_values[i++],-1,&tmp)), +#endif /* ENABLE_PLTCL_UTF */ ObjectIdGetDatum(typelem), Int32GetDatum(tupdesc->attrs[attnum - 1]->atttypmod)); +#ifdef ENABLE_PLTCL_UTF + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ } rettup = SPI_modifytuple(trigdata->tg_relation, rettup, tupdesc->natts, @@ -1486,6 +1561,9 @@ HeapTuple *volatile tuples; volatile TupleDesc tupdesc = NULL; sigjmp_buf save_restart; +#ifdef ENABLE_PLTCL_UTF + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ char *usage = "syntax error - 'SPI_exec " "?-count n? " @@ -1558,7 +1636,12 @@ /************************************************************ * Execute the query and handle return codes ************************************************************/ +#ifndef ENABLE_PLTCL_UTF spi_rc = SPI_exec(argv[query_idx], count); +#else /* ENABLE_PLTCL_UTF */ + spi_rc = SPI_exec(Tcl_UtfToExternalDString(NULL,argv[query_idx],-1,&tmp), count); + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); switch (spi_rc) @@ -1717,6 +1800,9 @@ int hashnew; sigjmp_buf save_restart; Tcl_HashTable *query_hash; +#ifdef ENABLE_PLTCL_UTF + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ /************************************************************ * Don't do anything if we are already in restart mode @@ -1794,7 +1880,12 @@ /************************************************************ * Prepare the plan and check for errors ************************************************************/ +#ifndef ENABLE_PLTCL_UTF plan = SPI_prepare(argv[1], nargs, qdesc->argtypes); +#else /* ENABLE_PLTCL_UTF */ + plan = SPI_prepare(Tcl_UtfToExternalDString(NULL,argv[1],-1,&tmp), nargs, qdesc->argtypes); + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ if (plan == NULL) { @@ -1913,6 +2004,9 @@ volatile TupleDesc tupdesc = NULL; sigjmp_buf save_restart; Tcl_HashTable *query_hash; +#ifdef ENABLE_PLTCL_UTF + Tcl_DString tmp; +#endif /* ENABLE_PLTCL_UTF */ char *usage = "syntax error - 'SPI_execp " "?-nulls string? ?-count n? " @@ -2080,9 +2174,16 @@ { qdesc->argvalues[j] = FunctionCall3(&qdesc->arginfuncs[j], +#ifndef ENABLE_PLTCL_UTF CStringGetDatum(callargs[j]), +#else /* ENABLE_PLTCL_UTF */ + CStringGetDatum(Tcl_UtfToExternalDString(NULL,callargs[j],-1,&tmp)), +#endif /* ENABLE_PLTCL_UTF */ ObjectIdGetDatum(qdesc->argtypelems[j]), Int32GetDatum(qdesc->arglen[j])); +#ifdef ENABLE_PLTCL_UTF + Tcl_DStringFree(&tmp); +#endif /* ENABLE_PLTCL_UTF */ } /************************************************************ @@ -2303,7 +2404,11 @@ int tupno, HeapTuple tuple, TupleDesc tupdesc) { int i; +#ifndef ENABLE_PLTCL_UTF char *outputstr; +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString outputstr; +#endif /* ENABLE_PLTCL_UTF */ char buf[64]; Datum attr; bool isnull; @@ -2373,12 +2478,24 @@ ************************************************************/ if (!isnull && OidIsValid(typoutput)) { +#ifndef ENABLE_PLTCL_UTF outputstr = DatumGetCString(OidFunctionCall3(typoutput, attr, ObjectIdGetDatum(typelem), Int32GetDatum(tupdesc->attrs[i]->attlen))); Tcl_SetVar2(interp, *arrptr, *nameptr, outputstr, 0); pfree(outputstr); +#else /* ENABLE_PLTCL_UTF */ + Tcl_SetVar2(interp, *arrptr, *nameptr, + Tcl_ExternalToUtfDString(NULL, + DatumGetCString(OidFunctionCall3( + typoutput, + attr, + ObjectIdGetDatum(typelem), + Int32GetDatum(tupdesc->attrs[i]->attlen))), + -1,&outputstr), 0); + Tcl_DStringFree(&outputstr); +#endif /* ENABLE_PLTCL_UTF */ } else Tcl_UnsetVar2(interp, *arrptr, *nameptr, 0); @@ -2395,7 +2512,11 @@ Tcl_DString *retval) { int i; +#ifndef ENABLE_PLTCL_UTF char *outputstr; +#else /* ENABLE_PLTCL_UTF */ + Tcl_DString outputstr; +#endif /* ENABLE_PLTCL_UTF */ Datum attr; bool isnull; @@ -2443,13 +2564,27 @@ ************************************************************/ if (!isnull && OidIsValid(typoutput)) { +#ifndef ENABLE_PLTCL_UTF outputstr = DatumGetCString(OidFunctionCall3(typoutput, attr, ObjectIdGetDatum(typelem), Int32GetDatum(tupdesc->attrs[i]->attlen))); +#endif /* not ENABLE_PLTCL_UTF */ Tcl_DStringAppendElement(retval, attname); +#ifndef ENABLE_PLTCL_UTF Tcl_DStringAppendElement(retval, outputstr); pfree(outputstr); +#else /* ENABLE_PLTCL_UTF */ + Tcl_DStringAppendElement(retval, + Tcl_ExternalToUtfDString(NULL, + DatumGetCString(OidFunctionCall3(typoutput, + attr, + ObjectIdGetDatum(typelem), + Int32GetDatum(tupdesc->attrs[i]->attlen))), + -1,&outputstr) + ); + Tcl_DStringFree(&outputstr); +#endif /* ENABLE_PLTCL_UTF */ } } }