Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | added some support functions for struct jimff_typeinfo, and some more error conditions to jimff_import_symbol() |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
68b67b478963d69fc6fff26cd19daddf |
User & Date: | grable 2018-11-03 01:15:25.366 |
Context
2018-11-03
| ||
01:25 | fixed pointer imports check-in: aa53dedc32 user: grable tags: trunk | |
01:15 | added some support functions for struct jimff_typeinfo, and some more error conditions to jimff_import_symbol() check-in: 68b67b4789 user: grable tags: trunk | |
2018-11-02
| ||
18:50 | simplified makefile and removed an old assert check-in: 77f0f6ca06 user: grable tags: trunk | |
Changes
Changes to jimff-commands.c.
︙ | ︙ | |||
302 303 304 305 306 307 308 309 310 311 312 313 314 315 | Jim_SetResultFormatted( interp, lib ? "%#s: symbol \"%s\" not found in library \"%s\"" : "%#s: symbol \"%s\" not found", argv0, name, lib ? lib->name : NULL); return JIM_ERR; } else if(sym == JIMFF_INVALID_TYPETAG) { Jim_SetResultFormatted( interp, "%#s: invalid typetag for symbol \"%s\"", argv0, name); return JIM_ERR; } switch(symboltype) { #ifdef JIMFF_ENABLE_JIM_VARACCESS case JIMFF_SYM_VARIABLE: { Jim_Obj* varname = Jim_NewStringObj( interp, sym->name, -1); Jim_SetVariableAccess( interp, varname, jimff_varaccess, NULL, NULL, sym); | > > > > > > | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | Jim_SetResultFormatted( interp, lib ? "%#s: symbol \"%s\" not found in library \"%s\"" : "%#s: symbol \"%s\" not found", argv0, name, lib ? lib->name : NULL); return JIM_ERR; } else if(sym == JIMFF_INVALID_TYPETAG) { Jim_SetResultFormatted( interp, "%#s: invalid typetag for symbol \"%s\"", argv0, name); return JIM_ERR; } else if(sym == JIMFF_REDEFINED_SIZE) { Jim_SetResultFormatted( interp, "%#s: invalid pointer size for redefined symbol \"%s\"", argv0, name); return JIM_ERR; } else if(sym == JIMFF_REDEFINED_TYPETAG) { Jim_SetResultFormatted( interp, "%#s: typetag mismatch for redefined symbol \"%s\"", argv0, name); return JIM_ERR; } switch(symboltype) { #ifdef JIMFF_ENABLE_JIM_VARACCESS case JIMFF_SYM_VARIABLE: { Jim_Obj* varname = Jim_NewStringObj( interp, sym->name, -1); Jim_SetVariableAccess( interp, varname, jimff_varaccess, NULL, NULL, sym); |
︙ | ︙ |
Changes to jimff.c.
︙ | ︙ | |||
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | typeinfo->numcallbacks = numcallbacks; } else { typeinfo->callbacks = NULL; typeinfo->numcallbacks = 0; } return 1; } static unsigned long jimff_context_epoch = 0; /**************************************************************************************************** * jimff context */ #define JIMFF_ASSOC_NAME "jimff" //NOTE: used as error result for any function that takes a typetag | > > > > > > > > > > > > > > > > > > > | > > > | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | typeinfo->numcallbacks = numcallbacks; } else { typeinfo->callbacks = NULL; typeinfo->numcallbacks = 0; } return 1; } static void jimff_free_typeinfo( struct jimff_typeinfo* typeinfo) { free((void*)typeinfo->typetag); free((void*)typeinfo->pointersizes); for( int i = 0; i < typeinfo->numcallbacks; i++) free((void*)typeinfo->callbacks[i]); free((void*)typeinfo->callbacks); } //NOTE: returns boolean 0 or 1 static int jimff_compare_typeinfo( const struct jimff_typeinfo* a, const struct jimff_typeinfo* b) { if( a->argc != b->argc || strcmp( a->typetag, b->typetag)) return 0; for( int i = 0; i < a->numpointers; i++) { if( a->pointersizes[i] != b->pointersizes[i]) return 0; } for( int i = 0; i < a->numcallbacks; i++) { if( strcmp( a->callbacks[i], b->callbacks[i])) return 0; } return 1; } static unsigned long jimff_context_epoch = 0; /**************************************************************************************************** * jimff context */ #define JIMFF_ASSOC_NAME "jimff" //NOTE: used as error result for any function that takes a typetag #define JIMFF_INVALID_TYPETAG ((void*)1) //NOTE: used by jimff_import_symbol() to report errors for typeinfo mismatch when redefining a symbol #define JIMFF_REDEFINED_SIZE ((void*)2) #define JIMFF_REDEFINED_TYPETAG ((void*)3) JIMFF_API struct jimff_context* jimff_newcontext( Jim_Interp* interp, const char* name, int flags) { assert( interp ); assert( name ); struct jimff_context* ctx = malloc(sizeof(*ctx)); ctx->flags = flags; |
︙ | ︙ | |||
400 401 402 403 404 405 406 | struct jimff_typeinfo typeinfo = {0}; // check if symbol is already imported if(sym = jimff_find_symbol( lib, name)) { if(!alias || !strcmp( name, alias)) { // only return symbols if they match exactly if(tag == JIMFF_SYM_POINTER) { | | | > | > > | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | struct jimff_typeinfo typeinfo = {0}; // check if symbol is already imported if(sym = jimff_find_symbol( lib, name)) { if(!alias || !strcmp( name, alias)) { // only return symbols if they match exactly if(tag == JIMFF_SYM_POINTER) { if(sym->tag != tag || sym->size != (size_t)argument.size) return JIMFF_REDEFINED_SIZE; } else { //TODO: find a better way to compare symbol typetags if(!jimff_validate_typetag( argument.typetag, &typeinfo)) return JIMFF_INVALID_TYPETAG; int fail = (sym->tag != tag || !jimff_compare_typeinfo( &sym->typeinfo, &typeinfo)); jimff_free_typeinfo(&typeinfo); if(fail) return JIMFF_REDEFINED_TYPETAG; } sym->flags &= ~JIMFF_FLAG_DELETED; return sym; } link = sym; link->numlinks++; addr = sym->addr; |
︙ | ︙ | |||
443 444 445 446 447 448 449 | sym->library = lib; JIMFF_LIST_PUSH( lib->syms, sym); return sym; } | < < < < < < < | 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | sym->library = lib; JIMFF_LIST_PUSH( lib->syms, sym); return sym; } //NOTE: should only be called by jimff_free_library() static void jimff_free_symbol( struct jimff_symbol* sym) { if(!sym) return; free((void*)sym->name); jimff_free_typeinfo(&sym->typeinfo); free(sym); } |
︙ | ︙ |