⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inspect.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
strINSPECTgetSignature(int *ret, str *mod, str *fcn){	Symbol s;	char buf[BUFSIZ];	str ps, tail;	BAT *b = BATnew(TYPE_str, TYPE_str, 12);	if (b == 0)		throw(MAL, "inspect.getSignature", "failed to create BAT");	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	if (s == 0)		throw(MAL, "inspect.getSignature", "failed to find <module>.<function>");	snprintf(buf,BUFSIZ,"%s.%s",*mod,*fcn);	while (s != NULL) {		if (idcmp(s->name, *fcn) == 0) {			char *c, *w;			ps = instruction2str(s->def, getSignature(s), 0);			c = strchr(ps, '(');			if (c == 0)				continue;			tail= strstr(c,"address");			if( tail)				*tail = 0;			if (tail && (w=strchr(tail, ';')) )				*w = 0;			BUNins(b, buf, c, FALSE);			GDKfree(ps);		}		s = s->peer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_input_result") <= 0)		BATname(b, "view_input_result");	BATroles(b,"view","input");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 530 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTgetAddress(int *ret, str *mod, str *fcn){	Symbol s;	char buf[BUFSIZ];	str ps, tail;	BAT *b = BATnew(TYPE_str, TYPE_str, 12);	if (b == 0)		throw(MAL, "inspect.getAddress", "failed to create BAT");	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	if (s == 0)		throw(MAL, "inspect.getAddress", "failed to find <module>.<function>");	snprintf(buf,BUFSIZ,"%s.%s",*mod,*fcn);	while (s != NULL) {		if (idcmp(s->name, *fcn) == 0) {			char *c,*w;			ps = instruction2str(s->def, getSignature(s), 0);			c = strchr(ps, '(');			if (c == 0)				continue;			tail= strstr(c,"address");			if( tail){				*tail = 0;				for( tail=tail+7; isspace((int) *tail); tail++)  ;			}			if (tail && (w=strchr(tail, ';')) )				*w = 0;			BUNins(b, buf, (tail? tail: "nil"), FALSE);			GDKfree(ps);		}		s = s->peer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_input_result") <= 0)		BATname(b, "view_input_result");	BATroles(b,"view","input");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 571 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTgetComment(int *ret, str *mod, str *fcn){	Symbol s;	char buf[BUFSIZ];	BAT *b = BATnew(TYPE_str, TYPE_str, 12);	if (b == 0)		throw(MAL, "inspect.getSignature", "failed to create BAT");	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	if (s == 0)		throw(MAL, "inspect.getSignature", "failed to find <module>.<function>");	snprintf(buf,BUFSIZ,"%s.%s",*mod,*fcn);	while (s != NULL) {		if (idcmp(s->name, *fcn) == 0) {			BUNins(b, buf, s->def->help, FALSE);		}		s = s->peer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_input_result") <= 0)		BATname(b, "view_input_result");	BATroles(b,"view","input");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 597 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTgetSource(str *ret, str *mod, str *fcn){	Symbol s;	char *buf;	size_t len,lim;	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	if (s == 0)		throw(MAL, "inspect.getSignature", 			"Failed to find <module>.<function>");	buf= (char*) GDKmalloc(BUFSIZ);	snprintf(buf,BUFSIZ,"%s.%s",*mod,*fcn);	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	buf[0]=0;	len= 0;	lim= BUFSIZ;	while (s) {		int i;		str ps;		for (i = 0; i < s->def->stop; i++) {			ps = instruction2str(s->def, getInstrPtr(s->def, i), 0);			if( strlen(ps) >= lim-len){				/* expand the buffer */				char *bn;				bn= GDKmalloc(lim+BUFSIZ);				strcpy(bn,buf);				GDKfree(buf);				buf=bn;				lim+= BUFSIZ;			}			strcat(buf+len,ps+1);			len+= strlen(ps)-1;			buf[len++]='\n';			buf[len]=0;			GDKfree(ps);		}		s = s->peer;	}	*ret= buf;	return MAL_SUCCEED;}strINSPECTsymbolType(int *ret, str *mod, str *fcn){	Symbol s;	BAT *b = BATnew(TYPE_str, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getType", "failed to create BAT");	s = findMALSymbol(*mod, *fcn);	if (s == 0)		throw(MAL, "inspect.getSignature", "failed to find <module>.<function>");	while (s != NULL) {		if (idcmp(s->name, *fcn) == 0) {			str t = getTypeName(getDestType(s->def, getSignature(s)));			BUNins(b, s->name, t, FALSE);			GDKfree(t);		}		s = s->peer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_fcn_type") <= 0)		BATname(b, "view_fcn_type");	BATroles(b,"view","fcn");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 668 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTatom_names(int *ret){	int i;	BAT *b = BATnew(TYPE_int, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getAtomNames", "failed to create BAT");	for (i = 0; i < GDKatomcnt; i++)		BUNins(b, &i, ATOMname(i), FALSE);	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_atom_name") <= 0)		BATname(b, "view_atom_name");	BATroles(b,"view","atom");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 685 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTgetEnvironment(int *ret){	BAT *b;	b= GDKenv;	if (b == 0)		throw(MAL, "inspect.getEnvironment", "failed to create BAT");	BBPfix(*ret = b->batCacheid);	return MAL_SUCCEED;}strINSPECTatom_sup_names(int *ret){	int i, k;	BAT *b = BATnew(TYPE_int, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getAtomSuper", "failed to create BAT");	for (i = 0; i < GDKatomcnt; i++) {		for (k = BATatoms[i].storage; k > TYPE_str; k = BATatoms[k].storage)			;		BUNins(b, &i, ATOMname(k), FALSE);	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_atom_sup_name") <= 0)		BATname(b, "view_atom_sup_name");	BATroles(b,"view","atom");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 718 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTatom_sizes(int *ret){	int i;	size_t s;	BAT *b = BATnew(TYPE_int, TYPE_int, 256);	if (b == 0)		throw(MAL, "inspect.getAtomSizes", "failed to create BAT");	for (i = 0; i < GDKatomcnt; i++) {		s = ATOMsize(i);		BUNins(b, &i, &s, FALSE);	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_atom_size") <= 0)		BATname(b, "view_atom_size");	BATroles(b,"view","atom");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 739 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}/* calculate to trimmed storage space */lngINSPECTcalcSize(MalBlkPtr mb){	lng size,args=0,i;	InstrPtr p;	for(i=0;i<mb->stop; i++){		p= getInstrPtr(mb,i);		args += (p->argc-1)* sizeof(*p->argv);	}	size = (sizeof(InstrRecord) +sizeof(InstrPtr)) * mb->stop;	size += (sizeof(VarRecord)+ sizeof(InstrPtr)) * mb->vtop;	size += args;	return size;}strINSPECTgetSize(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	lng *ret = (lng*) getArgReference(stk,p,0);	*ret= INSPECTcalcSize(mb);	return MAL_SUCCEED;}strINSPECTgetModuleSize(int *ret, str *mod){	Symbol s;	Module m;	int i;	lng total=0;	BAT *b = BATnew(TYPE_str, TYPE_lng, 256);	if (b == 0)		throw(MAL, "inspect.getSize", "failed to create BAT");	m = findModule(MCgetClient()->nspace, putName(*mod, strlen(*mod)));	if (m == 0)		throw(MAL, "inspect.getSize", 				"failed to find <module>.<function>");	for( i=0; i<MAXSCOPE; i++){		s= m->subscope[i];		while (s != NULL) {			lng size;			total+= (size = INSPECTcalcSize(s->def));			BUNins(b, s->name, &size, FALSE);			s = s->peer;		}	}	BUNins(b, *mod, &total, FALSE);	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	#line 113 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	if (BBPindex("view_input_result") <= 0)		BATname(b, "view_input_result");	BATroles(b,"view","input");	BATmode(b,TRANSIENT);	BATfakeCommit(b);	*ret = b->batCacheid;	BBPkeepref(*ret);#line 795 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"	return MAL_SUCCEED;}strINSPECTgetFunctionSize(lng *ret, str *mod, str *fcn){	Symbol s;	s = findMALSymbol(putName(*mod, strlen(*mod)), putName(*fcn, strlen(*fcn)));	if (s == 0)		throw(MAL, "inspect.getSize", 			"failed to find <module>.<function>");	*ret= INSPECTcalcSize(s->def);	return MAL_SUCCEED;}#line 812 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"strINSPECTshowFunction(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	Client c = MCgetClient();	(void) p;	(void) stk;	printFunction(c->fdout, mb, LIST_INPUT);	return MAL_SUCCEED;}strINSPECTshowFunction3(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str modnme = getArgName(mb, p, 1);	str fcnnme = getArgName(mb, p, 2);	Module scope = NULL;	Symbol s = NULL;	Client c = MCgetClient();	scope = findModule(c->nspace, modnme);	if (scope)		s = findSymbolInModule(scope, putName(fcnnme, strlen(fcnnme)));	if (s == NULL){		char buf[BUFSIZ];		snprintf(buf,BUFSIZ,"Could not find %s.%s\n", modnme, fcnnme);		throw(MAL, "inspect.showSource",buf);	} else		printFunction(c->fdout, s->def, LIST_INPUT);	(void) stk;		/* fool compiler */	return MAL_SUCCEED;}strINSPECTtypename(str *ret, int *tpe){	*ret = getTypeName(*tpe);	return MAL_SUCCEED;}strINSPECTtypeIndex(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int *ret;	ret = (int *) getArgReference(stk, pci, 0);	*ret = getTailType(getArgType(mb, pci, 1));	return MAL_SUCCEED;}strINSPECTtypeName(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str *hn, *tn =0;	hn = (str *) getArgReference(stk, pci, 0);	if( pci->retc== 2){		tn = (str *) getArgReference(stk, pci, 1);		*hn = getTypeName(getHeadType(getArgType(mb, pci, 2)));		*tn = getTypeName(getTailType(getArgType(mb, pci, 2)));	} else		*hn = getTypeName(getArgType(mb, pci, 1));	return MAL_SUCCEED;}#line 879 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/inspect.mx"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -