You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by pe...@apache.org on 2012/06/03 20:54:26 UTC

svn commit: r1345740 - /subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp

Author: peters
Date: Sun Jun  3 18:54:26 2012
New Revision: 1345740

URL: http://svn.apache.org/viewvc?rev=1345740&view=rev
Log:
Remove a cast that is both ugly, and apparently illegal in g++ 4.7.

* subversion/libsvn_auth_kwallet/kwallet.cpp
  (q_argc, q_argv): New.
  (kwallet_password_get, kwallet_password_set):
   Use q_argc and q_argv instead of trying to open-code them.

Modified:
    subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp

Modified: subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp?rev=1345740&r1=1345739&r2=1345740&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp (original)
+++ subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp Sun Jun  3 18:54:26 2012
@@ -60,6 +60,9 @@
 /* KWallet simple provider, puts passwords in KWallet                    */
 /*-----------------------------------------------------------------------*/
 
+static int q_argc = 1;
+static char q_argv0[] = "svn"; // Build non-const char * from string constant
+static char *q_argv[] = { q_argv0 };
 
 static const char *
 get_application_name(apr_hash_t *parameters,
@@ -212,12 +215,11 @@ kwallet_password_get(svn_boolean_t *done
   QCoreApplication *app;
   if (! qApp)
     {
-      int argc = 1;
-      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
+      int argc = q_argc;
+      app = new QCoreApplication(argc, q_argv);
     }
 
-  KCmdLineArgs::init(1,
-                     (char *[1]) {(char *) "svn"},
+  KCmdLineArgs::init(q_argc, q_argv,
                      get_application_name(parameters, pool),
                      "subversion",
                      ki18n(get_application_name(parameters, pool)),
@@ -289,12 +291,11 @@ kwallet_password_set(svn_boolean_t *done
   QCoreApplication *app;
   if (! qApp)
     {
-      int argc = 1;
-      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
+      int argc = q_argc;
+      app = new QCoreApplication(argc, q_argv);
     }
 
-  KCmdLineArgs::init(1,
-                     (char *[1]) {(char *) "svn"},
+  KCmdLineArgs::init(q_argc, q_argv,
                      get_application_name(parameters, pool),
                      "subversion",
                      ki18n(get_application_name(parameters, pool)),



Re: svn commit: r1345740 - /subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp

Posted by Greg Stein <gs...@gmail.com>.
On Jun 3, 2012 6:42 PM, "Peter Samuelson" <pe...@p12n.org> wrote:
>
>
> [Greg Stein]
> > > -      int argc = 1;
> > > -      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
> > > +      int argc = q_argc;
> > > +      app = new QCoreApplication(argc, q_argv);
> >
> > Why keep argc around? Just use q_argc.
>
> Because argc is passed by reference (int &argc) and I figured the only
> reason to do that is if you intend to modify it.

I f'ing hate C++ ... how freaking insane is it when you can't see the
difference between pass-by-value and pass-by-reference?! That you have to
double-check the signature of every call!

Ugh.

> But looking closer, this code is only ever called once, so fair enough.

Nah. Keep the code so the 1 doesn't get changed. You never really know
since you *are* in a library. Maybe more calls will arrive. I'd say, just
add a comment explaining above.

Thanks!

>
> Anyway, those two instances have a lot more duplicate code so I'll
> probably commit a followup soon to de-dupe it, and I'll remove the
> extra variable too.

*nod*

Cheers,
-g

Re: svn commit: r1345740 - /subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp

Posted by Peter Samuelson <pe...@p12n.org>.
[Greg Stein]
> > -      int argc = 1;
> > -      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
> > +      int argc = q_argc;
> > +      app = new QCoreApplication(argc, q_argv);
> 
> Why keep argc around? Just use q_argc.

Because argc is passed by reference (int &argc) and I figured the only
reason to do that is if you intend to modify it.

But looking closer, this code is only ever called once, so fair enough.

Anyway, those two instances have a lot more duplicate code so I'll
probably commit a followup soon to de-dupe it, and I'll remove the
extra variable too.

Re: svn commit: r1345740 - /subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp

Posted by Greg Stein <gs...@gmail.com>.
On Jun 3, 2012 2:54 PM, <pe...@apache.org> wrote:
>...
> +++ subversion/trunk/subversion/libsvn_auth_kwallet/kwallet.cpp Sun Jun
 3 18:54:26 2012
> @@ -60,6 +60,9 @@
>  /* KWallet simple provider, puts passwords in KWallet
 */
>
 /*-----------------------------------------------------------------------*/
>
> +static int q_argc = 1;
> +static char q_argv0[] = "svn"; // Build non-const char * from string
constant
> +static char *q_argv[] = { q_argv0 };
>
>  static const char *
>  get_application_name(apr_hash_t *parameters,
> @@ -212,12 +215,11 @@ kwallet_password_get(svn_boolean_t *done
>   QCoreApplication *app;
>   if (! qApp)
>     {
> -      int argc = 1;
> -      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
> +      int argc = q_argc;
> +      app = new QCoreApplication(argc, q_argv);

Why keep argc around? Just use q_argc.

>     }
>
> -  KCmdLineArgs::init(1,
> -                     (char *[1]) {(char *) "svn"},
> +  KCmdLineArgs::init(q_argc, q_argv,
>                      get_application_name(parameters, pool),
>                      "subversion",
>                      ki18n(get_application_name(parameters, pool)),
> @@ -289,12 +291,11 @@ kwallet_password_set(svn_boolean_t *done
>   QCoreApplication *app;
>   if (! qApp)
>     {
> -      int argc = 1;
> -      app = new QCoreApplication(argc, (char *[1]) {(char *) "svn"});
> +      int argc = q_argc;
> +      app = new QCoreApplication(argc, q_argv);

Likewise.

>     }
>
> -  KCmdLineArgs::init(1,
> -                     (char *[1]) {(char *) "svn"},
> +  KCmdLineArgs::init(q_argc, q_argv,
>                      get_application_name(parameters, pool),
>                      "subversion",
>                      ki18n(get_application_name(parameters, pool)),
>
>