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

2 problems with global constants. #1291

Closed
stephan57160 opened this issue Jul 26, 2022 · 3 comments
Closed

2 problems with global constants. #1291

stephan57160 opened this issue Jul 26, 2022 · 3 comments

Comments

@stephan57160
Copy link
Contributor

stephan57160 commented Jul 26, 2022

Problem: global constants name and descriptions are buggy, compared to per-class constants.

  • constant names with spaces are handled correctly when defined per class (in foo.api), but not when defined globaly (project.xml).
  • when I looked for a fix, I also identified something I fixed last year, for class constant descriptions.

Solution: Fix generated global constant names and their description.

Example:
Extract of project.xml:

  <constant name = "global constant stuff" value = "123" type = "string" >
    this is a
    multi-line comment
    for global constant
  </constant>

Generated file:

#define GLOBAL CONSTANT STUFF  "123"           //
    this is a
    multi-line comment
    for global constant

As a consequence, C compilation fails:

make[1]: Entering directory `/home/cbox_dev/git/zproject-issues-testing'
  CC       src/src_libfbp_la-foo.lo
In file included from src/../include/libfoobar.h:18:0,
                 from src/fbp_classes.h:35,
                 from src/foo.c:21:
src/../include/fbp_library.h:95:5: error: unknown type name 'this'
     this is a
     ^
src/../include/fbp_library.h:95:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
     this is a
             ^

I know it's not the rule, but as both fixes are really close, would you accept a single PR for both ?

@stephan57160 stephan57160 changed the title Multiline global constant description produces buggy C header file. 2 problems with global constants. Jul 26, 2022
@stephan57160
Copy link
Contributor Author

For referene :

prompt> grep CONSTANT\.NAME zproject/zproject_class.gsl 
#define $(CONSTANT.NAME)\
#define $(CONSTANT.NAME)\
#define $(CONSTANT.NAME)\
#define $(CONSTANT.NAME)\t$(constant.value) //  $(constant.?'')
prompt>

@stephan57160
Copy link
Contributor Author

Additionnally, I would add $(PROJECT.PREFIX:c)_ as a prefix for a global constant name, like it is for project version constants.
Without project.prefix:

//  FOOBARPROJECT version macros for compile-time API detection
#define FOOBARPROJECT_VERSION_MAJOR 4
#define FOOBARPROJECT_VERSION_MINOR 5
#define FOOBARPROJECT_VERSION_PATCH 6

with project.prefix = "FBP" :

#define FBP_VERSION_MAJOR 4
#define FBP_VERSION_MINOR 5
#define FBP_VERSION_PATCH 6

But ... this would break existing projects ...

stephan57160 added a commit to stephan57160/zproject that referenced this issue Aug 1, 2022
Project constant definition:
```
  <constant name = "global constant stuff" value = "123" type = "string" >
    this is a
    multi-line comment
    for global constant
  </constant>

```

Generated header file:

```
make[1]: Entering directory `/home/cbox_dev/git/zproject-issues-testing'
  CC       src/src_libfbp_la-foo.lo
In file included from src/../include/libfoobar.h:18:0,
                 from src/fbp_classes.h:35,
                 from src/foo.c:21:
src/../include/fbp_library.h:95:5: error: unknown type name 'this'
     this is a
     ^
src/../include/fbp_library.h:95:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
     this is a
             ^
...
```

See zeromq#1291 for more details.

Solution: Apply a similar fix than zeromq#1283, but on global constants.
```
// this is a
// multi-line comment
// for global constant
```

Additionnally, a few blank lines are added to separate the constants
definitions, from each other.

Note:
to look like the project version constants:
```
```
This particular modification is not applied with this PR
stephan57160 added a commit to stephan57160/zproject that referenced this issue Aug 1, 2022
Project constant definition:
```
  <constant name = "global constant stuff" value = "123" type = "string" >
    this is a
    multi-line comment
    for global constant
  </constant>

```

Generated header file:
```
    this is a
    multi-line comment
    for global constant
```

Compilation failure:
```
make[1]: Entering directory `/home/cbox_dev/git/zproject-issues-testing'
  CC       src/src_libfbp_la-foo.lo
In file included from src/../include/libfoobar.h:18:0,
                 from src/fbp_classes.h:35,
                 from src/foo.c:21:
src/../include/fbp_library.h:95:5: error: unknown type name 'this'
     this is a
     ^
src/../include/fbp_library.h:95:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
     this is a
             ^
...
```

See zeromq#1291 for more details.

Solution: Apply a similar fix than zeromq#1283, but on global constants.
```
// this is a
// multi-line comment
// for global constant
    this is a
    multi-line comment
    for global constant
```

Additionnally, a few blank lines are added to separate the constants
definitions, from each other.

Note:
`$(PROJECT.PREFIX:c)_` to look like the project version constants:
```
```
This particular modification is not applied with this PR
stephan57160 added a commit to stephan57160/zproject that referenced this issue Aug 1, 2022
Project constant definition:
```
  <constant name = "global constant stuff" value = "123" type = "string" >
    this is a
    multi-line comment
    for global constant
  </constant>

```

Generated header file:
```
    this is a
    multi-line comment
    for global constant
```

Compilation failure:
```
make[1]: Entering directory `/home/cbox_dev/git/zproject-issues-testing'
  CC       src/src_libfbp_la-foo.lo
In file included from src/../include/libfoobar.h:18:0,
                 from src/fbp_classes.h:35,
                 from src/foo.c:21:
src/../include/fbp_library.h:95:5: error: unknown type name 'this'
     this is a
     ^
src/../include/fbp_library.h:95:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
     this is a
             ^
...
```

See zeromq#1291 for more details.

Solution: Apply a similar fix than zeromq#1283, but on global constants.
```
// this is a
// multi-line comment
// for global constant
```

Additionnally, a few blank lines are added to separate the constants
definitions, from each other.

Note:
Global constants should be prefixed with `$(PROJECT.PREFIX:c)_`,
like for version constants, but this is not applied here.
@stephan57160
Copy link
Contributor Author

Closing, as PR is accepted.

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

No branches or pull requests

1 participant