summaryrefslogtreecommitdiff
path: root/src/c_client.py
AgeCommit message (Collapse)Author
2024-04-15Always write C code in UTF-8Uli Schlachter
Some people apparently use non-utf8 locales and this caused errors when xcb-proto started using some "fancy" quote marks. Fix this by always using utf8 encoding. Fixes: https://gitlab.freedesktop.org/xorg/lib/libxcb/-/issues/72 Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-04-10c_client: Fix crash in xcb_randr_set_monitorIlya Pominov
Take into account c_need_sizeof when evaluating xcb_protocol_request_t.count Incorrect xcb_protocol_request_t.count causes a segmentation fault when calling functions: - xcb_randr_set_monitor{_checked} - xcb_input_change_feedback_control{_checked} - xcb_input_change_device_control{_unchecked} Steps to reproduce: Call xcb_randr_set_monitor() with valid arguments OBSERVED RESULT Segmentation fault ``` Process terminating with default action of signal 11 (SIGSEGV) Access not within mapped region at address 0x780 at 0x4852925: memmove (in /usr/libexec/valgrind/vgpreload_memcheck- amd64-linux.so) by 0x486967C: memcpy (string_fortified.h:29) by 0x486967C: send_request (xcb_out.c:59) by 0x486967C: send_request (xcb_out.c:46) by 0x486967C: xcb_send_request_with_fds64 (xcb_out.c:338) by 0x48699FC: xcb_send_request (xcb_out.c:359) by 0x4891F11: xcb_randr_set_monitor_checked (randr.c:5350) ``` EXPECTED RESULT Function returns cookie Amend: 77b594f9583ea0247ff27130316d8e045da7f921 Signed-off-by: Ilya Pominov <ipominov@astralinux.ru>
2022-10-16Fix handling of documented enum parametersDemi Marie Obenour
Previously this would crash the code generator. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
2021-09-20Improve/fix docs for reply fds functionsUli Schlachter
Fixes: https://gitlab.freedesktop.org/xorg/lib/libxcb/-/issues/56 Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-07-30c_client.py: Implement handling of <length> elementPovilas Kanapickas
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-07-30c_client: Extract _c_get_field_mapping_for_expr()Povilas Kanapickas
2021-07-30c_client.py: Use get_expr_field_names directly to resolve list fieldsPovilas Kanapickas
Using get_expr_fields() is only needed in case we are doing things that can span multiple types easily, e.g. when deciding what data to pass via function parameters and so on. In _c_serialize_helper_list_field() we are building function body, so acquiring field names via get_expr_field_names() is enough. Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-07-30c_client.py: Extract get_expr_field_names()Povilas Kanapickas
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2019-01-07c_client: fix "adress" typoAlan Coopersmith
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2017-06-05c_client: Add support for lists of FDsDaniel Stone
Matching xcbgen changes, add support having a ListType which contains file descriptors. Use this to send a variable number of FDs to the server, including when the list size is not fixed. Signed-off-by: Daniel Stone <daniels@collabora.com>
2017-06-05c_client: Don't serialise non-wire fieldsDaniel Stone
For when we have a variable-sized field followed by a fixed field, make sure we do not serialise non-wire fields. Signed-off-by: Daniel Stone <daniels@collabora.com>
2017-03-11add support for eventstructChristian Linhart
eventstruct allows to use events as part of requests. This is, e.g., needed by xcb_input_send_extension_event. Signed-off-by: Christian Linhart <chris@demorecorder.com>
2017-03-11move symbol lookup of sumof expr to the parserChristian Linhart
replace the complicated symboltable lookup for sumof expr by accessing the lenfield of the expr-object. This requires the corresponding patch for xcb/proto which sets the lenfield accordingly. This should be OK because for official releases we define that dependency in the build system. For getting versions off the HEAD of the git repo, it should be obvious that xcb/proto and xcb/libxcb have to be updated together. I have tested this patch and it generates exactly the same code as before. Tested-by: Christian Linhart <chris@demorecorder.com> Signed-off-by: Christian Linhart <chris@demorecorder.com>
2016-05-28Fix inconsistent use of tabs vs. space.Thomas Klausner
Needed for at least python-3.5.x. Signed-off-by: Thomas Klausner <wiz@NetBSD.org> Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-01do not serialize pads by default anymoreChristian Linhart
Pads should not be serialized/deserialized to maintain ABI compatibility when adding explicit align pads. Therefore this pad switches off serialization of pads unless it is enforced by serialize=true in the xml-definition of that pad Signed-off-by: Christian Linhart <chris@demorecorder.com>
2016-01-06calculate lengthless listJaya Tiwari
Some rework done by Christian Linhart Signed-off-by: Jaya Tiwari <tiwari.jaya18@gmail.com> Signed-off-by: Christian Linhart <chris@demorecorder.com>
2016-01-06Fix handling of align-pads in end-iteratorsChristian Linhart
If a list is preceded by an align-pad, then accessor for the end-iterator returned a wrong value. Reason: the length of the align-iterator was added to a pointer of list-member type. Therefore, the length was multiplied by the size of the list-member type, due to C pointer arithmetic rules. This has looked like the following, e.g., in xcb_randr_get_crtc_transform_pending_params_end: i.data = ((xcb_render_fixed_t *) prev.data) + ((-prev.index) & (4 - 1)) + (R->pending_nparams); This bug was introduced with the following commit: http://cgit.freedesktop.org/xcb/libxcb/commit/?id=4033d39d4da21842bb1396a419dfc299591c3b1f The fix handles this by casting to char* before adding the align, and then casting the result to the member type. Signed-off-by: Christian Linhart <chris@demorecorder.com>
2016-01-06set the align-offset as provided by protoChristian Linhart
instead of using the lower bits of the pointer address. This fixes a bug reported by Peter Hutterer in off-list communication back in June 2015. This requires the alignment-checker patches in xcb/proto. Signed-off-by: Christian Linhart <chris@demorecorder.com>
2015-08-13make lists after align-pads workChristian Linhart
Handle align-pads when generating an end-function in the same way as handling them when generating an accessor or iterator function. Signed-off-by: Christian Linhart <chris@demorecorder.com>
2015-07-04make support for server side stuff optionalChristian Linhart
and make it disabled by default with an EXPERIMENTAL warning reason: this feature is unfinished and we want to have flexibility for ABI/API changes, while still being able to make a release soon Signed-off-by: Christian Linhart <chris@demorecorder.com>
2015-06-12Code generator: Use xcb_send_request_with_fds()Uli Schlachter
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-05-30c_client.py: don't generate useless empty /** < */ commentsRan Benita
(This does not change doxygen's output or warnings). Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-05-30c_client.py: use pattern matching with enumerate()Ran Benita
Signed-off-by: Ran Benita <ran234@gmail.com>
2015-03-15c_client.py: make condition easier to follow in _c_complex()Ran Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: don't add /* <name> */ before references to 'S'Ran Benita
The name can be understood from the type of S already. For examples, look for 'S->' in xkb.c or xinput.c. Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: RĂ©mi Cardona <remi@gentoo.org>
2015-03-15c_client.py: remove duplicated `cookie_type` argument for requestsRan Benita
It is implied already inside the function by the `void` argument. Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: spell out keyword arguments in c_request() for clarityRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: simplify _c_reply_has_fds()Ran Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: remove commented debug statementsRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: use C99 initializers instead of commentsRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: remove end-of-function commentsRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: no need to compare bools to True/FalseRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: use "foo".join() instead of reduceRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: fix indentationRan Benita
(Also remove unnecessary parens around the condition). Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: use comprehensions instead of map/filterRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: use print as a function for python3 compatibilityRan Benita
This works for all python>=2.6, which is what configure requires. Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: fix pyflakes errorsRan Benita
c_client.py:2: 'from xml.etree.cElementTree import *' used; unable to detect undefined names c_client.py:3: 'basename' imported but unused c_client.py:9: 'time' imported but unused c_client.py:1437: local variable 'list_obj' is assigned to but never used c_client.py:1745: local variable 'varfield' is assigned to but never used c_client.py:2050: local variable 'length' is assigned to but never used c_client.py:2416: local variable 'R_obj' is assigned to but never used c_client.py:2441: local variable 'S_obj' is assigned to but never used Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: simplify maximum expressionRan Benita
Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-03-15c_client.py: remove unneeded call to get_serialize_params()Ran Benita
The results are not used, and the function doesn't have side effects. Signed-off-by: Ran Benita <ran234@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
2015-02-22Adding accessors for requestsJaya Tiwari
Added accessor functions for requests the same way they were added for structs,events and replies. Lists for replies have accessor functions now. Signed-off-by: Jaya Tiwari <tiwari.jaya18@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com> Comment from the Reviewer Christian Linhart: I have tested your patch after fixing the issues with the patch-format. It looks good: * only adds new functions, and does not modify existing functions. Therefore it is API and ABI compatible. * adds accessors for varsized-stuff in requests. This is needed for server-side XCB and may be useful for implementing X11-protocol proxies.
2014-11-03generator: support parametrized structsChristian Linhart
Parametrized structs contain paramref expressions which refer to the value of a field defined in the context where the struct is used. Implementing the parametrized structs turned out to be somewhat easier than previously thought because the generator already had some support for type-parametrization because this is needed when case or bitcase refers to fields outside of the switch. So I decided to go with the flow and to implement the solution which best fits the current implementation. I did the following: * I provided a way to specify fieldref with an explicitely given type: This resulted in <paramref type="CARD8>fieldname</paramref> A paramref is just a fieldref with an explicit type. The type is necessary because there is no local field of that name where the type can be derived from. * then I tested it and made several changes in the generator such that it really works. Basically the generated code is as follows: * The parameter appears on the parameter list of the sizeof-function of the parametrized struct. When that function gets called, an appropriate argument is supplied. * The parameter also appears as an additional member of the iterator-struct for the iterator of lists of that parametrized struct. This way, the next-function can get the value of that parameter from the iterator. When the iterator is created, this iterator-member is set accordingly. * When the paramref appears in the length-expression of a list, then the parameter appears on the parameterlist of the "length" and "end" functions. When these functions get called, an appropriate argument is supplied. Some comments: * I did not implement inline structs. This would probably have been more complicated, and at least some additional effort. But that can be implemented later if needed. (Inline structs could probably use some code from switch-case/bitcase which is already kind of an inlined struct but one has to be careful not to break the functionality of switch-case/bitcase. Support for inline structs inside lists must probably be implemented from scratch...) * The paramref expression refers to a field of the same name in the struct/request/... where it is used. So it is not possible to pass the value of arbitrary fields or even expressions to the parametrized struct. This would have been possible with the previously discussed <typearg>. That can be added later, if needed. ( Wont be too complicated ) * So this is pretty much like the proposal from Ran Benita. changes for V2 of this patch, according to suggestions from Ran Benita: * replace map with list comprehension because map returns an iterator instead of a list from Python 3 on, so it cannot be added to a list anymore. * removed "self" parameter of function additional_params_to_str and accessed the variable additional_params from the outer function directly. changes for V2 of this patch: * adapt to revision 2 of patchset ListInputDevices * style fixes for similar things that Ran Benita has found in my previous patches Message-ID: <54574397.4060000@DemoRecorder.com> Patch-Thread-Subject: [Xcb] parametrized structs implemented Patch-Set: ParametrizedStruct Patch-Number: libxcb 1/1 Patch-Version: V3 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
2014-11-03generator: support listelement-refChristian Linhart
Support for listelement-ref needs the following three changes (in the order as they appear in the patch): * making the current list-element accessible with the variable xcb_listelement which is a pointer to the list-element * supporting lists of simple-type for sumof with a nested expression * using the variable for resolving a listelement-ref expression Changes for V2 of this patch: - adapt to removal of patch "libxcb 2/6" from patchset "ListInputDevices". Changes for V3 of this patch: - adapt to V2 of patch "libxcb 5/6" from patchset "ListInputDevices" Changes for V4 of this patch: - adapt to revision 2 of the patchset "ListInputDevices" Message-ID: <545743A0.50907@DemoRecorder.com> Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes Patch-Set: PopcountList Patch-Number: libxcb 4/4 Patch-Version: V4 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
2014-11-03generator: _c_accessor_get_length: remove buggy special caseChristian Linhart
The function _c_accessor_get_length had a special case handling for intermixed var and fixed size fields. However: * The implementation of that special case was buggy: It tried to call a python-dict as a function which causes Python to abort the program with a stacktrace and error message. So this code was never used. * The case it tried to handle is handeled elsewhere in the meantime: in _c_helper_absolute_name by previous patches made by me. Message-ID: <1409845851-38950-3-git-send-email-chris@demorecorder.com> Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes Patch-Set: PopcountList Patch-Number: libxcb 3/4 Patch-Version: V1 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
2014-11-03generator: generate accessors for events, tooChristian Linhart
Accessors are generally needed for var-sized fields and fields after var-sized fields. Generic events can have ver-sized fields. Therefore they need accessors. Message-ID: <1409845851-38950-2-git-send-email-chris@demorecorder.com> Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes Patch-Set: PopcountList Patch-Number: libxcb 2/4 Patch-Version: V1 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
2014-11-03generator: no type-setup for eventcopies anymoreChristian Linhart
_c_type_setup is not called for eventcopies anymore: Reasons: * the type-setup of an eventcopy would overwrite members of the original event object such as c_type, ... * it is needed for the next patch, i.e., generating accessors: type_setup would create sizeof-etc funtions which called undefined accessor functions. Sizeof-functions are generated for compatibility: Reason: * Type-setup of eventcopies has previously generated sizeof-functions for eventcopies. So, we still need to generate these functions. These new sizeof-functions simply call the sizeof-function of the defining event of the eventcopy. Message-ID: <1409845851-38950-1-git-send-email-chris@demorecorder.com> Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes Patch-Set: PopcountList Patch-Number: libxcb 1/4 Patch-Version: V1 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
2014-11-03_c_helper_fieldaccess_expr: remove handling for empty sepChristian Linhart
The loop-variable "sep" is never empty in function "_c_helper_fieldaccess_expr", after a fix elsewhere. Therefore I removed the handling of the case of "sep" being empty. Thanks to Ran Benita for the hint that this can be removed. Signed-off-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <545627C2.3050608@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: libxcb 9/9 Patch-Version: V1
2014-11-03function _c_helper_fieldaccess_expr: improve descriptionChristian Linhart
Signed-off-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <545627BA.1000909@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: libxcb 8/9 Patch-Version: V1
2014-11-03rename _c_helper_absolute_name to _c_helper_fieldaccess_exprChristian Linhart
The function _c_helper_absolute_name was named in a misleading way. It computes a C-expression for accessing a field of an xcb-type. Therefore the name _c_helper_fieldaccess_expr is more appropriate. Note: Patch 6 of this series has been removed during the review process. Signed-off-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <545627AE.2040200@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: libxcb 7/9 Patch-Version: V1
2014-11-03generator: sumof with nested expressionChristian Linhart
Support sumof with a nested expression. The nested expression is computed for every list-element and the result of the computation is added to the sum. This way, sumof can be applied to a list of structs, and, e.g., compute the sum of a specific field of that struct. example: <struct name="SumofTest_Element"> <field type="CARD16" name="foo" /> <field type="CARD16" name="bar" /> </struct> <struct name="SumofTest_FieldAccess"> <field type="CARD32" name="len" /> <list type="SumofTest_Element" name="mylist1"> <fieldref>len</fieldref> </list> <list type="CARD16" name="mylist2"> <sumof ref="mylist1"> <fieldref>bar</fieldref> </sumof> </list> </struct> generated tmpvar: int xcb_pre_tmp_1; /* sumof length */ int xcb_pre_tmp_2; /* sumof loop counter */ int64_t xcb_pre_tmp_3; /* sumof sum */ const xcb_input_sumof_test_element_t* xcb_pre_tmp_4; /* sumof list ptr */ generated code: /* mylist2 */ /* sumof start */ xcb_pre_tmp_1 = _aux->len; xcb_pre_tmp_3 = 0; xcb_pre_tmp_4 = xcb_input_sumof_test_field_access_mylist_1(_aux); for ( xcb_pre_tmp_2 = 0; xcb_pre_tmp_2 < xcb_pre_tmp_1; xcb_pre_tmp_2++) { xcb_pre_tmp_3 += xcb_pre_tmp_4->bar; xcb_pre_tmp_4++; } /* sumof end. Result is in xcb_pre_tmp_3 */ xcb_block_len += xcb_pre_tmp_3 * sizeof(uint16_t); changes for V2 of this patch: * explicitely set the member access operator in the prefix-tuple passed to function _c_helper_field_mapping. This enables us to simplify function "_c_helper_absolute_name" (which will be renamed "_c_helper_fieldaccess_expr" soon) V3: Changed style and formatting according to suggestions from Ran Benita Signed-off-by: Christian Linhart <chris@DemoRecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <54562798.8040500@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: libxcb 5/9 Patch-Version: V3
2014-11-03generator: sumof: support any type, generate explicit codeChristian Linhart
A sumof-expression now generates explicit code ( for-loop etc ) instead of calling xcb_sumof. This way, it supports any type which can be added. Previously, only uint_8 was supported. Here's an example and the generated code: xml: <struct name="SumofTest"> <field type="CARD32" name="len" /> <list type="CARD16" name="mylist1"> <fieldref>len</fieldref> </list> <list type="CARD8" name="mylist2"> <sumof ref="mylist1"/> </list> </struct> declaration of tempvars at the start of enclosing function: int xcb_pre_tmp_1; /* sumof length */ int xcb_pre_tmp_2; /* sumof loop counter */ int64_t xcb_pre_tmp_3; /* sumof sum */ const uint16_t* xcb_pre_tmp_4; /* sumof list ptr */ code: /* mylist2 */ /* sumof start */ xcb_pre_tmp_1 = _aux->len; xcb_pre_tmp_3 = 0; xcb_pre_tmp_4 = xcb_input_sumof_test_mylist_1(_aux); for ( xcb_pre_tmp_2 = 0; xcb_pre_tmp_2 < xcb_pre_tmp_1; xcb_pre_tmp_2++) { xcb_pre_tmp_3 += *xcb_pre_tmp_4; xcb_pre_tmp_4++; } /* sumof end. Result is in xcb_pre_tmp_3 */ xcb_block_len += xcb_pre_tmp_3 * sizeof(uint8_t); This patch is also a preparation for sumof which can access fields of lists of struct, etc. V2: Changed style and formatting according to suggestions from Ran Benita Signed-off-by: Christian Linhart <chris@DemoRecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <54562774.8030306@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: libxcb 4/9 Patch-Version: V2