pike.git
/
src
/
program.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/program.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: program.c,v 1.
614
2007/05/13
14
:
55
:
26
mast Exp $
+
|| $Id: program.c,v 1.
615
2007/05/13
15
:
45
:
32
mast Exp $
*/ #include "global.h" #include "program.h" #include "object.h" #include "dynamic_buffer.h" #include "pike_types.h" #include "stralloc.h" #include "las.h" #include "lex.h"
pike.git/src/program.c:3429:
for(e=0;e<Pike_compiler->new_program->num_inherits;e++) Pike_compiler->new_program->inherits[e].storage_offset+=available; Pike_compiler->new_program->storage_needed+=available; } return (size_t) offset; } typedef void (*oldhandlertype)(struct object *);
-
static
void compat_event_handler(int e)
+
+
/*
Function pointer checked by gc_object_is_live. */
+
void compat_event_handler(int e)
{ oldhandlertype handler; debug_malloc_touch(Pike_fp->current_object); handler=((oldhandlertype *)Pike_fp->context.prog->program)[e]; if(handler) handler(Pike_fp->current_object); debug_malloc_touch(Pike_fp->current_object); } static void add_compat_event_handler(void) {
pike.git/src/program.c:3460:
#else /* !HAVE_COMPUTED_GOTO */ for(e=0;e<sizeof(Pike_compiler->new_program->event_handler);e++) add_to_program(tmp[e]); #endif /* HAVE_COMPUTED_GOTO */ } Pike_compiler->new_program->event_handler=compat_event_handler; } } /*
-
*
set
a callback
used
to
initialize
clones
of
this program
-
* the init function
is
called
at clone time
-
* This function is obsolete
,
use
pike_set_prog_event_callback
instead
.
+
*
Set
a callback to
be
called
when
this program is
cloned.
+
*
+
* This function is
almost
obsolete
;
see
pike_set_prog_event_callback
+
* for details
.
*/ PMOD_EXPORT void set_init_callback(void (*init)(struct object *)) { add_compat_event_handler(); ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_INIT]=init; } /*
-
*
set
a callback
used
to
de-initialize
clones of this program
-
*
the
exit function is called at destruct
-
* This function is obsolete
,
use
pike_set_prog_event_callback
instead
.
+
*
Set
a callback to
be
called when
clones of this program
are
+
*
destructed.
+
*
+
* This function is
almost
obsolete
;
see
pike_set_prog_event_callback
+
* for details
.
*/ PMOD_EXPORT void set_exit_callback(void (*exit)(struct object *)) { add_compat_event_handler(); ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_EXIT]=exit; } /* * This callback is used by the gc to traverse all references to * objects. It should call some gc_recurse_* function exactly once for
pike.git/src/program.c:3496:
* If a reference is shared between objects, it should be traversed * once for every instance sharing it. * * The callback might be called more than once for the same instance * during a gc pass. The gc assumes that the references are enumerated * in the same order in that case. * * The callback is called after any mapped variables on the object * have been recursed (and possibly freed). *
-
* This function is obsolete
,
use
pike_set_prog_event_callback
instead
.
+
* This function is
almost
obsolete
;
see
pike_set_prog_event_callback
+
* for details
.
*/ PMOD_EXPORT void set_gc_recurse_callback(void (*m)(struct object *)) { add_compat_event_handler(); ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_GC_RECURSE]=m; } /* * This callback is used by the gc to count all references to objects. * It should call gc_check, gc_check_(weak_)svalues or * gc_check_(weak_)short_svalue exactly once for each reference that * the pike internals doesn't know about. * * If a reference is shared between objects, it should be counted once * for all shared instances. The return value from gc_check is useful * to ensure this; it's zero when called the first time for its * argument. *
-
* This function is obsolete
,
use
pike_set_prog_event_callback
instead
.
+
* This function is
almost
obsolete
;
see
pike_set_prog_event_callback
+
* for details
.
*/ PMOD_EXPORT void set_gc_check_callback(void (*m)(struct object *)) { add_compat_event_handler(); ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_GC_CHECK]=m; }
-
+
/*
+
* Set a callback to be called when any of the special program events
+
* occur. The event type is sent as an integer argument. The events
+
* include, but might not be limited to, the following:
+
*
+
* PROG_EVENT_INIT
+
* An object is being cloned from the program. See set_init_callback
+
* for details.
+
* PROG_EVENT_EXIT
+
* An object is being destructed. See set_exit_callback for details.
+
* PROG_EVENT_GC_RECURSE
+
* An object is being recursed by the gc. See
+
* set_gc_recurse_callback for details.
+
* PROG_EVENT_GC_CHECK
+
* An object is being checked by the gc. See set_gc_check_callback
+
* for details.
+
*
+
* Using this instead of the set_*_callback functions saves some space
+
* in the program (four function pointers) and is a bit more
+
* efficient.
+
*
+
* Otoh, it forces the gc to handle all clones as "live" since the
+
* callback might act on PROG_EVENT_EXIT. So if there's no need to do
+
* anything for that event, using the set_*_callback functions allows
+
* the gc to handle the object more efficiently if it occurs in
+
* cycles.
+
*/
PMOD_EXPORT void pike_set_prog_event_callback(void (*cb)(int)) { #ifdef PIKE_DEBUG if(Pike_compiler->new_program->event_handler) Pike_fatal("Program already has an event handler!\n"); #endif Pike_compiler->new_program->event_handler=cb; } PMOD_EXPORT void pike_set_prog_optimize_callback(node *(*opt)(node *))