Skip to content

Commit c4873d0

Browse files
authored
Improvements to package/atom access in the sysout from maiko C code (#372)
* Display atom name in error message if get_package_atom() fails * Various fixes to package/atom handling in testtool.c Remove S_TOPVAL and S_MAKEATOM which only existed to deal with an old issue with dbx where you supposedly couldn't enter a string with "\" in it. Remove countchar(), which is functionally identical to strlen(), and adjust code that used it. Adjust return type of MAKEATOM() to be the LispPTR that it should be, instead of int. Limit find_package_from_name() to examining only the number of entries that are present in the *PACKAGE-FROM-INDEX* array, instead of walking off the end. MakeAtom68k() now drops into uraid() if asked to look up an atom that does not exist (Make... is a misnomer, it will never *make* the atom, only lookup an existing one)
1 parent 01a8948 commit c4873d0

File tree

3 files changed

+16
-64
lines changed

3 files changed

+16
-64
lines changed

inc/testtooldefs.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ void doko(void);
2121
void dumpl(LispPTR laddr);
2222
void dumps(LispPTR laddr);
2323
void printPC(void);
24-
int countchar(char *string);
2524
void dump_bf(Bframe *bf);
2625
void dump_fx(struct frameex1 *fx_addr68k);
2726
void dump_stackframe(struct frameex1 *fx_addr68k);
2827
void dump_CSTK(int before);
2928
void btv(void);
3029
int get_framename(struct frameex1 *fx_addr68k);
3130
FX *get_nextFX(FX *fx);
32-
int MAKEATOM(char *string);
31+
LispPTR MAKEATOM(char *string);
3332
LispPTR *MakeAtom68k(char *string);
3433
void GETTOPVAL(char *string);
35-
void S_TOPVAL(char *string);
36-
int S_MAKEATOM(char *string);
3734
void all_stack_dump(DLword start, DLword end, DLword silent);
3835
void dtd_chain(DLword type);
3936
void Trace_FNCall(int numargs, int atomindex, int arg1, LispPTR *tos);

src/gcarray.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ LispPTR get_package_atom(const char *char_base, DLword charlen, const char *pack
278278
packindex = find_package_from_name(packname, packlen);
279279

280280
if (packindex < 0) {
281-
printf("getting package index is failed \n");
281+
printf("getting package index failed %s:%s\n", packname, char_base);
282282
return (0xffffffff);
283283
}
284284

src/testtool.c

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <stdio.h>
4747
#include <stdlib.h>
4848
#include <setjmp.h>
49+
#include <string.h>
4950

5051
#include "lispemul.h"
5152
#include "lispmap.h"
@@ -58,7 +59,9 @@
5859
#include "debug.h"
5960
#include "dbprint.h"
6061
#include "tosfns.h"
62+
#include "array.h"
6163

64+
#include "commondefs.h"
6265
#include "testtooldefs.h"
6366
#include "dbgtooldefs.h"
6467
#include "gcarraydefs.h"
@@ -107,16 +110,17 @@ void print_atomname(LispPTR index)
107110
/* */
108111
/************************************************************************/
109112

110-
#define PACKAGES_LIMIT 255
111-
/** GET PACKAGE INDEX from PACKAGE FULL NAME */
112113
int find_package_from_name(const char *packname, int len) {
113114
int index;
114115
PACKAGE *package;
115116
NEWSTRINGP *namestring;
116117
DLword len2;
117118
char *pname;
119+
struct arrayheader *pi_array;
118120

119-
for (index = 1; index <= PACKAGES_LIMIT; index++) {
121+
/* assumes the *PACKAGE-FROM-INDEX* array is simple with no offset */
122+
pi_array = (struct arrayheader *)Addr68k_from_LADDR(*Package_from_Index_word);
123+
for (index = 1; index < pi_array->totalsize; index++) {
120124
package = (PACKAGE *)Addr68k_from_LADDR(aref1(*Package_from_Index_word, index));
121125
namestring = (NEWSTRINGP *)Addr68k_from_LADDR(package->NAME);
122126
pname = (char *)Addr68k_from_LADDR(namestring->base);
@@ -848,18 +852,6 @@ void printPC(void) {
848852
printf("PC: O%o ", pc);
849853
}
850854

851-
/***************************/
852-
int countchar(char *string) {
853-
int cnt = 0;
854-
855-
while (*string != '\0') {
856-
string++;
857-
cnt++;
858-
}
859-
860-
return (cnt);
861-
}
862-
863855
void dump_bf(Bframe *bf) {
864856
DLword *ptr;
865857
printf("\n*** Basic Frame");
@@ -1025,10 +1017,8 @@ FX *get_nextFX(FX *fx) {
10251017

10261018
} /* get_nextFX end */
10271019

1028-
int MAKEATOM(char *string) {
1029-
int length;
1030-
length = countchar(string);
1031-
return (make_atom(string, 0, length, 0));
1020+
LispPTR MAKEATOM(char *string) {
1021+
return (make_atom(string, 0, strlen(string), 0));
10321022
}
10331023

10341024
/************************************************************************/
@@ -1041,8 +1031,11 @@ int MAKEATOM(char *string) {
10411031
/************************************************************************/
10421032

10431033
LispPTR *MakeAtom68k(char *string) {
1044-
int index;
1045-
index = make_atom(string, 0, countchar(string), 0);
1034+
LispPTR index;
1035+
index = make_atom(string, 0, strlen(string), 0);
1036+
if (index == 0xffffffff) {
1037+
error("MakeAtom68k: no such atom found");
1038+
}
10461039
#ifdef BIGVM
10471040
index = (ATOMS_HI << 16) + (index * 10) + NEWATOM_VALUE_OFFSET;
10481041
#else
@@ -1071,44 +1064,6 @@ void GETTOPVAL(char *string) {
10711064
printf("'%s': no such symbol.\n", string);
10721065
}
10731066

1074-
/************************************************************************/
1075-
/* */
1076-
/* S _ T O P V A L */
1077-
/* */
1078-
/* Given a string that's an atom name minus the initial \, */
1079-
/* print the atom's top-level value. This is here because */
1080-
/* DBX won't put \'s in strings you type. */
1081-
/* */
1082-
/************************************************************************/
1083-
1084-
void S_TOPVAL(char *string) {
1085-
int index;
1086-
LispPTR *cell68k;
1087-
int length;
1088-
char dummy[256];
1089-
1090-
dummy[0] = '\\';
1091-
for (length = 1; *string != '\0'; length++, string++) { dummy[length] = *string; }
1092-
1093-
index = make_atom(dummy, 0, length, 0);
1094-
cell68k = (LispPTR *)GetVALCELL68k(index);
1095-
print(*cell68k);
1096-
}
1097-
1098-
/***************/
1099-
int S_MAKEATOM(char *string) {
1100-
int index = 0;
1101-
int length;
1102-
char dummy[256];
1103-
1104-
dummy[0] = '\\';
1105-
for (length = 1; *string != '\0'; length++, string++) { dummy[length] = *string; }
1106-
1107-
index = make_atom(dummy, 0, length, 0);
1108-
printf("#Atomindex : %d\n", index);
1109-
return (index);
1110-
}
1111-
11121067
/****************************************************************************/
11131068
/* all_stack_dump(start,end)
11141069
*/

0 commit comments

Comments
 (0)