Check-in [c4fcd3fe3d]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added -packed switch to wrap and unwrap, even though the default and only mode right now is packed
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:c4fcd3fe3da7e16412bcfdca0c0ed91770fc2007773657a22f6e8fd5c7896cbb
User & Date: grable 2018-11-01 00:32:05
Context
2018-11-01
00:54
beginnings of unwrapping arrays, though commented out for now check-in: d013f0e2ff user: grable tags: trunk
00:32
added -packed switch to wrap and unwrap, even though the default and only mode right now is packed check-in: c4fcd3fe3d user: grable tags: trunk
00:15
added pointer wrap and unwrap commands for easier struct handling, also made read, write and copy more robust check-in: d3173296b6 user: grable tags: trunk
Changes

Changes to jimff-commands.c.

489
490
491
492
493
494
495

496

497
498
499
500
501
502
503
504






505
506
507
508
509
510
511
512
513
514
515
516
517
518
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588

589
590
591
592
593
594
595
596
597
598






599
600
601
602
603
604
605
606
607
608
609
...
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
...
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678



679
680
681
682
683
684
685
...
893
894
895
896
897
898
899

900
901
902
903
904
905
906
	
err_not_dynamic_pointer:
	Jim_SetResultFormatted( ctx->interp, "%#s %s: argument #1 \"%#s\" is not a valid dynamic pointer", argv0, modes[mode], argv[1]);
	return JIM_ERR;
}

static int fn_pointer_unwrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {

	struct jimff_context* ctx = Jim_CmdPrivData(interp);

	void* ptr;
	int size;
	int len;
	const char* typetag;
	int offs;
	int sz;
	Jim_Obj* list;
	int index;






	
	if(argc < 3) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "pointer typetag ?varNames...?");
		return JIM_ERR;
	}
	
	ptr = jimff_getpointer( ctx, argv[1], &size, 0);
	if(size == -1) goto err_not_pointer;
	if(!ptr) goto err_null_pointer;
	
	typetag = Jim_GetString( argv[2], &len);
	if(len == 0) goto err_invalid_typetag;
	
................................................................................
	}
	
	if(list) Jim_SetResult( interp, list);
	else Jim_SetResultInt( interp, index - 3);
	return JIM_OK;
		
err_not_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is not a valid pointer", argv[0], argv[1]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is null pointer", argv[0], argv[1]);
	return JIM_ERR;
	
err_invalid_typetag:
	Jim_SetResultFormatted( interp, "%#s: argument #2 \"%#s\" is not a valid typetag", argv[0], argv[2]);
	return JIM_ERR;
	
err_structs_unsupported:
	Jim_SetResultFormatted( interp, "%#s: structs not supported", argv[0]);
	return JIM_ERR;
	
#undef struct_elem
#undef GET_ELEM
}

static int fn_pointer_wrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {

	struct jimff_context* ctx = Jim_CmdPrivData(interp);

	void* ptr;
	int size;
	int len;
	const char* typetag;
	int offs;
	Jim_Obj* list;
	int index;
	union jimff_result tmp;
	int sz;
	void* p;






	
	if(argc < 4) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "pointer typetag values...");
		return JIM_ERR;
	}
	
	ptr = jimff_getpointer( ctx, argv[1], &size, 0);
	if(size == -1) goto err_not_pointer;
	if(!ptr) goto err_null_pointer;
	
................................................................................
			case 'c':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed char, tmp.l); break;
			case 'b':
			case 'C':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned char, tmp.l); break;
			case 's':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed short, tmp.l); break;
			case 'S':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned short, tmp.l); break;
			case 'i':		if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed int, tmp.l); break;
			case 'I':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned int, tmp.l); break;
			case 'a':	
			case 'l':		if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed long, tmp.l); break;
			case 'L':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned long, tmp.l); break;
			case 'A':
			case 'q':
			case 'w':	if(Jim_GetWide( interp, GET_ARG(), &tmp.w) != JIM_OK) return JIM_ERR; struct_elem( signed long long, tmp.w); break;
			case 'Q':
			case 'W':	if(Jim_GetWide( interp, GET_ARG(), &tmp.w) != JIM_OK) return JIM_ERR; struct_elem( unsigned long long, tmp.W); break;
................................................................................
		}
	}
	
	Jim_SetResultInt( interp, list ? index : index - 3);
	return JIM_OK;
		
err_not_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is not a valid pointer", argv[0], argv[1]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is null pointer", argv[0], argv[1]);
	return JIM_ERR;
	
err_invalid_typetag:
	Jim_SetResultFormatted( interp, "%#s: argument #2 \"%#s\" is not a valid typetag", argv[0], argv[2]);
	return JIM_ERR;
	
err_structs_unsupported:
	Jim_SetResultFormatted( interp, "%#s: structs not supported", argv[0]);
	return JIM_ERR;
	
err_invalid_pointer:
	Jim_SetResultFormatted( interp, "%#s: encountered invalid pointer", argv[0]);
	return JIM_ERR;



}

// out of bounds checking used by various raw pointer commands, if len=0 it is ignored
#define check_oob( name, ptr, size, offs, len)												\
		void* name ## _start = (ptr) + (offs);												\
		void* name ## _stop = (ptr) + (size);												\
		if(name ## _start < (ptr)) goto err_offset_oob;									\
................................................................................
	Jim_SetResultFormatted( interp, "%#s: pointer \"%#s\" is not a valid pointer", argv[0], argv[arg]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: pointer \"%#s\" is null pointer", argv[0], argv[arg]);
	return JIM_ERR;
}


