pike.git
/
src
/
constants.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/constants.c:9:
#include "pike_macros.h" #include "program.h" #include "pike_types.h" #include "stralloc.h" #include "pike_memory.h" #include "interpret.h" #include "mapping.h" #include "pike_error.h" #include "pike_security.h" #include "gc.h"
+
#include "block_allocator.h"
-
#include "block_alloc.h"
-
+
struct mapping *builtin_constants = 0; #ifdef PIKE_DEBUG struct callable *first_callable = NULL; #endif
-
+
/* This is the mapping returned by all_constants(). */
PMOD_EXPORT struct mapping *get_builtin_constants(void) { return builtin_constants; } void low_add_efun(struct pike_string *name, struct svalue *fun) { struct svalue s; SET_SVAL(s, T_STRING, 0, string, name);
pike.git/src/constants.c:61:
free_string(key); } PMOD_EXPORT void add_global_program(const char *name, struct program *p) { struct svalue s; SET_SVAL(s, T_PROGRAM, 0, program, p); low_add_constant(name, p?&s:NULL); }
-
#undef
INIT_BLOCK
-
#define
INIT
_
BLOCK(X)
do { \
-
DO
_
IF
_
DEBUG
(
DOUBLELINK
(
first_
callable,
X
)
)
;
\
-
} while (0)
+
static
struct block
_
allocator
callable
_
allocator
+
=
BA
_
INIT
_
PAGES
(
sizeof(struct
callable
)
,
2
);
-
#undef
EXIT
_
BLOCK
-
#define EXIT
_
BLOCK
(
X)
do
{
\
-
DO
_
IF_
DEBUG
(
DOUBLEUNLINK (first_callable,
X
)
)
;
\
-
free_type(
X
->type);
\
-
free_string(
X
->name);
\
-
X
->name=0;
\
-
EXIT_PIKE_MEMOBJ(
X
);
\
-
}while
(
0
)
+
void
really
_
free
_
callable
(
struct
callable
*
c)
{
+
#ifdef
PIKE_DEBUG
+
DOUBLEUNLINK (first_callable,
c
);
+
#endif
+
free_type(
c
->type);
+
free_string(
c
->name);
+
c
->name=0;
+
EXIT_PIKE_MEMOBJ(
c
);
+
ba_free(&callable_allocator,
c);
+
}
-
BLOCK
_
ALLOC
_
FILL
_
PAGES
(callable,
2
)
+
void count
_
memory
_
in
_
callables
(
size_t * num, size_t * size) {
+
ba_count_all(&
callable
_allocator
,
num, size
)
;
+
}
+
void free_all_callable_blocks() {
+
ba_destroy(&callable_allocator);
+
}
int global_callable_flags=0; /* Eats one ref to 'type' and 'name' */ PMOD_EXPORT struct callable *low_make_callable(c_fun fun, struct pike_string *name, struct pike_type *type, int flags, optimize_fun optimize, docode_fun docode) {
-
struct callable *f=
alloc
_callable();
+
struct callable *f=
(struct callable*)ba_
alloc
(&callable
_
allocator);
+
#ifdef PIKE_DEBUG
+
DOUBLELINK(first_
callable
, f
);
+
#endif
INIT_PIKE_MEMOBJ(f, T_STRUCT_CALLABLE); f->function=fun; f->name=name; f->type=type; f->prog=Pike_compiler->new_program; f->flags=flags; f->docode=docode; f->optimize=optimize; f->internal_flags = global_callable_flags; #ifdef PIKE_DEBUG
pike.git/src/constants.c:152:
free_string(n); } PMOD_EXPORT void add_efun(const char *name, c_fun fun, const char *type, int flags) { add_efun2(name,fun,type,flags,0,0); } PMOD_EXPORT void quick_add_efun(const char *name, ptrdiff_t name_length, c_fun fun,
-
const char *type, ptrdiff_t type_length,
+
const char *type, ptrdiff_t
UNUSED(
type_length
)
,
int flags, optimize_fun optimize, docode_fun docode) { struct svalue s; struct pike_string *n; struct pike_type *t; #ifdef PIKE_DEBUG if(simple_mapping_string_lookup(builtin_constants, name))
pike.git/src/constants.c:206:
visit_string_ref (c->name, REF_TYPE_NORMAL); } /* Looks like the c->prog isn't refcounted..? */ /* visit_program_ref (c->prog, REF_TYPE_NORMAL); */ } #ifdef PIKE_DEBUG void present_constant_profiling(void) {
-
struct callable
_block
*
b
;
-
size_t e;
-
for(
b
=
callable
_
blocks
;
b
;
b=b->next)
-
{
-
for(e
=
0;e<NELEM(b->x);e++)
-
{
-
if(b
->
x[e].name
)
-
{
-
fprintf(stderr,"%010ld @E@: %s\n",
b
->
x[e].
runs,
b
->
x[e].
name->str);
+
struct callable *
c
;
+
for
(c
=
first_
callable;
c
;
c
=
c
->
next
) {
+
fprintf(stderr,"%010ld @E@: %s\n",
c
->runs,
c
->name->str);
} }
-
}
-
}
+
#endif void init_builtin_constants(void) { builtin_constants = allocate_mapping(300); } void exit_builtin_constants(void) { #ifdef DO_PIKE_CLEANUP if(builtin_constants) { free_mapping(builtin_constants); builtin_constants=0; } #endif }