-
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 compatibility for c++ #1191
Open
s-wakaba
wants to merge
1
commit into
samtools:develop
Choose a base branch
from
s-wakaba:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,11 @@ typedef struct { | |
int depth; | ||
} ks_isort_stack_t; | ||
|
||
#ifndef __cplusplus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could probably just get rid of the |
||
#define KSORT_SWAP(type_t, a, b) { register type_t t=(a); (a)=(b); (b)=t; } | ||
#else | ||
#define KSORT_SWAP(type_t, a, b) { type_t t=(a); (a)=(b); (b)=t; } | ||
#endif | ||
|
||
#define KSORT_INIT(name, type_t, __sort_lt) KSORT_INIT_(_ ## name, , type_t, __sort_lt) | ||
#define KSORT_INIT_STATIC(name, type_t, __sort_lt) KSORT_INIT_(_ ## name, static klib_unused, type_t, __sort_lt) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Havind to declare this is mildly annoying, as we don't want it to be called directly. I guess not listing what any of the parameters are makes this less likely, but it would be good to at least have a comment above it saying "Do not call this function directly, only use it via the hts_expand() and hts_expand0() macros".
We could alternately define a few extra macros so we can wrap
extern "C" { ... }
around the existing declarations inhts_expand()
andhts_expand0()
. It does end up being a bit ugly though, so maybe just having the "do not use" comment would be the best solution.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.
It turns out you can't put
extern "C"
on the existing block-local declarations as it's only valid at namespace scope.But why is C++ code using
hts_expand()
orhts_expand0()
anyway? Both macros are documented as “Do not use this macro”, and C++ code in particular has better facilities available to it.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.
This did cross my mind.
@s-wakaba What C++ code is using these macros?
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.
I'm making my bam manipulation tool based on code of samtools and these macros are used in it. I hadn't noticed that these macros are obsoleted. Is it better to update samtools code?
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.
The replacement for
hts_expand()
andhts_expand0()
ishts_resize()
. The difference is that instead of killing your program if it runs out of memory,hts_resize()
returns an error code which means you can handle the problem more gracefully. You do have to check the return value and handle the error condition yourself, though.hts_expand()
is fine in cases where you don't mind the program exiting if you've run out of memory. For example samtools will generally give up anyway if you run out of memory, sohts_expand()
just makes it happen in a faster and possibly less tidy way.For c++ code, I'd have thought you would use c++ features like
vector<>
and exceptions to get growable memory allocations. But I guess this depends on how the data needs to interact with HTSlib structures.I note that the helper function used by
hts_resize()
needs to be visible in the header file due to the wayhts_resize()
works, so I guess we can live withhts_realloc_or_die()
being the same as long as it gets a similar comment.