Skip to content

What does fmemopen() do in file format readers? #1023

Open

Description

@szhorvat

If HAVE_FMEMOPEN is defined, the file format readers make use of fmemopen(). Example:

rigraph/src/rinterface_extra.c

Lines 6423 to 6427 in 323f1b4

#if HAVE_FMEMOPEN == 1
file=fmemopen(RAW(pvfile), Rf_xlength(pvfile), "r");
#else
file=fopen(CHAR(STRING_ELT(pvfile, 0)), "r");
#endif

  • Is this code correct at all? It seems to me that depending on this macro, pvfile is interpreter either as the contents of a file, or a file name. These are not interchangeable.
  • If this code is present, why are we not making use of HAVE_FMEMOPEN?

This needs to be reviewed by someone familiar with R internals and R's facilities to treat strings as files. Can we make use of this and gain better performance when parsing contents of strings?

Activity

  1. szhorvat commented on Dec 25, 2023

    @szhorvat
    MemberAuthor

    Related: f936f3c This references a "bug 604907" which I cannot find (@ntamas is this an old Launchpad bug?) The claim that fmemopen is too slow is very surprising ...

  2. szhorvat commented on Dec 25, 2023

    @szhorvat
    MemberAuthor

    It was probably this bug: igraph/igraph#197

    fmemopen is available on macOS now, and it is definitely much faster than creating a file and reading from it if the data is not too large. We do use fmemopen to improve fuzzing performance.

  3. szhorvat commented on Dec 25, 2023

    @szhorvat
    MemberAuthor

    Supporting fast reading from strings would be a new feature that takes time to implement. It takes a lot more than just defining HAVE_FMEMOPEN.

    For now, I would recommend removing all mentions of HAVE_FMEMOPEN, as this is broken and dead code that's just confusing, and blocks auto-generation of these functions.

  4. modified the milestones: upkeep, autogen on Feb 20, 2024
  5. maelle commented on Jul 6, 2026

    @maelle
    Contributor

    Sort of related: #2717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions