Skip to Content.
Sympa Menu

freetds - RE: [freetds] pbcb: replacing strcpy(3)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] pbcb: replacing strcpy(3)
  • Date: Thu, 8 May 2003 10:02:23 -0400

> From: Frediano Ziglio [mailto:freddyz77 AT tin.it]
> Sent: May 8, 2003 2:24 AM
> Il gio, 2003-05-08 alle 06:51, James K.Lowden ha scritto:
>
> James, dstr_* was designed to be extended in such way...

Yes, I thought that might be the case. Honestly, I don't like the opacity
of DSTR, nor the casts, and I'm not convinced of the advantage of never
pointing to NULL. I realize those could all be fixed, but you seem to think
they're good things.... :-) I'd like a more transparent, less manhandled
approach.

Still, I think we should all discuss this. However we address counted
strings, they're going to be a pervasive metaphor, and it would be nice if
we all liked the way they're done.

I've thought many times of adding a C++ module to use basic_string<>. That
to me would be the most elegant approach, but at a heavy cost of
dependencies and, I fear, portability. I'm not aware of a generalized
standalone counted string library for C, something that would happy dealing
in UCS-2, and that ideally could engage iconv.

> TDS_PBCB* pbcb_cpy (iconv_t cd, TDS_PBCB* dest, const TDS_PBCB* src);
> TDS_PBCB* pbcb_strcpy (iconv_t cd, TDS_PBCB* pbcb, const char *src);
>
> Why pass iconv_t just to copy a buffer?

Not just to copy a buffer, to convert a buffer. If cd == -1, copy. Else
use iconv to convert from src to dest.

I think perhaps rather than returning a pointer, the functions should return
inbytesleft from iconv (normally 0). If nonzero, the caller can examine
errno and decide what to do.

> All I need (in query.c) is a function to return byte count of
> converted
> string... Something like tds_get_converted_length(TDSICONVINFO * ic,
> const char* s, size_t length);

We could do that, it's true. The advantage of your idea is that there's no
buffer allocation.

I think it's a very loose design, though: here we use iconv to count the
length of the converted string (discarding the output), there we call
tds_put_string() and expect it to do the same conversion. For every
tds_put_string(), two independent calls to iconv() in two different
functions.

For all data except [n]text, the maximum buffer size is 8000 bytes; for
metadata, 512 bytes. For that reason, I would avoid malloc(3), favoring
fixed buffers instead. Let iconv convert once, preserve the output, send
the length and the data as required by the protocol. That would require
e.g. tds_submit_query() to maintain 3 such buffers, but I think that's a
good trade-off for the simplicity.

Regards,

--jkl


The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that we do not accept account orders and/or
instructions by e-mail, and therefore will not be responsible for carrying
out such orders and/or instructions.






Archive powered by MHonArc 2.6.24.

Top of Page