PATCH: cups dynamic patch , take 2

Marcus Meissner marcus at jet.franken.de
Mon Nov 11 14:14:49 CST 2002


Hi,

This is the second try, as discussed. I am not sure I like it  
without the prototype checks.

Alexandre, your call ;)

Ciao, Marcus

Changelog:
	Load needed CUPS functions fully dynamically, no longer needs
	cups in development system.

Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.90
diff -u -r1.90 configure.ac
--- configure.ac	8 Nov 2002 19:34:52 -0000	1.90
+++ configure.ac	11 Nov 2002 20:05:55 -0000
@@ -362,17 +362,6 @@
 fi
 AC_SUBST(CURSESLIBS)
 
-CUPSLIBS=""
-dnl **** Check for CUPS ****
-wine_cv_warn_cups_h=no
-AC_CHECK_LIB(cups,cupsGetPPD,
-	[AC_CHECK_HEADER(cups/cups.h,
-	    [AC_DEFINE(HAVE_CUPS, 1, [Define if we have CUPS])
-	    CUPSLIBS="-lcups"],
-            wine_cv_warn_cups_h=yes)]
-)
-AC_SUBST(CUPSLIBS)
-
 dnl **** Check for SANE ****
 AC_CHECK_PROG(sane_devel,sane-config,sane-config,no)
 if test "$sane_devel" = "no"
@@ -856,6 +845,7 @@
   WINE_GET_SONAME(Xext,XextCreateExtension,[$X_LIBS -lX11 $X_EXTRA_LIBS])
   WINE_GET_SONAME(Xrender,XRenderQueryExtension,[$X_LIBS -lXext -lX11 $X_EXTRA_LIBS])
   WINE_GET_SONAME(freetype,FT_Init_FreeType,[$X_LIBS])
+  WINE_GET_SONAME(cups,cupsGetDefault)
 fi
 
 
@@ -1596,14 +1586,6 @@
   echo "*** Warning: you explicitly linked in a thread-safe OpenGL version. If you"
   echo "*** experience unusual crashes on DirectDraw games, try first to disable OpenGL"
   echo "*** support before reporting bugs."
-fi
-
-if test "$wine_cv_warn_cups_h" = "yes"
-then
-  echo
-  echo "*** Note: You have cups runtime libraries, but no development"
-  echo "*** libraries. Install the cups-devel package or whichever package"
-  echo "*** contains cups.h to enable CUPS support in Wine."
 fi
 
 if test "$wine_cv_msg_freetype" = "yes"
Index: dlls/wineps/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/wineps/Makefile.in,v
retrieving revision 1.21
diff -u -r1.21 Makefile.in
--- dlls/wineps/Makefile.in	24 Jun 2002 23:44:18 -0000	1.21
+++ dlls/wineps/Makefile.in	11 Nov 2002 20:05:55 -0000
@@ -5,7 +5,6 @@
 MODULE    = wineps.dll
 IMPORTS   = user32 gdi32 winspool.drv advapi32 kernel32
 ALTNAMES  = wineps16.dll
-EXTRALIBS = @CUPSLIBS@
 EXTRAINCL = @FREETYPEINCL@
 
 LDDLLFLAGS = @LDDLLFLAGS@
Index: dlls/wineps/init.c
===================================================================
RCS file: /home/wine/wine/dlls/wineps/init.c,v
retrieving revision 1.41
diff -u -r1.41 init.c
--- dlls/wineps/init.c	4 Nov 2002 23:53:43 -0000	1.41
+++ dlls/wineps/init.c	11 Nov 2002 20:05:56 -0000
@@ -20,6 +20,7 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
 
 #include <string.h>
 #ifdef HAVE_UNISTD_H
@@ -33,12 +34,14 @@
 #include "winspool.h"
 #include "winerror.h"
 
-#ifdef HAVE_CUPS
-# include <cups/cups.h>
+#ifndef CUPS_SONAME
+#define CUPS_SONAME "libcups.so"
 #endif
 
 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
 
+static void *cupshandle = NULL;
+
 static PSDRV_DEVMODEA DefaultDevmode =
 {
   { /* dmPublic */
@@ -127,12 +130,21 @@
 		HeapDestroy(PSDRV_Heap);
 		return FALSE;
 	    }
+	    /* dynamically load CUPS if not yet loaded */
+	    if (!cupshandle) {
+		cupshandle = wine_dlopen(CUPS_SONAME, RTLD_NOW, NULL, 0);
+		if (!cupshandle) cupshandle = (void*)-1;
+	    }
             break;
 
 	case DLL_PROCESS_DETACH:
 
 	    DeleteObject( PSDRV_DefaultFont );
 	    HeapDestroy( PSDRV_Heap );
+	    if (cupshandle && (cupshandle != (void*)-1)) {
+		wine_dlclose(cupshandle, NULL, 0);
+		cupshandle = NULL;
+	    }
             break;
     }
 
@@ -491,24 +502,26 @@
 	goto cleanup;
     }
 
