GnuCOBOL  2.0
A free COBOL compiler
call.c File Reference
#include "config.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ltdl.h>
#include "libcob.h"
#include "coblocal.h"
#include "system.def"
Include dependency graph for call.c:

Go to the source code of this file.

Data Structures

struct  call_hash
 
struct  struct_handle
 
struct  system_table
 

Macros

#define _GNU_SOURCE   1
 
#define COB_LIB_EXPIMP
 
#define COB_MAX_COBCALL_PARMS   16
 
#define CALL_BUFF_SIZE   256U
 
#define CALL_BUFF_MAX   (CALL_BUFF_SIZE - 1U)
 
#define HASH_SIZE   131U
 
#define COB_SYSTEM_GEN(x, y, z)   { x, {(void *(*)(void *))z} },
 

Functions

static void set_resolve_error (const char *msg, const char *entry)
 
static void cob_set_library_path (const char *path)
 
static void do_cancel_module (struct call_hash *p, struct call_hash **base_hash, struct call_hash *prev)
 
static void * cob_get_buff (const size_t buffsize)
 
static void cache_dynload (const char *path, lt_dlhandle handle)
 
static size_t cache_preload (const char *path)
 
static COB_INLINE unsigned int hash (const unsigned char *s)
 
static void insert (const char *name, void *func, lt_dlhandle handle, cob_module *module, const char *path, const unsigned int nocanc)
 
static void * lookup (const char *name)
 
static void * cob_resolve_internal (const char *name, const char *dirent, const int fold_case)
 
static const char * cob_chk_dirp (const char *name)
 
static char * cob_chk_call_path (const char *name, char **dirent)
 
const char * cob_resolve_error (void)
 
void cob_call_error (void)
 
void cob_set_cancel (cob_module *m)
 
void * cob_resolve (const char *name)
 
void * cob_resolve_cobol (const char *name, const int fold_case, const int errind)
 
void * cob_resolve_func (const char *name)
 
void * cob_call_field (const cob_field *f, const struct cob_call_struct *cs, const unsigned int errind, const int fold_case)
 
void cob_cancel (const char *name)
 
void cob_cancel_field (const cob_field *f, const struct cob_call_struct *cs)
 
int cob_call (const char *name, const int argc, void **argv)
 
int cob_func (const char *name, const int argc, void **argv)
 
void * cob_savenv (struct cobjmp_buf *jbuf)
 
void * cob_savenv2 (struct cobjmp_buf *jbuf, const int jsize)
 
void cob_longjmp (struct cobjmp_buf *jbuf)
 
void cob_exit_call (void)
 
void cob_init_call (cob_global *lptr, cob_settings *sptr)
 

Variables

static struct call_hash ** call_table
 
static struct struct_handlebase_preload_ptr
 
static struct struct_handlebase_dynload_ptr
 
static cob_globalcobglobptr
 
static cob_settingscobsetptr
 
static char ** resolve_path
 
static char * resolve_error
 
static char * resolve_alloc
 
static char * resolve_error_buff
 
static void * call_buffer
 
static char * call_filename_buff
 
static char * call_entry_buff
 
static unsigned char * call_entry2_buff
 
static lt_dlhandle mainhandle
 
static size_t call_lastsize
 
static size_t resolve_size
 
static unsigned int cob_jmp_primed
 
static const struct system_table system_tab []
 
static const unsigned char hexval [] = "0123456789ABCDEF"
 
static unsigned char valid_char [256]
 
static const unsigned char pvalid_char []
 

Macro Definition Documentation

#define _GNU_SOURCE   1

Definition at line 26 of file call.c.

#define CALL_BUFF_MAX   (CALL_BUFF_SIZE - 1U)

Definition at line 120 of file call.c.

Referenced by set_resolve_error().

#define CALL_BUFF_SIZE   256U

Definition at line 119 of file call.c.

Referenced by cob_init_call().

#define COB_LIB_EXPIMP

Definition at line 113 of file call.c.

#define COB_MAX_COBCALL_PARMS   16

Definition at line 118 of file call.c.

#define COB_SYSTEM_GEN (   x,
  y,
 
)    { x, {(void *(*)(void *))z} },

Definition at line 183 of file call.c.

#define HASH_SIZE   131U

Definition at line 122 of file call.c.

Referenced by cob_exit_call(), cob_init_call(), and hash().

Function Documentation

static void cache_dynload ( const char *  path,
lt_dlhandle  handle 
)
static

Definition at line 431 of file call.c.

References base_dynload_ptr, cob_malloc(), cob_strdup(), struct_handle::handle, struct_handle::next, and struct_handle::path.

Referenced by cob_resolve_internal().

432 {
433  struct struct_handle *dynptr;
434 
435  for (dynptr = base_dynload_ptr; dynptr; dynptr = dynptr->next) {
436  if (!strcmp (path, dynptr->path)) {
437  if (!dynptr->handle) {
438  dynptr->handle = handle;
439  return;
440  }
441  }
442  }
443  dynptr = cob_malloc (sizeof (struct struct_handle));
444  dynptr->path = cob_strdup (path);
445  dynptr->handle = handle;
446  dynptr->next = base_dynload_ptr;
447  base_dynload_ptr = dynptr;
448 }
struct struct_handle * next
Definition: call.c:140
lt_dlhandle handle
Definition: call.c:142
const char * path
Definition: call.c:141
char * cob_strdup(const char *)
Definition: common.c:1308
void * cob_malloc(const size_t size)
Definition: common.c:1250
static struct struct_handle * base_dynload_ptr
Definition: call.c:159

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t cache_preload ( const char *  path)
static

Definition at line 451 of file call.c.

References base_preload_ptr, cob_malloc(), __cob_settings::cob_preload_str, cob_strcat(), cob_strdup(), struct_handle::handle, struct_handle::next, NULL, struct_handle::path, PATHSEP_STR, and R_OK.

Referenced by cob_init_call().

452 {
453  struct struct_handle *preptr;
454  lt_dlhandle libhandle;
455 
456 #if defined(_WIN32) || defined(__CYGWIN__)
457  struct struct_handle *last_elem;
458  last_elem = NULL;
459 #endif
460 
461  /* Check for duplicate */
462  for (preptr = base_preload_ptr; preptr; preptr = preptr->next) {
463  if (!strcmp (path, preptr->path)) {
464  return 1;
465  }
466 #if defined(_WIN32) || defined(__CYGWIN__)
467  /* Save last element of preload list */
468  if (!preptr->next) last_elem = preptr;
469 #endif
470  }
471 
472  if (access (path, R_OK) != 0) {
473  return 0;
474  }
475 
476  libhandle = lt_dlopen (path);
477  if (!libhandle) {
478  return 0;
479  }
480 
481  preptr = cob_malloc (sizeof (struct struct_handle));
482  preptr->path = cob_strdup (path);
483  preptr->handle = libhandle;
484 
485 #if defined(_WIN32) || defined(__CYGWIN__)
486  /*
487  * Observation: dlopen (POSIX) and lt_dlopen (UNIX) are overloading
488  * symbols with equal name. So if we load two libraries with equal
489  * named symbols, the last one wins and is loaded.
490  * LoadLibrary (Win32) ignores any equal named symbol
491  * if another library with this symbol was already loaded.
492  *
493  * In Windows (including MinGW/CYGWIN) we need to load modules
494  * in the same order as we save them to COB_PRE_LOAD due to issues
495  * if we have got two modules with equal entry points.
496  */
497  if(last_elem) {
498  last_elem->next = preptr;
499  }
500  else {
501  preptr->next = NULL;
502  base_preload_ptr = preptr;
503  }
504 #else
505  preptr->next = base_preload_ptr;
506  base_preload_ptr = preptr;
507 #endif
508 
509 
510  if(!cobsetptr->cob_preload_str) {
512  }
513  else {
516  }
517 
518  return 1;
519 }
struct struct_handle * next
Definition: call.c:140
char * cob_preload_str
Definition: coblocal.h:220
lt_dlhandle handle
Definition: call.c:142
static cob_settings * cobsetptr
Definition: call.c:162
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define PATHSEP_STR
Definition: common.h:501
const char * path
Definition: call.c:141
char * cob_strdup(const char *)
Definition: common.c:1308
char * cob_strcat(char *str1, char *str2)
Definition: common.c:4270
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define R_OK
Definition: cobc.h:58
static struct struct_handle * base_preload_ptr
Definition: call.c:158

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_call ( const char *  name,
const int  argc,
void **  argv 
)

