pike.git/
src/
constants.c
Branch:
Tag:
Non-build tags
All tags
No tags
1997-01-27
1997-01-27 01:11:27 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
244ce6ed005589b28f315164ff73d4b416472ffe (
94
lines) (+
21
/-
73
)
[
Show
|
Annotate
]
Branch:
7.9
global constants are now stored in mappings
Rev: src/constants.c:1.6
Rev: src/constants.h:1.3
11:
#include "stralloc.h" #include "memory.h" #include "interpret.h"
+
#include "mapping.h"
-
static struct hash_table *efun_hash = 0;
+
static INT32 num_callable=0;
-
+
static struct mapping *builtin_constants = 0;
-
struct
efun
*
lookup
_
efun(struct pike
_
string *name
)
+
struct
mapping
*
get
_
builtin_constants
()
{
-
struct hash
_
entry
*h
;
+
if(!builtin_constants)
+
builtin
_
constants=allocate_mapping(20)
;
-
if(!efun_hash)
return
0;
-
h=hash
_
lookup(efun_hash, name)
;
-
if(!h) return 0;
-
return BASEOF(h, efun, link);
+
return
builtin
_
constants
;
} void low_add_efun(struct pike_string *name, struct svalue *fun) {
-
struct
efun
*parent
;
+
struct
svalue
s
;
-
parent
=
lookup
_
efun
(
name
);
+
if(!builtin_constants)
+
builtin_constants
=
allocate
_
mapping
(
20
);
-
if(!parent)
-
{
-
if(!fun) return
;
+
s.type=T_STRING;
+
s.subtype=0;
+
s.u.string=name
;
-
parent=ALLOC_STRUCT(efun);
-
copy_shared_string(parent->link.s,name);
-
efun_hash=hash_insert(efun_hash, &parent->link);
-
}else{
-
free_svalue(& parent->function);
-
-
/* Disable efun */
-
if(
!
fun)
+
if(fun)
{
-
efun
_
hash=hash_unlink
(
efun
_
hash
, &
parent->link
);
-
free
_
string
(
parent->link.
s);
-
free((char *)parent);
-
return;
+
mapping
_
insert
(
builtin
_
constants
, &
s, fun
);
+
}else{
+
map
_
delete
(
builtin_constants, &
s);
} }
-
assign_svalue_no_free(& parent->function, fun);
-
}
-
-
+
struct callable *make_callable(c_fun fun, char *name, char *type,
107:
add_efun2(name,fun,type,flags,0,0); }
-
static void push_efun_entry(struct hash_entry *h)
-
{
-
struct efun *f;
-
check_stack(1);
-
f=BASEOF(h, efun, link);
-
push_string(f->link.s);
-
f->link.s->refs++;
-
copy_svalues_recursively_no_free(sp,& f->function,1,0);
-
sp++;
-
}
-
-
void push_all_efuns_on_stack()
-
{
-
if(efun_hash)
-
map_hashtable(efun_hash,push_efun_entry);
-
}
-
-
static void free_one_hashtable_entry(struct hash_entry *h)
-
{
-
struct efun *f;
-
f=BASEOF(h, efun, link);
-
free_svalue(& f->function);
-
free((char *)f);
-
}
-
+
void cleanup_added_efuns() {
-
if(
efun
_
hash
)
+
if(
builtin
_
constants
)
{
-
free_
hashtable
(
efun
_
hash,free_one_hashtable_entry
);
-
efun
_
hash
=0;
+
free_
mapping
(
builtin
_
constants
);
+
builtin
_
constants
=0;
}
-
+
}
-
-
void count_memory_in_constants(INT32 *num_, INT32 *size_)
-
{
-
INT32 size=0, num=0;
-
if(efun_hash)
-
{
-
size=sizeof(struct hash_table) +
-
efun_hash->mask*sizeof(struct hash_entry)+
-
efun_hash->entries*sizeof(struct efun);
-
num=efun_hash->entries;
-
}
-
*num_=num;
-
*size_=size;
-
}
-
+
void count_memory_in_callables(INT32 *num_, INT32 *size_) { *num_=num_callable; *size_=num_callable*sizeof(struct callable); }