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

Conflict caused by typedef SSIZE_T ssize_t; #137

Closed
p0358 opened this issue Mar 16, 2023 · 5 comments
Closed

Conflict caused by typedef SSIZE_T ssize_t; #137

p0358 opened this issue Mar 16, 2023 · 5 comments
Assignees
Labels

Comments

@p0358
Copy link

p0358 commented Mar 16, 2023

Description:
There's this line in rapidcsv:

typedef SSIZE_T ssize_t;

However some codebases that include for example nghttp2 may have already set up ssize_t as a macro on project level.

The solution is to check #ifndef ssize_t before trying to define ssize_t, otherwise we'll get an error that we're trying to redefine a base type.

How to reproduce it:

#define ssize_t=__int64
#define _SSIZE_T_DEFINED=1

Environment:

  • Version: v8.69
  • OS / distro: Windows 10 with nghttp2 library included
@d99kris
Copy link
Owner

d99kris commented Mar 17, 2023

Hi @p0358 - thanks for reporting the bug. It's an interesting problem! While checking #ifndef ssize_t will work in this particular scenario, I believe it will not work if another header has typedef'ed ssize_t to something else.

Actually ssize_t is mostly used internally in rapidcsv and not exposed much in the public API. I'm wondering if maybe it makes sense to replace it with int64_t to avoid the problem altogether. I'll need to do some research and get back.

@sven-molkenstruck
Copy link
Contributor

sven-molkenstruck commented Mar 17, 2023

@d99kris If you want to keep your typedef, I suggest to move it into your rapidcsv namespace. That should avoid conflicts with potential typedefs in other headers.

@d99kris
Copy link
Owner

d99kris commented Mar 26, 2023

Thanks for the suggestion @Sven-HP - that is true! But I think I'm more inclined to drop the typedef and simply use a standard integer type. I'd prefer if portable apps would not need stuff like rapidcsv::ssize_t x = doc.GetColumnIdx("name"); when they do interact with an API exposing the type.

I've been thinking about which type to use, and I think regular int will do. For CSV files with over 2 billion rows or columns it probably becomes impractical to use rapidcsv anyway (as rapidcsv keeps the entire parsed CSV in memory so the memory usage would be... quite high..). int64_t would be a safer choice, but it has performance impact on 32-bit environments.

@d99kris
Copy link
Owner

d99kris commented Mar 26, 2023

I've created a PR #139 for switching ssize_t usage to int. Feel free to provide feedback on the change in the review. If there are no major concerns I will proceed to merge it next weekend probably.

@d99kris d99kris closed this as completed in 5dcefe0 Apr 1, 2023
d99kris added a commit that referenced this issue Apr 1, 2023
fixes #137 - switch ssize_t usage to int
@d99kris
Copy link
Owner

d99kris commented Apr 1, 2023

Thanks for checking the PR @Sven-HP!

This issue should be fixed now. Please let me know if you still encounter any issues @p0358. Thanks.

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

No branches or pull requests

3 participants