-#ifdef HAVE_CUPS
-    {
-	ppd = cupsGetPPD(name);
+    if (cupshandle != (void*)-1) {
+	const char *(*pcupsGetPPD)(const char*) = NULL;
 
-	if (ppd) {
-	    needed=strlen(ppd)+1;
-	    ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
-	    memcpy(ppdFileName, ppd, needed);
-	    ppdType=REG_SZ;
-	    res = ERROR_SUCCESS;
-	    /* we should unlink() that file later */
-	} else {
-	    res = ERROR_FILE_NOT_FOUND;
-	    WARN("Did not find ppd for %s\n",name);
+	pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
+	if (pcupsGetPPD) {
+	    ppd = pcupsGetPPD(name);
+
+	    if (ppd) {
+		needed=strlen(ppd)+1;
+		ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
+		memcpy(ppdFileName, ppd, needed);
+		ppdType=REG_SZ;
+		res = ERROR_SUCCESS;
+		/* we should unlink() that file later */
+	    } else {
+		res = ERROR_FILE_NOT_FOUND;
+		WARN("Did not find ppd for %s\n",name);
+	    }
 	}
     }
-#endif
-
     if (!ppdFileName) {
         res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
         if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
Index: dlls/winspool/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/winspool/Makefile.in,v
retrieving revision 1.21
diff -u -r1.21 Makefile.in
--- dlls/winspool/Makefile.in	22 Oct 2002 00:47:33 -0000	1.21
+++ dlls/winspool/Makefile.in	11 Nov 2002 20:05:56 -0000
@@ -5,7 +5,6 @@
 VPATH     = @srcdir@
 MODULE    = winspool.drv
 IMPORTS   = advapi32 kernel32
-EXTRALIBS = @CUPSLIBS@
 
 LDDLLFLAGS = @LDDLLFLAGS@
 SYMBOLFILE = $(MODULE).tmp.o
Index: dlls/winspool/info.c
===================================================================
RCS file: /home/wine/wine/dlls/winspool/info.c,v
retrieving revision 1.60
diff -u -r1.60 info.c
--- dlls/winspool/info.c	22 Oct 2002 00:47:33 -0000	1.60
+++ dlls/winspool/info.c	11 Nov 2002 20:05:57 -0000
@@ -23,14 +23,16 @@
  */
 
 #include "config.h"
+#include "wine/port.h"
+#include "wine/library.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <stddef.h>
-#ifdef HAVE_CUPS
-# include <cups/cups.h>
+#ifndef CUPS_SONAME
+# define CUPS_SONAME "libcups.so.2"
 #endif
 #include "winspool.h"
 #include "winbase.h"
@@ -115,21 +117,38 @@
     }
 }
 
-#ifdef HAVE_CUPS
 BOOL
 CUPS_LoadPrinters(void) {
+    int (*pcupsGetPrinters)(char ***) = NULL;
+    const char *(*pcupsGetDefault)(void) = NULL;
+    const char *(*pcupsGetPPD)(const char*) = NULL;
     char		**printers;
     int			i,nrofdests,hadprinter = FALSE;
     PRINTER_INFO_2A	pinfo2a;
-    const char*		def = cupsGetDefault();
+    const char*		def;
+    void *cupshandle = NULL;
 
-    nrofdests = cupsGetPrinters(&printers);
+    cupshandle = wine_dlopen(CUPS_SONAME, RTLD_NOW, NULL, 0);
+    if (!cupshandle) 
+	return FALSE;
+
+#define DYNCUPS(x) 					\
+    	p##x = wine_dlsym(cupshandle, #x, NULL,0);	\
+	if (!p##x) return FALSE;
+
+    DYNCUPS(cupsGetDefault);
+    DYNCUPS(cupsGetPPD);
+    DYNCUPS(cupsGetPrinters);
+#undef DYNCUPS
+
+    def = pcupsGetDefault();
 
     if (def && !strcmp(def,"none")) /* CUPS has "none" for no default printer */
     	def = NULL;
 
+    nrofdests = pcupsGetPrinters(&printers);
     for (i=0;i<nrofdests;i++) {
-	const char *ppd = cupsGetPPD(printers[i]);
+	const char *ppd = pcupsGetPPD(printers[i]);
 	char	*port,*devline;
 
 	if (!ppd) {
@@ -180,9 +199,9 @@
 	}
 	HeapFree(GetProcessHeap(),0,port);
     }
+    wine_dlclose(cupshandle, NULL, 0);
     return hadprinter;
 }
-#endif
 
 static BOOL
 PRINTCAP_ParseEntry(char *pent,BOOL isfirst) {
@@ -341,11 +360,9 @@
 	ERR("Failed adding PS Driver (%ld)\n",GetLastError());
         return;
     }
-#ifdef HAVE_CUPS
     /* If we have any CUPS based printers, skip looking for printcap printers */
     if (CUPS_LoadPrinters())
 	return;
-#endif
 
     /* Check for [ppd] section in config file before parsing /etc/printcap */
 
@@ -1827,7 +1844,7 @@
     RegCloseKey(hkeyPrinter);
     RegCloseKey(hkeyPrinters);
 
-    TRACE("returing %d needed = %ld\n", ret, needed);
+    TRACE("returning %d needed = %ld\n", ret, needed);
     if(pcbNeeded) *pcbNeeded = needed;
     if(!ret)
         SetLastError(ERROR_INSUFFICIENT_BUFFER);
@@ -2544,10 +2561,12 @@
 		      DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded,
 		      LPDWORD pcReturned)
 {
-    FIXME("stub\n");
+    FIXME("(%p,first=%ld,no=%ld,level=%ld,job=%p,cb=%ld,%p,%p), stub!\n",
+	hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned
+    );
     if(pcbNeeded) *pcbNeeded = 0;
     if(pcReturned) *pcReturned = 0;
-    return TRUE;
+    return FALSE;
 }
 
 
@@ -2559,10 +2578,12 @@
 		      DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded,
 		      LPDWORD pcReturned)
 {
-    FIXME("stub\n");
+    FIXME("(%p,first=%ld,no=%ld,level=%ld,job=%p,cb=%ld,%p,%p), stub!\n",
+	hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned
+    );
     if(pcbNeeded) *pcbNeeded = 0;
     if(pcReturned) *pcReturned = 0;
-    return TRUE;
+    return FALSE;
 }
 
 /*****************************************************************************



More information about the wine-patches mailing list