[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing Pika-syle and JNI-style

Jim Blandy wrote:

In Pika:
- Forgetting an UNGCPRO corrupts the GC's data structures, and may
  fail only intermittently.  Irregular exits (return; goto; break;
  continue) require attention.  longjmp is even harder.
- Functions may only return Scheme values by reference; they may not
  provide them as their (syntactic) return values.  Instead of writing
  "f (g (x))", you must write:

    g (&frame.x, &frame.temp);
    f (&frame.temp, &frame.temp2);

  In other words, you must write your code as linear series of
  operations which work by side-effects.
- Since the API functions all expect pointers to t_scm_word values,
  this discourages people from passing them around directly, but it
  can still be done --- e.g. "frame.x = frame.y;" --- and doing so
  will usually work.  But doing so is a bug.
- Variable declarations are cluttered with enclosing structs and GCPRO
  / UNGCPRO calls.

This of course cries out for a C++ interface which can alleviate
these problems:

class ScmVal
  void *ref;
  ~ScmVal() { UNGCPRO(ref); }
  ... copy constructor etc ...;

Then f(g(x)) becomes:
ScmVal g (ScmVal x) { ... }
	--Per Bothner
per@xxxxxxxxxxx   http://per.bothner.com/