From a1bb1366d400b1e12d32ef0a70465827faed9229 Mon Sep 17 00:00:00 2001
From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org>
Date: Fri, 3 Apr 1998 02:18:34 +0200
Subject: [PATCH] fixes for static linking

Rev: src/modules/Image/encodings/png.c:1.5
Rev: src/modules/Image/image.c:1.95
Rev: src/modules/_Image_JPEG/image_jpeg.c:1.14
Rev: src/modules/_Image_XFace/image_xface.c:1.2
---
 src/modules/Image/encodings/png.c      | 14 +++--------
 src/modules/Image/image.c              | 35 ++++++++++++++++++++------
 src/modules/_Image_JPEG/image_jpeg.c   | 11 ++++++--
 src/modules/_Image_XFace/image_xface.c |  9 ++++++-
 4 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/src/modules/Image/encodings/png.c b/src/modules/Image/encodings/png.c
index db63b79173..06a71e519a 100644
--- a/src/modules/Image/encodings/png.c
+++ b/src/modules/Image/encodings/png.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: png.c,v 1.4 1998/04/02 01:07:03 mirar Exp $");
+RCSID("$Id: png.c,v 1.5 1998/04/03 00:18:31 mirar Exp $");
 
 #include "config.h"
 
@@ -1097,7 +1097,7 @@ void exit_image_png(void)
    free_string(param_type);
 }
 
-void init_image_png(void)
+struct object *init_image_png(void)
 {
    start_new_program();
 
@@ -1164,12 +1164,6 @@ void init_image_png(void)
    param_alpha=make_shared_string("alpha");
    param_bpp=make_shared_string("bpp");
    param_type=make_shared_string("type");
-
-   push_object(clone_object(end_program(),0));
-   {
-     struct pike_string *s=make_shared_string("PNG");
-     add_constant(s,sp-1,0);
-     free_string(s);
-   }
-   pop_stack();
+   
+   return clone_object(end_program(),0);
 }
diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c
index f500652ef0..7eb1412781 100644
--- a/src/modules/Image/image.c
+++ b/src/modules/Image/image.c
@@ -1,9 +1,9 @@
-/* $Id: image.c,v 1.94 1998/04/01 05:37:21 mirar Exp $ */
+/* $Id: image.c,v 1.95 1998/04/03 00:18:29 mirar Exp $ */
 
 /*
 **! module Image
 **! note
-**!	$Id: image.c,v 1.94 1998/04/01 05:37:21 mirar Exp $
+**!	$Id: image.c,v 1.95 1998/04/03 00:18:29 mirar Exp $
 **! class image
 **!
 **!	The main object of the <ref>Image</ref> module, this object
@@ -82,7 +82,7 @@
 
 #include "stralloc.h"
 #include "global.h"
-RCSID("$Id: image.c,v 1.94 1998/04/01 05:37:21 mirar Exp $");
+RCSID("$Id: image.c,v 1.95 1998/04/03 00:18:29 mirar Exp $");
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"
@@ -3124,22 +3124,30 @@ extern void init_font_programs(void);
 extern void exit_font(void);
 extern void init_colortable_programs(void);
 extern void exit_colortable(void);
+
+/* encoders */
+
 extern void init_image_gif(void);
 extern void exit_image_gif(void);
 extern void init_image_pnm(void);
 extern void exit_image_pnm(void);
 extern void init_image_xwd(void);
 extern void exit_image_xwd(void);
-extern void init_image_png(void);
-extern void exit_image_png(void);
 extern void init_image_x(void);
 extern void exit_image_x(void);
 
+/* dynamic encoders (dependent on other modules, loaded dynamically) */
+
+extern struct object* init_image_png(void);
+extern void exit_image_png(void);
+
 static struct pike_string 
    *magic_JPEG, 
    *magic_XFace, 
    *magic_PNG;
 
+static struct object *png_object=NULL;
+
 static void image_index_magic(INT32 args)
 {
    struct svalue tmp;
@@ -3163,6 +3171,15 @@ static void image_index_magic(INT32 args)
       SAFE_APPLY_MASTER("resolv",2);
       return;
    }
+   else if (sp[-1].u.string==magic_PNG)
+   {
+      pop_stack();
+      if (!png_object)
+	 png_object=init_image_png();
+      png_object->refs++;
+      push_object(png_object);
+      return;
+   }
    push_object(THISOBJ); THISOBJ->refs++;
    tmp=sp[-1], sp[-1]=sp[-2], sp[-2]=tmp;
    f_arrow(2);
