/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* dtopen() with handle placed in specific vm region25*/2627#include <dt.h>2829typedef struct Dc_s30{31Dtdisc_t ndisc;32Dtdisc_t* odisc;33Vmalloc_t* vm;34} Dc_t;3536static int37eventf(Dt_t* dt, int op, void* data, Dtdisc_t* disc)38{39Dc_t* dc = (Dc_t*)disc;40int r;4142if (dc->odisc->eventf && (r = (*dc->odisc->eventf)(dt, op, data, dc->odisc)))43return r;44return op == DT_ENDOPEN ? 1 : 0;45}4647static void*48memoryf(Dt_t* dt, void* addr, size_t size, Dtdisc_t* disc)49{50return vmresize(((Dc_t*)disc)->vm, addr, size, VM_RSMOVE);51}5253/*54* open a dictionary using disc->memoryf if set or vm otherwise55*/5657Dt_t*58_dtnew(Vmalloc_t* vm, Dtdisc_t* disc, Dtmethod_t* meth, unsigned long version)59{60Dt_t* dt;61Dc_t dc;6263dc.odisc = disc;64dc.ndisc = *disc;65dc.ndisc.eventf = eventf;66if (!dc.ndisc.memoryf)67dc.ndisc.memoryf = memoryf;68dc.vm = vm;69if (dt = _dtopen(&dc.ndisc, meth, version))70dtdisc(dt, disc, DT_SAMECMP|DT_SAMEHASH);71return dt;72}7374#undef dtnew7576Dt_t*77dtnew(Vmalloc_t* vm, Dtdisc_t* disc, Dtmethod_t* meth)78{79return _dtnew(vm, disc, meth, 20050420L);80}818283