From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Remove const qualifier on a couple of pointed-to types
Date: Tue, 15 Jun 2021 06:20:52 -0400 [thread overview]
Message-ID: <20210615102052.GA3199@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 557 bytes --]
gnat_argv is defined as pointer to const memory in argv.c but declared
and accessed as pointer to mutable memory in rtinit.c, which breaks the
One Definition Rule in C++. Its initialization is also non-standard.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* argv.c: Add include of <stdlib.h> for the runtime.
(gnat_argv): Change type to char ** and initialize to NULL.
(gnat_envp): Likewise.
* argv-lynxos178-raven-cert.c: Add include of <stdlib.h>.
(gnat_argv): Change type to char ** and initialize to NULL.
(gnat_envp): Likewise.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1472 bytes --]
diff --git a/gcc/ada/argv-lynxos178-raven-cert.c b/gcc/ada/argv-lynxos178-raven-cert.c
--- a/gcc/ada/argv-lynxos178-raven-cert.c
+++ b/gcc/ada/argv-lynxos178-raven-cert.c
@@ -41,6 +41,7 @@
minimal support for Ada.Command_Line.Command_Name */
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
@@ -53,8 +54,8 @@ extern "C" {
the binder-generated file so they need to be defined here */
int gnat_argc = 0;
-const char **gnat_argv = (const char **) 0;
-const char **gnat_envp = (const char **) 0;
+char **gnat_argv = NULL;
+char **gnat_envp = NULL;
int
__gnat_len_arg (int arg_num)
diff --git a/gcc/ada/argv.c b/gcc/ada/argv.c
--- a/gcc/ada/argv.c
+++ b/gcc/ada/argv.c
@@ -44,6 +44,7 @@
#ifdef IN_RTS
#include "runtime.h"
+#include <stdlib.h>
#include <string.h>
#else
#include "config.h"
@@ -60,14 +61,13 @@ extern "C" {
envp of the main program is saved under gnat_envp. */
int gnat_argc = 0;
-const char **gnat_argv = (const char **) 0;
-const char **gnat_envp = (const char **) 0;
+char **gnat_argv = NULL;
+char **gnat_envp = NULL;
#if defined (_WIN32) && !defined (RTX)
/* Note that on Windows environment the environ point to a buffer that could
be reallocated if needed. It means that gnat_envp needs to be updated
before using gnat_envp to point to the right environment space */
-#include <stdlib.h>
/* for the environ variable definition */
#define gnat_envp (environ)
#endif
reply other threads:[~2021-06-15 10:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210615102052.GA3199@adacore.com \
--to=derodat@adacore.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).