@@ -3404,7 +3421,6 @@ void pike_module_init(void)
    init_image_gif();
    init_image_pnm();
    init_image_xwd();
-   init_image_png();
    init_image_x();
 }
 
@@ -3421,7 +3437,12 @@ void pike_module_exit(void)
   exit_image_gif();
   exit_image_pnm();
   exit_image_xwd();
-  exit_image_png();
+  if (png_object) 
+  {
+     free_object(png_object);
+     png_object=NULL;
+     exit_image_png();
+  }
   exit_image_x();
 
   free_string(magic_PNG);
diff --git a/src/modules/_Image_JPEG/image_jpeg.c b/src/modules/_Image_JPEG/image_jpeg.c
index 18bae57342..12a1520c53 100644
--- a/src/modules/_Image_JPEG/image_jpeg.c
+++ b/src/modules/_Image_JPEG/image_jpeg.c
@@ -1,5 +1,5 @@
 /*
- * $Id: image_jpeg.c,v 1.13 1998/03/28 13:45:55 grubba Exp $
+ * $Id: image_jpeg.c,v 1.14 1998/04/03 00:18:33 mirar Exp $
  */
 
 #include "config.h"
@@ -22,7 +22,7 @@
 #undef HAVE_STDLIB_H
 #endif
 #include "global.h"
-RCSID("$Id: image_jpeg.c,v 1.13 1998/03/28 13:45:55 grubba Exp $");
+RCSID("$Id: image_jpeg.c,v 1.14 1998/04/03 00:18:33 mirar Exp $");
 
 #include "pike_macros.h"
 #include "object.h"
@@ -40,7 +40,12 @@ RCSID("$Id: image_jpeg.c,v 1.13 1998/03/28 13:45:55 grubba Exp $");
 
 #include "../Image/image.h"
 
+#ifdef DYNAMIC_MODULE
 static struct program *image_program=NULL;
+#else
+extern struct program *image_program=NULL; 
+/* Image module is probably linked static too. */
+#endif
 
 #endif /* HAVE_JPEGLIB_H */
 
@@ -594,6 +599,7 @@ void pike_module_exit(void)
 void pike_module_init(void)
 {
 #ifdef HAVE_JPEGLIB_H
+#ifdef DYNAMIC_MODULE
    push_string(make_shared_string("Image"));
    push_int(0);
    SAFE_APPLY_MASTER("resolv",2);
@@ -604,6 +610,7 @@ void pike_module_init(void)
       image_program=program_from_svalue(sp-1);
    }
    pop_n_elems(1);
+#endif /* DYNAMIC_MODULE */
 
    if (image_program)
    {
diff --git a/src/modules/_Image_XFace/image_xface.c b/src/modules/_Image_XFace/image_xface.c
index 673fde3c19..4d123d5932 100644
--- a/src/modules/_Image_XFace/image_xface.c
+++ b/src/modules/_Image_XFace/image_xface.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: image_xface.c,v 1.1 1998/02/13 18:57:23 marcus Exp $");
+RCSID("$Id: image_xface.c,v 1.2 1998/04/03 00:18:34 mirar Exp $");
 
 #include "config.h"
 
@@ -29,7 +29,12 @@ RCSID("$Id: image_xface.c,v 1.1 1998/02/13 18:57:23 marcus Exp $");
 
 #include "../Image/image.h"
 
+#ifdef DYNAMIC_MODULE
 static struct program *image_program=NULL;
+#else
+extern struct program *image_program=NULL; 
+/* Image module is probably linked static too. */
+#endif
 
 #endif /* HAVE_GMP_H */
 
@@ -285,6 +290,7 @@ void pike_module_exit(void)
 void pike_module_init(void)
 {
 #ifdef HAVE_GMP_H
+#ifdef DYNAMIC_MODULE
    push_string(make_shared_string("Image"));
    push_int(0);
    SAFE_APPLY_MASTER("resolv",2);
@@ -295,6 +301,7 @@ void pike_module_init(void)
       image_program=program_from_svalue(sp-1);
    }
    pop_n_elems(1);
+#endif /* DYNAMIC_MODULE */
 
    if (image_program)
    {
-- 
GitLab