7 static char *rcsid_gdb_stype_c = "$Header$";
11 /************************************************************************
15 * GDB - System Data Type Definitions
17 * Author: Noah Mendelsohn
18 * Copyright: 1986 MIT Project Athena
19 * For copying and distribution information, please see
20 * the file <mit-copyright.h>.
22 * This file initializes the definitions for all system defined
23 * data types, and it includes the type specific semantic routines
24 * for each of the system defined types.
26 * The initialization routine which adds these type definitions
27 * to the type definition table is at the end of this source file.
29 ************************************************************************
31 * This file is organized into one section for each system
32 * defined type followed at the end by a final section which
33 * initializes the type tables. Each of the type specific
34 * sections does #defines for each type specific parameter. The
35 * gdb_i_stype initialization routine at the end of this source
36 * file uses these defines to initialize the appropriate entry in
37 * the type definition tables.
39 * NOTE: some of the type definitions in this file may be machine
42 ************************************************************************/
44 #include <mit-copyright.h>
49 extern u_long ntohl(), htonl();
51 #include <netinet/in.h> /* for htonl routine */
54 /************************************************************************
58 ************************************************************************/
60 #define IN_LEN (sizeof(int))
62 #define IN_NULL g_in_null
63 #define IN_CDLEN g_in_cdlen
64 #define IN_ENC g_in_enc
65 #define IN_DEC g_in_dec
66 #define IN_FORM g_in_form
67 #define IN_NAME "INTEGER_T"
69 #define IN_EXTERNSIZE 4 /* length of an encoded */
71 /*----------------------------------------------------------*/
75 /* Fill in a null value for an integer.
77 /*----------------------------------------------------------*/
81 char *dp; /* pointer to the data */
83 *((int *)dp) = 0; /* fill in a null value */
86 /*----------------------------------------------------------*/
90 /* Return coded length for an integer. We're currently
91 /* using the Berkeley 'htonl' routine which converts
92 /* an integer (actually a long, ahem!) to a canonical
95 /*----------------------------------------------------------*/
101 char *dp; /* pointer to the data */
102 HALF_CONNECTION hcon;
104 return IN_EXTERNSIZE;
107 /*----------------------------------------------------------*/
111 /* Encode an integer for transmission
113 /*----------------------------------------------------------*/
117 g_in_enc(dp, hcon, outp)
118 char *dp; /* pointer to data */
119 HALF_CONNECTION hcon; /* connection descriptor */
120 char *outp; /* place to put the output */
122 register char *cp; /* next char in output */
123 register char *op = outp;
124 register char *endp = outp+IN_EXTERNSIZE;
126 unsigned long converted; /* the integer goes here */
127 /* in network byte order*/
130 * Put it in network format, then copy one byte at a time to
131 * account for the fact that the RT has trouble with unaligned longs
134 converted = htonl(*(u_long *)dp);
136 cp = (char *)&converted;
142 return (int)(endp); /* return pointer to next */
143 /* unused output byte*/
146 /*----------------------------------------------------------*/
150 /* Decode an integer from external form to local
154 /*----------------------------------------------------------*/
158 g_in_dec(outp, hcon, inp)
159 char *inp; /* pointer to data */
160 HALF_CONNECTION hcon; /* connection descriptor */
161 char *outp; /* place to put the output */
163 register char *ip = inp; /* next byte of input */
165 register char *bp; /* next byte in buffer */
168 * Copy a byte at a time to buffer to account for RT difficulties
169 * with unaligned ints.
171 bp = (char *)&buffer;
178 * Convert it and return pointer to next byte of input.
181 *(int *)outp = ntohl((u_long)buffer);
185 /*----------------------------------------------------------*/
189 /* Format an integer on output logging file for
192 /*----------------------------------------------------------*/
196 char *name; /* string name of the field */
197 char *dp; /* pointer to the data */
199 fprintf(gdb_log, "INTEGER_T\t%s=%d\n",name,(*(int *)dp));
203 /************************************************************************/
207 /************************************************************************/
209 #define ST_LEN (sizeof(STRING))
210 #define ST_ALI (sizeof(int))
211 #define ST_NULL g_st_null
212 #define ST_CDLEN g_st_cdlen
213 #define ST_ENC g_st_enc
214 #define ST_DEC g_st_dec
215 #define ST_FORM g_st_form
216 #define ST_NAME "STRING_T"
218 /*----------------------------------------------------------*/
222 /* Fill in a null value for a string.
224 /*----------------------------------------------------------*/
227 char *dp; /* pointer to the data */
229 register STRING *stp = (STRING *)dp; /* re-type as string */
230 STRING_DATA(*stp) = NULL; /* no data */
231 MAX_STRING_SIZE(*stp) = 0; /* for cleanliness */
234 /*----------------------------------------------------------*/
238 /* Return coded length for a string. We have to send the
239 /* actual length of the data along with the data itself.
240 /* For this reason, we leave space for a coded integer
241 /* in addition to the data bytes. We actually call the
242 /* integer coding routines to code the length.
244 /* Note that a separate type understanding null termination
245 /* might be an interesting optimization someday.
247 /*----------------------------------------------------------*/
251 char *dp; /* pointer to the data */
252 HALF_CONNECTION hcon;
254 register STRING *stp = (STRING *)dp; /* re-type as string */
256 return (MAX_STRING_SIZE(*stp) +
257 g_in_cdlen((char *)&MAX_STRING_SIZE(*stp),hcon));
260 /*----------------------------------------------------------*/
264 /* Encode a string for transmission
266 /*----------------------------------------------------------*/
269 g_st_enc(dp, hcon, outp)
270 char *dp; /* pointer to data */
271 HALF_CONNECTION hcon; /* connection descriptor */
272 char *outp; /* place to put the output */
274 register STRING *stp = (STRING *)dp; /* re-type as string */
276 register char *nextp; /* place to put next output */
279 * Use the integer coding routine to get the length encoded first
282 len = MAX_STRING_SIZE(*stp); /* length of both source */
284 nextp = (char *)g_in_enc((char *)&len, hcon, outp);
287 * Now, copy the data itself after the encoded integer length
290 memcpy(nextp, STRING_DATA(*stp), len);
291 /* copy the data without */
292 /* changing representation*/
293 return (int)(nextp+len);
296 /*----------------------------------------------------------*/
300 /* Decode a string from external form. We always
301 /* allocate new space for the string, intentionally
302 /* ignoring any which may have been in use before. If we
303 /* freed it, we would not be robust against calls on
304 /* uninitialized fields. This may have nasty side
305 /* effects if the intention was to leave 'gas' at the end
306 /* of the string, but we want to accurately copy the
307 /* data. Note that string_free is robust against null
310 /*----------------------------------------------------------*/
313 g_st_dec(outp, hcon, inp)
314 char *inp; /* pointer to input data */
315 HALF_CONNECTION hcon; /* connection descriptor */
316 char *outp; /* place to put the output */
318 register STRING *stp = (STRING *)outp; /* re-type as string */
320 register char *nextp; /* next byte to scan */
322 * Use the integer coding routine to get the length encoded first
325 nextp = (char *)g_in_dec((char *)&len, hcon, inp);
329 * Allocate memory for the string. If length is 0, then null it
330 * out. Note that we had considered freeing any existing strings
331 * which might be there, but this turns out to cause lots of
332 * trouble for the many callers who don't want to initialize before
336 STRING_DATA(*stp) = NULL;
337 MAX_STRING_SIZE(*stp) = 0;
340 (void) string_alloc(stp, len); /* this sets string length */
341 /* in addition to doing the */
345 * Now, copy the data itself
347 memcpy(STRING_DATA(*stp), nextp, len); /* copy the data without */
348 /* changing representation*/
349 return (int)(nextp+len);
352 /*----------------------------------------------------------*/
356 /* Format a string on output logging file for
359 /*----------------------------------------------------------*/
363 char *name; /* string name of the field */
364 char *dp; /* pointer to the data */
366 register STRING *stp = (STRING *)dp; /* re-type as string */
368 register char *cp; /* next char to print */
369 register char *past_end; /* 1st one not to print */
371 len = MAX_STRING_SIZE(*stp);
372 fprintf(gdb_log, "STRING_T\t%s[%d]=\"", name,len);
375 fprintf(gdb_log, "\"\n");
380 cp = STRING_DATA(*stp);
383 while (cp < past_end)
384 (void) putc(*cp++, gdb_log);
386 fprintf(gdb_log,"\"\n");
390 /************************************************************************/
394 /************************************************************************/
396 #define RL_LEN (sizeof(double))
397 #define RL_ALI RL_LEN
398 #define RL_NULL g_rl_null
399 #define RL_CDLEN g_rl_cdlen
400 #define RL_ENC g_rl_enc
401 #define RL_DEC g_rl_dec
402 #define RL_FORM g_rl_form
403 #define RL_NAME "REAL_T"
405 #define RL_EXTERNSIZE 32 /* length of ascii coding */
406 /* must change lengths in */
407 /* encode and decode */
408 /* routines to match*/
409 /*----------------------------------------------------------*/
413 /* Fill in a null value for an real.
415 /*----------------------------------------------------------*/
418 char *dp; /* pointer to the data */
420 *((double *)dp) = 0.0; /* fill in a null value */
423 /*----------------------------------------------------------*/
427 /* Return coded length for an real. For now, we just
428 /* code as a 12 digit ASCII converted string. Obviously,
429 /* we can do much better in the future.
431 /*----------------------------------------------------------*/
437 char *dp; /* pointer to the data */
438 HALF_CONNECTION hcon;
440 return RL_EXTERNSIZE;
443 /*----------------------------------------------------------*/
447 /* Encode an real for transmission
449 /*----------------------------------------------------------*/
453 g_rl_enc(dp, hcon, outp)
454 char *dp; /* pointer to data */
455 HALF_CONNECTION hcon; /* connection descriptor */
456 char *outp; /* place to put the output */
458 register char *cp; /* next char in output */
459 register char *endp = outp+RL_EXTERNSIZE;
462 * Convert the data into printable ASCII in the output stream
463 * Note that the width in the format below must be less than
464 * RL_EXTERNSIZE, because sprintf needs space for its terminating
468 (void) sprintf(outp,"%30le",*((double *)dp));
471 * Sprintf produces output of unpredictable length, and with
472 * a null termination. Pad it out to the desired length.
475 cp = outp + strlen(outp); /* find out where convertd */
478 *cp++ = ' '; /* pad to desired length */
480 return (int)(outp+RL_EXTERNSIZE); /* return pointer to next */
481 /* unused output byte*/
484 /*----------------------------------------------------------*/
488 /* Decode an real from external form
490 /*----------------------------------------------------------*/
494 g_rl_dec(outp, hcon, inp)
495 char *inp; /* pointer to data */
496 HALF_CONNECTION hcon; /* connection descriptor */
497 char *outp; /* place to put the output */
499 (void) sscanf(inp,"%30le", (double *)outp);
500 return (int)(inp+RL_EXTERNSIZE);
503 /*----------------------------------------------------------*/
507 /* Format an real on output logging file for
510 /*----------------------------------------------------------*/
514 char *name; /* string name of the field */
515 char *dp; /* pointer to the data */
517 fprintf(gdb_log, "REAL_T\t\t%s=%le\n",name,*((double *)dp) );
521 /************************************************************************/
525 /************************************************************************/
527 #define DT_LEN 25 /* see ingres definition */
528 #define DT_ALI 1 /* char data, need not align */
529 #define DT_NULL g_dt_null
530 #define DT_CDLEN g_dt_cdlen
531 #define DT_ENC g_dt_enc
532 #define DT_DEC g_dt_dec
533 #define DT_FORM g_dt_form
534 #define DT_NAME "DATE_T"
536 #define DT_EXTERNSIZE DT_LEN /* length of ascii coding */
537 /* must change lengths in */
538 /* encode and decode */
539 /* routines to match*/
540 /*----------------------------------------------------------*/
544 /* Fill in a null value for a date.
546 /*----------------------------------------------------------*/
549 char *dp; /* pointer to the data */
551 register char *cp = dp; /* next character to fill in */
552 register char *endp = dp + DT_LEN;
555 * Fill the field with character blanks
561 /*----------------------------------------------------------*/
565 /* Return coded length for an date. For now, we just
566 /* code as a 25 digit ASCII converted string.
568 /*----------------------------------------------------------*/
574 char *dp; /* pointer to the data */
575 HALF_CONNECTION hcon;
577 return DT_EXTERNSIZE;
580 /*----------------------------------------------------------*/
584 /* Encode a date for transmission
586 /*----------------------------------------------------------*/
590 g_dt_enc(dp, hcon, outp)
591 char *dp; /* pointer to data */
592 HALF_CONNECTION hcon; /* connection descriptor */
593 char *outp; /* place to put the output */
595 register char *ip = dp; /* next char in input */
596 register char *op = outp; /* next char in output */
597 register char *endp = op+DT_EXTERNSIZE;
600 * Copy the input untransformed to the output
604 *op++ = *ip++; /* pad to desired length */
606 return (int)(endp); /* return pointer to next */
607 /* unused output byte*/
610 /*----------------------------------------------------------*/
614 /* Decode an date from external form
616 /*----------------------------------------------------------*/
620 g_dt_dec(outp, hcon, inp)
621 char *inp; /* pointer to data */
622 HALF_CONNECTION hcon; /* connection descriptor */
623 char *outp; /* place to put the output */
625 register char *ip = inp; /* next char in input */
626 register char *op = outp; /* next char in output */
627 register char *endp = op+DT_EXTERNSIZE;
630 * Copy the input untransformed to the output
634 *op++ = *ip++; /* pad to desired length */
636 return (int)(endp); /* return pointer to next */
637 /* unused output byte*/
640 /*----------------------------------------------------------*/
644 /* Format a date on output logging file for
647 /*----------------------------------------------------------*/
651 char *name; /* string name of the field */
652 char *dp; /* pointer to the data */
654 char buf[DT_EXTERNSIZE+1];
656 memcpy(buf, dp, DT_EXTERNSIZE); /* copy date to buffer */
657 buf[DT_EXTERNSIZE] = '\0'; /* null terminate it */
658 fprintf(gdb_log, "DATE_T\t\t%s=%s\n",name,buf);
662 /************************************************************************/
664 /* TUPLE_DESCRIPTOR_T
666 /* The external representation of a tuple descriptor will be to
667 /* send the count of the number of fields, and then a one byte
668 /* signed integer describing each type followed by all the
669 /* corresponding null terminated strings. The tuple descriptor
670 /* will really get re-created wth proper offsets and lengths upon
671 /* receipt by the create_tuple_descriptor operation.
673 /************************************************************************/
675 #define TPD_LEN (sizeof(TUPLE_DESCRIPTOR))
676 #define TPD_ALI (sizeof(TUPLE_DESCRIPTOR))
677 #define TPD_NULL g_tpd_null
678 #define TPD_CDLEN g_tpd_cdlen
679 #define TPD_ENC g_tpd_enc
680 #define TPD_DEC g_tpd_dec
681 #define TPD_FORM g_tpd_form
682 #define TPD_NAME "TUPLE_DESCRIPTOR_T"
684 /*----------------------------------------------------------*/
688 /* Fill in a null value for a tuple_descriptor.
690 /*----------------------------------------------------------*/
693 char *dp; /* pointer to the data */
695 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)dp;
697 /* tuple_descriptor */
698 (*tdp) = NULL; /* no data */
701 /*----------------------------------------------------------*/
705 /* Return coded length for a tuple_descriptor.
707 /*----------------------------------------------------------*/
711 char *dp; /* pointer to the data */
712 HALF_CONNECTION hcon;
714 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
716 /* tuple_descriptor */
717 register int coded_len; /* the value we're trying */
721 * Validate the descriptor
724 GDB_GIVEUP("g_tpd_cdlen (coded length) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
725 GDB_CHECK_TPD(tdp,"g_tpd_cdlen: compute coded length of tuple descriptor")
727 coded_len = g_in_cdlen((char *)&(tdp->field_count),hcon);
728 /* we're going to send */
729 /* the field count as a */
732 coded_len += tdp->str_len + tdp->field_count;
733 /* space for all the */
734 /* strings, with nulls, */
735 /* and for the one byte */
742 /*----------------------------------------------------------*/
746 /* Encode a tuple_descriptor for transmission
748 /*----------------------------------------------------------*/
751 g_tpd_enc(dp, hcon, outp)
752 char *dp; /* pointer to data */
753 HALF_CONNECTION hcon; /* connection descriptor */
754 char *outp; /* place to put the output */
756 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
758 /* tuple_descriptor */
759 register char *nextp; /* place to put next output */
761 register int i; /* a loop counter */
764 * Validate the descriptor
767 GDB_GIVEUP("g_tpd_enc (encode) was given a null tuple descriptor\nthis may be due to an attempt to transmit invalid data")
768 GDB_CHECK_TPD(tdp,"g_tpd_enc: encode tuple descriptor")
771 * Use the integer coding routine to send the number of fields first
774 nextp = (char *)g_in_enc((char *)&(tdp->field_count), hcon, outp);
777 * Next, put in the one byte codes for each of the field types
780 for (i=0; i<tdp->field_count; i++) {
781 *nextp++ = tdp->var[i].type & 0xff; /* put out the one byte */
786 * Finally, copy all the null terminated strings.
788 memcpy(nextp,((char *)(tdp))+gdb_descriptor_length(tdp->field_count),
789 tdp->str_len); /* copy the string data all */
791 return (int)(nextp+tdp->str_len);
794 /*----------------------------------------------------------*/
798 /* Decode a tuple_descriptor from external form. For
799 /* safety in memory management, we always re-allocate the
800 /* space for the tuple_descriptor. If the pointer passed
801 /* to us is not null, then we assume that it points to a
802 /* legal tuple descriptor, which we first free. Because
803 /* data representation may change, we must re-do the
804 /* create-tuple-descriptor, so it can determine the local
805 /* machine dependent representation and alignment rules
808 /*----------------------------------------------------------*/
810 #define GDB_MAX_DECODED_FIELDS 100
813 g_tpd_dec(outp, hcon, inp)
814 char *inp; /* pointer to input data */
815 HALF_CONNECTION hcon; /* connection descriptor */
816 char *outp; /* place to put the output */
818 register TUPLE_DESCRIPTOR *tdp = (TUPLE_DESCRIPTOR *)outp;
820 /* tuple_descriptor */
821 int field_count; /* number of fields in the */
822 /* newly received descriptor*/
823 register int i; /* a loop counter */
825 register int tmp; /* working variable to hold */
826 /* type while they're being */
828 char *nextt; /* next byte to scan for */
829 /* a type code byte*/
830 char *nextn; /* next byte to scan for */
832 char *field_names[GDB_MAX_DECODED_FIELDS];
833 /* put pointers to the */
834 /* field names here */
835 FIELD_TYPE field_types[GDB_MAX_DECODED_FIELDS];
836 /* put the field types in */
839 * Use the integer coding routine to get the number of fields
842 nextt = (char *)g_in_dec((char *)&field_count, hcon, inp);
843 if (field_count > GDB_MAX_DECODED_FIELDS)
844 GDB_GIVEUP("g_tpd_dec: Trying to decode tuple descriptor with too many fields.\n")
848 * For each field, pick up its type code, being sure to sign extend,
849 * and a pointer to its string name.
851 nextn = nextt + field_count; /* there is one byte of */
852 /* type info for each field, */
853 /* after that comes the */
854 /* first string. nextn */
855 /* now points to the first */
857 for (i=0; i<field_count; i++) {
858 tmp = *nextt++; /* type code, may need */
861 tmp |= ((~0) ^ 0xff); /* sign extend if needed */
862 /* this is the most machine */
863 /* independent sign extension */
864 /* I could come up with. */
865 /* Presumes char is one byte, */
866 /* but makes no assumption */
867 /* about sizeof(int) */
868 field_types[i] = tmp;
869 field_names[i] = nextn; /* pointer to name of the */
871 nextn += strlen(nextn) +1; /* set up for possible name */
876 * In case there was already a tuple descriptor here, free it.
879 delete_tuple_descriptor(*tdp);
882 * Create a new descriptor based on the information we have received.
884 *tdp = create_tuple_descriptor(field_count, field_names, field_types);
889 /*----------------------------------------------------------*/
893 /* Format a tuple_descriptor on output logging file for
896 /*----------------------------------------------------------*/
900 char *name; /* tuple_descriptor name of the field */
901 char *dp; /* pointer to the data */
903 register TUPLE_DESCRIPTOR tdp = *((TUPLE_DESCRIPTOR *)dp);
905 /* tuple_descriptor */
906 register int i; /* loop variable through */
907 /* field definitions */
911 * Handle the special case where the descriptor is null
914 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=NULL)\n", name);
919 * Validate the descriptor
921 GDB_CHECK_TPD(tdp,"g_tpd_form: format tuple descriptor")
924 * Descriptor is not null
926 fprintf(gdb_log, "TUPLE_DESCRIPTOR %s (loc=0x%x)\n", name, tdp);
928 for (i=0; i<tdp->field_count; i++) {
929 fprintf(gdb_log,"\tField Type Code = %3d %20s\tField Name=%s\n" ,
931 STR_PROPERTY(tdp->var[i].type,NAME_PROPERTY),
934 fprintf(gdb_log,"\n");
938 /************************************************************************/
942 /* There is a distinction between the type tuple_t and the
943 /* type tuple_data_t. Tuple_t is a complete self-contained
944 /* tuple, with its descriptor. It actually refers to the
945 /* tuple variable itself, which is a pointer. Tuple_data
946 /* is only the data portion of the tuple, not the descriptor.
947 /* It is used when the receiving tuple is already allocated,
948 /* with a correct descriptor, for sending just the data.
950 /* Note that some of the routines for tuple_t could have been
951 /* implemented in terms of tuple_data_t routines. For the
952 /* moment, they have not been, but that may later be changed.
953 /* Doesn't seem to make much difference as long as they are
954 /* short and simple, and this way does save a bit of overhead.
956 /************************************************************************/
958 #define TP_LEN (sizeof(TUPLE))
959 #define TP_ALI TP_LEN
960 #define TP_NULL g_tp_null
961 #define TP_CDLEN g_tp_cdlen
962 #define TP_ENC g_tp_enc
963 #define TP_DEC g_tp_dec
964 #define TP_FORM g_tp_form
965 #define TP_NAME "TUPLE_T"
967 /*----------------------------------------------------------*/
971 /* Fill in a null value for a tuple.
973 /*----------------------------------------------------------*/
976 char *dp; /* pointer to the data */
978 *((TUPLE *)dp) = NULL;
981 /*----------------------------------------------------------*/
985 /* Return coded length for a tuple. We have to send the
986 /* descriptor along with the data itself. We do this
987 /* with calls to the appropriate encodeing routines.
989 /*----------------------------------------------------------*/
993 char *dp; /* pointer to the data */
994 HALF_CONNECTION hcon;
996 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
997 register int len; /* accumulated length */
998 register int i; /* index to fields */
999 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1002 * Validate the tuple
1005 GDB_GIVEUP("g_tp_cdlen (coded length) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1006 GDB_CHECK_TUP(tup,"g_tp_cdlen: compute coded length of tuple")
1009 * First, get length of the descriptor when coded.
1012 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1013 len = g_tpd_cdlen((char *)&tpd,hcon);
1016 * Now, for each field, add in its coded length
1019 for (i=0; i<tpd->field_count; i++) {
1020 len += (int)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1021 CODED_LENGTH_PROPERTY)
1022 (FIELD_FROM_TUPLE(tup, i),hcon);
1028 /*----------------------------------------------------------*/
1032 /* Encode a tuple for transmission
1034 /*----------------------------------------------------------*/
1037 g_tp_enc(dp, hcon, outp)
1038 char *dp; /* pointer to data */
1039 HALF_CONNECTION hcon; /* connection descriptor */
1040 char *outp; /* place to put the output */
1042 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1043 register int i; /* index to fields */
1044 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1045 char *op; /* next byte of output */
1048 * Validate the tuple
1051 GDB_GIVEUP("g_tp_enc (encode) was given a null tuple\nthis may be due to an attempt to transmit invalid data")
1052 GDB_CHECK_TUP(tup,"g_tp_enc: encode tuple")
1055 * First, get the tuple descriptor and encode it
1058 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1059 op = (char *)g_tpd_enc((char *)&tpd, hcon, outp);
1062 * Now, for each field, code it
1065 for (i=0; i<tpd->field_count; i++) {
1066 op = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1068 (FIELD_FROM_TUPLE(tup, i),hcon, op);
1074 /*----------------------------------------------------------*/
1078 /* Decode a tuple from external form. For safety
1079 /* in memory management, we always re-allocate the
1080 /* space for the tuple, so the lengths come out right.
1081 /* This may have nasty side effects if the intention
1082 /* was to leave 'gas' at the end of the tuple, but
1083 /* we want to accurately copy the data. Note that
1084 /* tuple_free is robust against null pointers.
1086 /*----------------------------------------------------------*/
1089 g_tp_dec(outp, hcon, inp)
1090 char *inp; /* pointer to input data */
1091 HALF_CONNECTION hcon; /* connection descriptor */
1092 char *outp; /* place to put the output */
1094 register TUPLE tup; /* the new tuple */
1095 register int i; /* index to fields */
1096 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1097 char *ip; /* next byte of input */
1100 * First, get the tuple descriptor and decode it
1103 tpd = NULL; /* so decode will know */
1104 /* there's no existing one */
1106 ip = (char *)g_tpd_dec((char *)&tpd, hcon, inp);
1109 * Now make an empty tuple based on the descriptor
1112 tup = create_tuple(tpd);
1115 * The tuple descriptor has a reference count of 2 here, one
1116 * from the tpd_dec routine, and one from the create_tuple.
1117 * Since we don't expect to explicitly undo the two separately,
1118 * we decrement the count here.
1121 UNREFERENCE_TUPLE_DESCRIPTOR(tpd); /* decr. the reference count */
1124 * Now, for each field, decode it.
1127 for (i=0; i<tpd->field_count; i++) {
1128 ip = (char *)FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1130 (FIELD_FROM_TUPLE(tup, i),hcon, ip);
1133 *((TUPLE *)outp) = tup; /* put the new tuple */
1134 /* pointer where the */
1135 /* caller wants it */
1139 /*----------------------------------------------------------*/
1143 /* Format a tuple on output logging file for
1146 /*----------------------------------------------------------*/
1150 char *name; /* tuple name of the field */
1151 char *dp; /* pointer to the data */
1153 register TUPLE tup = *((TUPLE *)dp); /* deref as tuple */
1154 register int i; /* index to fields */
1155 TUPLE_DESCRIPTOR tpd; /* descriptor for this tuple */
1159 * Handle special case where tuple is null
1163 fprintf(gdb_log,"\nTUPLE Name=%s is NULL\n---------------------------\n",name);
1167 GDB_CHECK_TUP(tup,"g_tp_form: format tuple")
1169 * Get the descriptor--for now, we won't print it
1171 tpd = DESCRIPTOR_FROM_TUPLE(tup);
1177 fprintf(gdb_log,"\nTUPLE at address: 0x%x Name=%s\n---------------------------\n",tup,name);
1180 * Now, for each field, print it
1183 for (i=0; i<tpd->field_count; i++) {
1184 FCN_PROPERTY(FIELD_TYPE_IN_TUPLE(tpd,i),
1186 (tpd->var[i].name,FIELD_FROM_TUPLE(tup, i));
1189 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");
1467 /************************************************************************/
1471 /* Relations consist of link lists of tuples, all of which are
1472 /* presumed to share a tuple descriptor. For transmission,
1473 /* these are encoded as follows:
1475 /* 1) A count of the number of tuples, sent as a properly coded
1478 /* 2) The tuple descriptor itself, encoded by its encoding routine.
1480 /* 3) For each tuple, its tuple data, encoded using the routines
1481 /* of the tuple_data_t type.
1483 /************************************************************************/
1485 #define REL_LEN (sizeof(RELATION))
1486 #define REL_ALI REL_LEN
1487 #define REL_NULL g_rel_null
1488 #define REL_CDLEN g_rel_cdlen
1489 #define REL_ENC g_rel_enc
1490 #define REL_DEC g_rel_dec
1491 #define REL_FORM g_rel_form
1492 #define REL_NAME "RELATION_T"
1495 /*----------------------------------------------------------*/
1499 /* Fill in a null value for a relation. Maybe we should
1500 /* check for an existing relation and properly free it,
1501 /* but for now, we don't.
1503 /*----------------------------------------------------------*/
1506 char *dp; /* pointer to the data */
1508 *((RELATION *)dp) = NULL;
1511 /*----------------------------------------------------------*/
1515 /* Return coded length for a relation.
1517 /*----------------------------------------------------------*/
1520 g_rel_cdlen(dp,hcon)
1521 char *dp; /* pointer to the data */
1522 HALF_CONNECTION hcon;
1524 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1525 int len; /* accumulated length */
1526 register TUPLE t; /* index to a tuple */
1527 int tuple_count = 0; /* number of tuples in this */
1529 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1533 * Validate the relation
1536 GDB_GIVEUP("g_rel_cdlen (coded length) was given null relation\nthis may be due to an attempt to transmit invalid data")
1537 GDB_CHECK_REL(rel,"g_rel_cdlen: compute coded length of relation")
1539 * First, get the tuple descriptor for this relation
1542 tpd = DESCRIPTOR_FROM_RELATION(rel);
1545 * Count the number of tuples in the relation
1547 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1548 t = NEXT_TUPLE_IN_RELATION(rel,t))
1551 * Start with the coded length for the tuple count and the
1552 * descriptor, which are sent first.
1555 len = g_in_cdlen((char *)&tuple_count, hcon); /* length of tuple_count */
1557 len += g_tpd_cdlen((char *)&tpd, hcon);
1560 * Now, for each tuple, add in its coded length
1563 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1564 t = NEXT_TUPLE_IN_RELATION(rel,t))
1565 len += g_tdt_cdlen((char *)t, hcon);
1570 /*----------------------------------------------------------*/
1574 /* Encode a relation for transmission
1576 /*----------------------------------------------------------*/
1579 g_rel_enc(dp, hcon, outp)
1580 char *dp; /* pointer to data */
1581 HALF_CONNECTION hcon; /* connection descriptor */
1582 char *outp; /* place to put the output */
1584 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1585 char *op; /* pointer to next unused */
1587 register TUPLE t; /* index to a tuple */
1588 int tuple_count = 0; /* number of tuples in this */
1590 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1594 * Validate the relation
1597 GDB_GIVEUP("g_rel_enc (encode) was given null relation\nthis may be due to an attempt to transmit invalid data")
1598 GDB_CHECK_REL(rel,"g_rel_enc: encode relation")
1601 * First, get the tuple descriptor for this relation
1604 tpd = DESCRIPTOR_FROM_RELATION(rel);
1607 * Count the number of tuples in the relation
1609 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1610 t = NEXT_TUPLE_IN_RELATION(rel,t))
1613 * Encode the count and the tuple descriptor for this relation
1616 op = (char *)g_in_enc((char *)&tuple_count, hcon,outp);
1617 /* length of tuple_count */
1619 op = (char *)g_tpd_enc((char *)&tpd, hcon,op);
1622 * Now, encode each tuple
1625 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1626 t = NEXT_TUPLE_IN_RELATION(rel,t))
1627 op = (char *)g_tdt_enc((char *)t, hcon, op);
1632 /*----------------------------------------------------------*/
1636 /* Decode a relation from external form. We should
1637 /* really check to make sure the relation we are given
1638 /* is null, and if not, call delete_relation on it
1639 /* first. For the moment, we just presume it's null.
1641 /* We proceed by decoding the integer count and the
1642 /* tuple descriptor, from which we create the null
1643 /* relation. We then loop for each tuple, doing a
1644 /* create, a decode, and an add to relation.
1646 /*----------------------------------------------------------*/
1649 g_rel_dec(outp, hcon, inp)
1650 char *inp; /* pointer to input data */
1651 HALF_CONNECTION hcon; /* connection descriptor */
1652 char *outp; /* place to put the output */
1654 register RELATION rel; /* build the relation here */
1655 char *ip; /* pointer to next unused */
1657 register TUPLE t; /* index to a tuple */
1658 register int i; /* loop counter on tuples */
1659 int tuple_count = 0; /* number of tuples in this */
1661 TUPLE_DESCRIPTOR tpd; /* descriptor for this */
1665 * First, get the field count and tuple descriptor for this relation
1668 ip = (char *)g_in_dec((char *)&tuple_count, hcon, inp);
1670 tpd = NULL; /* so decode will know */
1671 /* there's no existing one */
1673 ip = (char *)g_tpd_dec((char *)&tpd, hcon, ip);
1676 * Now, create a null relation using the descriptor
1679 rel = create_relation(tpd);
1682 * The reference count for the tuple descriptor is currently 2,
1683 * one from the tpd_dec and one from the create relation. Since
1684 * these will not be undone separately, we decrement the reference
1688 UNREFERENCE_TUPLE_DESCRIPTOR(tpd);
1691 * For each tuple, create it, receive it, add it to the relation
1694 for (i=0; i<tuple_count; i++) {
1695 t = create_tuple(tpd);
1696 ip = (char *)g_tdt_dec((char *)t, hcon, ip);
1697 ADD_TUPLE_TO_RELATION(rel, t);
1701 * Now store the address of the created relation where requested
1702 * and return pointer to next available input byte.
1705 *((RELATION *)outp) = rel;
1710 /*----------------------------------------------------------*/
1714 /* Format a relation on output logging file for
1717 /*----------------------------------------------------------*/
1720 g_rel_form(name, dp)
1721 char *name; /* relation name of the field */
1722 char *dp; /* pointer to the data */
1724 register RELATION rel = *((RELATION *)dp); /* deref as relation */
1730 * Handle special case where relation is null
1734 fprintf(gdb_log,"\nRELATION Name=%s is NULL\n===========================\n",name);
1738 GDB_CHECK_REL(rel,"g_rel_form: format relation")
1744 fprintf(gdb_log,"\nRELATION at address: 0x%x Name=%s\n===========================\n",rel,name);
1747 * Now, for each field, print it
1750 for (t=FIRST_TUPLE_IN_RELATION(rel); t != NULL;
1751 t = NEXT_TUPLE_IN_RELATION(rel,t)){
1752 (void) sprintf(buffer,"Number %d",++count);
1753 g_tdt_form(buffer,(char *)t);
1756 fprintf(gdb_log,"END_OF_RELATION\n");
1760 /************************************************************************/
1762 /* DECLARE AND INITIALIZE THE SYSTEM TYPE DEFINITION
1765 /* This representation is clearly a real pain to keep up to date
1766 /* properly, mostly because C has such a lousy pre-processor.
1767 /* Probably this should be re-arranged so an initialization routine
1768 /* is called to set up the tables, but even that might be a nuissance.
1770 /************************************************************************/
1772 /*----------------------------------------------------------*/
1776 /* Called at startup to initialize the type table with
1777 /* the entries for the system types.
1779 /*----------------------------------------------------------*/
1781 #define ITYPE(inx,lp,ap,np,clp,ep,dp,fp,name) {\
1782 g_type_table[inx][LENGTH_PROPERTY].i = lp; \
1783 g_type_table[inx][ALIGNMENT_PROPERTY].i = ap; \
1784 g_type_table[inx][NULL_PROPERTY].f = np; \
1785 g_type_table[inx][CODED_LENGTH_PROPERTY].f = clp; \
1786 g_type_table[inx][ENCODE_PROPERTY].f = ep; \
1787 g_type_table[inx][DECODE_PROPERTY].f = dp; \
1788 g_type_table[inx][FORMAT_PROPERTY].f = fp; \
1789 g_type_table[inx][NAME_PROPERTY].cp = name; \
1795 gdb_n_types = SYSTEM_TYPE_COUNT;
1797 ITYPE(INTEGER_T,IN_LEN,IN_ALI,IN_NULL,IN_CDLEN,IN_ENC,IN_DEC,IN_FORM,
1799 ITYPE(STRING_T,ST_LEN,ST_ALI,ST_NULL,ST_CDLEN,ST_ENC,ST_DEC,ST_FORM,
1801 ITYPE(REAL_T,RL_LEN,RL_ALI,RL_NULL,RL_CDLEN,RL_ENC,RL_DEC,RL_FORM,
1803 ITYPE(DATE_T,DT_LEN,DT_ALI,DT_NULL,DT_CDLEN,DT_ENC,DT_DEC,DT_FORM,
1805 ITYPE(TUPLE_DESCRIPTOR_T,TPD_LEN,TPD_ALI,TPD_NULL,TPD_CDLEN,TPD_ENC,
1806 TPD_DEC,TPD_FORM,TPD_NAME)
1807 ITYPE(TUPLE_T,TP_LEN,TP_ALI,TP_NULL,TP_CDLEN,TP_ENC,TP_DEC,TP_FORM,
1809 ITYPE(TUPLE_DATA_T,TDT_LEN,TDT_ALI,TDT_NULL,TDT_CDLEN,TDT_ENC,TDT_DEC,
1811 ITYPE(RELATION_T,REL_LEN,REL_ALI,REL_NULL,REL_CDLEN,REL_ENC,REL_DEC,