#ifndef JIMFF_DISABLE_INFO_COMMAND
static Jim_Obj* jimff_typeinfo_typetag( Jim_Interp* interp, struct jimff_typeinfo* typeinfo, int pretty) {
	Jim_Obj* str = Jim_NewStringObj( interp, "", -1);
	int nump = 0;
	int numcb = 0;
	char buffer[256];







>

>








>
>
>
>
>
>






|







 







|



|



|



|







>

>










>
>
>
>
>
>



|







 







|







 







|



|



|



|



|

>
>
>







 







>







489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
...
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
...
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
...
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
	
err_not_dynamic_pointer:
	Jim_SetResultFormatted( ctx->interp, "%#s %s: argument #1 \"%#s\" is not a valid dynamic pointer", argv0, modes[mode], argv[1]);
	return JIM_ERR;
}

static int fn_pointer_unwrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);
	int packed = 0;
	void* ptr;
	int size;
	int len;
	const char* typetag;
	int offs;
	int sz;
	Jim_Obj* list;
	int index;
	
	if(argc >= 1 && Jim_StringCompareImmediate( interp, argv[1], "-packed")) {
		packed = 1;
		argv++;
		argc--;
	}
	
	if(argc < 3) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "pointer typetag ?varNames...?");
		return JIM_ERR;
	}

	ptr = jimff_getpointer( ctx, argv[1], &size, 0);
	if(size == -1) goto err_not_pointer;
	if(!ptr) goto err_null_pointer;
	
	typetag = Jim_GetString( argv[2], &len);
	if(len == 0) goto err_invalid_typetag;
	
................................................................................
	}
	
	if(list) Jim_SetResult( interp, list);
	else Jim_SetResultInt( interp, index - 3);
	return JIM_OK;
		
err_not_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is not a valid pointer", argv0, argv[1]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is null pointer", argv0, argv[1]);
	return JIM_ERR;
	
err_invalid_typetag:
	Jim_SetResultFormatted( interp, "%#s: argument #2 \"%#s\" is not a valid typetag", argv0, argv[2]);
	return JIM_ERR;
	
err_structs_unsupported:
	Jim_SetResultFormatted( interp, "%#s: structs not supported", argv0);
	return JIM_ERR;
	
#undef struct_elem
#undef GET_ELEM
}

static int fn_pointer_wrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);
	int packed = 0;
	void* ptr;
	int size;
	int len;
	const char* typetag;
	int offs;
	Jim_Obj* list;
	int index;
	union jimff_result tmp;
	int sz;
	void* p;
	
	if(argc >= 1 && Jim_StringCompareImmediate( interp, argv[1], "-packed")) {
		packed = 1;
		argv++;
		argc--;
	}	
	
	if(argc < 4) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "?-packed? pointer typetag values...");
		return JIM_ERR;
	}
	
	ptr = jimff_getpointer( ctx, argv[1], &size, 0);
	if(size == -1) goto err_not_pointer;
	if(!ptr) goto err_null_pointer;
	
................................................................................
			case 'c':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed char, tmp.l); break;
			case 'b':
			case 'C':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned char, tmp.l); break;
			case 's':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed short, tmp.l); break;
			case 'S':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned short, tmp.l); break;
			case 'i':		if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed int, tmp.l); break;
			case 'I':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned int, tmp.l); break;
			case 'a':
			case 'l':		if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( signed long, tmp.l); break;
			case 'L':	if(Jim_GetLong( interp, GET_ARG(), &tmp.l) != JIM_OK) return JIM_ERR; struct_elem( unsigned long, tmp.l); break;
			case 'A':
			case 'q':
			case 'w':	if(Jim_GetWide( interp, GET_ARG(), &tmp.w) != JIM_OK) return JIM_ERR; struct_elem( signed long long, tmp.w); break;
			case 'Q':
			case 'W':	if(Jim_GetWide( interp, GET_ARG(), &tmp.w) != JIM_OK) return JIM_ERR; struct_elem( unsigned long long, tmp.W); break;
................................................................................
		}
	}
	
	Jim_SetResultInt( interp, list ? index : index - 3);
	return JIM_OK;
		
err_not_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is not a valid pointer", argv0, argv[1]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: argument #1 \"%#s\" is null pointer", argv0, argv[1]);
	return JIM_ERR;
	
err_invalid_typetag:
	Jim_SetResultFormatted( interp, "%#s: argument #2 \"%#s\" is not a valid typetag", argv0, argv[2]);
	return JIM_ERR;
	
err_structs_unsupported:
	Jim_SetResultFormatted( interp, "%#s: structs not supported", argv0);
	return JIM_ERR;
	
err_invalid_pointer:
	Jim_SetResultFormatted( interp, "%#s: encountered invalid pointer", argv0);
	return JIM_ERR;
	
#undef struct_elem
#undef GET_ARG
}

// out of bounds checking used by various raw pointer commands, if len=0 it is ignored
#define check_oob( name, ptr, size, offs, len)												\
		void* name ## _start = (ptr) + (offs);												\
		void* name ## _stop = (ptr) + (size);												\
		if(name ## _start < (ptr)) goto err_offset_oob;									\
................................................................................
	Jim_SetResultFormatted( interp, "%#s: pointer \"%#s\" is not a valid pointer", argv[0], argv[arg]);
	return JIM_ERR;
	
err_null_pointer:
	Jim_SetResultFormatted( interp, "%#s: pointer \"%#s\" is null pointer", argv[0], argv[arg]);
	return JIM_ERR;
}
#undef check_oob

#ifndef JIMFF_DISABLE_INFO_COMMAND
static Jim_Obj* jimff_typeinfo_typetag( Jim_Interp* interp, struct jimff_typeinfo* typeinfo, int pretty) {
	Jim_Obj* str = Jim_NewStringObj( interp, "", -1);
	int nump = 0;
	int numcb = 0;
	char buffer[256];