nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0175-Remove-nested-functions-from-videoinfo-iterators.patch

f96e0b
From 9b2828fc730a0d09ff5934a44bb0e25e7fdf06f2 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Fri, 1 Mar 2013 11:11:36 +0100
f96e0b
Subject: [PATCH 175/482] 	Remove nested functions from videoinfo
f96e0b
 iterators.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                      |  4 ++++
f96e0b
 grub-core/commands/videoinfo.c | 34 ++++++++++++++++++++--------------
f96e0b
 grub-core/video/efi_gop.c      | 23 ++++++++++++-----------
f96e0b
 grub-core/video/i386/pc/vbe.c  |  4 ++--
f96e0b
 include/grub/video.h           |  2 +-
f96e0b
 5 files changed, 39 insertions(+), 28 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 3ca1fed..7f5bcfa 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,9 @@
f96e0b
 2013-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	Remove nested functions from videoinfo iterators.
f96e0b
+
f96e0b
+2013-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	* grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Fix compilation
f96e0b
 	for 64-bit platforms.
f96e0b
 
f96e0b
diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c
f96e0b
index 4a11576..7a75c9d 100644
f96e0b
--- a/grub-core/commands/videoinfo.c
f96e0b
+++ b/grub-core/commands/videoinfo.c
f96e0b
@@ -27,23 +27,28 @@
f96e0b
 
f96e0b
 GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
 
f96e0b
-static unsigned height, width, depth; 
f96e0b
-static struct grub_video_mode_info *current_mode;
f96e0b
+struct hook_ctx
f96e0b
+{
f96e0b
+  unsigned height, width, depth; 
f96e0b
+  struct grub_video_mode_info *current_mode;
f96e0b
+};
f96e0b
 
f96e0b
 static int
