GNOME Bugzilla – Bug 670373
modules/printing/cups/gtkprintbackendcups.c won't build with CUPS 1.6
Last modified: 2012-04-24 15:23:00 UTC
CUPS 1.6 (currently in development) deprecates most ppd functions and makes private most ipp structs, requiring the use of new accessor functions. The deprecated functions used by gtkprintbackendcups.c are: ppdFindAttr() ppdFindCustomOption() ppdFirstCustomParam() ppdNextCustomParam() The ipp structs used are ipp_t and ipp_attr_t (the former is used to retrieve instances of the latter). A few cases are trivial and can be solved either with macros or a brief ifdef block, but most of them are in cups_request_printer_list_cb, a convoluted 500+ line function which will require extensive refactoring to consolidate the ifdeffed blocks. I'll prepare a series of changesets with the simple changes, the refactoring (which I may break up into multiple changesets), and the final 1.6 ifdefs.
Created attachment 207958 [details] [review] The easy part of cups 1.6 accommodation Adds a test for Cups-1.6 to configure which sets HAVE_CUPS_API_1_6. Sets _PPD_DEPRECATED to empty to suppress the deprecated warnings from ppd.h Creates some simple replacement macros to simulate the Cups 1.6 getter functions where that will work. Replaces in place attribute search routines where they can be simply separated from the rest of the code. As noted, this doesn't completely fix the problem.
Created attachment 207968 [details] [review] More comprehensive than the predecessor Once I dug into cups_printer_list_cb() I found a bunch more opportunities for simple fixes. This gets all of them except the list iteration, which is implemented using the ipp_t argument in Cups 1.6 and so is less tractable.
Created attachment 208010 [details] [review] Refactoring Patch 1 Makes some static constant declarations file-scoped to enable extract-function refactorings.
Created attachment 208011 [details] [review] Refactoring Patch 2 Not really needed for Cups 1.6 fixes, but I don't like magic numbers.
Created attachment 208012 [details] [review] Refactoring Patch 3 Typedef struct PrinterSetupInfo to hold all of the many variables set from IPP Attributes and then passed to the GtkPrinter attributes, for easy passing to functions.
Created attachment 208014 [details] [review] Refactoring Patch 3 Realized I'd forgotten to free the PrinterSetupInfo.
Created attachment 208015 [details] [review] Refactoring Patch 4 Extract the first function, cups_printer_handle_attribute()
Created attachment 208016 [details] [review] Refactoring Patch 5 Extract the second function, cups_create_printer.
Created attachment 208017 [details] [review] Refactoring Patch 6 Move some variables out of the main part of the outer for loop into their scopes so that the declarations are out of the block that's going to be duplicated. Besides, it's annoying to have variables declared outside of the scope they're needed in, especially in an overly-long function.
Created attachment 208018 [details] [review] Finally, the fix! Set up the loop and increment it according to the Cups API version.
Created attachment 208019 [details] [review] One more, some minor fixes in gtkcupsutils.c
The lot of them will need to be backported to 2.4 and 3.2.
Comment on attachment 208019 [details] [review] One more, some minor fixes in gtkcupsutils.c Pushed to master, gtk-3-4, and gtk-2-24