lua-users home
lua-l archive

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



Would the userdata approach allow bygone string arguments to be GC'ed?

If it does, it would have a slight benefit towards the current make- table-up-front approach. Then again, if strings could be pushed in C saying "this memory will always be there", there wouldn't be much difference again.

In other words, could Lua have a 'lua_pushstring()' that does not make a copy of the string contents but uses the ones in ROM/argv that the code author says won't ever vanish. I believe that would be welcome in 5.2?

LUA_API void (lua_pushlstring_fixed) (lua_State *L, const char *s, size_t l);

and

#define lua_pushliteral(L, s)	\
	lua_pushlstring_fixed(L, "" s, (sizeof(s)/sizeof(char))-1)

-asko


Gé Weijers kirjoitti 20.12.2007 kello 8:27:

This is a bit of a problem.

Alternatively the arguments could be passed in as a single argument, i.e. an array, or a userdata object pretending to be a read-only array (implementing the length and index operations). The userdata object would not require the allocation of a potentially massive array to store a copy of the argument vector, but would copy the contents of 'argv' to the lua interpreter one string at a time.

The worst case argument vector would be about ARG/MAX zero-byte strings, which would require LUAI_MAXCSTACK to be equal to ARG_MAX, i.e. insanely large.

Gé

On Dec 19, 2007, at 4:03 PM, Norman Ramsey wrote:

Package: lua5.1
Version: 5.1.2-4
Severity: normal

I just got this rather unhappy result:

: nr@homedog 10445 ; label-by-hand -udir /home/nr/tmp/tt2 *
lua5.1: stack overflow (too many arguments to script)


It seems to me that the Lua interpreter should accept as many
arguments as the local operating system is willing to provide.  This
number is fairly fuzzy (see http://tinyurl.com/nn8yd for a good
discussion of the issues), but the current default of 2048 is
unreasonably small for a stock Debian system.  ARG_MAX is 131072 on
this system, so supposing we assume each argument is an 8.3 pathname
with a trailing null, even leaving room for some environment this is
space for about ten thousand arguments.  I suggest that when Lua is
built for Debian that line 445 of luaconf.h be changed so that
LUAI_MAXCSTACK is more in that range.


Norman


-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable'), (50, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.22-3-k7 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages lua5.1 depends on:
ii libc6 2.7-3 GNU C Library: Shared libraries ii libreadline5 5.2-3 GNU readline and history libraries

lua5.1 recommends no packages.

-- no debconf information

--
Gé Weijers
ge@weijers.org