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

Add "deprecated" warnings for uses of old C runtime function names #10675

Merged
merged 7 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ otherlibs/win32unix/stat.c typo.long-line
otherlibs/win32unix/symlink.c typo.long-line

runtime/sak.c typo.non-ascii
runtime/caml/compatibility.h typo.very-long-line

stdlib/hashbang typo.white-at-eol typo.missing-lf

Expand Down
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Working version
- #10549: Stack overflow detection and naked pointers checking for ARM64
(Xavier Leroy, review by Stephen Dolan)

* #10675: Emit deprecation warnings when old C runtime function names
are used. This will break C stub code that uses these old names and
treats warnings as errors. The workaround is to use the new names.
(Xavier Leroy and David Allsopp, review by Sébastien Hinderer and
Damien Doligez)

### Code generation and optimizations:

Expand Down
4 changes: 2 additions & 2 deletions runtime/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CAMLprim value caml_array_set_addr(value array, value index, value newval)
{
intnat idx = Long_val(index);
if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error();
Modify(&Field(array, idx), newval);
caml_modify(&Field(array, idx), newval);
return Val_unit;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ CAMLprim value caml_array_unsafe_get(value array, value index)
static value caml_array_unsafe_set_addr(value array, value index,value newval)
{
intnat idx = Long_val(index);
Modify(&Field(array, idx), newval);
caml_modify(&Field(array, idx), newval);
return Val_unit;
}

Expand Down
435 changes: 219 additions & 216 deletions runtime/caml/compatibility.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions runtime/caml/major_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct {

typedef struct {
void *block; /* address of the malloced block this chunk lives in */
asize_t alloc; /* in bytes, used for compaction */
asize_t allocated; /* in bytes, used for compaction */
asize_t size; /* in bytes */
char *next;
mark_entry redarken_first; /* first block in chunk to redarken */
Expand All @@ -40,7 +40,7 @@ typedef struct {

#define Chunk_head(c) (((heap_chunk_head *) (c)) - 1)
#define Chunk_size(c) Chunk_head(c)->size
#define Chunk_alloc(c) Chunk_head(c)->alloc
#define Chunk_alloc(c) Chunk_head(c)->allocated
#define Chunk_next(c) Chunk_head(c)->next
#define Chunk_block(c) Chunk_head(c)->block

Expand Down
4 changes: 3 additions & 1 deletion runtime/caml/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ extern void caml_alloc_small_dispatch (intnat wosize, int flags,

/* Deprecated alias for [caml_modify] */

#define Modify(fp,val) caml_modify((fp), (val))
#define Modify(fp,val) \
CAML_DEPRECATED("Modify", "caml_modify") \
caml_modify((fp), (val))

#endif /* CAML_INTERNALS */

Expand Down
44 changes: 38 additions & 6 deletions runtime/caml/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include <stdlib.h>
#include <stdarg.h>

/* Basic types and constants */

typedef size_t asize_t;
/* Deprecation warnings */

#if defined(__GNUC__) || defined(__clang__)
/* Supported since at least GCC 3.1 */
Expand All @@ -45,6 +43,34 @@ typedef size_t asize_t;
#define CAMLdeprecated_typedef(name, type) typedef type name
#endif

#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L || _MSC_VER >= 1925

#define CAML_STRINGIFY(x) #x
#ifdef _MSC_VER
#define CAML_MAKEWARNING1(x) CAML_STRINGIFY(message(x))
#else
#define CAML_MAKEWARNING1(x) CAML_STRINGIFY(GCC warning x)
#endif
#define CAML_MAKEWARNING2(y) CAML_MAKEWARNING1(#y)
#define CAML_PREPROWARNING(x) _Pragma(CAML_MAKEWARNING2(x))
#define CAML_DEPRECATED(name1,name2) \
CAML_PREPROWARNING(name1 is deprecated: use name2 instead)

#else

#define CAML_PREPROWARNING(msg)
#define CAML_DEPRECATED(name1,name2)

#endif

/* Basic types and constants */

typedef size_t asize_t;

#ifndef NULL
#define NULL 0
#endif

#ifdef CAML_INTERNALS
CAMLdeprecated_typedef(addr, char *);
#endif /* CAML_INTERNALS */
Expand Down Expand Up @@ -378,9 +404,15 @@ CAMLextern int caml_read_directory(char_os * dirname,
struct ext_table * contents);

/* Deprecated aliases */
#define caml_aligned_malloc caml_stat_alloc_aligned_noexc
#define caml_strdup caml_stat_strdup
#define caml_strconcat caml_stat_strconcat
#define caml_aligned_malloc \
CAML_DEPRECATED("caml_aligned_malloc", "caml_stat_alloc_aligned_noexc") \
caml_stat_alloc_aligned_noexc
#define caml_strdup \
CAML_DEPRECATED("caml_strdup", "caml_stat_strdup") \
caml_stat_strdup
#define caml_strconcat \
CAML_DEPRECATED("caml_strconcat", "caml_stat_strconcat") \
caml_stat_strconcat

#ifdef CAML_INTERNALS

Expand Down
16 changes: 0 additions & 16 deletions testsuite/tests/compatibility/main.ml

This file was deleted.

1 change: 0 additions & 1 deletion testsuite/tests/compatibility/main.reference

This file was deleted.

20 changes: 0 additions & 20 deletions testsuite/tests/compatibility/stub.c

This file was deleted.