You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2021/05/04 14:05:01 UTC
[GitHub] [daffodil] tuxji opened a new pull request #553: Fix a C portability problem
tuxji opened a new pull request #553:
URL: https://github.com/apache/daffodil/pull/553
Some older C compilers (e.g., gcc 4.8.2 on CentOS 7) don't allow a
local variable to be declared inside a for loop condition. It's much
easier to move the declaration outside the for loop condition than it
is to override the compiler with a different driver name or the
correct driver options.
DAFFODIL-2507
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] tuxji commented on a change in pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
tuxji commented on a change in pull request #553:
URL: https://github.com/apache/daffodil/pull/553#discussion_r626029507
##########
File path: daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libruntime/infoset.c
##########
@@ -132,7 +132,8 @@ walkInfosetNode(const VisitEventHandler *handler, const InfosetBase *infoNode)
const ERD **const childrenERDs = infoNode->erd->childrenERDs;
const size_t * offsets = infoNode->erd->offsets;
- for (size_t i = 0; i < count && !error; i++)
+ size_t i;
+ for (i = 0; i < count && !error; i++)
{
const size_t offset = offsets[i];
Review comment:
Yes, I realized there is a setting we can use: -pedantic -std=gnu99. I've enabled it, found some more problems, and fixed them in my latest commit. The -pedantic option turns on some warnings about code that doesn't conform strictly to the C standard. The -std=gnu99 option checks the C99 standard with GNU extensions, allowing us to keep using <unistd.h> for getopt and so on for all the functions that aren't available with -std=c99. Note that there's nothing really GNU-ish about getopt, it's more of a Unix / POSIX extension than a GNU extension.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] tuxji commented on pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
tuxji commented on pull request #553:
URL: https://github.com/apache/daffodil/pull/553#issuecomment-832649689
Still need another +1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] mbeckerle commented on a change in pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
mbeckerle commented on a change in pull request #553:
URL: https://github.com/apache/daffodil/pull/553#discussion_r626530478
##########
File path: daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libruntime/infoset.h
##########
@@ -26,22 +26,26 @@
// Prototypes needed for compilation
-typedef struct ElementRuntimeData ERD;
-typedef struct InfosetBase InfosetBase;
-typedef struct PState PState;
-typedef struct UState UState;
-typedef struct VisitEventHandler VisitEventHandler;
-
-typedef void (*ERDInitSelf)(InfosetBase *infoNode);
-typedef void (*ERDParseSelf)(InfosetBase *infoNode, PState *pstate);
-typedef void (*ERDUnparseSelf)(const InfosetBase *infoNode, UState *ustate);
-typedef const Error *(*InitChoiceRD)(const InfosetBase *infoNode, const InfosetBase *rootElement);
-
-typedef const Error *(*VisitStartDocument)(const VisitEventHandler *handler);
-typedef const Error *(*VisitEndDocument)(const VisitEventHandler *handler);
-typedef const Error *(*VisitStartComplex)(const VisitEventHandler *handler, const InfosetBase *base);
-typedef const Error *(*VisitEndComplex)(const VisitEventHandler *handler, const InfosetBase *base);
-typedef const Error *(*VisitNumberElem)(const VisitEventHandler *handler, const ERD *erd, const void *number);
+struct ERD;
Review comment:
Surprising to me that this typedef isn't portable. Seriously you can't suppress the need to use the struct keyword everywhere you use these types? Ugh.
Can we upgrade our usage to a newer still-standard revision of the C language that has this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] tuxji merged pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
tuxji merged pull request #553:
URL: https://github.com/apache/daffodil/pull/553
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] tuxji commented on a change in pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
tuxji commented on a change in pull request #553:
URL: https://github.com/apache/daffodil/pull/553#discussion_r626592946
##########
File path: daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libruntime/infoset.h
##########
@@ -26,22 +26,26 @@
// Prototypes needed for compilation
-typedef struct ElementRuntimeData ERD;
-typedef struct InfosetBase InfosetBase;
-typedef struct PState PState;
-typedef struct UState UState;
-typedef struct VisitEventHandler VisitEventHandler;
-
-typedef void (*ERDInitSelf)(InfosetBase *infoNode);
-typedef void (*ERDParseSelf)(InfosetBase *infoNode, PState *pstate);
-typedef void (*ERDUnparseSelf)(const InfosetBase *infoNode, UState *ustate);
-typedef const Error *(*InitChoiceRD)(const InfosetBase *infoNode, const InfosetBase *rootElement);
-
-typedef const Error *(*VisitStartDocument)(const VisitEventHandler *handler);
-typedef const Error *(*VisitEndDocument)(const VisitEventHandler *handler);
-typedef const Error *(*VisitStartComplex)(const VisitEventHandler *handler, const InfosetBase *base);
-typedef const Error *(*VisitEndComplex)(const VisitEventHandler *handler, const InfosetBase *base);
-typedef const Error *(*VisitNumberElem)(const VisitEventHandler *handler, const ERD *erd, const void *number);
+struct ERD;
Review comment:
I wouldn't mind upgrading to C11 as a minimum requirement. C11 would make practically all of those changes unnecessary because C11 allows us to redefine typedefs, declare a local variable in a for loop's condition, and define anonymous unions (error.c instead of error.arg.c). However, we would have to make CodeGenerator.scala pass -std=gnu11 to the C compiler when daffodil runs TDML tests. That option is supported and understood by the gcc and clang versions I tested on CentOS 7 and they compile the code without complaining.
The problem is that I don't believe that -std=gnu11 is a standard option which every C compiler understands or that every C compiler in use now can compile C11-level code with getopt and other Unix functions. Once you start building for an embedded platform, you might be using an esoteric C compiler not derived from gcc or clang anymore. On a HPC machine, you might be using Intel's C compiler. I just googled to find documentation for Intel's C compiler. It accepts the -std option (here's the [page](https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/language-options/std-qstd.html)), but it goes up only as high as gnu99 (and c11, but I don't think -std=c11 would let us call getopt and company just like it doesn't in clang and gcc).
I think it's quite possible a user might have a C compiler which won't accept -std=gnu11, and it might compile only C99-level code if we pass only -I and -o options (like what happens with both gcc and clang on CentOS 7). My fear is that we'd still need to make these changes later anyway, so we might as well merge these changes to save us time. The safest thing for a portable daffodil installation would be to pass only -I and -o options to unknown C compilers when running TDML tests on users' platforms, although we could make CodeGenerator.scala read a CFLAGS environment variable and add its value to the compiler options too. Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil] stevedlawrence commented on a change in pull request #553: Fix a C portability problem
Posted by GitBox <gi...@apache.org>.
stevedlawrence commented on a change in pull request #553:
URL: https://github.com/apache/daffodil/pull/553#discussion_r625895323
##########
File path: daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libruntime/infoset.c
##########
@@ -132,7 +132,8 @@ walkInfosetNode(const VisitEventHandler *handler, const InfosetBase *infoNode)
const ERD **const childrenERDs = infoNode->erd->childrenERDs;
const size_t * offsets = infoNode->erd->offsets;
- for (size_t i = 0; i < count && !error; i++)
+ size_t i;
+ for (i = 0; i < count && !error; i++)
{
const size_t offset = offsets[i];
Review comment:
Is there a setting we can enable so that we can error when we add non-portable code? Even if we only set it for GitHub actions so we can catch it before it's merged if there are concerns about enabling it all time?
##########
File path: BUILD.md
##########
@@ -43,6 +43,27 @@ commands (or set them to `true` to disable C compilation altogether)
if you don't want `sbt compile` to call your C compiler with `cc` and
`ar` as the default commands.
+## CentOS 7
+
+You can use the `yum` package manager to install most of the tools
+needed to build Daffodil:
+
+ sudo dnf install gcc git java-11-openjdk-devel llvm make pkgconfig
Review comment:
Should this be yum instead of dnf? Does CentOS 7 have dnf? Should this also be gcc instead of clang like we suggest for fedora, or is clang not even available?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org