--- freem/src/symtab_bltin.c 2025/03/26 15:17:12 1.7 +++ freem/src/symtab_bltin.c 2025/05/18 18:15:38 1.15 @@ -1,5 +1,5 @@ /* - * $Id: symtab_bltin.c,v 1.7 2025/03/26 15:17:12 snw Exp $ + * $Id: symtab_bltin.c,v 1.15 2025/05/18 18:15:38 snw Exp $ * FreeM local system table and user-defined special variable table * * @@ -24,6 +24,30 @@ * along with FreeM. If not, see . * * $Log: symtab_bltin.c,v $ + * Revision 1.15 2025/05/18 18:15:38 snw + * Add ZEDIT command for editing routines + * + * Revision 1.14 2025/05/14 12:22:04 snw + * Further work on shared memory + * + * Revision 1.13 2025/04/19 21:52:20 snw + * Remove extraneous symbol table debugging message + * + * Revision 1.12 2025/04/14 19:56:27 snw + * Working towards FreeBSD fix + * + * Revision 1.11 2025/04/13 04:22:43 snw + * Fix snprintf calls + * + * Revision 1.10 2025/04/10 01:24:39 snw + * Remove C++ style comments + * + * Revision 1.9 2025/04/09 19:52:02 snw + * Eliminate as many warnings as possible while building with -Wall + * + * Revision 1.8 2025/04/04 12:46:13 snw + * Patch Solaris 8 crash and bump version to 0.63.1-rc1 + * * Revision 1.7 2025/03/26 15:17:12 snw * Fall back to global-backed SSVNs when memory-backed globals fail in attempt to fix Tru64 * @@ -53,6 +77,7 @@ #include "merr.h" #include "consttbl.h" #include "shmmgr.h" +#include "log.h" /* Turn this on to get tons of lovely debugging messages about symbol-table calls */ @@ -118,38 +143,43 @@ void symtab_init (void) shm_config->hdr->PSIZE = DEFPSIZE; shm_config->hdr->argptr = mbpartition; - fprintf (stderr, "symtab_init: initializing memory-backed globals\r\n"); + + logprintf (FM_LOG_INFO, "symtab_init: initializing memory-backed globals"); semid_symtab = semget (symtab_sk, 1, 0666 | IPC_CREAT); if (semid_symtab == -1) { - fprintf (stderr, "symtab_init: failed to create symbol table semaphore\r\n"); - exit (1); + logprintf (FM_LOG_FATAL, "symtab_init: failed to create symbol table semaphore"); } else { - fprintf (stderr, "symtab_init: symbol table semaphore created with semid %d\r\n", semid_symtab); + logprintf (FM_LOG_INFO, "symtab_init: symbol table semaphore created with semid %d", semid_symtab); } +#if defined(__sun__) + logprintf (FM_LOG_WARNING, "symtab_init: falling back to global-backed structured system variables"); + shm_config->hdr->use_mb_globals = FALSE; + return; +#endif + + arg.val = 1; if (semctl (semid_symtab, 0, SETVAL, arg) == -1) { - fprintf (stderr, "symtab_init: failed to initialize symbol table semaphore\r\n"); - exit (1); + logprintf (FM_LOG_FATAL, "symtab_init: failed to initialize symbol table semaphore"); } else { - fprintf (stderr, "symtab_init: symbol table semaphore initialized\r\n"); + logprintf (FM_LOG_INFO, "symtab_init: symbol table semaphore initialized"); } - fprintf (stderr, "symtab_init: allocating partition for memory-backed globals\r\n"); + logprintf (FM_LOG_INFO, "symtab_init: allocating partition for memory-backed globals"); mbpartition = (char *) shm_alloc ((size_t) PSIZE + 2); if (mbpartition != NULL) { shm_config->hdr->use_mb_globals = TRUE; + shm_config->hdr->partition = mbpartition; } else { - fprintf (stderr, "symtab_init: falling back to global-backed structured system variables\r\n"); + logprintf (FM_LOG_WARNING, "symtab_init: falling back to global-backed structured system variables"); shm_config->hdr->use_mb_globals = FALSE; } - - shm_config->hdr->partition = mbpartition; if (symtab_get_sem ()) { for (i = 0; i < 128; i++) shm_config->hdr->alphptr[i] = 0L; @@ -161,12 +191,15 @@ void symtab_init (void) semid_symtab = semget (symtab_sk, 1, 0); if (semid_symtab == -1) { - fprintf (stderr, "symtab_init: could not attach to symbol table semaphore\r\n"); + logprintf (FM_LOG_FATAL, "symtab_init: could not attach to symbol table semaphore"); exit (1); } - - mbpartition = shm_config->hdr->partition; + if (shm_config->hdr->use_mb_globals == TRUE) { + mbpartition = SOA(shm_config->hdr->partition); + } + + symtab_release_sem (); } } @@ -192,7 +225,7 @@ short symtab_get_sem(void) sleep (1); } - fprintf (stderr, "symtab_get_sem: fail\r\n"); + logprintf (FM_LOG_ERROR, "symtab_get_sem: fail"); have_symtab_sem = FALSE; return FALSE; @@ -218,6 +251,11 @@ void symtab_shm (short action, char *key register int i; char *old_partition = partition; + /* + global (action, key, data); + return; + */ + if (shm_config->hdr->use_mb_globals == FALSE) { symtab_bltin (action, key, data); return; @@ -275,7 +313,7 @@ void symtab_shm (short action, char *key } else { - fprintf (stderr, "symtab_shm: failed to acquire symbol table sempahore\r\n"); + logprintf (FM_LOG_FATAL, "symtab_shm: failed to acquire symbol table sempahore"); } writing_mb = FALSE; @@ -373,7 +411,7 @@ void symtab_bltin (short action, char *k stcnv_m2c (tt_with); stcnv_m2c (tt_key); - snprintf (key, 100, "%s%s\201\201", tt_with, tt_key); + sprintf (key, "%s%s\201\201", tt_with, tt_key); no_with: @@ -579,7 +617,7 @@ no_with: /* OLD get_sym routine */ if ((i = alphptr[(int) key[0]])) { -// printf ("alphptr match; writing_mb = %d\r\n", writing_mb); +/* printf ("alphptr match; writing_mb = %d\r\n", writing_mb); */ k = 1; j = i + 1; /* first char always matches! */ @@ -628,10 +666,6 @@ no_with: return; - - - - case set_sym: /* store/create variable */ @@ -1829,7 +1863,7 @@ zinvend: *newptr++ = k1; *newptr++ = set_sym; - //if (mcmnd != ZNEW) test = FALSE; + /*if (mcmnd != ZNEW) test = FALSE; */ return; @@ -1896,7 +1930,7 @@ zinvend: char esbuf[256]; - snprintf (esbuf, 255, "%d\201", estack); + snprintf (esbuf, sizeof (esbuf) - 1, "%d\201", estack); j = stcpy (newptr, esbuf);