Skip to content

Add missing fields to errors

Uli Schlachter requested to merge psychon/xcbproto:invent-error-fields into master

All X11 errors have the same fields. There are no differences.

In a perfect world, the XML could thus just say "define an error" and xcbgen would do all the rest. However, the world is imperfect and we already have a mixture of fields defined in the XML. Some of the XML even defines trailing padding, while most does not.

This commit makes xcbgen add all fields to X11 errors, but those that are already defined in the XML are skipped and left as-is. Due to the structure of the code, this requires pretending that a different XML was read, i.e. the code now modifies the in-memory structure of ElementTree to add the missing fields to the in-memory representation of the XML. This is the simplest way that I found to append elements. The existing mechanisms can only prepend fields.

The approach taken by this commit was suggested by Peter Harris. Thanks a lot for this idea, it's a lot simpler than my previous approach.

Fixes: #16 (closed) Signed-off-by: Uli Schlachter psychon@znc.in


This commit causes the following changes to libxcb's generated code. The only semi-interesting part is record.h, because it already defines a bad_value field (under a different name), but the patch handles that correctly.

diff --git a/src/damage.h b/src/damage.h
index 213517f..ff99ccb 100644
--- a/src/damage.h
+++ b/src/damage.h
@@ -53,6 +53,9 @@ typedef struct xcb_damage_bad_damage_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_damage_bad_damage_error_t;
 
 /**
diff --git a/src/randr.h b/src/randr.h
index 6235638..f59726b 100644
--- a/src/randr.h
+++ b/src/randr.h
@@ -90,6 +90,9 @@ typedef struct xcb_randr_bad_output_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_randr_bad_output_error_t;
 
 /** Opcode for xcb_randr_bad_crtc. */
@@ -102,6 +105,9 @@ typedef struct xcb_randr_bad_crtc_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_randr_bad_crtc_error_t;
 
 /** Opcode for xcb_randr_bad_mode. */
@@ -114,6 +120,9 @@ typedef struct xcb_randr_bad_mode_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_randr_bad_mode_error_t;
 
 /** Opcode for xcb_randr_bad_provider. */
@@ -126,6 +135,9 @@ typedef struct xcb_randr_bad_provider_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_randr_bad_provider_error_t;
 
 typedef enum xcb_randr_rotation_t {
diff --git a/src/record.h b/src/record.h
index 34c41c1..cfd33f3 100644
--- a/src/record.h
+++ b/src/record.h
@@ -171,6 +171,8 @@ typedef struct xcb_record_bad_context_error_t {
     uint8_t  error_code;
     uint16_t sequence;
     uint32_t invalid_record;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_record_bad_context_error_t;
 
 /**
diff --git a/src/render.h b/src/render.h
index 795c76d..d6f84d5 100644
--- a/src/render.h
+++ b/src/render.h
@@ -196,6 +196,9 @@ typedef struct xcb_render_pict_format_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_render_pict_format_error_t;
 
 /** Opcode for xcb_render_picture. */
@@ -208,6 +211,9 @@ typedef struct xcb_render_picture_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_render_picture_error_t;
 
 /** Opcode for xcb_render_pict_op. */
@@ -220,6 +226,9 @@ typedef struct xcb_render_pict_op_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_render_pict_op_error_t;
 
 /** Opcode for xcb_render_glyph_set. */
@@ -232,6 +241,9 @@ typedef struct xcb_render_glyph_set_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_render_glyph_set_error_t;
 
 /** Opcode for xcb_render_glyph. */
@@ -244,6 +256,9 @@ typedef struct xcb_render_glyph_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_render_glyph_error_t;
 
 /**
diff --git a/src/xfixes.h b/src/xfixes.h
index 358bdb5..6af8fb6 100644
--- a/src/xfixes.h
+++ b/src/xfixes.h
@@ -234,6 +234,9 @@ typedef struct xcb_xfixes_bad_region_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_xfixes_bad_region_error_t;
 
 typedef enum xcb_xfixes_region_enum_t {
diff --git a/src/xinput.h b/src/xinput.h
index 0a06d71..d0fea01 100644
--- a/src/xinput.h
+++ b/src/xinput.h
@@ -4093,6 +4093,9 @@ typedef struct xcb_input_device_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_input_device_error_t;
 
 /** Opcode for xcb_input_event. */
@@ -4105,6 +4108,9 @@ typedef struct xcb_input_event_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_input_event_error_t;
 
 /** Opcode for xcb_input_mode. */
@@ -4117,6 +4123,9 @@ typedef struct xcb_input_mode_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_input_mode_error_t;
 
 /** Opcode for xcb_input_device_busy. */
@@ -4129,6 +4138,9 @@ typedef struct xcb_input_device_busy_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_input_device_busy_error_t;
 
 /** Opcode for xcb_input_class. */
@@ -4141,6 +4153,9 @@ typedef struct xcb_input_class_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_input_class_error_t;
 
 /**
diff --git a/src/xprint.h b/src/xprint.h
index 2763dd0..0825bbc 100644
--- a/src/xprint.h
+++ b/src/xprint.h
@@ -699,6 +699,9 @@ typedef struct xcb_x_print_bad_context_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_x_print_bad_context_error_t;
 
 /** Opcode for xcb_x_print_bad_sequence. */
@@ -711,6 +714,9 @@ typedef struct xcb_x_print_bad_sequence_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_x_print_bad_sequence_error_t;
 
 /**
diff --git a/src/xv.h b/src/xv.h
index c0bcfe8..9e50008 100644
--- a/src/xv.h
+++ b/src/xv.h
@@ -260,6 +260,9 @@ typedef struct xcb_xv_bad_port_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_xv_bad_port_error_t;
 
 /** Opcode for xcb_xv_bad_encoding. */
@@ -272,6 +275,9 @@ typedef struct xcb_xv_bad_encoding_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_xv_bad_encoding_error_t;
 
 /** Opcode for xcb_xv_bad_control. */
@@ -284,6 +290,9 @@ typedef struct xcb_xv_bad_control_error_t {
     uint8_t  response_type;
     uint8_t  error_code;
     uint16_t sequence;
+    uint32_t bad_value;
+    uint16_t minor_opcode;
+    uint8_t  major_opcode;
 } xcb_xv_bad_control_error_t;
 
 /** Opcode for xcb_xv_video_notify. */

CC @peterh (and again: Thanks a lot for the great idea on how to fix this in a simple way)

Edited by Uli Schlachter

Merge request reports