24. Runtime
- Methodexit
void
exit(int
returncode
,void
|string
fmt
,mixed
...extra
)- Description
Exit the whole Pike program with the given
returncode
.Using
exit()
with any other value than0
(zero) indicates that something went wrong during execution. See your system manuals for more information about return codes.The arguments after the
returncode
will be used for a call towerror
to output a message on stderr.- See also
_exit()
- Method_exit
void
_exit(int
returncode
)- Description
This function does the same as
exit
, but doesn't bother to clean up the Pike interpreter before exiting. This means that no destructors will be called, caches will not be flushed, file locks might not be released, and databases might not be closed properly.Use with extreme caution.
- See also
exit()
- Methodatexit
void
atexit(function
(:void
)callback
)- Description
This function puts the
callback
in a queue of callbacks to call when pike exits. The call order is reversed, i.e. callbacks that have been added earlier are called aftercallback
.- Note
Please note that
atexit
callbacks are not called if Pike exits abnormally.- See also
exit()
,_exit()
- Methodtrace
int
trace(int
level
,void
|string
facility
,void
|int
all_threads
)- Description
This function changes the trace level for the subsystem identified by
facility
tolevel
. Iffacility
is zero or left out, it changes the global trace level which affects all subsystems.Enabling tracing causes messages to be printed to stderr. A higher trace level includes the output from all lower levels. The lowest level is zero which disables all trace messages.
See the -t command-line option for more information.
- Parameter
level
If
facility
is specified then there is typically only one trace level for it, i.e. it's an on-or-off toggle. The global trace levels, whenfacility
isn't specified, are:1
Trace calls to Pike functions and garbage collector runs.
2
Trace calls to builtin functions.
3
Trace every interpreted opcode.
4
Also trace the opcode arguments.
- Parameter
facility
Valid facilities are:
"gc"
Trace the doings of the garbage collector. The setting is never thread local.
level
has two different meanings:- 1..2
Trace the start and end of each gc run.
- 3..
Additionally show info about the collected garbage, to aid hunting down garbage problems. This currently shows gc'd trampolines. Note that the output can be very bulky and is somewhat low-level technical. Also note that pike currently has to be configured with
--with-rtldebug
to enable this.
- Parameter
all_threads
Trace levels are normally thread local, so changes affect only the current thread. To change the level in all threads, pass a nonzero value in this argument.
- Returns
The old trace level in the current thread is returned.
- Methodbacktrace
array
(Pike.BacktraceFrame
) backtrace(int
|void
flags
)- Description
Get a description of the current call stack.
- Parameter
flags
A bit mask of flags affecting generation of the backtrace.
Currently a single flag is defined:
1
Return
LiveBacktraceFrame
s. This flag causes the frame objects to track changes (as long as they are in use), and makes eg local variables for functions available for inspection or change.Note that since these values are "live", they may change or dissapear at any time unless the corresponding thread has been halted or similar.
- Returns
The description is returned as an array with one entry for each call frame on the stack.
The entries are represented by
Pike.BacktraceFrame
objects.The current call frame will be last in the array.
- Note
Please note that the frame order may be reversed in a later version of Pike to accommodate for deferred backtraces.
- Note
Note that the arguments reported in the backtrace are the current values of the variables, and not the ones that were at call-time. This can be used to hide sensitive information from backtraces (eg passwords).
- Note
In old versions of Pike the entries used to be represented by arrays of the following format:
Array string
file
A string with the filename if known, else zero.
int
line
An integer containing the linenumber if known, else zero.
function
(:void
)fun
The function that was called at this level.
mixed
|void
...args
The arguments that the function was called with.
The above format is still supported by eg
describe_backtrace()
.- See also
catch()
,throw()
- Methodgc
int
gc(mapping
|array
|void
quick
)- Description
Force garbage collection.
- Parameter
quick
Perform a quick garbage collection on just this value, which must have been made weak by
set_weak_flag()
. All values that only have a single reference fromquick
will then be freed.When
quick
hasn't been specified or isUNDEFINED
, this function checks all the memory for cyclic structures such as arrays containing themselves and frees them if appropriate. It also frees up destructed objects and things with only weak references.Normally there is no need to call this function since Pike will call it by itself every now and then. (Pike will try to predict when 20% of all arrays/object/programs in memory is 'garbage' and call this routine then.)
- Returns
The amount of garbage is returned. This is the number of arrays, mappings, multisets, objects and programs that had no nonweak external references during the garbage collection. It's normally the same as the number of freed things, but there might be some difference since _destruct() functions are called during freeing, which can cause more things to be freed or allocated.
- See also
Pike.gc_parameters
,Debug.gc_status
- Methodquery_num_arg
int
query_num_arg()- Description
Returns the number of arguments given when the previous function was called.
This is useful for functions that take a variable number of arguments.
- See also
call_function()