lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Jan 06, 2012 at 11:00:11PM -0700, HyperHacker wrote:
> On Fri, Jan 6, 2012 at 12:17, Roberto Ierusalimschy
<snip>
> > I do not see a simple way to write this in a portable way (respecting
> > alignment requirements for word access). For strings already internal to
> > Lua we know about their alignment, but external strings (the ones to be
> > internalized) may start anywhere. We would need to do some arithmetic
> > with addresses, something invalid in ANSI C.
> >
> > -- Roberto
> >
> 
> That seems terribly amusing, given that C is supposed to be low-level.
> There's no way to convert the address to an integer and slow-copy the
> first few bytes until we're at an aligned address?

Yes and no. In environments like Unix and Win32 this is perfectly fine as
long as your stride and alignment are less than the page size. But reading
even single byte beyond a malloc'd region is undefined behavior in ISO C,
and of course Lua strives to adhere to the C standard. There may very well
be environments where doing so could cause things to go sideways. Also, it
would cause Valgrind to pitch a fit, and in my book anything which makes
Valgrind bothersome to use had better be exceptionally worthwhile.