Definition at line 1080 of file call.c.

References _, __cob_global::cob_call_params, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_free(), cob_malloc(), COB_MAX_FIELD_PARAMS, cob_resolve_cobol(), cob_runtime_error(), cob_stop_run(), cob_call_union::funcint, cob_call_union::funcvoid, and unlikely.

Referenced by cob_func().

1081 {
1082  void **pargv;
1083  cob_call_union unifunc;
1084  int i;
1085 
1086  if (unlikely(!cobglobptr)) {
1088  }
1089  if (argc < 0 || argc > COB_MAX_FIELD_PARAMS) {
1090  cob_runtime_error (_("Invalid number of arguments to '%s'"), "cob_call");
1091  cob_stop_run (1);
1092  }
1093  if (unlikely(!name)) {
1094  cob_runtime_error (_("NULL parameter passed to '%s'"), "cob_call");
1095  cob_stop_run (1);
1096  }
1097  unifunc.funcvoid = cob_resolve_cobol (name, 0, 1);
1098  pargv = cob_malloc (COB_MAX_FIELD_PARAMS * sizeof(void *));
1099  /* Set number of parameters */
1100  cobglobptr->cob_call_params = argc;
1101  for (i = 0; i < argc; ++i) {
1102  pargv[i] = argv[i];
1103  }
1104 #if COB_MAX_FIELD_PARAMS == 16 || \
1105  COB_MAX_FIELD_PARAMS == 36 || \
1106  COB_MAX_FIELD_PARAMS == 56 || \
1107  COB_MAX_FIELD_PARAMS == 76 || \
1108  COB_MAX_FIELD_PARAMS == 96
1109 #else
1110 #error "Invalid COB_MAX_FIELD_PARAMS value"
1111 #endif
1112  i = unifunc.funcint (pargv[0], pargv[1], pargv[2], pargv[3]
1113  ,pargv[4], pargv[5], pargv[6], pargv[7]
1114  ,pargv[8], pargv[9], pargv[10], pargv[11]
1115  ,pargv[12], pargv[13], pargv[14], pargv[15]
1116 #if COB_MAX_FIELD_PARAMS > 16
1117  ,pargv[16], pargv[17], pargv[18], pargv[19]
1118  ,pargv[20], pargv[21], pargv[22], pargv[23]
1119  ,pargv[24], pargv[25], pargv[26], pargv[27]
1120  ,pargv[28], pargv[29], pargv[30], pargv[31]
1121  ,pargv[32], pargv[33], pargv[34], pargv[35]
1122 #if COB_MAX_FIELD_PARAMS > 36
1123  ,pargv[36], pargv[37], pargv[38], pargv[39]
1124  ,pargv[40], pargv[41], pargv[42], pargv[43]
1125  ,pargv[44], pargv[45], pargv[46], pargv[47]
1126  ,pargv[48], pargv[49], pargv[50], pargv[51]
1127  ,pargv[52], pargv[53], pargv[54], pargv[55]
1128 #if COB_MAX_FIELD_PARAMS > 56
1129  ,pargv[56], pargv[57], pargv[58], pargv[59]
1130  ,pargv[60], pargv[61], pargv[62], pargv[63]
1131  ,pargv[64], pargv[65], pargv[66], pargv[67]
1132  ,pargv[68], pargv[69], pargv[70], pargv[71]
1133  ,pargv[72], pargv[73], pargv[74], pargv[75]
1134 #if COB_MAX_FIELD_PARAMS > 76
1135  ,pargv[76], pargv[77], pargv[78], pargv[79]
1136  ,pargv[80], pargv[81], pargv[82], pargv[83]
1137  ,pargv[84], pargv[85], pargv[86], pargv[87]
1138  ,pargv[88], pargv[89], pargv[90], pargv[91]
1139  ,pargv[92], pargv[93], pargv[94], pargv[95]
1140 #endif
1141 #endif
1142 #endif
1143 #endif
1144  );
1145  cob_free (pargv);
1146  return i;
1147 }
void cob_free(void *mptr)
Definition: common.c:1284
void * cob_resolve_cobol(const char *name, const int fold_case, const int errind)
Definition: call.c:923
int cob_call_params
Definition: common.h:1204
void * funcvoid
Definition: common.h:1010
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
int(* funcint)()
Definition: common.h:1009
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define COB_MAX_FIELD_PARAMS
Definition: common.h:559
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_call_error ( void  )

Definition at line 878 of file call.c.

References cob_resolve_error(), cob_runtime_error(), and cob_stop_run().

Referenced by cob_call_field(), cob_resolve_cobol(), and main().

879 {
881  cob_stop_run (1);
882 }
const char * cob_resolve_error(void)
Definition: call.c:864
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_call_field ( const cob_field f,
const struct cob_call_struct cs,
const unsigned int  errind,
const int  fold_case 
)

Definition at line 957 of file call.c.

References cob_call_error(), cob_chk_call_path(), cob_call_struct::cob_cstr_call, cob_call_struct::cob_cstr_name, COB_EC_PROGRAM_NOT_FOUND, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_field_to_string(), cob_free(), cob_get_buff(), cob_resolve_internal(), cob_set_exception(), cob_call_union::funcvoid, NULL, cob_field::size, system_table::syst_call, system_table::syst_name, and unlikely.

959 {
960  void *p;
961  const struct cob_call_struct *s;
962  const struct system_table *psyst;
963  char *buff;
964  char *entry;
965  char *dirent;
966 
967  if (unlikely(!cobglobptr)) {
969  }
970 
971  buff = cob_get_buff (f->size + 1);
972  cob_field_to_string (f, buff, f->size);
973 
974  entry = cob_chk_call_path (buff, &dirent);
975 
976  /* Check if system routine */
977  for (psyst = system_tab; psyst->syst_name; ++psyst) {
978  if (!strcmp (entry, psyst->syst_name)) {
979  if (dirent) {
980  cob_free (dirent);
981  }
982  return psyst->syst_call.funcvoid;
983  }
984  }
985 
986 
987  /* Check if contained program */
988  for (s = cs; s && s->cob_cstr_name; s++) {
989  if (!strcmp (entry, s->cob_cstr_name)) {
990  if (dirent) {
991  cob_free (dirent);
992  }
993  return s->cob_cstr_call.funcvoid;
994  }
995  }
996 
997  p = cob_resolve_internal (entry, dirent, fold_case);
998  if (dirent) {
999  cob_free (dirent);
1000  }
1001  if (unlikely(!p)) {
1002  if (errind) {
1003  cob_call_error ();
1004  } else {
1006  return NULL;
1007  }
1008  }
1009  return p;
1010 }
void cob_free(void *mptr)
Definition: common.c:1284
static void * cob_get_buff(const size_t buffsize)
Definition: call.c:420
static const struct system_table system_tab[]
Definition: call.c:186
const char * cob_cstr_name
Definition: common.h:1021
void * funcvoid
Definition: common.h:1010
void cob_field_to_string(const cob_field *, void *, const size_t)
Definition: common.c:1492
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
size_t size
Definition: common.h:951
void cob_call_error(void)
Definition: call.c:878
static char * cob_chk_call_path(const char *name, char **dirent)
Definition: call.c:825
const char * syst_call
Definition: codegen.c:67
static void * cob_resolve_internal(const char *name, const char *dirent, const int fold_case)
Definition: call.c:599
const char * syst_name
Definition: codegen.c:66
cob_call_union cob_cstr_call
Definition: common.h:1022

