Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for enum entries initialized using a macro #174

Closed
emezh opened this issue Jun 27, 2023 · 4 comments · Fixed by #175
Closed

Add support for enum entries initialized using a macro #174

emezh opened this issue Jun 27, 2023 · 4 comments · Fixed by #175

Comments

@emezh
Copy link

emezh commented Jun 27, 2023

Consider the following C code:

/**
 * My Define
 */
#define MY_BITMASK  0x8000U

/**
 * My Define mask
 */
#define MY_MASKED( base_enum ) ((base_enum) | MY_BITMASK )

/**
 * My enum
 */
typedef enum {
    VALUE_0,          /**< my value 0*/
    VALUE_1,          /**< my value 1*/
    VALUE_2 = MY_MASKED( VALUE_0 ),     /**< my value 2*/
    VALUE_3 = MY_MASKED( VALUE_1 ),     /**< my value 3*/
} my_value_e;

When running sphinx with sphinx-c-autodoc it gives the following error:

.../venv_py3/lib/python3.8/site-packages/sphinx_c_autodoc/loader.py:docstring of my.h:1: ERROR: Error in "c:enumerator" directive:
invalid option data: duplicate option "module".
.. c:enumerator:: VALUE_3 = ((VALUE_1) | 32768U)
   :module: hx_cv_frame.h
   :module: hx_cv_frame.h
   my value 2
   my value 3

and the generated HTML doesn't contain VALUE_2 and VALUE_3 in the list of enum members.

Removing VALUE_3 from enum makes the error disappear (and VALUE_2 renders ok in HTML), but in real life, I have a lot of enums using MY_MASKED macro.
Is it possible to add support for multiple entries using MY_MASKED macro?

Thanks

@speedyleion
Copy link
Owner

Thanks for the nice minimal example. I'll have to play with it, but I think in general yes it should support this.

This part seems like it might be a bug in sphinx-c-autodoc

.. c:enumerator:: VALUE_3 = ((VALUE_1) | 32768U)

Looking at, https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#directive-c-enumerator
it says

.. c:enumerator:: name

I don't think the = and what not should be there.

@speedyleion speedyleion linked a pull request Jun 29, 2023 that will close this issue
@speedyleion
Copy link
Owner

@emezh it looks like 1.2.2 is stuck publishing for some reason... https://github.com/speedyleion/sphinx-c-autodoc/actions/runs/5407519287.

I'm going to let it spin overnight and if it doesn't fix itself I'll manually publish

@emezh
Copy link
Author

emezh commented Jun 29, 2023

@speedyleion Many thanks for the quick fix. Looks like there are some hick-ups with github since yesterday. I'm out for the most part of the next two weeks, so it may take some time before I can verify and report back.
Thanks again!

@speedyleion
Copy link
Owner

Took an extra day, but it's published now, https://pypi.org/project/sphinx-c-autodoc/1.2.2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants