Skip to content
Tcl Source Code View Ticket
Login

View Ticket

bytearray object converted to string on searched by regexp

Closed / Wont Fix1402763fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2006-01-11 11:09:05
I consider the following a bug (in version 8.4.11)

set fd [open [select_file]]

# Although irrelevant, in the actual test case the file
selected is a pdf file.

fconfigure $fd -encoding binary -translation binary
set inp [read $fd]

# Here the type (and internal representation) of 'inp'
is 'bytearray' as it indeed should be.

regexp -- "stream\x0d\x0a(.+?)\x0d\endstream" $inp x frag

# Now the Tcl_Obj record that 'inp' refers to is the
same as above but the type now is
# 'string' and the value of both the 'bytes' and the
'internalRep' pointer is different from
# its previous value. The string the latter points to
seems to be in UCS-16 form.
# I did not check whether the string value had been
changed. If not why was it necessary to copy?

Joe Németh (NJG on wiki.tcl.tk)
dkfplain2006-01-11 18:43:49
Logged In: YES 
user_id=79902

Quite apart from the fact that you shouldn't be relying on
the internal rep of objects in the first place, it is still
reasonable to expect that REs would be able to use a
bytearray object without conversion (after all, all they
really need is constant time indexing).
hobbsplain2006-01-12 00:31:53
Logged In: YES 
user_id=72656

Regardless of what might be possible, this is 100% the
expected behavior.  The RE engine currently operates on
unicode strings.  It doesn't take bytearrays, it doesn't
take utf-8 strings - it wants unicode strings.
hobbs Ticket [1402763fff]: 2 changes [History diff]2006-01-12 00:31:54
dkfplain2006-01-12 04:43:49
Logged In: YES 
user_id=79902

Further review indicates that converting the RE engine core
to take either unicode arrays or bytecode arrays is
"impractical" (i.e. lots of work) since the base token size
is a rather deeply hard-coded concept.

Given that I (and Jeff too) have no intention of introducing
optimizations in this area, this is a definite Wont Fix. (We
have never guaranteed preservation of internal reps anyway!)
Log in (anonymous is fine) to add a comment.