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

main: ban fpos_t #3727

Open
masatake opened this issue May 15, 2023 · 4 comments
Open

main: ban fpos_t #3727

masatake opened this issue May 15, 2023 · 4 comments
Milestone

Comments

@masatake
Copy link
Member

fpos_t has caused making our code complicated.

Will ctags deal with files larger than sizeof(long)?
I think it will not.

So I would like to use only ftell/fseek, not together with fsetpos/fgetpos.

Anjuta-ctags took the way I like.

https://gitlab.gnome.org/Archive/anjuta/-/commit/91f5e7fe0a6e4d548f4888711cdaaf7bedab6f85
https://gitlab.gnome.org/Archive/anjuta/-/commit/0adbb5451148027bc6cb283acbfd98c5dc79aad0

What do you think?

@k-takata
Copy link
Member

k-takata commented May 17, 2023

You may need to consider that long is 32 bits on Windows.
Windows has the 64-bit version of fseek:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fseek-fseeki64?view=msvc-170
If we don't need to consider the files that are larger than 2 GB, simply using long should be okay.
Otherwise, the source code of Vim might be helpful:
https://github.com/vim/vim/blob/c0da540466c89e388e7a15a12bab2f9fc42d9671/src/vim.h#L384-L416
(MSWIN is defined inside Vim. Normally we can use _WIN32 instead. PROTO is used for the cproto command, so this can be ignored.)

@masatake
Copy link
Member Author

@k-takata, thank you for the suggestion. Only about input, I think 2GB is large enough.
For output, 2GB is too small.

@k-takata
Copy link
Member

Oh, I remember that we've already done this in readtag:

static rt_off_t readtags_ftell(FILE *fp)
{
rt_off_t pos;
#ifdef _WIN32
pos = _ftelli64(fp);
#else
pos = ftell(fp);
#endif
return pos;
}
static int readtags_fseek(FILE *fp, rt_off_t pos, int whence)
{
int ret;
#ifdef _WIN32
ret = _fseeki64(fp, pos, whence);
#else
ret = fseek(fp, pos, whence);
#endif
return ret;
}

@masatake
Copy link
Member Author

Nice! We should reuse it.

@masatake masatake changed the title [RFC] ban fpos_t Ban fpos_t May 17, 2023
@masatake masatake changed the title Ban fpos_t main: ban fpos_t Dec 18, 2023
@masatake masatake added this to the 6.2 milestone Dec 28, 2023
@masatake masatake modified the milestones: 6.2, 6.3 Feb 24, 2024
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

2 participants