Skip to Content.
Sympa Menu

freetds - [freetds] new dstr changes

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: [freetds] new dstr changes
  • Date: Tue, 29 Aug 2006 17:26:36 +0200

Hi,
I'm trying to extend our small DSTR "library". Some reason for doing
so
- support for multi-byte string like ucs2. This will simplify string
handling in query.c. Mainly length is embedded in the string
- memory allocation, limited length setting. Useful for returning
strings without reallocating every time
Currently I added a dstr_len to DSTR_STRUCT getting something like

struct DSTR_STRUCT {
size_t dstr_len;
/* keep always at last */
char dstr_s[1];
};
typedef struct DSTR_STRUCT *DSTR;

(perhaps unsigned int or TDS_UINT is enough)

The buffer is always null terminated (there is a single NUL at end for C
compatibility)

Some questions before writing a new implementation raised in my mind:
- if a allocate a string with asprintf/strdup I have to reallocate
buffer to accomodate dstr_len, perhaps it would be better to define DSTR
as

struct DSTR_STRUCT {
size_t dstr_len;
char *dstr_s;
};
typedef struct DSTR_STRUCT DSTR;

or even

struct DSTR_STRUCT {
size_t dstr_len;
char *dstr_s;
};
typedef struct DSTR_STRUCT *DSTR;

(note that many tds_dstr_* return DSTR as NULL...)

I also noted that in code there is some code to use a static allocated
buffer if possible (bcp if I reminds correctly), perhaps something like

struct DSTR_STRUCT {
size_t dstr_len;
/** 1 allocated statically, do not reallocate 0 dynamically */
int dstr_static;
/* keep always at last */
char *dstr_s;
};

tds_dstr_init_static(DSTR * s, char* src, size_t len);

could help... the final question is always... which is the better?

freddy77





Archive powered by MHonArc 2.6.24.

Top of Page