--- freem/src/symtab_bltin.c 2025/02/28 20:06:07 1.2 +++ freem/src/symtab_bltin.c 2025/04/14 19:56:27 1.12 @@ -1,23 +1,11 @@ /* - * * - * * * - * * * - * *************** - * * * * * - * * MUMPS * - * * * * * - * *************** - * * * - * * * - * * - * - * symtab.c + * $Id: symtab_bltin.c,v 1.12 2025/04/14 19:56:27 snw Exp $ * FreeM local system table and user-defined special variable table * * - * Author: Serena Willis + * Author: Serena Willis * Copyright (C) 1998 MUG Deutschland - * Copyright (C) 2020 Coherent Logic Development LLC + * Copyright (C) 2020, 2025 Coherent Logic Development LLC * * * This file is part of FreeM. @@ -35,6 +23,37 @@ * You should have received a copy of the GNU Affero Public License * along with FreeM. If not, see . * + * $Log: symtab_bltin.c,v $ + * 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 + * + * Revision 1.6 2025/03/24 04:13:11 snw + * Replace action macro dat with fra_dat to avoid symbol conflict on OS/2 + * + * Revision 1.5 2025/03/24 02:01:41 snw + * Work around some OS/2 incompatibilities in symbol table code + * + * Revision 1.4 2025/03/09 19:50:47 snw + * Second phase of REUSE compliance and header reformat + * + * + * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC + * SPDX-License-Identifier: AGPL-3.0-or-later **/ #include @@ -54,10 +73,11 @@ symbol-table calls */ /* #define DEBUG_SYM */ +short st_use_shm = FALSE; short restoring_consts = FALSE; int semid_symtab; -#if !defined(__OpenBSD__) && !defined(__APPLE__) +#if !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__OS2__) union semun { int val; /* Value for SETVAL */ struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ @@ -113,6 +133,7 @@ void symtab_init (void) shm_config->hdr->PSIZE = DEFPSIZE; shm_config->hdr->argptr = mbpartition; + fprintf (stderr, "symtab_init: initializing memory-backed globals\r\n"); semid_symtab = semget (symtab_sk, 1, 0666 | IPC_CREAT); @@ -124,6 +145,13 @@ void symtab_init (void) fprintf (stderr, "symtab_init: symbol table semaphore created with semid %d\r\n", semid_symtab); } +#if defined(__sun__) + fprintf (stderr, "symtab_init: falling back to global-backed structured system variables\r\n"); + 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"); @@ -136,9 +164,14 @@ void symtab_init (void) fprintf (stderr, "symtab_init: allocating partition for memory-backed globals\r\n"); mbpartition = (char *) shm_alloc ((size_t) PSIZE + 2); - NULLPTRCHK(mbpartition,"symtab_init"); - - shm_config->hdr->partition = mbpartition; + 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"); + shm_config->hdr->use_mb_globals = FALSE; + } if (symtab_get_sem ()) { for (i = 0; i < 128; i++) shm_config->hdr->alphptr[i] = 0L; @@ -153,9 +186,12 @@ void symtab_init (void) fprintf (stderr, "symtab_init: could not attach to symbol table semaphore\r\n"); exit (1); } - - mbpartition = shm_config->hdr->partition; + if (shm_config->hdr->use_mb_globals == TRUE) { + mbpartition = shm_config->hdr->partition; + } + + symtab_release_sem (); } } @@ -206,6 +242,11 @@ void symtab_shm (short action, char *key unsigned long stptrs[128]; register int i; char *old_partition = partition; + + if (shm_config->hdr->use_mb_globals == FALSE) { + symtab_bltin (action, key, data); + return; + } partition = mbpartition; writing_mb = TRUE; @@ -357,7 +398,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: @@ -563,7 +604,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! */ @@ -606,6 +647,9 @@ no_with: } while (i < PSIZE); } + else { + printf ("alphptr not found\r\n"); + } merr_raise (M6); data[0] = EOL; @@ -948,7 +992,7 @@ old0: /* entry from getinc */ /* end of set_sym section */ - case dat: + case fra_dat: /* note: we assume EOL