Here is the call graph for this function:

void cob_cancel ( const char *  name)

Definition at line 1013 of file call.c.

References _, call_table, cob_chk_dirp(), cob_fatal_error(), COB_FERROR_INITIALIZED, cob_runtime_error(), cob_stop_run(), do_cancel_module(), hash(), call_hash::name, call_hash::next, NULL, and unlikely.

Referenced by cob_cancel_field(), and cob_func().

1014 {
1015  const char *entry;
1016  struct call_hash *p;
1017  struct call_hash **q;
1018  struct call_hash *r;
1019 
1020  if (unlikely(!cobglobptr)) {
1022  }
1023  if (unlikely(!name)) {
1024  cob_runtime_error (_("NULL parameter passed to '%s'"), "cob_cancel");
1025  cob_stop_run (1);
1026  }
1027  entry = cob_chk_dirp (name);
1028 
1029 #ifdef COB_ALT_HASH
1030  q = &call_table;
1031  p = *q;
1032 #else
1033  q = &call_table[hash ((const unsigned char *)entry)];
1034  p = *q;
1035 #endif
1036  r = NULL;
1037  for (; p; p = p->next) {
1038  if (strcmp (entry, p->name) == 0) {
1039  do_cancel_module (p, q, r);
1040  return;
1041  }
1042  r = p;
1043  }
1044 }
static struct call_hash ** call_table
Definition: call.c:155
static COB_INLINE unsigned int hash(const unsigned char *s)
Definition: call.c:523
static const char * cob_chk_dirp(const char *name)
Definition: call.c:807
static void do_cancel_module(struct call_hash *p, struct call_hash **base_hash, struct call_hash *prev)
Definition: call.c:354
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
#define _(s)
Definition: cobcrun.c:59
const char * name
Definition: call.c:131
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct call_hash * next
Definition: call.c:130
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_cancel_field ( const cob_field f,
const struct cob_call_struct cs 
)

Definition at line 1047 of file call.c.

References cob_cancel(), cob_chk_dirp(), cob_call_struct::cob_cstr_cancel, cob_call_struct::cob_cstr_name, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_field_to_string(), cob_get_buff(), cob_call_union::funcint, cob_call_union::funcvoid, call_hash::name, NULL, cob_field::size, and unlikely.

1048 {
1049  char *name;
1050  const char *entry;
1051  const struct cob_call_struct *s;
1052 
1053  int (*cancel_func)(const int, void *, void *, void *, void *);
1054 
1055  if (unlikely(!cobglobptr)) {
1057  }
1058  if (!f || f->size == 0) {
1059  return;
1060  }
1061  name = cob_get_buff (f->size + 1);
1062  cob_field_to_string (f, name, f->size);
1063  entry = cob_chk_dirp (name);
1064 
1065  /* Check if contained program */
1066  for (s = cs; s && s->cob_cstr_name; s++) {
1067  if (!strcmp (entry, s->cob_cstr_name)) {
1068  if (s->cob_cstr_cancel.funcvoid) {
1069  cancel_func = s->cob_cstr_cancel.funcint;
1070  (void)cancel_func (-1, NULL, NULL, NULL,
1071  NULL);
1072  }
1073  return;
1074  }
1075  }
1076  cob_cancel (entry);
1077 }
static void * cob_get_buff(const size_t buffsize)
Definition: call.c:420
static const char * cob_chk_dirp(const char *name)
Definition: call.c:807
const char * cob_cstr_name
Definition: common.h:1021
void cob_cancel(const char *name)
Definition: call.c:1013
void * funcvoid
Definition: common.h:1010
void cob_field_to_string(const cob_field *, void *, const size_t)
Definition: common.c:1492
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
const char * name
Definition: call.c:131
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int(* funcint)()
Definition: common.h:1009
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
size_t size
Definition: common.h:951
cob_call_union cob_cstr_cancel
Definition: common.h:1023

Here is the call graph for this function:

static char* cob_chk_call_path ( const char *  name,
char **  dirent 
)
static

Definition at line 825 of file call.c.

References cob_strdup(), and NULL.

Referenced by cob_call_field(), cob_resolve(), and cob_resolve_cobol().

