1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2010 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Common Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.opensource.org/licenses/cpl1.0.txt * 11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * Phong Vo <kpv@research.att.com> * 20 * * 21 ***********************************************************************/ 22 #pragma prototyped 23 24 /* 25 * dtopen() with handle placed in specific vm region 26 */ 27 28 #include <dt.h> 29 30 typedef struct Dc_s 31 { 32 Dtdisc_t ndisc; 33 Dtdisc_t* odisc; 34 Vmalloc_t* vm; 35 } Dc_t; 36 37 static int 38 eventf(Dt_t* dt, int op, void* data, Dtdisc_t* disc) 39 { 40 Dc_t* dc = (Dc_t*)disc; 41 int r; 42 43 if (dc->odisc->eventf && (r = (*dc->odisc->eventf)(dt, op, data, dc->odisc))) 44 return r; 45 return op == DT_ENDOPEN ? 1 : 0; 46 } 47 48 static void* 49 memoryf(Dt_t* dt, void* addr, size_t size, Dtdisc_t* disc) 50 { 51 return vmresize(((Dc_t*)disc)->vm, addr, size, VM_RSMOVE); 52 } 53 54 /* 55 * open a dictionary using disc->memoryf if set or vm otherwise 56 */ 57 58 Dt_t* 59 dtnew(Vmalloc_t* vm, Dtdisc_t* disc, Dtmethod_t* meth) 60 { 61 Dt_t* dt; 62 Dc_t dc; 63 64 dc.odisc = disc; 65 dc.ndisc = *disc; 66 dc.ndisc.eventf = eventf; 67 if (!dc.ndisc.memoryf) 68 dc.ndisc.memoryf = memoryf; 69 dc.vm = vm; 70 if (dt = dtopen(&dc.ndisc, meth)) 71 dtdisc(dt, disc, DT_SAMECMP|DT_SAMEHASH); 72 return dt; 73 } 74