Skip to content

Commit

Permalink
libavutil: Deprecate av_fopen_utf8, provide an avpriv version
Browse files Browse the repository at this point in the history
Since every DLL can use an individual CRT on Windows, having
an exported function that opens a FILE* won't work if that
FILE* is going to be used from a different DLL (or from user
application code).

Internally within the libraries, the issue can be worked around
by duplicating the function in all libraries (this already happened
implicitly because the function resided in file_open.c) and renaming
the function to ff_fopen_utf8 (so that it doesn't end up exported from
the DLLs) and duplicating it in all libraries that use it.

This makes the avpriv_fopen_utf8 / ff_fopen_utf8 function work in
the exact same way as the existing avpriv_open / ff_open, with the
same setup as introduced in e743e7a.

That mechanism doesn't work for external users, thus deprecate the
existing function.

Signed-off-by: Martin Storsjö <martin@martin.st>
  • Loading branch information
mstorsjo committed May 23, 2022
1 parent 3fb9244 commit 4cdc14a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ libavutil: 2021-04-27

API changes, most recent first:

2022-05-23 - xxxxxxxxx - lavu 57.25.100 - avutil.h
Deprecate av_fopen_utf8() without replacement.

2022-03-16 - xxxxxxxxxx - all libraries - version_major.h
Add lib<name>/version_major.h as new installed headers, which only
contain the major version number (and corresponding API deprecation
Expand Down
2 changes: 1 addition & 1 deletion fftools/fopen_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <stdio.h>

/* The fopen_utf8 function here is essentially equivalent to av_fopen_utf8,
/* The fopen_utf8 function here is essentially equivalent to avpriv_fopen_utf8,
* except that it doesn't set O_CLOEXEC, and that it isn't exported
* from a different library. (On Windows, each DLL might use a different
* CRT, and FILE* handles can't be shared across them.) */
Expand Down
1 change: 1 addition & 0 deletions libavfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OBJS = allfilters.o \
version.o \
video.o \

OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o
OBJS-$(HAVE_THREADS) += pthread.o

# subsystems
Expand Down
1 change: 1 addition & 0 deletions libavfilter/file_open.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "libavutil/file_open.c"
6 changes: 6 additions & 0 deletions libavutil/avutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,18 @@ unsigned av_int_list_length_for_size(unsigned elsize,
#define av_int_list_length(list, term) \
av_int_list_length_for_size(sizeof(*(list)), list, term)

#if FF_API_AV_FOPEN_UTF8
/**
* Open a file using a UTF-8 filename.
* The API of this function matches POSIX fopen(), errors are returned through
* errno.
* @deprecated Avoid using it, as on Windows, the FILE* allocated by this
* function may be allocated with a different CRT than the caller
* who uses the FILE*. No replacement provided in public API.
*/
attribute_deprecated
FILE *av_fopen_utf8(const char *path, const char *mode);
#endif

/**
* Return the fractional representation of the internal time base.
Expand Down
9 changes: 8 additions & 1 deletion libavutil/file_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int avpriv_tempfile(const char *prefix, char **filename, int log_offset, void *l
return fd; /* success */
}

FILE *av_fopen_utf8(const char *path, const char *mode)
FILE *avpriv_fopen_utf8(const char *path, const char *mode)
{
int fd;
int access;
Expand Down Expand Up @@ -188,3 +188,10 @@ FILE *av_fopen_utf8(const char *path, const char *mode)
return NULL;
return fdopen(fd, mode);
}

#if FF_API_AV_FOPEN_UTF8
FILE *av_fopen_utf8(const char *path, const char *mode)
{
return avpriv_fopen_utf8(path, mode);
}
#endif
8 changes: 8 additions & 0 deletions libavutil/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
#include <stdio.h>
#include "config.h"
#include "attributes.h"
#include "timer.h"
Expand Down Expand Up @@ -183,8 +184,10 @@ void avpriv_request_sample(void *avc,
#pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
#endif

#define avpriv_fopen_utf8 ff_fopen_utf8
#define avpriv_open ff_open
#define avpriv_tempfile ff_tempfile

#define PTRDIFF_SPECIFIER "Id"
#define SIZE_SPECIFIER "Iu"
#else
Expand Down Expand Up @@ -256,6 +259,11 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
av_warn_unused_result
int avpriv_open(const char *filename, int flags, ...);

/**
* Open a file using a UTF-8 filename.
*/
FILE *avpriv_fopen_utf8(const char *path, const char *mode);

/**
* Wrapper to work around the lack of mkstemp() on mingw.
* Also, tries to create file in /tmp first, if possible.
Expand Down
5 changes: 3 additions & 2 deletions libavutil/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
*/

#define LIBAVUTIL_VERSION_MAJOR 57
#define LIBAVUTIL_VERSION_MINOR 24
#define LIBAVUTIL_VERSION_MICRO 101
#define LIBAVUTIL_VERSION_MINOR 25
#define LIBAVUTIL_VERSION_MICRO 100

#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
Expand Down Expand Up @@ -113,6 +113,7 @@
#define FF_API_FIFO_OLD_API (LIBAVUTIL_VERSION_MAJOR < 58)
#define FF_API_XVMC (LIBAVUTIL_VERSION_MAJOR < 58)
#define FF_API_OLD_CHANNEL_LAYOUT (LIBAVUTIL_VERSION_MAJOR < 58)
#define FF_API_AV_FOPEN_UTF8 (LIBAVUTIL_VERSION_MAJOR < 58)

/**
* @}
Expand Down
1 change: 1 addition & 0 deletions tests/ref/fate/source
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ libavcodec/reverse.c
libavdevice/file_open.c
libavdevice/reverse.c
libavfilter/af_arnndn.c
libavfilter/file_open.c
libavfilter/log2_tab.c
libavformat/file_open.c
libavformat/golomb_tab.c
Expand Down

0 comments on commit 4cdc14a

Please sign in to comment.