summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-09-09 07:58:30 -0700
committerRobin Watts <robin.watts@artifex.com>2012-09-09 08:01:42 -0700
commitc8c6869df74b949d4c7c8a0c481c54f3b974e332 (patch)
tree0ff5b25875526a66e9658e75b4d429436c9498cf
parent7254338bbdcc9b80805c644712edd5d24b781fcb (diff)
downloadghostpdl-apitest.tar.gz
Simple apitest program.apitest
-rw-r--r--gs/base/ugcclib.mak1
-rw-r--r--gs/base/unix-end.mak3
-rw-r--r--gs/base/unixlink.mak19
-rw-r--r--gs/psi/apitest.c99
-rw-r--r--gs/psi/iapi.c12
-rw-r--r--gs/psi/int.mak5
6 files changed, 132 insertions, 7 deletions
diff --git a/gs/base/ugcclib.mak b/gs/base/ugcclib.mak
index 760ff6ad9..ba1385844 100644
--- a/gs/base/ugcclib.mak
+++ b/gs/base/ugcclib.mak
@@ -174,7 +174,6 @@ $(GS_XE): $(ld_tr) $(ECHOGS_XE) $(LIB_ALL) $(DEVS_ALL) $(GLOBJ)gslib.$(OBJ) $(LI
$(ECHOGS_XE) -a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS)
if [ x$(XLIBDIR) != x ]; then LD_RUN_PATH=$(XLIBDIR); export LD_RUN_PATH; fi; $(SH) <$(ldt_tr)
-
GSLIB_A=libgsgraph.a
lar_tr=$(GLOBJ)lar.tr
$(GSLIB_A): $(obj_tr) $(ECHOGS_XE) $(LIB_ALL) $(DEVS_ALL) $(LIB_ONLY)
diff --git a/gs/base/unix-end.mak b/gs/base/unix-end.mak
index 6249e5fd1..6e5f99127 100644
--- a/gs/base/unix-end.mak
+++ b/gs/base/unix-end.mak
@@ -43,6 +43,9 @@ DEBUGDEFS=GENOPT='-DDEBUG' CFLAGS='$(CFLAGS_DEBUG) $(GCFLAGS) $(XCFLAGS)'\
debug:
$(MAKE) $(DEBUGDEFS) default
+debug-apitest:
+ $(MAKE) $(DEBUGDEFS) apitest
+
debugclean:
$(MAKE) $(DEBUGDEFS) clean
diff --git a/gs/base/unixlink.mak b/gs/base/unixlink.mak
index cd044fa2b..76af552d6 100644
--- a/gs/base/unixlink.mak
+++ b/gs/base/unixlink.mak
@@ -64,3 +64,22 @@ $(GS_XE): $(ld_tr) $(ECHOGS_XE) $(XE_ALL) $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ)
DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= DEVICE_DEVS20= \
DEVICE_DEVS_EXTRA= \
$(SH) <$(ldt_tr)
+
+APITEST_XE=$(BINDIR)$(D)apitest$(XE)
+
+apitest: $(APITEST_XE)
+
+$(APITEST_XE): $(ld_tr) $(ECHOGS_XE) $(XE_ALL) $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ) $(PSOBJ)apitest.$(OBJ)
+ $(ECHOGS_XE) -w $(ldt_tr) -n - $(CCLD) $(LDFLAGS) -o $(APITEST_XE)
+ $(ECHOGS_XE) -a $(ldt_tr) -n -s $(PSOBJ)gsromfs$(COMPILE_INITS).$(OBJ) $(PSOBJ)apitest.$(OBJ) -s
+ cat $(ld_tr) >>$(ldt_tr)
+ $(ECHOGS_XE) -a $(ldt_tr) -s - $(EXTRALIBS) $(STDLIBS)
+ if [ x$(XLIBDIR) != x ]; then LD_RUN_PATH=$(XLIBDIR); export LD_RUN_PATH; fi; \
+ XCFLAGS= XINCLUDE= XLDFLAGS= XLIBDIRS= XLIBS= \
+ FEATURE_DEVS= DEVICE_DEVS= DEVICE_DEVS1= DEVICE_DEVS2= DEVICE_DEVS3= \
+ DEVICE_DEVS4= DEVICE_DEVS5= DEVICE_DEVS6= DEVICE_DEVS7= DEVICE_DEVS8= \
+ DEVICE_DEVS9= DEVICE_DEVS10= DEVICE_DEVS11= DEVICE_DEVS12= \
+ DEVICE_DEVS13= DEVICE_DEVS14= DEVICE_DEVS15= DEVICE_DEVS16= \
+ DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= DEVICE_DEVS20= \
+ DEVICE_DEVS_EXTRA= \
+ $(SH) <$(ldt_tr)
diff --git a/gs/psi/apitest.c b/gs/psi/apitest.c
new file mode 100644
index 000000000..7d0469377
--- /dev/null
+++ b/gs/psi/apitest.c
@@ -0,0 +1,99 @@
+#include <pthread.h>
+#include "ierrors.h"
+#include "iapi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define NUM_THREADS 10
+
+static int my_argc;
+static char **my_argv;
+static int my_argv_file;
+
+static void *gs_main(void *arg)
+{
+ int threadnum = (int)(void *)arg;
+ int code, code1;
+ char text[256];
+ void *minst;
+ char **gsargv;
+ int gsargc;
+ int i, pos, len;
+
+ gsargv = malloc(sizeof(*gsargv)*my_argc);
+ if (!gsargv)
+ {
+ fprintf(stderr, "Failed to allocate arg space in thread %d\n", threadnum);
+ return (void *)-1;
+ }
+
+ for (i=0; i < my_argc; i++)
+ gsargv[i] = my_argv[i];
+ gsargv[my_argv_file] = text;
+ gsargc = my_argc;
+
+ strncpy(text, my_argv[my_argv_file], sizeof(text));
+ text[sizeof(text)-1]=0;
+ pos = strlen(text);
+ len = sizeof(text)+1-pos;
+ snprintf(text+pos, len, "%d", threadnum);
+
+ code = gsapi_new_instance(&minst, NULL);
+ if (code < 0)
+ {
+ fprintf(stderr, "gsapi_new_instance failure in thread %d\n", threadnum);
+ return (void *)-1;
+ }
+
+ code = gsapi_init_with_args(minst, gsargc, gsargv);
+ code1 = gsapi_exit(minst);
+ if ((code == 0) || (code == e_Quit))
+ code = code1;
+
+ gsapi_delete_instance(minst);
+
+ if ((code == 0) || (code == e_Quit))
+ return (void *)0;
+
+ return (void *)1;
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ pthread_t thread[NUM_THREADS];
+
+ my_argc = argc;
+ my_argv = argv;
+
+ for (i=0; i < argc; i++)
+ if (!strcmp(argv[i], "-o"))
+ break;
+
+ if (i >= argc-1)
+ {
+ fprintf(stderr, "Expected a -o argument to rewrite!\n");
+ exit(EXIT_FAILURE);
+ }
+ my_argv_file = i+1;
+
+ for (i=0; i < NUM_THREADS; i++)
+ {
+ if (pthread_create(&thread[i], NULL, gs_main, (void *)i) < 0)
+ {
+ fprintf(stderr, "Thread %d creation failed\n", i);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ for (i=0; i < NUM_THREADS; i++)
+ {
+ if (pthread_join(thread[i], NULL) < 0)
+ {
+ fprintf(stderr, "Thread %d join failed\n", i);
+ exit(EXIT_FAILURE);
+ }
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/gs/psi/iapi.c b/gs/psi/iapi.c
index 540d148b5..2846aab45 100644
--- a/gs/psi/iapi.c
+++ b/gs/psi/iapi.c
@@ -33,8 +33,8 @@
/* number of threads to allow per process
* currently more than 1 is guarenteed to fail
*/
-static int gsapi_instance_counter = 0;
-static const int gsapi_instance_max = 1;
+//static int gsapi_instance_counter = 0;
+//static const int gsapi_instance_max = 1;
/* Return revision numbers and strings of Ghostscript. */
/* Used for determining if wrong GSDLL loaded. */
@@ -66,9 +66,9 @@ gsapi_new_instance(void **pinstance, void *caller_handle)
return e_Fatal;
/* limited to 1 instance, till it works :) */
- if ( gsapi_instance_counter >= gsapi_instance_max )
- return e_Fatal;
- ++gsapi_instance_counter;
+ //if ( gsapi_instance_counter >= gsapi_instance_max )
+ // return e_Fatal;
+ //++gsapi_instance_counter;
if (*pinstance == NULL)
/* first instance in this process */
@@ -120,7 +120,7 @@ gsapi_delete_instance(void *lib)
/* Release the memory (frees up everything) */
gs_malloc_release(minst->heap);
- --gsapi_instance_counter;
+ //--gsapi_instance_counter;
}
}
diff --git a/gs/psi/int.mak b/gs/psi/int.mak
index 16fc02f15..5d9bed461 100644
--- a/gs/psi/int.mak
+++ b/gs/psi/int.mak
@@ -1995,6 +1995,11 @@ $(PSOBJ)gs.$(OBJ) : $(PSSRC)gs.c $(GH)\
$(locale__h)
$(PSCC) $(PSO_)gs.$(OBJ) $(C_) $(PSSRC)gs.c
+$(PSOBJ)apitest.$(OBJ) : $(PSSRC)apitest.c $(GH)\
+ $(ierrors_h) $(iapi_h) $(imain_h) $(imainarg_h) $(iminst_h) $(gsmalloc_h)\
+ $(locale__h)
+ $(PSCC) $(PSO_)apitest.$(OBJ) $(C_) $(PSSRC)apitest.c
+
$(PSOBJ)iapi.$(OBJ) : $(PSSRC)iapi.c $(AK)\
$(string__h) $(ierrors_h) $(gscdefs_h) $(gstypes_h) $(iapi_h)\
$(iref_h) $(imain_h) $(imainarg_h) $(iminst_h) $(gslibctx_h)