f96e0b
-hook (const struct grub_video_mode_info *info)
f96e0b
+hook (const struct grub_video_mode_info *info, void *hook_arg)
f96e0b
 {
f96e0b
-  if (height && width && (info->width != width || info->height != height))
f96e0b
+  struct hook_ctx *ctx = hook_arg;
f96e0b
+
f96e0b
+  if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
f96e0b
     return 0;
f96e0b
 
f96e0b
-  if (depth && info->bpp != depth)
f96e0b
+  if (ctx->depth && info->bpp != ctx->depth)
f96e0b
     return 0;
f96e0b
 
f96e0b
   if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
f96e0b
     grub_printf ("        ");
f96e0b
   else
f96e0b
     {
f96e0b
-      if (current_mode && info->mode_number == current_mode->mode_number)
f96e0b
+      if (ctx->current_mode && info->mode_number == ctx->current_mode->mode_number)
f96e0b
 	grub_printf ("*");
f96e0b
       else
f96e0b
 	grub_printf (" ");
f96e0b
@@ -126,13 +131,14 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
f96e0b
 {
f96e0b
   grub_video_adapter_t adapter;
f96e0b
   grub_video_driver_id_t id;
f96e0b
+  struct hook_ctx ctx;
f96e0b
 
f96e0b
-  height = width = depth = 0;
f96e0b
+  ctx.height = ctx.width = ctx.depth = 0;
f96e0b
   if (argc)
f96e0b
     {
f96e0b
       char *ptr;
f96e0b
       ptr = args[0];
f96e0b
-      width = grub_strtoul (ptr, &ptr, 0);
f96e0b
+      ctx.width = grub_strtoul (ptr, &ptr, 0);
f96e0b
       if (grub_errno)
f96e0b
 	return grub_errno;
f96e0b
       if (*ptr != 'x')
f96e0b
@@ -140,13 +146,13 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
f96e0b
 			   N_("invalid video mode specification `%s'"),
f96e0b
 			   args[0]);
f96e0b
       ptr++;
f96e0b
-      height = grub_strtoul (ptr, &ptr, 0);
f96e0b
+      ctx.height = grub_strtoul (ptr, &ptr, 0);
f96e0b
       if (grub_errno)
f96e0b
 	return grub_errno;
f96e0b
       if (*ptr == 'x')
f96e0b
 	{
f96e0b
 	  ptr++;
f96e0b
-	  depth = grub_strtoul (ptr, &ptr, 0);
f96e0b
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
f96e0b
 	  if (grub_errno)
f96e0b
 	    return grub_errno;
f96e0b
 	}
f96e0b
@@ -175,12 +181,12 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
f96e0b
 	continue;
f96e0b
       }
f96e0b
 
f96e0b
-    current_mode = NULL;
f96e0b
+    ctx.current_mode = NULL;
f96e0b
 
f96e0b
     if (adapter->id == id)
f96e0b
       {
f96e0b
 	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
f96e0b
-	  current_mode = &info;
f96e0b
+	  ctx.current_mode = &info;
f96e0b
 	else
f96e0b
 	  /* Don't worry about errors.  */
f96e0b
 	  grub_errno = GRUB_ERR_NONE;
f96e0b
@@ -198,14 +204,14 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
f96e0b
     if (adapter->print_adapter_specific_info)
f96e0b
       adapter->print_adapter_specific_info ();
f96e0b
 
f96e0b
-    adapter->iterate (hook);
f96e0b
+    adapter->iterate (hook, &ctx;;
f96e0b
 
f96e0b
     if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
f96e0b
       print_edid (&edid_info);
f96e0b
     else
f96e0b
       grub_errno = GRUB_ERR_NONE;
f96e0b
 
f96e0b
-    current_mode = NULL;
f96e0b
+    ctx.current_mode = NULL;
f96e0b
 
f96e0b
     if (adapter->id != id)
f96e0b
       {
f96e0b
diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c
f96e0b
index 37a0015..f73a278 100644
f96e0b
--- a/grub-core/video/efi_gop.c
f96e0b
+++ b/grub-core/video/efi_gop.c
f96e0b
@@ -42,7 +42,7 @@ static int restore_needed;
f96e0b
 static grub_efi_handle_t gop_handle;
f96e0b
 
f96e0b
 static int
f96e0b
-grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info));
f96e0b
+grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
f96e0b
 
f96e0b
 static struct
f96e0b
 {
f96e0b
@@ -52,6 +52,14 @@ static struct
f96e0b
   grub_uint8_t *offscreen;
f96e0b
 } framebuffer;
f96e0b
 
f96e0b
+static int
f96e0b
+check_protocol_hook (const struct grub_video_mode_info *info __attribute__ ((unused)), void *hook_arg)
f96e0b
+{
f96e0b
+  int *have_usable_mode = hook_arg;
f96e0b
+  *have_usable_mode = 1;
f96e0b
+  return 1;
f96e0b
+}
f96e0b
+
f96e0b
 
f96e0b
 static int
f96e0b
 check_protocol (void)
f96e0b
@@ -60,13 +68,6 @@ check_protocol (void)
f96e0b
   grub_efi_uintn_t num_handles, i;
f96e0b
   int have_usable_mode = 0;
f96e0b
 
f96e0b
-  auto int hook (const struct grub_video_mode_info *info);
f96e0b
-  int hook (const struct grub_video_mode_info *info __attribute__ ((unused)))
f96e0b
-  {
f96e0b
-    have_usable_mode = 1;
f96e0b
-    return 1;
f96e0b
-  }
f96e0b
-
f96e0b
   handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL,
f96e0b
 				    &graphics_output_guid, NULL, &num_handles);
f96e0b
   if (!handles || num_handles == 0)
f96e0b
@@ -77,7 +78,7 @@ check_protocol (void)
f96e0b
       gop_handle = handles[i];
f96e0b
       gop = grub_efi_open_protocol (gop_handle, &graphics_output_guid,
f96e0b
 				    GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
f96e0b
-      grub_video_gop_iterate (hook);
f96e0b
+      grub_video_gop_iterate (check_protocol_hook, &have_usable_mode);
f96e0b
       if (have_usable_mode)
f96e0b
 	{
f96e0b
 	  grub_free (handles);
f96e0b
@@ -256,7 +257,7 @@ grub_video_gop_fill_mode_info (unsigned mode,
f96e0b
 }
f96e0b
 
f96e0b
 static int
f96e0b
-grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
f96e0b
+grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg)
f96e0b
 {
f96e0b
   unsigned mode;
f96e0b
 
f96e0b
@@ -282,7 +283,7 @@ grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
f96e0b
 	  grub_errno = GRUB_ERR_NONE;
f96e0b
 	  continue;
f96e0b
 	}
f96e0b
-      if (hook (&mode_info))
f96e0b
+      if (hook (&mode_info, hook_arg))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
   return 0;
f96e0b
diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c
f96e0b
index 81e5a8e..e8a8c7a 100644
f96e0b
--- a/grub-core/video/i386/pc/vbe.c
f96e0b
+++ b/grub-core/video/i386/pc/vbe.c
f96e0b
@@ -952,7 +952,7 @@ vbe2videoinfo (grub_uint32_t mode,
f96e0b
 }
f96e0b
 
f96e0b
 static int
f96e0b
-grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info))
f96e0b
+grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg)
f96e0b
 {
f96e0b
   grub_uint16_t *p;
f96e0b
   struct grub_vbe_mode_info_block vbe_mode_info;
f96e0b
@@ -969,7 +969,7 @@ grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info))
f96e0b
         }
f96e0b
 
f96e0b
       vbe2videoinfo (*p, &vbe_mode_info, &mode_info);
f96e0b
-      if (hook (&mode_info))
f96e0b
+      if (hook (&mode_info, hook_arg))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
   return 0;
f96e0b
diff --git a/include/grub/video.h b/include/grub/video.h
f96e0b
index 08f7300..9fe4783 100644
f96e0b
--- a/include/grub/video.h
f96e0b
+++ b/include/grub/video.h
f96e0b
@@ -372,7 +372,7 @@ struct grub_video_adapter
f96e0b
 
f96e0b
   grub_err_t (*get_active_render_target) (struct grub_video_render_target **target);
f96e0b
 
f96e0b
-  int (*iterate) (int (*hook) (const struct grub_video_mode_info *info));
f96e0b
+  int (*iterate) (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
f96e0b
 
f96e0b
   grub_err_t (*get_edid) (struct grub_video_edid_info *edid_info);
f96e0b
 
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b