-
Notifications
You must be signed in to change notification settings - Fork 447
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
Improve c++ compatibility of htslib header files #772
Conversation
The C99 standard was full of crap when it tried to tell the C++ committee what to do, so the comment doesn't need to be so detailed — at this point, disabling these macros in the absence of What about just avoiding using Defining #ifdef SIZE_MAX
#define SIZE_MAX_KS SIZE_MAX
#else
#define SIZE_MAX_KS ((size_t) -1)
#endif
…
// Use SIZE_MAX_KS within htslib/kstring.h
…
#undef SIZE_MAX_KS // Undef it at the end of the header file (Undeffing it afterwards so that other code (especially third-party code) just uses the standard nomenclature.) |
Yes, the I don't see why including I'd rather not have to jump through hoops in the rest of the file, just because of an ancient c/c++ incompatibility. |
Oops — you are quite right that <stdint.h> was never likely to operate like <assert.h>/ It would make me nervous in general to define names that are reserved to the compiler/standard library, especially in a public header, but YMMV. |
Allow room in kputuw_dig2r for the nul byte on the end of the string used to initialize it. gcc doesn't mind it being dropped but g++ complains. Avoid INTx_MIN, INTx_MAX and SIZE_MAX macros from <stdint.h> in htslib/*.h header files. Old versions of glibc (before 2.18), and possibly other libc implementations don't automatically supply them when compiling as c++. Easiest solution is to not use them in these headers. (See https://sourceware.org/bugzilla/show_bug.cgi?id=15366) Fixes samtools#771 (kstring.h error: initializer-string for array of chars is too long)
fbbaf9d
to
1048395
Compare
Mk.2 version (just pushed) avoids the problem by not using |
Nice 😄 Now that they exist, you might as well use |
vcf.c
Outdated
@@ -1731,7 +1731,7 @@ int vcf_hdr_write(htsFile *fp, const bcf_hdr_t *h) | |||
|
|||
void bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize) | |||
{ | |||
int32_t max = INT32_MIN + 1, min = INT32_MAX; | |||
int32_t max = BCF_MIN_BT_INT32 + 1, min = BCF_MAX_BT_INT32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are boundaries on the unencoded int32_t
values, so should just be
int32_t max = INT32_MIN, min = INT32_MAX;
and on the lines below you need to lose the + 8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting that. I was under the impression they were match for match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — looks good to me now.
4b9a7b9
to
025a05d
Compare
Allow room in kputuw_dig2r for the nul byte on the end of the string used to initialize it. gcc doesn't mind it being dropped but g++ complains.
Fix missing stdint.h limit macros when including htslib/kstring.h and htslib/vcf.h in a c++ compilation. The C99 standard says c++ implementations should only define them if __STDC_LIMIT_MACROS
is also defined. C++11 later put them back, but older versions of libc may not provide them without this.
As we can't be sure we're the first to include stdint.h, defining it in our header files may be too late. Instead suitable definitions are added for the macros that are used by each header.
Fixes #771 (kstring.h error: initializer-string for array of chars is too long)