For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > Re: Is there a way to dynamically determine (in 'c') if an Tcl_Obj is









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Is there a way to dynamically determine (in 'c') if an Tcl_Obj is
thelfter@gmail.com

2007-11-25, 7:18 pm

On Nov 25, 12:32 pm, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:
> Todd Helfter wrote:
>
> It works with arrays of Tcl_UniChar values. Those are *usually*
> sixteen bits wide, but can be configured to be larger. We don't
> recommend it!
>
>
> Do me a favour and don't confuse me either...
>
>
> You're doing a Tcl_GetString call followed by a strlen? Just use
> Tcl_GetStringFromObj instead. :-)
>
> Donal.


Hi Donal.

I'm not doing a Tcl_GetString. I was trying to 'generalize'....

Sigh.

I'm clearly failing to communicate my question in a meaningful way.

How about a code example.

snip ....

5200 char *arg_pcp = NULL;
5201 Tcl_UniChar *arg_upcp = NULL;

snip ....

5277 if (StmPtr->unicode) {
5278 arg_upcp = Tcl_GetUnicodeFromObj(objv[parm_cnt + 1],
&arg_pcp_len);
5279 } else {
5280 arg_pcp = Tcl_GetStringFromObj(objv[parm_cnt + 1],
&arg_pcp_len);
5281 }

snip ....

5340 /* allocate adequate space for reuse */
5341 tmp_col->column.valuesz = StmPtr->bindsize;
5342 if (StmPtr->unicode) {
5343 tmp_col->column.valuep = ckalloc((tmp_col->column.valuesz
+1) * sizeof(utext));
5344 } else {
5345 tmp_col->column.valuep = ckalloc(tmp_col->column.valuesz +
1);
5346 }

snip ....

Note * copy contents of Tcl_Obj to non-tcl memory space, as the oracle
library likes to mess around with this space.

5371 } else if (StmPtr->unicode) {
5372 memcpy(tmp_col->column.valuep,
5373 arg_upcp,
5374 ((arg_pcp_len+1)*sizeof(utext)));
5375 tmp_col->column.valuep[arg_pcp_len*sizeof(utext)] = L'\0';
5376 } else {
5377 memcpy(tmp_col->column.valuep,
5378 arg_pcp,
5379 arg_pcp_len);
5380 tmp_col->column.valuep[arg_pcp_len] = '\0';
5381 }

snip ....
NOTE that different parameters and additional OCI functions must be
used for a unicode/ucs-2 string.

5409 if (StmPtr->unicode) {
5410 mybindmax = (tmp_col->column.valuesz+1)*sizeof(utext);
5411 rc = OCI_BindByName(StmPtr->stmhp,
5412 (OCIBind **) &tmp_col->bindp,
5413 LogPtr->errhp,
5414 (text *) tmp_col->column.name,
5415 (sb4) tmp_col->column.namesz,
5416 (dvoid *) tmp_col->column.valuep,
5417 (ub4) mybindmax,
5418 (ub2) SQLT_STR,
5419 (dvoid *) &tmp_col->indp[0],
5420 (ub2 *) 0,
5421 (ub2 *) 0,
5422 (ub4) 0,
5423 (ub4 *) 0,
5424 (ub4) OCI_DEFAULT);
5425
5426 if (rc != OCI_SUCCESS) {
5427 Oratcl_Checkerr(interp,
5428 LogPtr->errhp,
5429 rc,
5430 1,
5431 &StmPtr->ora_rc,
5432 &StmPtr->ora_err);
5433 Oratcl_ColFree(tmp_col_head);
5434 StmPtr->bind_list = NULL;
5435 tcl_return = TCL_ERROR;
5436 goto common_exit;
5437 }
5438
5439 (void) OCI_AttrSet((dvoid *) tmp_col->bindp,
5440 OCI_HTYPE_BIND,
5441 &myucs2id,
5442 0,
5443 OCI_ATTR_CHARSET_ID,
5444 LogPtr->errhp);
5445 (void) OCI_AttrSet((dvoid *) tmp_col->bindp,
5446 OCI_HTYPE_BIND,
5447 &mybindmax,
5448 0,
5449 OCI_ATTR_MAXDATA_SIZE,
5450 LogPtr->errhp);
5451
5452 } else {
5453 rc = OCI_BindByName(StmPtr->stmhp,
5454 (OCIBind **) &tmp_col->bindp,
5455 LogPtr->errhp,
5456 (text *) tmp_col->column.name,
5457 (sb4) tmp_col->column.namesz,
5458 (dvoid *) tmp_col->column.valuep,
5459 (sb4) tmp_col->column.valuesz + 1,
5460 (ub2) SQLT_STR,
5461 (dvoid *) &tmp_col->indp[0],
5462 (ub2 *) 0,
5463 (ub2 *) 0,
5464 (ub4) 0,
5465 (ub4 *) 0,
5466 (ub4) OCI_DEFAULT);
5467 }


snip ....

so right now all my code is controlled by a 'unicode' flag that I'm
setting.

And my question is, should I just use wide characters all the time and
bail on the simple ascii '1 char = 1 byte' model.

-Todd
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com