826 {
827  char *p;
828  char *q;
829  size_t size1;
830  size_t size2;
831 
832  *dirent = NULL;
833  q = NULL;
834  size2 = 0;
835  for (p = (char *)name, size1 = 0; *p; p++, size1++) {
836  if (*p == '/' || *p == '\\') {
837  q = p + 1;
838  size2 = size1 + 1;
839  }
840  }
841  if (q) {
842  p = cob_strdup (name);
843  p[size2] = 0;
844  *dirent = p;
845  for (; *p; p++) {
846 #ifdef _WIN32
847  if (*p == '/') {
848  *p = '\\';
849  }
850 #else
851  if (*p == '\\') {
852  *p = '/';
853  }
854 #endif
855  }
856  return q;
857  }
858  return (char *)name;
859 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
char * cob_strdup(const char *)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* cob_chk_dirp ( const char *  name)
static

Definition at line 807 of file call.c.

References NULL.

Referenced by cob_cancel(), and cob_cancel_field().

808 {
809  const char *p;
810  const char *q;
811 
812  q = NULL;
813  for (p = name; *p; p++) {
814  if (*p == '/' || *p == '\\') {
815  q = p + 1;
816  }
817  }
818  if (q) {
819  return q;
820  }
821  return name;
822 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the caller graph for this function:

void cob_exit_call ( void  )

Definition at line 1204 of file call.c.

References call_table, cob_free(), struct_handle::handle, HASH_SIZE, call_hash::name, call_hash::next, struct_handle::next, NULL, call_hash::path, and struct_handle::path.

Referenced by cob_terminate_routines().

1205 {
1206  struct call_hash *p;
1207  struct call_hash *q;
1208  struct struct_handle *h;
1209  struct struct_handle *j;
1210 
1211 #ifndef COB_ALT_HASH
1212  size_t i;
1213 #endif
1214 
1215  if (call_filename_buff) {
1218  }
1219  if (call_entry_buff) {
1222  }
1223  if (call_entry2_buff) {
1226  }
1227  if (call_buffer) {
1229  call_buffer = NULL;
1230  }
1231  if (resolve_error_buff) {
1234  }
1235  if (resolve_alloc) {
1237  resolve_alloc = NULL;
1238  }
1239  if (resolve_path) {
1241  resolve_path = NULL;
1242  }
1243 
1244 #ifndef COB_ALT_HASH
1245  if (call_table) {
1246  for (i = 0; i < HASH_SIZE; ++i) {
1247  p = call_table[i];
1248 #else
1249  p = call_table;
1250 #endif
1251  for (; p;) {
1252  q = p;
1253  p = p->next;
1254  if (q->name) {
1255  cob_free ((void *)q->name);
1256  }
1257  if (q->path) {
1258  cob_free ((void *)q->path);
1259  }
1260  cob_free (q);
1261  }
1262 #ifndef COB_ALT_HASH
1263  }
1264  if (call_table) {
1265  cob_free (call_table);
1266  }
1267  call_table = NULL;
1268  }
1269 #endif
1270 
1271  for (h = base_preload_ptr; h;) {
1272  j = h;
1273  if (h->path) {
1274  cob_free ((void *)h->path);
1275  }
1276  if (h->handle) {
1277  lt_dlclose (h->handle);
1278  }
1279  h = h->next;
1280  cob_free (j);
1281  }
1283  for (h = base_dynload_ptr; h;) {
1284  j = h;
1285  if (h->path) {
1286  cob_free ((void *)h->path);
1287  }
1288  if (h->handle) {
1289  lt_dlclose (h->handle);
1290  }
1291  h = h->next;
1292  cob_free (j);
1293  }
1295 
1296 #if !defined(_WIN32) && !defined(USE_LIBDL)
1297  lt_dlexit ();
1298 #if 0 /* RXWRXW - ltdl leak */
1299  /* Weird - ltdl leaks mainhandle - This appears to work but .. */
1300  cob_free (mainhandle);
1301 #endif
1302 #endif
1303 
1304 }
void cob_free(void *mptr)
Definition: common.c:1284
struct struct_handle * next
Definition: call.c:140
static char * resolve_alloc
Definition: call.c:166
static char ** resolve_path
Definition: call.c:164
static struct call_hash ** call_table
Definition: call.c:155
static char * resolve_error_buff
Definition: call.c:167
lt_dlhandle handle
Definition: call.c:142
const char * name
Definition: call.c:131
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static void * call_buffer
Definition: call.c:168
const char * path
Definition: call.c:141
struct call_hash * next
Definition: call.c:130
static char * call_filename_buff
Definition: call.c:169
static char * call_entry_buff
Definition: call.c:170
static unsigned char * call_entry2_buff
Definition: call.c:171
static struct struct_handle * base_dynload_ptr
Definition: call.c:159
const char * path
Definition: call.c:135
#define HASH_SIZE
Definition: call.c:122
static lt_dlhandle mainhandle
Definition: call.c:173
static struct struct_handle * base_preload_ptr
Definition: call.c:158

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_func ( const char *  name,
const int  argc,
void **  argv 
)

Definition at line 1150 of file call.c.

References cob_call(), and cob_cancel().

1151 {
1152  int ret;
1153 
1154  ret = cob_call (name, argc, argv);
1155  cob_cancel (name);
1156  return ret;
1157 }
void cob_cancel(const char *name)
Definition: call.c:1013
int cob_call(const char *name, const int argc, void **argv)
Definition: call.c:1080

Here is the call graph for this function:

static void* cob_get_buff ( const size_t  buffsize)
static

Definition at line 420 of file call.c.

References call_buffer, cob_fast_malloc(), and cob_free().

Referenced by cob_call_field(), and cob_cancel_field().

421 {
422  if (buffsize > call_lastsize) {
423  call_lastsize = buffsize;
425  call_buffer = cob_fast_malloc (buffsize);
426  }
427  return call_buffer;
428 }
void cob_free(void *mptr)
Definition: common.c:1284
static size_t call_lastsize
Definition: call.c:175
static void * call_buffer
Definition: call.c:168
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_init_call ( cob_global lptr,
cob_settings sptr 
)

Definition at line 1307 of file call.c.

References cache_preload(), CALL_BUFF_SIZE, cob_fast_malloc(), cob_free(), COB_LIBRARY_PATH, __cob_settings::cob_library_path, cob_malloc(), COB_MEDIUM_BUFF, COB_MEDIUM_MAX, COB_MODULE_EXT, COB_NORMAL_BUFF, __cob_settings::cob_preload_str, cob_set_library_path(), COB_SMALL_BUFF, cob_strdup(), HASH_SIZE, NULL, PATHSEP_CHAR, PATHSEP_STR, resolve_size, and SLASH_CHAR.

Referenced by cob_init().

1308 {
1309  char *buff;
1310  char *s;
1311  char *p;
1312  size_t i;
1313 #ifndef HAVE_DESIGNATED_INITS
1314  const unsigned char *pv;
1315 #endif
1316 #ifdef __OS400__
1317  char *t;
1318 #endif
1319 
1320  cobglobptr = lptr;
1321  cobsetptr = sptr;
1322 
1325  resolve_path = NULL;
1326  resolve_alloc = NULL;
1327  resolve_error = NULL;
1329  mainhandle = NULL;
1330  call_buffer = NULL;
1334  call_table = NULL;
1335  call_lastsize = 0;
1336  resolve_size = 0;
1337  cob_jmp_primed = 0;
1338 
1339 #ifndef HAVE_DESIGNATED_INITS
1340  memset (valid_char, 0, sizeof(valid_char));
1341  for (pv = pvalid_char; *pv; ++pv) {
1342  valid_char[*pv] = 1;
1343  }
1344 #endif
1345 
1346  /* Big enough for anything from libdl/libltdl */
1348 
1349 #ifndef COB_ALT_HASH
1350  call_table = cob_malloc (sizeof (struct call_hash *) * HASH_SIZE);
1351 #endif
1352 
1355 
1356  buff = cob_fast_malloc ((size_t)COB_MEDIUM_BUFF);
1358  || strcmp(cobsetptr->cob_library_path, ".") == 0) {
1359  if (strcmp(COB_LIBRARY_PATH, ".") == 0) {
1360  snprintf (buff, (size_t)COB_MEDIUM_MAX, ".");
1361  } else {
1362  snprintf (buff, (size_t)COB_MEDIUM_MAX, ".%c%s",
1364  }
1365  } else {
1366  if (strcmp(COB_LIBRARY_PATH, ".") == 0) {
1367  snprintf (buff, (size_t)COB_MEDIUM_MAX, "%s%c.",
1369  } else {
1370  snprintf (buff, (size_t)COB_MEDIUM_MAX, "%s%c.%c%s",
1372  }
1373  }
1374  cob_set_library_path (buff);
1375 
1376  lt_dlinit ();
1377 
1378 #ifndef COB_BORKED_DLOPEN
1379  mainhandle = lt_dlopen (NULL);
1380 #endif
1381 
1382  if (cobsetptr->cob_preload_str != NULL) {
1383 
1385  s = strtok (p, PATHSEP_STR);
1386  for (; s; s = strtok (NULL, PATHSEP_STR)) {
1387 #ifdef __OS400__
1388  for (t = s; *t; ++t) {
1389  *t = toupper (*t);
1390  }
1391  cache_preload (t);
1392 #else
1393  for (i = 0; i < resolve_size; ++i) {
1394  buff[COB_MEDIUM_MAX] = 0;
1395  snprintf (buff, (size_t)COB_MEDIUM_MAX,
1396  "%s%c%s.%s",
1398  if (cache_preload (buff)) {
1399  break;
1400  }
1401  }
1402  /* If not found, try just using the name */
1403  if (i == resolve_size) {
1404  (void)cache_preload (s);
1405  }
1406 #endif
1407  }
1408  cob_free (p);
1409  }
1410  cob_free (buff);
1413 }
void cob_free(void *mptr)
Definition: common.c:1284
static char * resolve_error
Definition: call.c:165
static void cob_set_library_path(const char *path)
Definition: call.c:279
static char * resolve_alloc
Definition: call.c:166
static size_t resolve_size
Definition: call.c:176
static size_t cache_preload(const char *path)
Definition: call.c:451
static char ** resolve_path
Definition: call.c:164
static struct call_hash ** call_table
Definition: call.c:155
static size_t call_lastsize
Definition: call.c:175
char * cob_preload_str
Definition: coblocal.h:220
#define PATHSEP_CHAR
Definition: common.h:500
#define COB_NORMAL_BUFF
Definition: common.h:541
char * cob_library_path
Definition: coblocal.h:221
#define COB_SMALL_BUFF
Definition: common.h:540
#define COB_MEDIUM_BUFF
Definition: common.h:543
static char * resolve_error_buff
Definition: call.c:167
#define COB_MODULE_EXT
Definition: defaults.h:9
static cob_settings * cobsetptr
Definition: call.c:162
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static const unsigned char pvalid_char[]
Definition: call.c:262
static void * call_buffer
Definition: call.c:168
#define PATHSEP_STR
Definition: common.h:501
#define CALL_BUFF_SIZE
Definition: call.c:119
#define SLASH_CHAR
Definition: common.h:505
static cob_global * cobglobptr
Definition: call.c:161
static char * call_filename_buff
Definition: call.c:169
static unsigned char valid_char[256]
Definition: call.c:261
char * cob_strdup(const char *)
Definition: common.c:1308
static char * call_entry_buff
Definition: call.c:170
static unsigned int cob_jmp_primed
Definition: call.c:177
void * cob_malloc(const size_t size)
Definition: common.c:1250
static unsigned char * call_entry2_buff
Definition: call.c:171
#define COB_LIBRARY_PATH
Definition: defaults.h:8
static struct struct_handle * base_dynload_ptr
Definition: call.c:159
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
#define HASH_SIZE
Definition: call.c:122
#define COB_MEDIUM_MAX
Definition: common.h:549
static lt_dlhandle mainhandle
Definition: call.c:173
static struct struct_handle * base_preload_ptr
Definition: call.c:158

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_longjmp ( struct cobjmp_buf jbuf)

Definition at line 1186 of file call.c.

References _, cobjmp_buf::cbj_jmp_buf, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_runtime_error(), cob_stop_run(), and unlikely.

1187 {
1188  if (unlikely(!cobglobptr)) {
1190  }
1191  if (unlikely(!jbuf)) {
1192  cob_runtime_error (_("NULL parameter passed to '%s'"), "cob_longjmp");
1193  cob_stop_run (1);
1194  }
1195  if (!cob_jmp_primed) {
1196  cob_runtime_error (_("Call to 'cob_longjmp' with no prior 'cob_setjmp'"));
1197  cob_stop_run (1);
1198  }
1199  cob_jmp_primed = 0;
1200  longjmp (jbuf->cbj_jmp_buf, 1);
1201 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
jmp_buf cbj_jmp_buf
Definition: common.h:1238
static unsigned int cob_jmp_primed
Definition: call.c:177
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

void* cob_resolve ( const char *  name)

Definition at line 908 of file call.c.

References cob_chk_call_path(), cob_free(), and cob_resolve_internal().

Referenced by main().

909 {
910  void *p;
911  char *entry;
912  char *dirent;
913 
914  entry = cob_chk_call_path (name, &dirent);
915  p = cob_resolve_internal (entry, dirent, 0);
916  if (dirent) {
917  cob_free (dirent);
918  }
919  return p;
920 }
void cob_free(void *mptr)
Definition: common.c:1284
static char * cob_chk_call_path(const char *name, char **dirent)
Definition: call.c:825
static void * cob_resolve_internal(const char *name, const char *dirent, const int fold_case)
Definition: call.c:599

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_resolve_cobol ( const char *  name,
const int  fold_case,
const int  errind 
)

Definition at line 923 of file call.c.

References cob_call_error(), cob_chk_call_path(), COB_EC_PROGRAM_NOT_FOUND, cob_free(), cob_resolve_internal(), cob_set_exception(), and unlikely.

Referenced by cob_call(), cobxref_(), and GCic_().

924 {
925  void *p;
926  char *entry;
927  char *dirent;
928 
929  entry = cob_chk_call_path (name, &dirent);
930  p = cob_resolve_internal (entry, dirent, fold_case);
931  if (dirent) {
932  cob_free (dirent);
933  }
934  if (unlikely(!p)) {
935  if (errind) {
936  cob_call_error ();
937  }
939  }
940  return p;
941 }
void cob_free(void *mptr)
Definition: common.c:1284
#define unlikely(x)
Definition: common.h:437
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_call_error(void)
Definition: call.c:878
static char * cob_chk_call_path(const char *name, char **dirent)
Definition: call.c:825
static void * cob_resolve_internal(const char *name, const char *dirent, const int fold_case)
Definition: call.c:599

Here is the call graph for this function:

Here is the caller graph for this function:

const char* cob_resolve_error ( void  )

Definition at line 864 of file call.c.

References _, NULL, and resolve_error.

Referenced by cob_call_error().

865 {
866  const char *p;
867 
868  if (!resolve_error) {
869  p = _("Indeterminable error in resolve of COBOL CALL");
870  } else {
871  p = resolve_error;
873  }
874  return p;
875 }
static char * resolve_error
Definition: call.c:165
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the caller graph for this function:

void* cob_resolve_func ( const char *  name)

Definition at line 944 of file call.c.

References _, cob_resolve_internal(), cob_runtime_error(), cob_stop_run(), NULL, and unlikely.

945 {
946  void *p;
947 
948  p = cob_resolve_internal (name, NULL, 0);
949  if (unlikely(!p)) {
950  cob_runtime_error (_("User FUNCTION '%s' not found"), name);
951  cob_stop_run (1);
952  }
953  return p;
954 }
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static void * cob_resolve_internal(const char *name, const char *dirent, const int fold_case)
Definition: call.c:599
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

static void* cob_resolve_internal ( const char *  name,
const char *  dirent,
const int  fold_case 
)
static

Definition at line 599 of file call.c.

References _, cache_dynload(), call_entry2_buff, call_entry_buff, cob_fatal_error(), COB_FERROR_INITIALIZED, COB_FOLD_LOWER, COB_FOLD_UPPER, cob_malloc(), COB_MODULE_EXT, COB_NORMAL_MAX, cob_set_exception(), COB_SMALL_BUFF, cob_u8_t, call_hash::func, struct_handle::handle, insert(), likely, lookup(), __cob_settings::name_convert, struct_handle::next, NULL, struct_handle::path, R_OK, resolve_size, set_resolve_error(), SLASH_CHAR, and unlikely.

Referenced by cob_call_field(), cob_resolve(), cob_resolve_cobol(), and cob_resolve_func().

601 {
602  unsigned char *p;
603  const unsigned char *s;
604  void *func;
605  struct struct_handle *preptr;
606  lt_dlhandle handle;
607  size_t i;
608 
609  if (unlikely(!cobglobptr)) {
611  }
612  cob_set_exception (0);
613 
614  /* Search the cache */
615  func = lookup (name);
616  if (func) {
617  return func;
618  }
619 
620  /* Encode program name */
621  p = (unsigned char *)call_entry_buff;
622  s = (const unsigned char *)name;
623  if (unlikely(*s <= (unsigned char)'9' && *s >= (unsigned char)'0')) {
624  *p++ = (unsigned char)'_';
625  }
626  for (; *s; ++s) {
627  if (likely(valid_char[*s])) {
628  *p++ = *s;
629  } else {
630  *p++ = (unsigned char)'_';
631  if (*s == (unsigned char)'-') {
632  *p++ = (unsigned char)'_';
633  } else {
634  *p++ = hexval[*s / 16U];
635  *p++ = hexval[*s % 16U];
636  }
637  }
638  }
639  *p = 0;
640 
641  /* Check case folding */
642  switch (fold_case) {
643  case COB_FOLD_UPPER:
644  for (p = (unsigned char *)call_entry_buff; *p; p++) {
645  if (islower (*p)) {
646  *p = (cob_u8_t)toupper (*p);
647  }
648  }
649  break;
650  case COB_FOLD_LOWER:
651  for (p = (unsigned char *)call_entry_buff; *p; p++) {
652  if (isupper (*p)) {
653  *p = (cob_u8_t)tolower (*p);
654  }
655  }
656  break;
657  default:
658  break;
659  }
660 
661  /* Search the main program */
662  if (mainhandle != NULL) {
663  func = lt_dlsym (mainhandle, call_entry_buff);
664  if (func != NULL) {
665  insert (name, func, mainhandle, NULL, NULL, 1);
667  return func;
668  }
669  }
670 
671  /* Search preloaded modules */
672  for (preptr = base_preload_ptr; preptr; preptr = preptr->next) {
673  func = lt_dlsym (preptr->handle, call_entry_buff);
674  if (func != NULL) {
675  insert (name, func, preptr->handle, NULL, preptr->path, 1);
677  return func;
678  }
679  }
680 
681  /* Search dynamic modules */
682  for (preptr = base_dynload_ptr; preptr; preptr = preptr->next) {
683  if (!preptr->handle) {
684  continue;
685  }
686  func = lt_dlsym (preptr->handle, call_entry_buff);
687  if (func != NULL) {
688  insert (name, func, preptr->handle,
689  NULL, preptr->path, 1);
691  return func;
692  }
693  }
694 
695 #if 0 /* RXWRXW RTLD */
696 #if defined(USE_LIBDL) && defined (RTLD_DEFAULT)
697  func = lt_dlsym (RTLD_DEFAULT, call_entry_buff);
698  if (func != NULL) {
699  insert (name, func, NULL, NULL, NULL, 1);
701  return func;
702  }
703 #endif
704 #endif
705 
706  s = (const unsigned char *)name;
707 
708  /* Check if name needs conversion */
709  if (unlikely(cobsetptr->name_convert != 0)) {
710  if (!call_entry2_buff) {
712  }
713  p = call_entry2_buff;
714  for (; *s; ++s, ++p) {
715  if (cobsetptr->name_convert == 1 && isupper (*s)) {
716  *p = (cob_u8_t) tolower (*s);
717  } else if (cobsetptr->name_convert == 2 && islower (*s)) {
718  *p = (cob_u8_t) toupper (*s);
719  } else {
720  *p = *s;
721  }
722  }
723  *p = 0;
724  s = (const unsigned char *)call_entry2_buff;
725  }
726 
727  /* Search external modules */
728 #ifdef __OS400__
729  strcpy (call_filename_buff, s);
730  for(p = call_filename_buff; *p; ++p) {
731  *p = (cob_u8_t)toupper(*p);
732  }
733  handle = lt_dlopen (call_filename_buff);
734  if (handle != NULL) {
735  /* Candidate for future calls */
737  func = lt_dlsym (handle, call_entry_buff);
738  if (func != NULL) {
739  insert (name, func, handle, NULL, call_filename_buff, 0);
741  return func;
742  }
743  }
744 #else
745  if (dirent) {
746  snprintf (call_filename_buff, (size_t)COB_NORMAL_MAX,
747  "%s%s.%s", dirent, (char *)s, COB_MODULE_EXT);
749  if (access (call_filename_buff, R_OK) != 0) {
750  set_resolve_error (_("Cannot find module"), name);
751  return NULL;
752  }
753  handle = lt_dlopen (call_filename_buff);
754  if (handle != NULL) {
755  /* Candidate for future calls */
757  func = lt_dlsym (handle, call_entry_buff);
758  if (func != NULL) {
759  insert (name, func, handle, NULL,
760  call_filename_buff, 0);
762  return func;
763  }
764  }
765  set_resolve_error (_("Cannot find entry point"),
766  (const char *)s);
767  return NULL;
768  }
769  for (i = 0; i < resolve_size; ++i) {
771  if (resolve_path[i] == NULL) {
772  snprintf (call_filename_buff, (size_t)COB_NORMAL_MAX,
773  "%s.%s", (char *)s, COB_MODULE_EXT);
774  } else {
775  snprintf (call_filename_buff, (size_t)COB_NORMAL_MAX,
776  "%s%c%s.%s", resolve_path[i],
777  SLASH_CHAR,
778  (char *)s,
780  }
782  if (access (call_filename_buff, R_OK) == 0) {
783  handle = lt_dlopen (call_filename_buff);
784  if (handle != NULL) {
785  /* Candidate for future calls */
787  func = lt_dlsym (handle, call_entry_buff);
788  if (func != NULL) {
789  insert (name, func, handle, NULL,
790  call_filename_buff, 0);
792  return func;
793  }
794  }
795  set_resolve_error (_("Cannot find entry point"),
796  (const char *)s);
797  return NULL;
798  }
799  }
800 #endif
801 
802  set_resolve_error (_("Cannot find module"), name);
803  return NULL;
804 }
static char * resolve_error
Definition: call.c:165
struct struct_handle * next
Definition: call.c:140
static size_t resolve_size
Definition: call.c:176
static char ** resolve_path
Definition: call.c:164
static void insert(const char *name, void *func, lt_dlhandle handle, cob_module *module, const char *path, const unsigned int nocanc)
Definition: call.c:535
static void * lookup(const char *name)
Definition: call.c:581
static void cache_dynload(const char *path, lt_dlhandle handle)
Definition: call.c:431
#define COB_SMALL_BUFF
Definition: common.h:540
#define COB_MODULE_EXT
Definition: defaults.h:9
lt_dlhandle handle
Definition: call.c:142
#define cob_u8_t
Definition: common.h:27
static cob_settings * cobsetptr
Definition: call.c:162
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define SLASH_CHAR
Definition: common.h:505
void cob_set_exception(const int id)
Definition: common.c:1212
const char * path
Definition: call.c:141
#define COB_NORMAL_MAX
Definition: common.h:547
#define COB_FOLD_LOWER
Definition: common.h:587
static cob_global * cobglobptr
Definition: call.c:161
static const unsigned char hexval[]
Definition: call.c:192
#define COB_FERROR_INITIALIZED
Definition: common.h:692
static char * call_filename_buff
Definition: call.c:169
static void set_resolve_error(const char *msg, const char *entry)
Definition: call.c:269
static unsigned char valid_char[256]
Definition: call.c:261
static char * call_entry_buff
Definition: call.c:170
void * cob_malloc(const size_t size)
Definition: common.c:1250
static unsigned char * call_entry2_buff
Definition: call.c:171
static struct struct_handle * base_dynload_ptr
Definition: call.c:159
#define R_OK
Definition: cobc.h:58
#define COB_FOLD_UPPER
Definition: common.h:586
unsigned int name_convert
Definition: coblocal.h:219
static lt_dlhandle mainhandle
Definition: call.c:173
#define likely(x)
Definition: common.h:436
static struct struct_handle * base_preload_ptr
Definition: call.c:158

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_savenv ( struct cobjmp_buf jbuf)

Definition at line 1160 of file call.c.

References _, cobjmp_buf::cbj_jmp_buf, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_runtime_error(), cob_stop_run(), and unlikely.

Referenced by cob_savenv2().

1161 {
1162  if (unlikely(!cobglobptr)) {
1164  }
1165  if (unlikely(!jbuf)) {
1166  cob_runtime_error (_("NULL parameter passed to '%s'"), "cob_savenv");
1167  cob_stop_run (1);
1168  }
1169  if (cob_jmp_primed) {
1170  cob_runtime_error (_("Multiple call to 'cob_setjmp'"));
1171  cob_stop_run (1);
1172  }
1173  cob_jmp_primed = 1;
1174  return jbuf->cbj_jmp_buf;
1175 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
static cob_global * cobglobptr
Definition: call.c:161
#define COB_FERROR_INITIALIZED
Definition: common.h:692
jmp_buf cbj_jmp_buf
Definition: common.h:1238
static unsigned int cob_jmp_primed
Definition: call.c:177
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_savenv2 ( struct cobjmp_buf jbuf,
const int  jsize 
)

Definition at line 1178 of file call.c.

References cob_savenv(), and COB_UNUSED.

1179 {
1180  COB_UNUSED (jsize);
1181 
1182  return cob_savenv (jbuf);
1183 }
void * cob_savenv(struct cobjmp_buf *jbuf)
Definition: call.c:1160
#define COB_UNUSED(z)
Definition: common.h:535

Here is the call graph for this function:

void cob_set_cancel ( cob_module m)

Definition at line 885 of file call.c.

References call_table, cob_call_union::funcvoid, hash(), insert(), call_hash::module, __cob_module::module_entry, __cob_module::module_name, __cob_module::module_path, call_hash::name, call_hash::next, NULL, and call_hash::path.

Referenced by CHECKSRC_(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

886 {
887  struct call_hash *p;
888 
889 #ifdef COB_ALT_HASH
890  p = call_table;
891 #else
892  p = call_table[hash ((const unsigned char *)(m->module_name))];
893 #endif
894  for (; p; p = p->next) {
895  if (strcmp (m->module_name, p->name) == 0) {
896  p->module = m;
897  /* Set path in program module structure */
898  if (p->path && m->module_path && !*(m->module_path)) {
899  *(m->module_path) = p->path;
900  }
901  return;
902  }
903  }
904  insert (m->module_name, m->module_entry.funcvoid, NULL, m, NULL, 1);
905 }
cob_module * module
Definition: call.c:133
static struct call_hash ** call_table
Definition: call.c:155
static void insert(const char *name, void *func, lt_dlhandle handle, cob_module *module, const char *path, const unsigned int nocanc)
Definition: call.c:535
static COB_INLINE unsigned int hash(const unsigned char *s)
Definition: call.c:523
cob_call_union module_entry
Definition: common.h:1052
void * funcvoid
Definition: common.h:1010
const char * name
Definition: call.c:131
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct call_hash * next
Definition: call.c:130
const char * module_name
Definition: common.h:1049
const char ** module_path
Definition: common.h:1058
const char * path
Definition: call.c:135

Here is the call graph for this function:

Here is the caller graph for this function:

static void cob_set_library_path ( const char *  path)
static

Definition at line 279 of file call.c.

References cob_free(), cob_malloc(), NULL, PATHSEP_CHAR, PATHSEP_STR, resolve_alloc, and resolve_size.

Referenced by cob_init_call().

280 {
281  char *p;
282  char *pstr;
283  size_t i;
284  size_t size;
285  struct stat st;
286 
287  int flag;
288 
289  /* Clear the previous path */
290  if (resolve_path) {
293  }
294 
295  /* Count the number of separators */
296  i = 1;
297  size = 0;
298  for (p = (char *)path; *p; p++, size++) {
299  if (*p == PATHSEP_CHAR) {
300  i++;
301  }
302  }
303 
304  /* Build path array */
305  size++;
306  resolve_alloc = cob_malloc (size);
307  pstr = resolve_alloc;
308  for (p = (char *)path; *p; p++, pstr++) {
309 #ifdef _WIN32
310  if (*p == (unsigned char)'/') {
311  *pstr = (unsigned char)'\\';
312  continue;
313  }
314 #else
315  if (*p == (unsigned char)'\\') {
316  *pstr = (unsigned char)'/';
317  continue;
318  }
319 #endif
320  *pstr = *p;
321  }
322 
323  resolve_path = cob_malloc (sizeof (char *) * i);
324  resolve_size = 0;
325  pstr = resolve_alloc;
326  for (; ; ) {
327  p = strtok (pstr, PATHSEP_STR);
328  if (!p) {
329  break;
330  }
331  pstr = NULL;
332  if (stat (p, &st) || !(S_ISDIR (st.st_mode))) {
333  continue;
334  }
335 
336  /*
337  * look if we already have this path
338  */
339  flag = 0;
340  for (i = 0; i < resolve_size; i++) {
341  if(strcmp(resolve_path[i], p) == 0) {
342  flag = 1;
343  break;
344  }
345  }
346 
347  if (!flag) {
348  resolve_path[resolve_size++] = p;
349  }
350  }
351 }
void cob_free(void *mptr)
Definition: common.c:1284
static char * resolve_alloc
Definition: call.c:166
static size_t resolve_size
Definition: call.c:176
static char ** resolve_path
Definition: call.c:164
#define PATHSEP_CHAR
Definition: common.h:500
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define PATHSEP_STR
Definition: common.h:501
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_cancel_module ( struct call_hash p,
struct call_hash **  base_hash,
struct call_hash prev 
)
static

Definition at line 354 of file call.c.

References base_dynload_ptr, cob_free(), __cob_settings::cob_physical_cancel, __cob_module::flag_no_phys_canc, cob_call_union::funcint, cob_call_union::funcvoid, call_hash::handle, struct_handle::handle, call_hash::module, __cob_module::module_active, __cob_module::module_cancel, __cob_module::module_ref_count, call_hash::name, call_hash::next, struct_handle::next, call_hash::no_phys_cancel, NULL, and call_hash::path.

Referenced by cob_cancel().

356 {
357  struct struct_handle *dynptr;
358  int (*cancel_func)(const int, void *, void *, void *, void *);
359  int nocancel;
360  nocancel = 0;
361 
362  if (!p->module) {
363  return;
364  }
365  if (!p->module->module_cancel.funcvoid) {
366  return;
367  }
368  if (p->module->flag_no_phys_canc) {
369  nocancel = 1;
370  }
371  /* This should be impossible */
372  if (p->module->module_active) {
373  nocancel = 1;
374  }
375  if (p->module->module_ref_count &&
376  *(p->module->module_ref_count)) {
377  nocancel = 1;
378  }
379  cancel_func = p->module->module_cancel.funcint;
380  (void)cancel_func (-1, NULL, NULL, NULL, NULL);
381  p->module = NULL;
382 
383  if (nocancel) {
384  return;
385  }
387  return;
388  }
389  if (p->no_phys_cancel) {
390  return;
391  }
392  if (!p->handle) {
393  return;
394  }
395 
396  lt_dlclose (p->handle);
397 
398  dynptr = base_dynload_ptr;
399  for (; dynptr; dynptr = dynptr->next) {
400  if (dynptr->handle == p->handle) {
401  dynptr->handle = NULL;
402  }
403  }
404 
405  if (!prev) {
406  *base_hash = p->next;
407  } else {
408  prev->next = p->next;
409  }
410  if (p->name) {
411  cob_free ((void *)(p->name));
412  }
413  if (p->path) {
414  cob_free ((void *)(p->path));
415  }
416  cob_free (p);
417 }
void cob_free(void *mptr)
Definition: common.c:1284
struct struct_handle * next
Definition: call.c:140
cob_module * module
Definition: call.c:133
unsigned int module_active
Definition: common.h:1060
lt_dlhandle handle
Definition: call.c:134
lt_dlhandle handle
Definition: call.c:142
void * funcvoid
Definition: common.h:1010
static cob_settings * cobsetptr
Definition: call.c:162
unsigned int * module_ref_count
Definition: common.h:1057
const char * name
Definition: call.c:131
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned int no_phys_cancel
Definition: call.c:136
int(* funcint)()
Definition: common.h:1009
struct call_hash * next
Definition: call.c:130
static struct struct_handle * base_dynload_ptr
Definition: call.c:159
const char * path
Definition: call.c:135
cob_call_union module_cancel
Definition: common.h:1053
unsigned char flag_no_phys_canc
Definition: common.h:1078
unsigned int cob_physical_cancel
Definition: coblocal.h:218

Here is the call graph for this function:

Here is the caller graph for this function:

static COB_INLINE unsigned int hash ( const unsigned char *  s)
static

Definition at line 523 of file call.c.

References HASH_SIZE.

Referenced by cob_cancel(), cob_set_cancel(), insert(), and lookup().

524 {
525  unsigned int val = 0;
526 
527  while (*s) {
528  val += *s++;
529  }
530  return val % HASH_SIZE;
531 }
#define HASH_SIZE
Definition: call.c:122

Here is the caller graph for this function:

static void insert ( const char *  name,
void *  func,
lt_dlhandle  handle,
cob_module module,
const char *  path,
const unsigned int  nocanc 
)
static

Definition at line 535 of file call.c.

References call_table, cob_free(), cob_malloc(), COB_NORMAL_BUFF, cob_strdup(), call_hash::func, call_hash::handle, hash(), module, call_hash::module, call_hash::name, call_hash::next, call_hash::no_phys_cancel, NULL, and call_hash::path.

Referenced by cob_resolve_internal(), and cob_set_cancel().

538 {
539  struct call_hash *p;
540 #ifndef COB_ALT_HASH
541  unsigned int val;
542 #endif
543 
544  p = cob_malloc (sizeof (struct call_hash));
545  p->name = cob_strdup (name);
546  p->func = func;
547  p->handle = handle;
548  p->module = module;
549  if (path) {
550 #ifdef _WIN32
551  /* Malloced path or NULL */
552  p->path = _fullpath (NULL, path, 1);
553 #elif defined(HAVE_CANONICALIZE_FILE_NAME)
554  /* Malloced path or NULL */
555  p->path = canonicalize_file_name (path);
556 #elif defined(HAVE_REALPATH)
557  char *s;
558 
559  s = cob_malloc ((size_t)COB_NORMAL_BUFF);
560  if (realpath (path, s) != NULL) {
561  p->path = cob_strdup (s);
562  }
563  cob_free (s);
564 #endif
565  if (!p->path) {
566  p->path = cob_strdup (path);
567  }
568  }
569  p->no_phys_cancel = nocanc;
570 #ifdef COB_ALT_HASH
571  p->next = call_table;
572  call_table = p;
573 #else
574  val = hash ((const unsigned char *)name);
575  p->next = call_table[val];
576  call_table[val] = p;
577 #endif
578 }
void cob_free(void *mptr)
Definition: common.c:1284
cob_module * module
Definition: call.c:133
static struct call_hash ** call_table
Definition: call.c:155
static cob_module * module
Definition: cobxref.c.l.h:14
lt_dlhandle handle
Definition: call.c:134
static COB_INLINE unsigned int hash(const unsigned char *s)
Definition: call.c:523
#define COB_NORMAL_BUFF
Definition: common.h:541
void * func
Definition: call.c:132
const char * name
Definition: call.c:131
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned int no_phys_cancel
Definition: call.c:136
struct call_hash * next
Definition: call.c:130
char * cob_strdup(const char *)
Definition: common.c:1308
void * cob_malloc(const size_t size)
Definition: common.c:1250
const char * path
Definition: call.c:135

Here is the call graph for this function:

Here is the caller graph for this function:

static void* lookup ( const char *  name)
static

Definition at line 581 of file call.c.

References call_table, call_hash::func, hash(), call_hash::name, call_hash::next, and NULL.

Referenced by cob_resolve_internal().

582 {
583  struct call_hash *p;
584 
585 #ifdef COB_ALT_HASH
586  p = call_table;
587 #else
588  p = call_table[hash ((const unsigned char *)name)];
589 #endif
590  for (; p; p = p->next) {
591  if (strcmp (name, p->name) == 0) {
592  return p->func;
593  }
594  }
595  return NULL;
596 }
static struct call_hash ** call_table
Definition: call.c:155
static COB_INLINE unsigned int hash(const unsigned char *s)
Definition: call.c:523
void * func
Definition: call.c:132
const char * name
Definition: call.c:131
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct call_hash * next
Definition: call.c:130

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_resolve_error ( const char *  msg,
const char *  entry 
)
static

Definition at line 269 of file call.c.

References CALL_BUFF_MAX, COB_EC_PROGRAM_NOT_FOUND, cob_set_exception(), and resolve_error_buff.

Referenced by cob_resolve_internal().

270 {
272  snprintf (resolve_error_buff, (size_t)CALL_BUFF_MAX,
273  "%s '%s'", msg, entry);
276 }
static char * resolve_error
Definition: call.c:165
static char * resolve_error_buff
Definition: call.c:167
void cob_set_exception(const int id)
Definition: common.c:1212
#define CALL_BUFF_MAX
Definition: call.c:120

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct struct_handle* base_dynload_ptr
static

Definition at line 159 of file call.c.

Referenced by cache_dynload(), and do_cancel_module().

struct struct_handle* base_preload_ptr
static

Definition at line 158 of file call.c.

Referenced by cache_preload().

void* call_buffer
static

Definition at line 168 of file call.c.

Referenced by cob_get_buff().

unsigned char* call_entry2_buff
static

Definition at line 171 of file call.c.

Referenced by cob_resolve_internal().

char* call_entry_buff
static

Definition at line 170 of file call.c.

Referenced by cob_resolve_internal().

char* call_filename_buff
static

Definition at line 169 of file call.c.

size_t call_lastsize
static

Definition at line 175 of file call.c.

struct call_hash** call_table
static

Definition at line 155 of file call.c.

Referenced by cob_cancel(), cob_exit_call(), cob_set_cancel(), insert(), and lookup().

unsigned int cob_jmp_primed
static

Definition at line 177 of file call.c.

cob_global* cobglobptr
static

Definition at line 161 of file call.c.

cob_settings* cobsetptr
static

Definition at line 162 of file call.c.

const unsigned char hexval[] = "0123456789ABCDEF"
static

Definition at line 192 of file call.c.

lt_dlhandle mainhandle
static

Definition at line 173 of file call.c.

const unsigned char pvalid_char[]
static
Initial value:
=
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"

Definition at line 262 of file call.c.

char* resolve_alloc
static

Definition at line 166 of file call.c.

Referenced by cob_set_library_path().

char* resolve_error
static

Definition at line 165 of file call.c.

Referenced by cob_resolve_error().

char* resolve_error_buff
static

Definition at line 167 of file call.c.

Referenced by set_resolve_error().

char** resolve_path
static

Definition at line 164 of file call.c.

size_t resolve_size
static

Definition at line 176 of file call.c.

Referenced by cob_init_call(), cob_resolve_internal(), and cob_set_library_path().

const struct system_table system_tab[]
static

Definition at line 186 of file call.c.

unsigned char valid_char[256]
static

Definition at line 261 of file call.c.