2 * cdata.c - support functions for ktap_cdata
4 * This file is part of ktap by Jovi Zhangwei
6 * Copyright (C) 2012-2013 Jovi Zhangwei <jovi.zhangwei@gmail.com>.
8 * ktap is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * ktap is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "../../include/ktap_types.h"
24 #include "../../include/ktap_ffi.h"
25 #include "../kp_obj.h"
27 ktap_cdata *kp_cdata_new(ktap_state *ks)
31 cd = &kp_newobject(ks, KTAP_TCDATA, sizeof(ktap_cdata), NULL)->cd;
36 ktap_cdata *kp_cdata_new_ptr(ktap_state *ks, void *addr, csymbol_id id)
40 cd = kp_cdata_new(ks);
41 cd_set_csym_id(cd, id);
47 ktap_cdata *kp_cdata_new_struct(ktap_state *ks, void *val, csymbol_id id)
51 cd = kp_cdata_new(ks);
52 cd_set_csym_id(cd, id);
58 void kp_cdata_dump(ktap_state *ks, ktap_cdata *cd)
60 switch (cd_type(ks, cd)) {
62 kp_printf(ks, "pointer(%p)", cd_ptr(cd));
65 kp_printf(ks, "unsupported cdata type %d!\n", cd_type(ks, cd));