RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm-5_3: rpm/rpmio/ xruby.c

From: Jeff Johnson <jbj@rpm5.org>
Date: Mon 20 Sep 2010 - 19:49:29 CEST
Message-Id: <20100920174929.BF82DD41A6@rpm5.org>
  RPM Package Manager, CVS Repository
  /cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   20-Sep-2010 19:49:29
  Branch: rpm-5_3                          Handle: 2010092017492900

  Modified files:           (Branch: rpm-5_3)
    rpm/rpmio               xruby.c

  Log:
    - ruby: haul out the trash.

  Summary:
    Revision    Changes     Path
    1.1.2.6     +35 -51     rpm/rpmio/xruby.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/xruby.c
  ============================================================================
  $ cvs diff -u -r1.1.2.5 -r1.1.2.6 xruby.c
  --- rpm/rpmio/xruby.c	20 Sep 2010 16:29:12 -0000	1.1.2.5
  +++ rpm/rpmio/xruby.c	20 Sep 2010 17:49:29 -0000	1.1.2.6
  @@ -2,10 +2,6 @@
   
   #include "system.h"
   
  -#include <pthread.h>
  -
  -#include <argv.h>
  -
   #define	_RPMRUBY_INTERNAL
   #include <rpmruby.h>
   
  @@ -18,22 +14,9 @@
   
   #include "debug.h"
   
  -#define RUBYDBG(_l) if (_rpmruby_debug) fprintf _l
  -#define Trace(_x) do { rpmzLogAdd _x; } while (0)
  -
  -struct yarnThread_s {
  -    pthread_t id;
  -    int done;                   /* true if this thread has exited */
  -/*@dependent@*/ /*@null@*/
  -    yarnThread next;            /* for list of all launched threads */
  -};
  -
  -static struct rpmruby_s __ruby = {
  -	.nstack = (4 * 1024 * 1024)
  -};
  +static struct rpmruby_s __ruby;
   static rpmruby Xruby = &__ruby;
   
  -
   static VALUE relay_from_ruby_to_main(VALUE self)
   {
       return _rpmruby_ruby_to_main(Xruby, self);
  @@ -45,8 +28,6 @@
       VALUE result;
       rpmRC rc = RPMRC_FAIL;	/* assume failure */
   
  -RUBYDBG((stderr, "--> %s(%p,%s)\n", __FUNCTION__, ruby, fn));
  -
       result = rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)fn, &error);
       if (error) {
           fprintf(stderr, "rb_require('%s') failed with status=%d\n",
  @@ -68,7 +49,6 @@
   	rc = RPMRC_OK;
       }
   
  -RUBYDBG((stderr, "<-- %s(%p,%s) rc %d\n", __FUNCTION__, ruby, fn, rc));
       return rc;
   }
   
  @@ -78,8 +58,6 @@
       rpmzLog zlog = ruby->zlog;
       int i;
   
  -RUBYDBG((stderr, "--> %s(%p)\n", __FUNCTION__, _ruby));
  -
       Trace((zlog, "-- %s: running", __FUNCTION__));
   
       _rpmruby_ruby_to_main(ruby, Qnil);
  @@ -100,7 +78,7 @@
   
   	ruby_init_stack(&variable_in_this_stack_frame);
           ruby_init();
  -        ruby_init_loadpath();
  +	ruby_init_loadpath();
   
           /* allow Ruby script to relay */
           rb_define_module_function(rb_mKernel, "relay_from_ruby_to_main",
  @@ -123,16 +101,37 @@
   	Trace((zlog, "-- %s: interpreter terminated", __FUNCTION__));
       }
   
  +    /* Report interpreter end to main. */
       ruby->more = 0;
  -    _rpmruby_ruby_to_main(ruby, Qnil);
  -
  -    pthread_exit(NULL);
  +    /* Permit main thread to run without blocking. */
  +    yarnRelease(ruby->main_coroutine_lock);
   
       Trace((zlog, "-- %s: ended", __FUNCTION__));
  +    return NULL;
  +}
   
  -RUBYDBG((stderr, "<-- %s(%p)\n", __FUNCTION__, _ruby));
  +static int runOnce(rpmruby ruby)
  +{
  +    int ec = 0;
  +    yarnPossess(ruby->ruby_coroutine_lock);
  +    yarnPossess(ruby->main_coroutine_lock);
   
  -    return NULL;
  +    /* create a thread to house Ruby */
  +    ruby->thread = yarnLaunchStack((void (*)(void *))rpmrubyThread, ruby,
  +				ruby->stack, ruby->nstack);
  +assert(ruby->thread != NULL);
  +
  +    /* Relay control to ruby until nothing more to do. */
  +    ruby->more = (ruby->ac > 1);
  +    while (ruby->more)
  +        _rpmruby_main_to_ruby(ruby);
  +
  +    /* Permit ruby thread to run without blocking. */
  +    yarnRelease(ruby->ruby_coroutine_lock);
  +    /* Reap the ruby thread. */
  +    ruby->thread = yarnJoin(ruby->thread);
  +
  +    return ec;
   }
   
   #ifdef RUBY_GLOBAL_SETUP
  @@ -160,37 +159,22 @@
   
       /* initialize the relay mechanism */
       ruby->ruby_coroutine_lock = yarnNewLock(0);
  -    yarnPossess(ruby->ruby_coroutine_lock);
       ruby->main_coroutine_lock = yarnNewLock(0);
  -    yarnPossess(ruby->main_coroutine_lock);
   
  -    /* create a thread to house Ruby */
  -    ruby->thread = yarnLaunchStack((void (*)(void *))rpmrubyThread, ruby,
  -				ruby->stack, ruby->nstack);
  -assert(ruby->thread != NULL);
  +    ec = runOnce(ruby);
  +    if (ec) goto exit;
   
  -    /* relay control to Ruby until it is finished */
  -    ruby->more = (ruby->ac > 1);
  -    while (ruby->more)
  -        _rpmruby_main_to_ruby(ruby);
  -
  -    ec = 0;
  +#ifdef	NOWORKIE	/* XXX can't restart a ruby interpreter. */
  +    ec = runOnce(ruby);
  +    if (ec) goto exit;
  +#endif	/* NOWORKIE */
   
   exit:
       fprintf(stderr, "Main: Goodbye!\n");
  -ruby->zlog = rpmzLogDump(ruby->zlog, NULL);
   
  -#ifdef	NOTYET
  -    if (ruby->thread)
  -	ruby->thread = yarnJoin(ruby->thread);
  -#endif
  -ruby->thread = _free(ruby->thread);
  +ruby->zlog = rpmzLogDump(ruby->zlog, NULL);
   
  -#ifdef	NOTYET	/* XXX FIXME */
  -    yarnRelease(ruby->main_coroutine_lock);
  -#endif
       ruby->main_coroutine_lock = yarnFreeLock(ruby->main_coroutine_lock);
  -    yarnRelease(ruby->ruby_coroutine_lock);
       ruby->ruby_coroutine_lock = yarnFreeLock(ruby->ruby_coroutine_lock);
   
   ruby->av = argvFree(ruby->av);
  @@ .
Received on Mon Sep 20 19:49:29 2010
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.