7 static char *rcsid_gdb_stype_c = "$Header$";
30 /************************************************************************/
34 /* GDB - System Data Type Definitions
36 /* Author: Noah Mendelsohn
37 /* Copyright: 1986 MIT Project Athena
38 /* For copying and distribution information, please see
39 /* the file <mit-copyright.h>.
41 /* This file initializes the definitions for all system defined
42 /* data types, and it includes the type specific semantic routines
43 /* for each of the system defined types.
45 /* The initialization routine which adds these type definitions
46 /* to the type definition table is at the end of this source file.
48 /************************************************************************/
50 /* This file is organized into one section for each system
51 /* defined type followed at the end by a final section which
52 /* initializes the type tables. Each of the type specific
53 /* sections does #defines for each type specific parameter. The
54 /* gdb_i_stype initialization routine at the end of this source
55 /* file uses these defines to initialize the appropriate entry in
56 /* the type definition tables.
58 /* NOTE: some of the type definitions in this file may be machine
61 /************************************************************************/
63 #include <mit-copyright.h>
68 extern u_long ntohl(), htonl();
70 #include <netinet/in.h> /* for htonl routine */
72 /************************************************************************/
76 /************************************************************************/
78 #define IN_LEN (sizeof(int))
80 #define IN_NULL g_in_null
81 #define IN_CDLEN g_in_cdlen
82 #define IN_ENC g_in_enc
83 #define IN_DEC g_in_dec
84 #define IN_FORM g_in_form
85 #define IN_NAME "INTEGER_T"
87 #define IN_EXTERNSIZE 4 /* length of an encoded */
89 /*----------------------------------------------------------*/
93 /* Fill in a null value for an integer.
95 /*----------------------------------------------------------*/
99 char *dp; /* pointer to the data */
101 *((int *)dp) = 0; /* fill in a null value */
104 /*----------------------------------------------------------*/
108 /* Return coded length for an integer. We're currently
109 /* using the Berkeley 'htonl' routine which converts
110 /* an integer (actually a long, ahem!) to a canonical
113 /*----------------------------------------------------------*/
118 char *dp; /* pointer to the data */
119 HALF_CONNECTION hcon;
121 return IN_EXTERNSIZE;
124 /*----------------------------------------------------------*/
128 /* Encode an integer for transmission
130 /*----------------------------------------------------------*/
133 g_in_enc(dp, hcon, outp)
134 char *dp; /* pointer to data */
135 HALF_CONNECTION hcon; /* connection descriptor */
136 char *outp; /* place to put the output */
138 register char *cp; /* next char in output */
139 register char *op = outp;
140 register char *endp = outp+IN_EXTERNSIZE;
142 unsigned long converted; /* the integer goes here */
143 /* in network byte order*/
146 * Put it in network format, then copy one byte at a time to
147 * account for the fact that the RT has trouble with unaligned longs
150 converted = htonl(*(u_long *)dp);
152 cp = (char *)&converted;
158 return (int)(endp); /* return pointer to next */
159 /* unused output byte*/
162 /*----------------------------------------------------------*/
166 /* Decode an integer from external form to local
170 /*----------------------------------------------------------*/
173 g_in_dec(outp, hcon, inp)
174 char *inp; /* pointer to data */
175 HALF_CONNECTION hcon; /* connection descriptor */
176 char *outp; /* place to put the output */
178 register char *ip = inp; /* next byte of input */
180 register char *bp; /* next byte in buffer */
183 * Copy a byte at a time to buffer to account for RT difficulties
184 * with unaligned ints.
186 bp = (char *)&buffer;
193 * Convert it and return pointer to next byte of input.
196 *(int *)outp = ntohl((u_long)buffer);
200 /*----------------------------------------------------------*/
204 /* Format an integer on output logging file for
207 /*----------------------------------------------------------*/
211 char *name; /* string name of the field */
212 char *dp; /* pointer to the data */
214 fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
217 /************************************************************************/
221 /************************************************************************/
223 #define ST_LEN (sizeof(STRING))
224 #define ST_ALI (sizeof(int))
225 #define ST_NULL g_st_null
226 #define ST_CDLEN g_st_cdlen
227 #define ST_ENC g_st_enc
228 #define ST_DEC g_st_dec
229 #define ST_FORM g_st_form
230 #define ST_NAME "STRING_T"
232 /*----------------------------------------------------------*/
236 /* Fill in a null value for a string.
238 /*----------------------------------------------------------*/
241 char *dp; /* pointer to the data */
243 register STRING *stp = (STRING *)dp; /* re-type as string */
244 STRING_DATA(*stp) = NULL; /* no data */
245 MAX_STRING_SIZE(*stp) = 0; /* for cleanliness */
248 /*----------------------------------------------------------*/
252 /* Return coded length for a string. We have to send the
253 /* actual length of the data along with the data itself.
254 /* For this reason, we leave space for a coded integer
255 /* in addition to the data bytes. We actually call the
256 /* integer coding routines to code the length.
258 /* Note that a separate type understanding null termination
259 /* might be an interesting optimization someday.
261 /*----------------------------------------------------------*/
265 char *dp; /* pointer to the data */
266 HALF_CONNECTION hcon;
268 register STRING *stp = (STRING *)dp; /* re-type as string */
270 return (MAX_STRING_SIZE(*stp) +
271 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
274 /*----------------------------------------------------------*/
278 /* Encode a string for transmission
280 /*----------------------------------------------------------*/
283 g_st_enc(dp, hcon, outp)
284 char *dp; /* pointer to data */
285 HALF_CONNECTION hcon; /* connection descriptor */
286 char *outp; /* place to put the output */
288 register STRING *stp = (STRING *)dp; /* re-type as string */
290 register char *nextp; /* place to put next output */
293 * Use the integer coding routine to get the length encoded first
296 len = MAX_STRING_SIZE(*stp); /* length of both source */
298 nextp = (char *)g_in_enc((char *)&len, hcon, outp);
301 * Now, copy the data itself after the encoded integer length
304 bcopy(STRING_DATA(*stp), nextp, len);
305 /* copy the data without */
306 /* changing representation*/
307 return (int)(nextp+len);
310 /*----------------------------------------------------------*/
314 /* Decode a string from external form. We always
315 /* allocate new space for the string, intentionally
316 /* ignoring any which may have been in use before. If we
317 /* freed it, we would not be robust against calls on
318 /* uninitialized fields. This may have nasty side
319 /* effects if the intention was to leave 'gas' at the end
320 /* of the string, but we want to accurately copy the
321 /* data. Note that string_free is robust against null
324 /*----------------------------------------------------------*/
327 g_st_dec(outp, hcon, inp)
328 char *inp; /* pointer to input data */
329 HALF_CONNECTION hcon; /* connection descriptor */
330 char *outp; /* place to put the output */
332 register STRING *stp = (STRING *)outp; /* re-type as string */
334 register char *nextp; /* next byte to scan */
336 * Use the integer coding routine to get the length encoded first
339 nextp = (char *)g_in_dec((char *)&len, hcon, inp);
343 * Allocate memory for the string. If length is 0, then null it
344 * out. Note that we had considered freeing any existing strings
345 * which might be there, but this turns out to cause lots of
346 * trouble for the many callers who don't want to initialize before
350 STRING_DATA(*stp) = NULL;
351 MAX_STRING_SIZE(*stp) = 0;
354 (void) string_alloc(stp, len); /* this sets string length */
355 /* in addition to doing the */
359 * Now, copy the data itself
361 bcopy(nextp, STRING_DATA(*stp), len); /* copy the data without */
362 /* changing representation*/
363 return (int)(nextp+len);
366 /*----------------------------------------------------------*/
370 /* Format a string on output logging file for
373 /*----------------------------------------------------------*/
377 char *name; /* string name of the field */
378 char *dp; /* pointer to the data */
380 register STRING *stp = (STRING *)dp; /* re-type as string */
382 register char *cp; /* next char to print */
383 register char *past_end; /* 1st one not to print */
385 len = MAX_STRING_SIZE(*stp);
386 fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
389 fprintf(gdb_log, "\"\n");
394 cp = STRING_DATA(*stp);
397 while (cp < past_end)
398 (void) putc(*cp++, gdb_log);
400 fprintf(gdb_log,"\"\n");
403 /************************************************************************/
407 /************************************************************************/
409 #define RL_LEN (sizeof(double))
410 #define RL_ALI RL_LEN
411 #define RL_NULL g_rl_null
412 #define RL_CDLEN g_rl_cdlen
413 #define RL_ENC g_rl_enc
414 #define RL_DEC g_rl_dec
415 #define RL_FORM g_rl_form
416 #define RL_NAME "REAL_T"
418 #define RL_EXTERNSIZE 32 /* length of ascii coding */
419 /* must change lengths in */
420 /* encode and decode */
421 /* routines to match*/
422 /*----------------------------------------------------------*/
426 /* Fill in a null value for an real.
428 /*----------------------------------------------------------*/
431 char *dp; /* pointer to the data */
433 *((double *)dp) = 0.0; /* fill in a null value */
436 /*----------------------------------------------------------*/
440 /* Return coded length for an real. For now, we just
441 /* code as a 12 digit ASCII converted string. Obviously,
442 /* we can do much better in the future.
444 /*----------------------------------------------------------*/
449 char *dp; /* pointer to the data */
450 HALF_CONNECTION hcon;
452 return RL_EXTERNSIZE;
455 /*----------------------------------------------------------*/
459 /* Encode an real for transmission
461 /*----------------------------------------------------------*/
464 g_rl_enc(dp, hcon, outp)
465 char *dp; /* pointer to data */
466 HALF_CONNECTION hcon; /* connection descriptor */
467 char *outp; /* place to put the output */
469 register char *cp; /* next char in output */
470 register char *endp = outp+RL_EXTERNSIZE;
473 * Convert the data into printable ASCII in the output stream
474 * Note that the width in the format below must be less than
475 * RL_EXTERNSIZE, because sprintf needs space for its terminating
479 (void) sprintf(outp,"%30le",*((double *)dp));
482 * Sprintf produces output of unpredictable length, and with
483 * a null termination. Pad it out to the desired length.
486 cp = outp + strlen(outp); /* find out where convertd */
489 *cp++ = ' '; /* pad to desired length */
491 return (int)(outp+RL_EXTERNSIZE); /* return pointer to next */
492 /* unused output byte*/
495 /*----------------------------------------------------------*/
499 /* Decode an real from external form
501 /*----------------------------------------------------------*/
504 g_rl_dec(outp, hcon, inp)
505 char *inp; /* pointer to data */
506 HALF_CONNECTION hcon; /* connection descriptor */
507 char *outp; /* place to put the output */
509 (void) sscanf(inp,"%30le", (double *)outp);
510 return (int)(inp+RL_EXTERNSIZE);
513 /*----------------------------------------------------------*/
517 /* Format an real on output logging file for
520 /*----------------------------------------------------------*/
524 char *name; /* string name of the field */
525 char *dp; /* pointer to the data */
527 fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
530 /************************************************************************/
534 /************************************************************************/
536 #define DT_LEN 25 /* see ingres definition */
537 #define DT_ALI 1 /* char data, need not align */
538 #define DT_NULL g_dt_null
539 #define DT_CDLEN g_dt_cdlen
540 #define DT_ENC g_dt_enc
541 #define DT_DEC g_dt_dec
542 #define DT_FORM g_dt_form
543 #define DT_NAME "DATE_T"
545 #define DT_EXTERNSIZE DT_LEN /* length of ascii coding */
546 /* must change lengths in */
547 /* encode and decode */
548 /* routines to match*/
549 /*----------------------------------------------------------*/
553 /* Fill in a null value for a date.
555 /*----------------------------------------------------------*/
558 char *dp; /* pointer to the data */
560 register char *cp = dp; /* next character to fill in */
561 register char *endp = dp + DT_LEN;
564 * Fill the field with character blanks
570 /*----------------------------------------------------------*/
574 /* Return coded length for an date. For now, we just
575 /* code as a 25 digit ASCII converted string.
577 /*----------------------------------------------------------*/
582 char *dp; /* pointer to the data */
583 HALF_CONNECTION hcon;
585 return DT_EXTERNSIZE;
588 /*----------------------------------------------------------*/
592 /* Encode a date for transmission
594 /*----------------------------------------------------------*/
597 g_dt_enc(dp, hcon, outp)
598 char *dp; /* pointer to data */
599 HALF_CONNECTION hcon; /* connection descriptor */
600 char *outp; /* place to put the output */
602 register char *ip = dp; /* next char in input */
603 register char *op = outp; /* next char in output */
604 register char *endp = op+DT_EXTERNSIZE;
607 * Copy the input untransformed to the output
611 *op++ = *ip++; /* pad to desired length */
613 return (int)(endp); /* return pointer to next */
614 /* unused output byte*/
617 /*----------------------------------------------------------*/
621 /* Decode an date from external form
623 /*----------------------------------------------------------*/
626 g_dt_dec(outp, hcon, inp)
627 char *inp; /* pointer to data */
628 HALF_CONNECTION hcon; /* connection descriptor */
629 char *outp; /* place to put the output */
631 register char *ip = inp; /* next char in input */
632 register char *op = outp; /* next char in output */
633 register char *endp = op+DT_EXTERNSIZE;
636 * Copy the input untransformed to the output
640 *op++ = *ip++; /* pad to desired length */
642 return (int)(endp); /* return pointer to next */
643 /* unused output byte*/
646 /*----------------------------------------------------------*/
650 /* Format a date on output logging file for
653 /*----------------------------------------------------------*/
657 char *name; /* string name of the field */
658 char *dp; /* pointer to the data */
660 char buf[DT_EXTERNSIZE+1];
662 bcopy(dp, buf, DT_EXTERNSIZE); /* copy date to buffer */
663 buf[DT_EXTERNSIZE] = '\0'; /* null terminate it */
664 fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
667 /************************************************************************/
669 /* TUPLE_DESCRIPTOR_T
671 /* The external representation of a tuple descriptor will be to
672 /* send the count of the number of fields, and then a one byte
673 /* signed integer describing each type followed by all the
674 /* corresponding null terminated strings. The tuple descriptor
675 /* will really get re-created wth proper offsets and lengths upon
676 /* receipt by the create_tuple_descriptor operation.
678 /************************************************************************/
680 #define TPD_LEN (sizeof(TUPLE_DESCRIPTOR))
681 #define TPD_ALI (sizeof(TUPLE_DESCRIPTOR))
682 #define TPD_NULL g_tpd_null
683 #define TPD_CDLEN g_tpd_cdlen
684 #define TPD_ENC g_tpd_enc
685 #define TPD_DEC g_tpd_dec
686 #define TPD_FORM g_tpd_form
687 #define TPD_NAME "TUPLE_DESCRIPTOR_T"
689 /*----------------------------------------------------------*/
693 /* Fill in a null value for a tuple_descriptor.
695 /*----------------------------------------------------------*/
698 char *dp; /* pointer to the data */
700 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp;
702 /* tuple_descriptor */
703 (*tdp) = NULL; /* no data */
706 /*----------------------------------------------------------*/
710 /* Return coded length for a tuple_descriptor.
712 /*----------------------------------------------------------*/
716 char *dp; /* pointer to the data */
717 HALF_CONNECTION hcon;
719 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
721 /* tuple_descriptor */
722 register int coded_len; /* the value we're trying */
726 * Validate the descriptor
729 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
730 GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
732 coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
733 /* we're going to send */
734 /* the field count as a */
737 coded_len += tdp->str_len + tdp->field_count;
738 /* space for all the */
739 /* strings, with nulls, */
740 /* and for the one byte */
747 /*----------------------------------------------------------*/
751 /* Encode a tuple_descriptor for transmission
753 /*----------------------------------------------------------*/
756 g_tpd_enc(dp, hcon, outp)
757 char *dp; /* pointer to data */
758 HALF_CONNECTION hcon; /* connection descriptor */
759 char *outp; /* place to put the output */
761 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
763 /* tuple_descriptor */
764 register char *nextp; /* place to put next output */
766 register int i; /* a loop counter */
769 * Validate the descriptor
772 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
773 GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
776 * Use the integer coding routine to send the number of fields first
779 nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
782 * Next, put in the one byte codes for each of the field types
785 for (i=0; i<tdp->field_count; i++) {
786 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
791 * Finally, copy all the null terminated strings.
793 bcopy(((char *)(tdp))+gdb_descriptor_length(tdp->field_count),
794 nextp, tdp->str_len); /* copy the string data all */
796 return (int)(nextp+tdp->str_len);
799 /*----------------------------------------------------------*/
803 /* Decode a tuple_descriptor from external form. For
804 /* safety in memory management, we always re-allocate the
805 /* space for the tuple_descriptor. If the pointer passed
806 /* to us is not null, then we assume that it points to a
807 /* legal tuple descriptor, which we first free. Because
808 /* data representation may change, we must re-do the
809 /* create-tuple-descriptor, so it can determine the local
810 /* machine dependent representation and alignment rules
813 /*----------------------------------------------------------*/
815 #define GDB_MAX_DECODED_FIELDS 100
818 g_tpd_dec(outp, hcon, inp)
819 char *inp; /* pointer to input data */
820 HALF_CONNECTION hcon; /* connection descriptor */
821 char *outp; /* place to put the output */
823 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;
825 /* tuple_descriptor */
826 int field_count; /* number of fields in the */
827 /* newly received descriptor*/
828 register int i; /* a loop counter */
830 register int tmp; /* working variable to hold */
831 /* type while they're being */
833 char *nextt; /* next byte to scan for */
834 /* a type code byte*/
835 char *nextn; /* next byte to scan for */
837 char *field_names[GDB_MAX_DECODED_FIELDS];
838 /* put pointers to the */
839 /* field names here */
840 FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
841 /* put the field types in */
844 * Use the integer coding routine to get the number of fields
847 nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
848 if (field_count > GDB_MAX_DECODED_FIELDS)
849 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
853 * For each field, pick up its type code, being sure to sign extend,
854 * and a pointer to its string name.
856 nextn = nextt + field_count; /* there is one byte of */
857 /* type info for each field, */
858 /* after that comes the */
859 /* first string. nextn */
860 /* now points to the first */
862 for (i=0; i<field_count; i++) {
863 tmp = *nextt++; /* type code, may need */
866 tmp |= ((~0) ^ 0xff); /* sign extend if needed */
867 /* this is the most machine */
868 /* independent sign extension */
869 /* I could come up with. */
870 /* Presumes char is one byte, */
871 /* but makes no assumption */
872 /* about sizeof(int) */
873 field_types[i] = tmp;
874 field_names[i] = nextn; /* pointer to name of the */
876 nextn += strlen(nextn) +1; /* set up for possible name */
881 * In case there was already a tuple descriptor here, free it.
884 delete_tuple_descriptor(*tdp);
887 * Create a new descriptor based on the information we have received.
889 *tdp = create_tuple_descriptor(field_count, field_names, field_types);
894 /*----------------------------------------------------------*/
898 /* Format a tuple_descriptor on output logging file for
901 /*----------------------------------------------------------*/
905 char *name; /* tuple_descriptor name of the field */
906 char *dp; /* pointer to the data */
908 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
910 /* tuple_descriptor */
911 register int i; /* loop variable through */
912 /* field definitions */
916 * Handle the special case where the descriptor is null
919 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
924 * Validate the descriptor
926 GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
929 * Descriptor is not null
931 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
933 for (i=0; i<tdp->field_count; i++) {
934 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
936 STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
939 fprintf(gdb_log,"\n");
942 /************************************************************************/
946 /* There is a distinction between the type tuple_t and the
947 /* type tuple_data_t. Tuple_t is a complete self-contained
948 /* tuple, with its descriptor. It actually refers to the
949 /* tuple variable itself, which is a pointer. Tuple_data
950 /* is only the data portion of the tuple, not the descriptor.
951 /* It is used when the receiving tuple is already allocated,
952 /* with a correct descriptor, for sending just the data.
954 /* Note that some of the routines for tuple_t could have been
955 /* implemented in terms of tuple_data_t routines. For the
956 /* moment, they have not been, but that may later be changed.
957 /* Doesn't seem to make much difference as long as they are
958 /* short and simple, and this way does save a bit of overhead.
960 /************************************************************************/
962 #define TP_LEN (sizeof(TUPLE))
963 #define TP_ALI TP_LEN
964 #define TP_NULL g_tp_null
965 #define TP_CDLEN g_tp_cdlen
966 #define TP_ENC g_tp_enc
967 #define TP_DEC g_tp_dec
968 #define TP_FORM g_tp_form
969 #define TP_NAME "TUPLE_T"
971 /*----------------------------------------------------------*/
975 /* Fill in a null value for a tuple.
977 /*----------------------------------------------------------*/
980 char *dp; /* pointer to the data */
982 *((TUPLE *)dp) = NULL;
985 /*----------------------------------------------------------*/
989 /* Return coded length for a tuple. We have to send the
990 /* descriptor along with the data itself. We do this
991 /* with calls to the appropriate encodeing routines.
993 /*----------------------------------------------------------*/
997 char *dp; /* pointer to the data */
998 HALF_CONNECTION hcon;
1000 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1001 register int len; /* accumulated length */
1002 register int i; /* index to fields */
1003 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1006 * Validate the tuple
1009 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1010 GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1013 * First, get length of the descriptor when coded.
1016 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1017 len = g_tpd_cdlen((char *)&tpd,hcon);
1020 * Now, for each field, add in its coded length
1023 for (i=0; i<tpd->field_count; i++) {
1024 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1025 CODED_LENGTH_PROPERTY)
1026 (FIELD_FROM_TUPLE(tup, i),hcon);
1032 /*----------------------------------------------------------*/
1036 /* Encode a tuple for transmission
1038 /*----------------------------------------------------------*/
1041 g_tp_enc(dp, hcon, outp)
1042 char *dp; /* pointer to data */
1043 HALF_CONNECTION hcon; /* connection descriptor */
1044 char *outp; /* place to put the output */
1046 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1047 register int i; /* index to fields */
1048 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1049 char *op; /* next byte of output */
1052 * Validate the tuple
1055 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1056 GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1059 * First, get the tuple descriptor and encode it
1062 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1063 op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1066 * Now, for each field, code it
1069 for (i=0; i<tpd->field_count; i++) {
1070 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1072 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1078 /*----------------------------------------------------------*/
1082 /* Decode a tuple from external form. For safety
1083 /* in memory management, we always re-allocate the
1084 /* space for the tuple, so the lengths come out right.
1085 /* This may have nasty side effects if the intention
1086 /* was to leave 'gas' at the end of the tuple, but
1087 /* we want to accurately copy the data. Note that
1088 /* tuple_free is robust against null pointers.
1090 /*----------------------------------------------------------*/
1093 g_tp_dec(outp, hcon, inp)
1094 char *inp; /* pointer to input data */
1095 HALF_CONNECTION hcon; /* connection descriptor */
1096 char *outp; /* place to put the output */
1098 register TUPLE tup; /* the new tuple */
1099 register int i; /* index to fields */
1100 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1101 char *ip; /* next byte of input */
1104 * First, get the tuple descriptor and decode it
1107 tpd = NULL; /* so decode will know */
1108 /* there's no existing one */
1110 ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1113 * Now make an empty tuple based on the descriptor
1116 tup = create_tuple(tpd);
1119 * The tuple descriptor has a reference count of 2 here, one
1120 * from the tpd_dec routine, and one from the create_tuple.
1121 * Since we don't expect to explicitly undo the two separately,
1122 * we decrement the count here.
1125 UNREFERENCE_TUPLE_DESCRIPTOR(tpd); /* decr. the reference count */
1128 * Now, for each field, decode it.
1131 for (i=0; i<tpd->field_count; i++) {
1132 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1134 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1137 *((TUPLE *)outp) = tup; /* put the new tuple */
1138 /* pointer where the */
1139 /* caller wants it */
1143 /*----------------------------------------------------------*/
1147 /* Format a tuple on output logging file for
1150 /*----------------------------------------------------------*/
1154 char *name; /* tuple name of the field */
1155 char *dp; /* pointer to the data */
1157 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1158 register int i; /* index to fields */
1159 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1163 * Handle special case where tuple is null
1167 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1171 GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1173 * Get the descriptor--for now, we won't print it
1175 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1181 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1184 * Now, for each field, print it
1187 for (i=0; i<tpd->field_count; i++) {
1188 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1190 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1193 fprintf(gdb_log,"END_OF_TUPLE\n");
1196 /************************************************************************/
1200 /* The distinction between tuple_data_t and tuple_t is a
1201 /* subtle one. Tuple_t is used when a single tuple is to
1202 /* be decoded, outside of any larger context. It (re)allocates
1203 /* memory for both the tuple itself and its descriptor.
1205 /* Tuple_data is used in the case where the tuple and its
1206 /* descriptor are already allocated, but only the data is
1207 /* to be received. This is useful in cases like receiving an
1208 /* entire relation, in which the descriptor is common to
1209 /* all the tuples, and should not be resent or reallocated
1210 /* with each one. Receive relation can send the tuple descriptor
1211 /* once, then do a create_tuple followed by a decode tuple_data
1212 /* to receive the tuple field data into the existing tuple.
1214 /* Note that the definition of null is different in the two cases.
1215 /* The null value for a tuple is just a null pointer. The null
1216 /* for tuple data is to null each of the fields in the tuple
1217 /* recursively. The routines in this section may dereference
1218 /* null pointers if the tuples they are passed are null. Note
1219 /* also that there is one less level of indirection in passing
1220 /* data to these routines than to those of tuple_t.
1222 /* Note also that the null and decode routines supplied here
1223 /* presume that any fields with dependent memory (e.g. string_t
1224 /* fields have already been cleaned up.)
1226 /* Note that this is not quite a kosher type, in the sense that
1227 /* it's length is not fixed. The entry for length below
1228 /* is meaningless, because the real length is computed from the
1229 /* desc. Among other things, this means that TUPLEs cannot
1230 /* contain fields of this type.
1232 /************************************************************************/
1234 #define TDT_LEN (sizeof(TUPLE))
1235 #define TDT_ALI TDT_LEN
1236 #define TDT_NULL g_tdt_null
1237 #define TDT_CDLEN g_tdt_cdlen
1238 #define TDT_ENC g_tdt_enc
1239 #define TDT_DEC g_tdt_dec
1240 #define TDT_FORM g_tdt_form
1241 #define TDT_NAME "TUPLE_DATA_T"
1243 /*----------------------------------------------------------*/
1247 /* Fill in a null value for a tuple.
1249 /*----------------------------------------------------------*/
1252 char *dp; /* pointer to the data */
1254 TUPLE tup = (TUPLE)dp; /* dp is of type TUPLE, */
1255 /* which is actually */
1256 /* a pointer to the */
1258 TUPLE_DESCRIPTOR tpd; /* the descriptor for this */
1260 register int i; /* a loop counter */
1263 * For each field in the tuple, call its null routine
1265 tup->id = GDB_TUP_ID;
1267 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1269 for (i=0; i<tpd->field_count; i++) {
1270 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),NULL_PROPERTY)
1271 (FIELD_FROM_TUPLE(tup,i));
1275 /*----------------------------------------------------------*/
1279 /* Return coded length for tuple data. Since the descriptor
1280 /* for the tuple is known at both sides, we send only
1281 /* the coded fields, not even the field counts.
1283 /*----------------------------------------------------------*/
1286 g_tdt_cdlen(dp,hcon)
1287 char *dp; /* pointer to the data */
1288 HALF_CONNECTION hcon;
1290 register TUPLE tup = (TUPLE)dp; /* arg typed as tuple */
1291 register int len; /* accumulated length */
1292 register int i; /* index to fields */
1293 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1296 * Validate the tuple data
1299 GDB_GIVEUP("g_tdt_cdlen (coded length) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1300 GDB_CHECK_TUP(tup,"g_tdt_cdlen: compute coded length of tuple data")
1302 * First, find the tuple descriptor and set initial coded len to 0
1305 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1309 * Now, for each field, add in its coded length
1312 for (i=0; i<tpd->field_count; i++) {
1313 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1314 CODED_LENGTH_PROPERTY)
1315 (FIELD_FROM_TUPLE(tup, i),hcon);
1321 /*----------------------------------------------------------*/
1325 /* Encode tuple data for transmission.
1327 /*----------------------------------------------------------*/
1330 g_tdt_enc(dp, hcon, outp)
1331 char *dp; /* pointer to data */
1332 HALF_CONNECTION hcon; /* connection descriptor */
1333 char *outp; /* place to put the output */
1335 register TUPLE tup = (TUPLE)dp; /* type as tuple */
1336 register int i; /* index to fields */
1337 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1338 char *op = outp; /* next byte of output */
1341 * Validate the tuple data
1344 GDB_GIVEUP("g_tdt_enc (encode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1345 GDB_CHECK_TUP(tup,"g_tdt_enc: encode of tuple data")
1347 * First, get the tuple descriptor
1350 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1353 * Now, for each field, code it
1356 for (i=0; i<tpd->field_count; i++) {
1357 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1359 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1365 /*----------------------------------------------------------*/
1369 /* Decode tuple data from external form. We presume
1370 /* that the tuple itself is allocated, and the descriptor
1371 /* properly set up for the local machine representation.
1372 /* Here we just decode the fields.
1374 /*----------------------------------------------------------*/
1377 g_tdt_dec(outp, hcon, inp)
1378 char *inp; /* pointer to input data */
1379 HALF_CONNECTION hcon; /* connection descriptor */
1380 char *outp; /* place to put the output */
1382 register TUPLE tup = (TUPLE)outp; /* the filled in tuple */
1383 register int i; /* index to fields */
1384 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1385 char *ip = inp; /* next byte of input */
1388 * Validate the tuple data
1391 GDB_GIVEUP("g_tdt_dec (decode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1392 GDB_CHECK_TUP(tup,"g_tdt_dec: decode of tuple data")
1394 * First, get the tuple descriptor
1397 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1400 * Now, for each field, decode it.
1403 for (i=0; i<tpd->field_count; i++) {
1404 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1406 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1412 /*----------------------------------------------------------*/
1416 /* Format tuple data on output logging file for
1419 /*----------------------------------------------------------*/
1422 g_tdt_form(name, dp)
1423 char *name; /* tuple name of the field */
1424 char *dp; /* pointer to the data */
1426 register TUPLE tup = (TUPLE)dp; /* as tuple */
1427 register int i; /* index to fields */
1428 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1432 * Handle special case where we're given a null address for the
1436 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1442 * Validate the tuple data
1444 GDB_CHECK_TUP(tup,"g_tdt_form: format tuple data")
1446 * Get the descriptor--for now, we won't print it
1448 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1454 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1457 * Now, for each field, print it
1460 for (i=0; i<tpd->field_count; i++) {
1461 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1463 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1466 fprintf(gdb_log,"END_OF_TUPLE\n");
1469 /************************************************************************/
1473 /* Relations consist of link lists of tuples, all of which are
1474 /* presumed to share a tuple descriptor. For transmission,
1475 /* these are encoded as follows:
1477 /* 1) A count of the number of tuples, sent as a properly coded
1480 /* 2) The tuple descriptor itself, encoded by its encoding routine.
1482 /* 3) For each tuple, its tuple data, encoded using the routines
1483 /* of the tuple_data_t type.
1485 /************************************************************************/
1487 #define REL_LEN (sizeof(RELATION))
1488 #define REL_ALI REL_LEN
1489 #define REL_NULL g_rel_null
1490 #define REL_CDLEN g_rel_cdlen
1491 #define REL_ENC g_rel_enc
1492 #define REL_DEC g_rel_dec
1493 #define REL_FORM g_rel_form
1494 #define REL_NAME "RELATION_T"
1497 /*----------------------------------------------------------*/
1501 /* Fill in a null value for a relation. Maybe we should
1502 /* check for an existing relation and properly free it,
1503 /* but for now, we don't.
1505 /*----------------------------------------------------------*/
1508 char *dp; /* pointer to the data */
1510 *((RELATION *)dp) = NULL;
1513 /*----------------------------------------------------------*/
1517 /* Return coded length for a relation.
1519 /*----------------------------------------------------------*/
1522 g_rel_cdlen(dp,hcon)
1523 char *dp; /* pointer to the data */
1524 HALF_CONNECTION hcon;
1526 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1527 int len; /* accumulated length */
1528 register TUPLE t; /* index to a tuple */
1529 int tuple_count = 0; /* number of tuples in this */
1531 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1535 * Validate the relation
1538 GDB_GIVEUP("g_rel_cdlen (coded length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1539 GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1541 * First, get the tuple descriptor for this relation
1544 tpd = DESCRIPTOR_FROM_RELATION(rel);
1547 * Count the number of tuples in the relation
1549 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1550 t = NEXT_TUPLE_IN_RELATION(rel,t))
1553 * Start with the coded length for the tuple count and the
1554 * descriptor, which are sent first.
1557 len = g_in_cdlen((char *)&tuple_count, hcon); /* length of tuple_count */
1559 len += g_tpd_cdlen((char *)&tpd, hcon);
1562 * Now, for each tuple, add in its coded length
1565 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1566 t = NEXT_TUPLE_IN_RELATION(rel,t))
1567 len += g_tdt_cdlen((char *)t, hcon);
1572 /*----------------------------------------------------------*/
1576 /* Encode a relation for transmission
1578 /*----------------------------------------------------------*/
1581 g_rel_enc(dp, hcon, outp)
1582 char *dp; /* pointer to data */
1583 HALF_CONNECTION hcon; /* connection descriptor */
1584 char *outp; /* place to put the output */
1586 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1587 char *op; /* pointer to next unused */
1589 register TUPLE t; /* index to a tuple */
1590 int tuple_count = 0; /* number of tuples in this */
1592 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1596 * Validate the relation
1599 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1600 GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1603 * First, get the tuple descriptor for this relation
1606 tpd = DESCRIPTOR_FROM_RELATION(rel);
1609 * Count the number of tuples in the relation
1611 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1612 t = NEXT_TUPLE_IN_RELATION(rel,t))
1615 * Encode the count and the tuple descriptor for this relation
1618 op = (char *)g_in_enc((char *)&tuple_count, hcon,outp);
1619 /* length of tuple_count */
1621 op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1624 * Now, encode each tuple
1627 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1628 t = NEXT_TUPLE_IN_RELATION(rel,t))
1629 op = (char *)g_tdt_enc((char *)t, hcon, op);
1634 /*----------------------------------------------------------*/
1638 /* Decode a relation from external form. We should
1639 /* really check to make sure the relation we are given
1640 /* is null, and if not, call delete_relation on it
1641 /* first. For the moment, we just presume it's null.
1643 /* We proceed by decoding the integer count and the
1644 /* tuple descriptor, from which we create the null
1645 /* relation. We then loop for each tuple, doing a
1646 /* create, a decode, and an add to relation.
1648 /*----------------------------------------------------------*/
1651 g_rel_dec(outp, hcon, inp)
1652 char *inp; /* pointer to input data */
1653 HALF_CONNECTION hcon; /* connection descriptor */
1654 char *outp; /* place to put the output */
1656 register RELATION rel; /* build the relation here */
1657 char *ip; /* pointer to next unused */
1659 register TUPLE t; /* index to a tuple */
1660 register int i; /* loop counter on tuples */
1661 int tuple_count = 0; /* number of tuples in this */
1663 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1667 * First, get the field count and tuple descriptor for this relation
1670 ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1672 tpd = NULL; /* so decode will know */
1673 /* there's no existing one */
1675 ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1678 * Now, create a null relation using the descriptor
1681 rel = create_relation(tpd);
1684 * The reference count for the tuple descriptor is currently 2,
1685 * one from the tpd_dec and one from the create relation. Since
1686 * these will not be undone separately, we decrement the reference
1690 UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1693 * For each tuple, create it, receive it, add it to the relation
1696 for (i=0; i<tuple_count; i++) {
1697 t = create_tuple(tpd);
1698 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1699 ADD_TUPLE_TO_RELATION(rel, t);
1703 * Now store the address of the created relation where requested
1704 * and return pointer to next available input byte.
1707 *((RELATION *)outp) = rel;
1712 /*----------------------------------------------------------*/
1716 /* Format a relation on output logging file for
1719 /*----------------------------------------------------------*/
1722 g_rel_form(name, dp)
1723 char *name; /* relation name of the field */
1724 char *dp; /* pointer to the data */
1726 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1732 * Handle special case where relation is null
1736 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1740 GDB_CHECK_REL(rel,"g_rel_form: format relation")
1746 fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1749 * Now, for each field, print it
1752 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1753 t = NEXT_TUPLE_IN_RELATION(rel,t)){
1754 (void) sprintf(buffer,"Number %d",++count);
1755 g_tdt_form(buffer,(char *)t);
1758 fprintf(gdb_log,"END_OF_RELATION\n");
1761 /************************************************************************/
1763 /* DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION
1766 /* This representation is clearly a real pain to keep up to date
1767 /* properly, mostly because C has such a lousy pre-processor.
1768 /* Probably this should be re-arranged so an initialization routine
1769 /* is called to set up the tables, but even that might be a nuissance.
1771 /************************************************************************/
1773 /*----------------------------------------------------------*/
1777 /* Called at startup to initialize the type table with
1778 /* the entries for the system types.
1780 /*----------------------------------------------------------*/
1782 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1783 g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1784 g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1785 g_type_table[inx][NULL_PROPERTY].f = np; \
1786 g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1787 g_type_table[inx][ENCODE_PROPERTY].f = ep; \
1788 g_type_table[inx][DECODE_PROPERTY].f = dp; \
1789 g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1790 g_type_table[inx][NAME_PROPERTY].cp = name; \
1796 gdb_n_types = SYSTEM_TYPE_COUNT;
1798 ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1800 ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1802 ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1804 ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1806 ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1807 TPD_DEC,TPD_FORM,TPD_NAME)
1808 ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1810 ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1812 ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,