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
39 /* This file initializes the definitions for all system defined
40 /* data types, and it includes the type specific semantic routines
41 /* for each of the system defined types.
43 /* The initialization routine which adds these type definitions
44 /* to the type definition table is at the end of this source file.
46 /************************************************************************/
48 /* This file is organized into one section for each system
49 /* defined type followed at the end by a final section which
50 /* initializes the type tables. Each of the type specific
51 /* sections does #defines for each type specific parameter. The
52 /* gdb_i_stype initialization routine at the end of this source
53 /* file uses these defines to initialize the appropriate entry in
54 /* the type definition tables.
56 /* NOTE: some of the type definitions in this file may be machine
59 /************************************************************************/
65 extern u_long ntohl(), htonl();
67 #include <netinet/in.h> /* for htonl routine */
69 /************************************************************************/
73 /************************************************************************/
75 #define IN_LEN (sizeof(int))
77 #define IN_NULL g_in_null
78 #define IN_CDLEN g_in_cdlen
79 #define IN_ENC g_in_enc
80 #define IN_DEC g_in_dec
81 #define IN_FORM g_in_form
82 #define IN_NAME "INTEGER_T"
84 #define IN_EXTERNSIZE 4 /* length of an encoded */
86 /*----------------------------------------------------------*/
90 /* Fill in a null value for an integer.
92 /*----------------------------------------------------------*/
96 char *dp; /* pointer to the data */
98 *((int *)dp) = 0; /* fill in a null value */
101 /*----------------------------------------------------------*/
105 /* Return coded length for an integer. We're currently
106 /* using the Berkeley 'htonl' routine which converts
107 /* an integer (actually a long, ahem!) to a canonical
110 /*----------------------------------------------------------*/
115 char *dp; /* pointer to the data */
116 HALF_CONNECTION hcon;
118 return IN_EXTERNSIZE;
121 /*----------------------------------------------------------*/
125 /* Encode an integer for transmission
127 /*----------------------------------------------------------*/
130 g_in_enc(dp, hcon, outp)
131 char *dp; /* pointer to data */
132 HALF_CONNECTION hcon; /* connection descriptor */
133 char *outp; /* place to put the output */
135 register char *cp; /* next char in output */
136 register char *op = outp;
137 register char *endp = outp+IN_EXTERNSIZE;
139 unsigned long converted; /* the integer goes here */
140 /* in network byte order*/
143 * Put it in network format, then copy one byte at a time to
144 * account for the fact that the RT has trouble with unaligned longs
147 converted = htonl(*(u_long *)dp);
149 cp = (char *)&converted;
155 return (int)(endp); /* return pointer to next */
156 /* unused output byte*/
159 /*----------------------------------------------------------*/
163 /* Decode an integer from external form to local
167 /*----------------------------------------------------------*/
170 g_in_dec(outp, hcon, inp)
171 char *inp; /* pointer to data */
172 HALF_CONNECTION hcon; /* connection descriptor */
173 char *outp; /* place to put the output */
175 register char *ip = inp; /* next byte of input */
177 register char *bp; /* next byte in buffer */
180 * Copy a byte at a time to buffer to account for RT difficulties
181 * with unaligned ints.
183 bp = (char *)&buffer;
190 * Convert it and return pointer to next byte of input.
193 *(int *)outp = ntohl((u_long)buffer);
197 /*----------------------------------------------------------*/
201 /* Format an integer on output logging file for
204 /*----------------------------------------------------------*/
208 char *name; /* string name of the field */
209 char *dp; /* pointer to the data */
211 fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
214 /************************************************************************/
218 /************************************************************************/
220 #define ST_LEN (sizeof(STRING))
221 #define ST_ALI (sizeof(int))
222 #define ST_NULL g_st_null
223 #define ST_CDLEN g_st_cdlen
224 #define ST_ENC g_st_enc
225 #define ST_DEC g_st_dec
226 #define ST_FORM g_st_form
227 #define ST_NAME "STRING_T"
229 /*----------------------------------------------------------*/
233 /* Fill in a null value for a string.
235 /*----------------------------------------------------------*/
238 char *dp; /* pointer to the data */
240 register STRING *stp = (STRING *)dp; /* re-type as string */
241 STRING_DATA(*stp) = NULL; /* no data */
242 MAX_STRING_SIZE(*stp) = 0; /* for cleanliness */
245 /*----------------------------------------------------------*/
249 /* Return coded length for a string. We have to send the
250 /* actual length of the data along with the data itself.
251 /* For this reason, we leave space for a coded integer
252 /* in addition to the data bytes. We actually call the
253 /* integer coding routines to code the length.
255 /* Note that a separate type understanding null termination
256 /* might be an interesting optimization someday.
258 /*----------------------------------------------------------*/
262 char *dp; /* pointer to the data */
263 HALF_CONNECTION hcon;
265 register STRING *stp = (STRING *)dp; /* re-type as string */
267 return (MAX_STRING_SIZE(*stp) +
268 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
271 /*----------------------------------------------------------*/
275 /* Encode a string for transmission
277 /*----------------------------------------------------------*/
280 g_st_enc(dp, hcon, outp)
281 char *dp; /* pointer to data */
282 HALF_CONNECTION hcon; /* connection descriptor */
283 char *outp; /* place to put the output */
285 register STRING *stp = (STRING *)dp; /* re-type as string */
287 register char *nextp; /* place to put next output */
290 * Use the integer coding routine to get the length encoded first
293 len = MAX_STRING_SIZE(*stp); /* length of both source */
295 nextp = (char *)g_in_enc((char *)&len, hcon, outp);
298 * Now, copy the data itself after the encoded integer length
301 bcopy(STRING_DATA(*stp), nextp, len);
302 /* copy the data without */
303 /* changing representation*/
304 return (int)(nextp+len);
307 /*----------------------------------------------------------*/
311 /* Decode a string from external form. We always
312 /* allocate new space for the string, intentionally
313 /* ignoring any which may have been in use before. If we
314 /* freed it, we would not be robust against calls on
315 /* uninitialized fields. This may have nasty side
316 /* effects if the intention was to leave 'gas' at the end
317 /* of the string, but we want to accurately copy the
318 /* data. Note that string_free is robust against null
321 /*----------------------------------------------------------*/
324 g_st_dec(outp, hcon, inp)
325 char *inp; /* pointer to input data */
326 HALF_CONNECTION hcon; /* connection descriptor */
327 char *outp; /* place to put the output */
329 register STRING *stp = (STRING *)outp; /* re-type as string */
331 register char *nextp; /* next byte to scan */
333 * Use the integer coding routine to get the length encoded first
336 nextp = (char *)g_in_dec((char *)&len, hcon, inp);
340 * Allocate memory for the string. If length is 0, then null it
341 * out. Note that we had considered freeing any existing strings
342 * which might be there, but this turns out to cause lots of
343 * trouble for the many callers who don't want to initialize before
347 STRING_DATA(*stp) = NULL;
348 MAX_STRING_SIZE(*stp) = 0;
351 (void) string_alloc(stp, len); /* this sets string length */
352 /* in addition to doing the */
356 * Now, copy the data itself
358 bcopy(nextp, STRING_DATA(*stp), len); /* copy the data without */
359 /* changing representation*/
360 return (int)(nextp+len);
363 /*----------------------------------------------------------*/
367 /* Format a string on output logging file for
370 /*----------------------------------------------------------*/
374 char *name; /* string name of the field */
375 char *dp; /* pointer to the data */
377 register STRING *stp = (STRING *)dp; /* re-type as string */
379 register char *cp; /* next char to print */
380 register char *past_end; /* 1st one not to print */
382 len = MAX_STRING_SIZE(*stp);
383 fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
386 fprintf(gdb_log, "\"\n");
391 cp = STRING_DATA(*stp);
394 while (cp < past_end)
395 (void) putc(*cp++, gdb_log);
397 fprintf(gdb_log,"\"\n");
400 /************************************************************************/
404 /************************************************************************/
406 #define RL_LEN (sizeof(double))
407 #define RL_ALI RL_LEN
408 #define RL_NULL g_rl_null
409 #define RL_CDLEN g_rl_cdlen
410 #define RL_ENC g_rl_enc
411 #define RL_DEC g_rl_dec
412 #define RL_FORM g_rl_form
413 #define RL_NAME "REAL_T"
415 #define RL_EXTERNSIZE 32 /* length of ascii coding */
416 /* must change lengths in */
417 /* encode and decode */
418 /* routines to match*/
419 /*----------------------------------------------------------*/
423 /* Fill in a null value for an real.
425 /*----------------------------------------------------------*/
428 char *dp; /* pointer to the data */
430 *((double *)dp) = 0.0; /* fill in a null value */
433 /*----------------------------------------------------------*/
437 /* Return coded length for an real. For now, we just
438 /* code as a 12 digit ASCII converted string. Obviously,
439 /* we can do much better in the future.
441 /*----------------------------------------------------------*/
446 char *dp; /* pointer to the data */
447 HALF_CONNECTION hcon;
449 return RL_EXTERNSIZE;
452 /*----------------------------------------------------------*/
456 /* Encode an real for transmission
458 /*----------------------------------------------------------*/
461 g_rl_enc(dp, hcon, outp)
462 char *dp; /* pointer to data */
463 HALF_CONNECTION hcon; /* connection descriptor */
464 char *outp; /* place to put the output */
466 register char *cp; /* next char in output */
467 register char *endp = outp+RL_EXTERNSIZE;
470 * Convert the data into printable ASCII in the output stream
471 * Note that the width in the format below must be less than
472 * RL_EXTERNSIZE, because sprintf needs space for its terminating
476 (void) sprintf(outp,"%30le",*((double *)dp));
479 * Sprintf produces output of unpredictable length, and with
480 * a null termination. Pad it out to the desired length.
483 cp = outp + strlen(outp); /* find out where convertd */
486 *cp++ = ' '; /* pad to desired length */
488 return (int)(outp+RL_EXTERNSIZE); /* return pointer to next */
489 /* unused output byte*/
492 /*----------------------------------------------------------*/
496 /* Decode an real from external form
498 /*----------------------------------------------------------*/
501 g_rl_dec(outp, hcon, inp)
502 char *inp; /* pointer to data */
503 HALF_CONNECTION hcon; /* connection descriptor */
504 char *outp; /* place to put the output */
506 (void) sscanf(inp,"%30le", (double *)outp);
507 return (int)(inp+RL_EXTERNSIZE);
510 /*----------------------------------------------------------*/
514 /* Format an real on output logging file for
517 /*----------------------------------------------------------*/
521 char *name; /* string name of the field */
522 char *dp; /* pointer to the data */
524 fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
527 /************************************************************************/
531 /************************************************************************/
533 #define DT_LEN 25 /* see ingres definition */
534 #define DT_ALI 1 /* char data, need not align */
535 #define DT_NULL g_dt_null
536 #define DT_CDLEN g_dt_cdlen
537 #define DT_ENC g_dt_enc
538 #define DT_DEC g_dt_dec
539 #define DT_FORM g_dt_form
540 #define DT_NAME "DATE_T"
542 #define DT_EXTERNSIZE DT_LEN /* length of ascii coding */
543 /* must change lengths in */
544 /* encode and decode */
545 /* routines to match*/
546 /*----------------------------------------------------------*/
550 /* Fill in a null value for a date.
552 /*----------------------------------------------------------*/
555 char *dp; /* pointer to the data */
557 register char *cp = dp; /* next character to fill in */
558 register char *endp = dp + DT_LEN;
561 * Fill the field with character blanks
567 /*----------------------------------------------------------*/
571 /* Return coded length for an date. For now, we just
572 /* code as a 25 digit ASCII converted string.
574 /*----------------------------------------------------------*/
579 char *dp; /* pointer to the data */
580 HALF_CONNECTION hcon;
582 return DT_EXTERNSIZE;
585 /*----------------------------------------------------------*/
589 /* Encode a date for transmission
591 /*----------------------------------------------------------*/
594 g_dt_enc(dp, hcon, outp)
595 char *dp; /* pointer to data */
596 HALF_CONNECTION hcon; /* connection descriptor */
597 char *outp; /* place to put the output */
599 register char *ip = dp; /* next char in input */
600 register char *op = outp; /* next char in output */
601 register char *endp = op+DT_EXTERNSIZE;
604 * Copy the input untransformed to the output
608 *op++ = *ip++; /* pad to desired length */
610 return (int)(endp); /* return pointer to next */
611 /* unused output byte*/
614 /*----------------------------------------------------------*/
618 /* Decode an date from external form
620 /*----------------------------------------------------------*/
623 g_dt_dec(outp, hcon, inp)
624 char *inp; /* pointer to data */
625 HALF_CONNECTION hcon; /* connection descriptor */
626 char *outp; /* place to put the output */
628 register char *ip = inp; /* next char in input */
629 register char *op = outp; /* next char in output */
630 register char *endp = op+DT_EXTERNSIZE;
633 * Copy the input untransformed to the output
637 *op++ = *ip++; /* pad to desired length */
639 return (int)(endp); /* return pointer to next */
640 /* unused output byte*/
643 /*----------------------------------------------------------*/
647 /* Format a date on output logging file for
650 /*----------------------------------------------------------*/
654 char *name; /* string name of the field */
655 char *dp; /* pointer to the data */
657 char buf[DT_EXTERNSIZE+1];
659 bcopy(dp, buf, DT_EXTERNSIZE); /* copy date to buffer */
660 buf[DT_EXTERNSIZE] = '\0'; /* null terminate it */
661 fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
664 /************************************************************************/
666 /* TUPLE_DESCRIPTOR_T
668 /* The external representation of a tuple descriptor will be to
669 /* send the count of the number of fields, and then a one byte
670 /* signed integer describing each type followed by all the
671 /* corresponding null terminated strings. The tuple descriptor
672 /* will really get re-created wth proper offsets and lengths upon
673 /* receipt by the create_tuple_descriptor operation.
675 /************************************************************************/
677 #define TPD_LEN (sizeof(TUPLE_DESCRIPTOR))
678 #define TPD_ALI (sizeof(TUPLE_DESCRIPTOR))
679 #define TPD_NULL g_tpd_null
680 #define TPD_CDLEN g_tpd_cdlen
681 #define TPD_ENC g_tpd_enc
682 #define TPD_DEC g_tpd_dec
683 #define TPD_FORM g_tpd_form
684 #define TPD_NAME "TUPLE_DESCRIPTOR_T"
686 /*----------------------------------------------------------*/
690 /* Fill in a null value for a tuple_descriptor.
692 /*----------------------------------------------------------*/
695 char *dp; /* pointer to the data */
697 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp;
699 /* tuple_descriptor */
700 (*tdp) = NULL; /* no data */
703 /*----------------------------------------------------------*/
707 /* Return coded length for a tuple_descriptor.
709 /*----------------------------------------------------------*/
713 char *dp; /* pointer to the data */
714 HALF_CONNECTION hcon;
716 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
718 /* tuple_descriptor */
719 register int coded_len; /* the value we're trying */
723 * Validate the descriptor
726 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
727 GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
729 coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
730 /* we're going to send */
731 /* the field count as a */
734 coded_len += tdp->str_len + tdp->field_count;
735 /* space for all the */
736 /* strings, with nulls, */
737 /* and for the one byte */
744 /*----------------------------------------------------------*/
748 /* Encode a tuple_descriptor for transmission
750 /*----------------------------------------------------------*/
753 g_tpd_enc(dp, hcon, outp)
754 char *dp; /* pointer to data */
755 HALF_CONNECTION hcon; /* connection descriptor */
756 char *outp; /* place to put the output */
758 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
760 /* tuple_descriptor */
761 register char *nextp; /* place to put next output */
763 register int i; /* a loop counter */
766 * Validate the descriptor
769 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
770 GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
773 * Use the integer coding routine to send the number of fields first
776 nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
779 * Next, put in the one byte codes for each of the field types
782 for (i=0; i<tdp->field_count; i++) {
783 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
788 * Finally, copy all the null terminated strings.
790 bcopy(((char *)(tdp))+gdb_descriptor_length(tdp->field_count),
791 nextp, tdp->str_len); /* copy the string data all */
793 return (int)(nextp+tdp->str_len);
796 /*----------------------------------------------------------*/
800 /* Decode a tuple_descriptor from external form. For
801 /* safety in memory management, we always re-allocate the
802 /* space for the tuple_descriptor. If the pointer passed
803 /* to us is not null, then we assume that it points to a
804 /* legal tuple descriptor, which we first free. Because
805 /* data representation may change, we must re-do the
806 /* create-tuple-descriptor, so it can determine the local
807 /* machine dependent representation and alignment rules
810 /*----------------------------------------------------------*/
812 #define GDB_MAX_DECODED_FIELDS 100
815 g_tpd_dec(outp, hcon, inp)
816 char *inp; /* pointer to input data */
817 HALF_CONNECTION hcon; /* connection descriptor */
818 char *outp; /* place to put the output */
820 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;
822 /* tuple_descriptor */
823 int field_count; /* number of fields in the */
824 /* newly received descriptor*/
825 register int i; /* a loop counter */
827 register int tmp; /* working variable to hold */
828 /* type while they're being */
830 char *nextt; /* next byte to scan for */
831 /* a type code byte*/
832 char *nextn; /* next byte to scan for */
834 char *field_names[GDB_MAX_DECODED_FIELDS];
835 /* put pointers to the */
836 /* field names here */
837 FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
838 /* put the field types in */
841 * Use the integer coding routine to get the number of fields
844 nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
845 if (field_count > GDB_MAX_DECODED_FIELDS)
846 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
850 * For each field, pick up its type code, being sure to sign extend,
851 * and a pointer to its string name.
853 nextn = nextt + field_count; /* there is one byte of */
854 /* type info for each field, */
855 /* after that comes the */
856 /* first string. nextn */
857 /* now points to the first */
859 for (i=0; i<field_count; i++) {
860 tmp = *nextt++; /* type code, may need */
863 tmp |= ((~0) ^ 0xff); /* sign extend if needed */
864 /* this is the most machine */
865 /* independent sign extension */
866 /* I could come up with. */
867 /* Presumes char is one byte, */
868 /* but makes no assumption */
869 /* about sizeof(int) */
870 field_types[i] = tmp;
871 field_names[i] = nextn; /* pointer to name of the */
873 nextn += strlen(nextn) +1; /* set up for possible name */
878 * In case there was already a tuple descriptor here, free it.
881 delete_tuple_descriptor(*tdp);
884 * Create a new descriptor based on the information we have received.
886 *tdp = create_tuple_descriptor(field_count, field_names, field_types);
891 /*----------------------------------------------------------*/
895 /* Format a tuple_descriptor on output logging file for
898 /*----------------------------------------------------------*/
902 char *name; /* tuple_descriptor name of the field */
903 char *dp; /* pointer to the data */
905 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
907 /* tuple_descriptor */
908 register int i; /* loop variable through */
909 /* field definitions */
913 * Handle the special case where the descriptor is null
916 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
921 * Validate the descriptor
923 GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
926 * Descriptor is not null
928 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
930 for (i=0; i<tdp->field_count; i++) {
931 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
933 STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
936 fprintf(gdb_log,"\n");
939 /************************************************************************/
943 /* There is a distinction between the type tuple_t and the
944 /* type tuple_data_t. Tuple_t is a complete self-contained
945 /* tuple, with its descriptor. It actually refers to the
946 /* tuple variable itself, which is a pointer. Tuple_data
947 /* is only the data portion of the tuple, not the descriptor.
948 /* It is used when the receiving tuple is already allocated,
949 /* with a correct descriptor, for sending just the data.
951 /* Note that some of the routines for tuple_t could have been
952 /* implemented in terms of tuple_data_t routines. For the
953 /* moment, they have not been, but that may later be changed.
954 /* Doesn't seem to make much difference as long as they are
955 /* short and simple, and this way does save a bit of overhead.
957 /************************************************************************/
959 #define TP_LEN (sizeof(TUPLE))
960 #define TP_ALI TP_LEN
961 #define TP_NULL g_tp_null
962 #define TP_CDLEN g_tp_cdlen
963 #define TP_ENC g_tp_enc
964 #define TP_DEC g_tp_dec
965 #define TP_FORM g_tp_form
966 #define TP_NAME "TUPLE_T"
968 /*----------------------------------------------------------*/
972 /* Fill in a null value for a tuple.
974 /*----------------------------------------------------------*/
977 char *dp; /* pointer to the data */
979 *((TUPLE *)dp) = NULL;
982 /*----------------------------------------------------------*/
986 /* Return coded length for a tuple. We have to send the
987 /* descriptor along with the data itself. We do this
988 /* with calls to the appropriate encodeing routines.
990 /*----------------------------------------------------------*/
994 char *dp; /* pointer to the data */
995 HALF_CONNECTION hcon;
997 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
998 register int len; /* accumulated length */
999 register int i; /* index to fields */
1000 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1003 * Validate the tuple
1006 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1007 GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1010 * First, get length of the descriptor when coded.
1013 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1014 len = g_tpd_cdlen((char *)&tpd,hcon);
1017 * Now, for each field, add in its coded length
1020 for (i=0; i<tpd->field_count; i++) {
1021 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1022 CODED_LENGTH_PROPERTY)
1023 (FIELD_FROM_TUPLE(tup, i),hcon);
1029 /*----------------------------------------------------------*/
1033 /* Encode a tuple for transmission
1035 /*----------------------------------------------------------*/
1038 g_tp_enc(dp, hcon, outp)
1039 char *dp; /* pointer to data */
1040 HALF_CONNECTION hcon; /* connection descriptor */
1041 char *outp; /* place to put the output */
1043 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1044 register int i; /* index to fields */
1045 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1046 char *op; /* next byte of output */
1049 * Validate the tuple
1052 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1053 GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1056 * First, get the tuple descriptor and encode it
1059 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1060 op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1063 * Now, for each field, code it
1066 for (i=0; i<tpd->field_count; i++) {
1067 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1069 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1075 /*----------------------------------------------------------*/
1079 /* Decode a tuple from external form. For safety
1080 /* in memory management, we always re-allocate the
1081 /* space for the tuple, so the lengths come out right.
1082 /* This may have nasty side effects if the intention
1083 /* was to leave 'gas' at the end of the tuple, but
1084 /* we want to accurately copy the data. Note that
1085 /* tuple_free is robust against null pointers.
1087 /*----------------------------------------------------------*/
1090 g_tp_dec(outp, hcon, inp)
1091 char *inp; /* pointer to input data */
1092 HALF_CONNECTION hcon; /* connection descriptor */
1093 char *outp; /* place to put the output */
1095 register TUPLE tup; /* the new tuple */
1096 register int i; /* index to fields */
1097 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1098 char *ip; /* next byte of input */
1101 * First, get the tuple descriptor and decode it
1104 tpd = NULL; /* so decode will know */
1105 /* there's no existing one */
1107 ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1110 * Now make an empty tuple based on the descriptor
1113 tup = create_tuple(tpd);
1116 * The tuple descriptor has a reference count of 2 here, one
1117 * from the tpd_dec routine, and one from the create_tuple.
1118 * Since we don't expect to explicitly undo the two separately,
1119 * we decrement the count here.
1122 UNREFERENCE_TUPLE_DESCRIPTOR(tpd); /* decr. the reference count */
1125 * Now, for each field, decode it.
1128 for (i=0; i<tpd->field_count; i++) {
1129 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1131 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1134 *((TUPLE *)outp) = tup; /* put the new tuple */
1135 /* pointer where the */
1136 /* caller wants it */
1140 /*----------------------------------------------------------*/
1144 /* Format a tuple on output logging file for
1147 /*----------------------------------------------------------*/
1151 char *name; /* tuple name of the field */
1152 char *dp; /* pointer to the data */
1154 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1155 register int i; /* index to fields */
1156 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1160 * Handle special case where tuple is null
1164 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1168 GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1170 * Get the descriptor--for now, we won't print it
1172 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1178 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1181 * Now, for each field, print it
1184 for (i=0; i<tpd->field_count; i++) {
1185 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1187 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1190 fprintf(gdb_log,"END_OF_TUPLE\n");
1193 /************************************************************************/
1197 /* The distinction between tuple_data_t and tuple_t is a
1198 /* subtle one. Tuple_t is used when a single tuple is to
1199 /* be decoded, outside of any larger context. It (re)allocates
1200 /* memory for both the tuple itself and its descriptor.
1202 /* Tuple_data is used in the case where the tuple and its
1203 /* descriptor are already allocated, but only the data is
1204 /* to be received. This is useful in cases like receiving an
1205 /* entire relation, in which the descriptor is common to
1206 /* all the tuples, and should not be resent or reallocated
1207 /* with each one. Receive relation can send the tuple descriptor
1208 /* once, then do a create_tuple followed by a decode tuple_data
1209 /* to receive the tuple field data into the existing tuple.
1211 /* Note that the definition of null is different in the two cases.
1212 /* The null value for a tuple is just a null pointer. The null
1213 /* for tuple data is to null each of the fields in the tuple
1214 /* recursively. The routines in this section may dereference
1215 /* null pointers if the tuples they are passed are null. Note
1216 /* also that there is one less level of indirection in passing
1217 /* data to these routines than to those of tuple_t.
1219 /* Note also that the null and decode routines supplied here
1220 /* presume that any fields with dependent memory (e.g. string_t
1221 /* fields have already been cleaned up.)
1223 /* Note that this is not quite a kosher type, in the sense that
1224 /* it's length is not fixed. The entry for length below
1225 /* is meaningless, because the real length is computed from the
1226 /* desc. Among other things, this means that TUPLEs cannot
1227 /* contain fields of this type.
1229 /************************************************************************/
1231 #define TDT_LEN (sizeof(TUPLE))
1232 #define TDT_ALI TDT_LEN
1233 #define TDT_NULL g_tdt_null
1234 #define TDT_CDLEN g_tdt_cdlen
1235 #define TDT_ENC g_tdt_enc
1236 #define TDT_DEC g_tdt_dec
1237 #define TDT_FORM g_tdt_form
1238 #define TDT_NAME "TUPLE_DATA_T"
1240 /*----------------------------------------------------------*/
1244 /* Fill in a null value for a tuple.
1246 /*----------------------------------------------------------*/
1249 char *dp; /* pointer to the data */
1251 TUPLE tup = (TUPLE)dp; /* dp is of type TUPLE, */
1252 /* which is actually */
1253 /* a pointer to the */
1255 TUPLE_DESCRIPTOR tpd; /* the descriptor for this */
1257 register int i; /* a loop counter */
1260 * For each field in the tuple, call its null routine
1262 tup->id = GDB_TUP_ID;
1264 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1266 for (i=0; i<tpd->field_count; i++) {
1267 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),NULL_PROPERTY)
1268 (FIELD_FROM_TUPLE(tup,i));
1272 /*----------------------------------------------------------*/
1276 /* Return coded length for tuple data. Since the descriptor
1277 /* for the tuple is known at both sides, we send only
1278 /* the coded fields, not even the field counts.
1280 /*----------------------------------------------------------*/
1283 g_tdt_cdlen(dp,hcon)
1284 char *dp; /* pointer to the data */
1285 HALF_CONNECTION hcon;
1287 register TUPLE tup = (TUPLE)dp; /* arg typed as tuple */
1288 register int len; /* accumulated length */
1289 register int i; /* index to fields */
1290 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1293 * Validate the tuple data
1296 GDB_GIVEUP("g_tdt_cdlen (coded length) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1297 GDB_CHECK_TUP(tup,"g_tdt_cdlen: compute coded length of tuple data")
1299 * First, find the tuple descriptor and set initial coded len to 0
1302 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1306 * Now, for each field, add in its coded length
1309 for (i=0; i<tpd->field_count; i++) {
1310 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1311 CODED_LENGTH_PROPERTY)
1312 (FIELD_FROM_TUPLE(tup, i),hcon);
1318 /*----------------------------------------------------------*/
1322 /* Encode tuple data for transmission.
1324 /*----------------------------------------------------------*/
1327 g_tdt_enc(dp, hcon, outp)
1328 char *dp; /* pointer to data */
1329 HALF_CONNECTION hcon; /* connection descriptor */
1330 char *outp; /* place to put the output */
1332 register TUPLE tup = (TUPLE)dp; /* type as tuple */
1333 register int i; /* index to fields */
1334 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1335 char *op = outp; /* next byte of output */
1338 * Validate the tuple data
1341 GDB_GIVEUP("g_tdt_enc (encode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1342 GDB_CHECK_TUP(tup,"g_tdt_enc: encode of tuple data")
1344 * First, get the tuple descriptor
1347 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1350 * Now, for each field, code it
1353 for (i=0; i<tpd->field_count; i++) {
1354 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1356 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1362 /*----------------------------------------------------------*/
1366 /* Decode tuple data from external form. We presume
1367 /* that the tuple itself is allocated, and the descriptor
1368 /* properly set up for the local machine representation.
1369 /* Here we just decode the fields.
1371 /*----------------------------------------------------------*/
1374 g_tdt_dec(outp, hcon, inp)
1375 char *inp; /* pointer to input data */
1376 HALF_CONNECTION hcon; /* connection descriptor */
1377 char *outp; /* place to put the output */
1379 register TUPLE tup = (TUPLE)outp; /* the filled in tuple */
1380 register int i; /* index to fields */
1381 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1382 char *ip = inp; /* next byte of input */
1385 * Validate the tuple data
1388 GDB_GIVEUP("g_tdt_dec (decode) was given null tuple data\nthis may be due to an attempt to transmit invalid data")
1389 GDB_CHECK_TUP(tup,"g_tdt_dec: decode of tuple data")
1391 * First, get the tuple descriptor
1394 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1397 * Now, for each field, decode it.
1400 for (i=0; i<tpd->field_count; i++) {
1401 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1403 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1409 /*----------------------------------------------------------*/
1413 /* Format tuple data on output logging file for
1416 /*----------------------------------------------------------*/
1419 g_tdt_form(name, dp)
1420 char *name; /* tuple name of the field */
1421 char *dp; /* pointer to the data */
1423 register TUPLE tup = (TUPLE)dp; /* as tuple */
1424 register int i; /* index to fields */
1425 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1429 * Handle special case where we're given a null address for the
1433 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1439 * Validate the tuple data
1441 GDB_CHECK_TUP(tup,"g_tdt_form: format tuple data")
1443 * Get the descriptor--for now, we won't print it
1445 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1451 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1454 * Now, for each field, print it
1457 for (i=0; i<tpd->field_count; i++) {
1458 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1460 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1463 fprintf(gdb_log,"END_OF_TUPLE\n");
1466 /************************************************************************/
1470 /* Relations consist of link lists of tuples, all of which are
1471 /* presumed to share a tuple descriptor. For transmission,
1472 /* these are encoded as follows:
1474 /* 1) A count of the number of tuples, sent as a properly coded
1477 /* 2) The tuple descriptor itself, encoded by its encoding routine.
1479 /* 3) For each tuple, its tuple data, encoded using the routines
1480 /* of the tuple_data_t type.
1482 /************************************************************************/
1484 #define REL_LEN (sizeof(RELATION))
1485 #define REL_ALI REL_LEN
1486 #define REL_NULL g_rel_null
1487 #define REL_CDLEN g_rel_cdlen
1488 #define REL_ENC g_rel_enc
1489 #define REL_DEC g_rel_dec
1490 #define REL_FORM g_rel_form
1491 #define REL_NAME "RELATION_T"
1494 /*----------------------------------------------------------*/
1498 /* Fill in a null value for a relation. Maybe we should
1499 /* check for an existing relation and properly free it,
1500 /* but for now, we don't.
1502 /*----------------------------------------------------------*/
1505 char *dp; /* pointer to the data */
1507 *((RELATION *)dp) = NULL;
1510 /*----------------------------------------------------------*/
1514 /* Return coded length for a relation.
1516 /*----------------------------------------------------------*/
1519 g_rel_cdlen(dp,hcon)
1520 char *dp; /* pointer to the data */
1521 HALF_CONNECTION hcon;
1523 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1524 int len; /* accumulated length */
1525 register TUPLE t; /* index to a tuple */
1526 int tuple_count = 0; /* number of tuples in this */
1528 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1532 * Validate the relation
1535 GDB_GIVEUP("g_rel_cdlen (coded length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1536 GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1538 * First, get the tuple descriptor for this relation
1541 tpd = DESCRIPTOR_FROM_RELATION(rel);
1544 * Count the number of tuples in the relation
1546 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1547 t = NEXT_TUPLE_IN_RELATION(rel,t))
1550 * Start with the coded length for the tuple count and the
1551 * descriptor, which are sent first.
1554 len = g_in_cdlen((char *)&tuple_count, hcon); /* length of tuple_count */
1556 len += g_tpd_cdlen((char *)&tpd, hcon);
1559 * Now, for each tuple, add in its coded length
1562 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1563 t = NEXT_TUPLE_IN_RELATION(rel,t))
1564 len += g_tdt_cdlen((char *)t, hcon);
1569 /*----------------------------------------------------------*/
1573 /* Encode a relation for transmission
1575 /*----------------------------------------------------------*/
1578 g_rel_enc(dp, hcon, outp)
1579 char *dp; /* pointer to data */
1580 HALF_CONNECTION hcon; /* connection descriptor */
1581 char *outp; /* place to put the output */
1583 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1584 char *op; /* pointer to next unused */
1586 register TUPLE t; /* index to a tuple */
1587 int tuple_count = 0; /* number of tuples in this */
1589 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1593 * Validate the relation
1596 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1597 GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1600 * First, get the tuple descriptor for this relation
1603 tpd = DESCRIPTOR_FROM_RELATION(rel);
1606 * Count the number of tuples in the relation
1608 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1609 t = NEXT_TUPLE_IN_RELATION(rel,t))
1612 * Encode the count and the tuple descriptor for this relation
1615 op = (char *)g_in_enc((char *)&tuple_count, hcon,outp);
1616 /* length of tuple_count */
1618 op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1621 * Now, encode each tuple
1624 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1625 t = NEXT_TUPLE_IN_RELATION(rel,t))
1626 op = (char *)g_tdt_enc((char *)t, hcon, op);
1631 /*----------------------------------------------------------*/
1635 /* Decode a relation from external form. We should
1636 /* really check to make sure the relation we are given
1637 /* is null, and if not, call delete_relation on it
1638 /* first. For the moment, we just presume it's null.
1640 /* We proceed by decoding the integer count and the
1641 /* tuple descriptor, from which we create the null
1642 /* relation. We then loop for each tuple, doing a
1643 /* create, a decode, and an add to relation.
1645 /*----------------------------------------------------------*/
1648 g_rel_dec(outp, hcon, inp)
1649 char *inp; /* pointer to input data */
1650 HALF_CONNECTION hcon; /* connection descriptor */
1651 char *outp; /* place to put the output */
1653 register RELATION rel; /* build the relation here */
1654 char *ip; /* pointer to next unused */
1656 register TUPLE t; /* index to a tuple */
1657 register int i; /* loop counter on tuples */
1658 int tuple_count = 0; /* number of tuples in this */
1660 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1664 * First, get the field count and tuple descriptor for this relation
1667 ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1669 tpd = NULL; /* so decode will know */
1670 /* there's no existing one */
1672 ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1675 * Now, create a null relation using the descriptor
1678 rel = create_relation(tpd);
1681 * The reference count for the tuple descriptor is currently 2,
1682 * one from the tpd_dec and one from the create relation. Since
1683 * these will not be undone separately, we decrement the reference
1687 UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1690 * For each tuple, create it, receive it, add it to the relation
1693 for (i=0; i<tuple_count; i++) {
1694 t = create_tuple(tpd);
1695 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1696 ADD_TUPLE_TO_RELATION(rel, t);
1700 * Now store the address of the created relation where requested
1701 * and return pointer to next available input byte.
1704 *((RELATION *)outp) = rel;
1709 /*----------------------------------------------------------*/
1713 /* Format a relation on output logging file for
1716 /*----------------------------------------------------------*/
1719 g_rel_form(name, dp)
1720 char *name; /* relation name of the field */
1721 char *dp; /* pointer to the data */
1723 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1729 * Handle special case where relation is null
1733 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1737 GDB_CHECK_REL(rel,"g_rel_form: format relation")
1743 fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1746 * Now, for each field, print it
1749 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1750 t = NEXT_TUPLE_IN_RELATION(rel,t)){
1751 (void) sprintf(buffer,"Number %d",++count);
1752 g_tdt_form(buffer,(char *)t);
1755 fprintf(gdb_log,"END_OF_RELATION\n");
1758 /************************************************************************/
1760 /* DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION
1763 /* This representation is clearly a real pain to keep up to date
1764 /* properly, mostly because C has such a lousy pre-processor.
1765 /* Probably this should be re-arranged so an initialization routine
1766 /* is called to set up the tables, but even that might be a nuissance.
1768 /************************************************************************/
1770 /*----------------------------------------------------------*/
1774 /* Called at startup to initialize the type table with
1775 /* the entries for the system types.
1777 /*----------------------------------------------------------*/
1779 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1780 g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1781 g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1782 g_type_table[inx][NULL_PROPERTY].f = np; \
1783 g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1784 g_type_table[inx][ENCODE_PROPERTY].f = ep; \
1785 g_type_table[inx][DECODE_PROPERTY].f = dp; \
1786 g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1787 g_type_table[inx][NAME_PROPERTY].cp = name; \
1793 gdb_n_types = SYSTEM_TYPE_COUNT;
1795 ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1797 ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1799 ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1801 ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1803 ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1804 TPD_DEC,TPD_FORM,TPD_NAME)
1805 ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1807 ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1809 ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,