Changeset 21202

Show
Ignore:
Timestamp:
07/04/08 02:15:06 (3 months ago)
Author:
ruoso
Message:

[smop] yet more work on the p6opaque implementation... Some nasty bug is causing a deadlock (yes... I know the reasons for locks to exist is to cause dead-locks, but that is what I got so far)

Location:
v6/smop
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • v6/smop/src/native_capture.c

    r21182 r21202  
    308308      if (res) { 
    309309        SMOP__Object* ret = res->value; 
     310        smop_lowlevel_unlock(capture); 
    310311        if (ret) { 
    311           smop_lowlevel_unlock(capture); 
    312312          return SMOP_REFERENCE(interpreter,ret); 
    313313        } else { 
  • v6/smop/src/p6opaque.sm0p

    r21201 r21202  
    113113 
    114114      if (invocant == SMOP__p6opaque__RI) { 
    115         fprintf(stderr, "[SMOP p6opaque] TODO: p6opaque RI's meta undefined yet\n"); 
    116115        ret = SMOP__NATIVE__bool_false; 
    117116      } else if (SMOP_RI(invocant) != (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { 
     
    119118        ret = SMOP__NATIVE__bool_false; 
    120119      } else { 
    121         if (set) 
     120 
     121        if (set) { 
    122122          smop_lowlevel_wrlock(invocant); 
    123         else 
     123        } else { 
    124124          smop_lowlevel_rdlock(invocant); 
     125        } 
    125126 
    126127        if (((SMOP__p6opaque_struct*)invocant)->metadata) { 
    127128          // we have our own metadata. 
    128           SMOP__Object* old = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 
    129           ret = old; 
     129          SMOP__Object* old = NULL; 
    130130          if (set) { 
     131            old = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 
    131132            ((SMOP__p6opaque_struct*)invocant)->metadata->how = set; 
    132             ret = set; 
    133133          } 
     134          ret = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 
    134135          smop_lowlevel_unlock(invocant); 
     136 
    135137          if (old) SMOP_RELEASE(interpreter, old); 
     138          SMOP_REFERENCE(interpreter, ret); 
    136139 
    137140        } else if (((SMOP__p6opaque_struct*)invocant)->instanceof) { 
     
    143146          if (set) { 
    144147            fprintf(stderr, "[SMOP p6opaque] Can't set how on a instance\n"); 
    145             SMOP_RELEASE(interpreter,set); 
    146148          } else { 
    147149 
     
    173175          ret = SMOP_REFERENCE(interpreter, set); 
    174176        } else { 
     177          smop_lowlevel_unlock(invocant); 
    175178          fprintf(stderr,"[SMOP p6opaque] TODO: invalid .^!how call\n"); 
     179          ret = SMOP__NATIVE__bool_false; 
    176180        } 
    177181      } 
     
    183187      ret = SMOP__NATIVE__bool_false; 
    184188    } 
     189 
     190  } else if (identifier == SMOP__ID__REPR_DESTROY) { 
     191 
     192    if (SMOP_RI(capture) == (SMOP__ResponderInterface*)SMOP__NATIVE__capture) { 
     193      SMOP__Object* invocant = SMOP__NATIVE__capture_invocant(interpreter,capture); 
     194 
     195      if (invocant == SMOP__p6opaque__RI) { 
     196        ret = SMOP__NATIVE__bool_false; 
     197      } else if (SMOP_RI(invocant) != (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { 
     198        fprintf(stderr, "[SMOP p6opaque] call to repr method with non p6opaque invocant\n"); 
     199        ret = SMOP__NATIVE__bool_false; 
     200      } else { 
     201        smop_lowlevel_wrlock(invocant); 
     202        SMOP__p6opaque_LOWL_metadata* m = ((SMOP__p6opaque_struct*)invocant)->metadata; 
     203        ((SMOP__p6opaque_struct*)invocant)->metadata = NULL; 
     204        smop_lowlevel_unlock(invocant); 
     205        SMOP_RELEASE(interpreter,m->how); 
     206        free(m); 
     207      } 
     208 
     209      SMOP_RELEASE(interpreter,invocant); 
     210    } else { 
     211      fprintf(stderr, "[SMOP p6opaque] TODO: non-native captures\n"); 
     212    } 
     213  } else if (identifier == SMOP__ID__DESTROYALL) { 
     214 
     215    ret = SMOP__NATIVE__bool_true; 
     216    SMOP__Object* frame; 
     217    SMOP__Object* continuation = SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
     218                                               SMOP__ID__continuation,  
     219                                               SMOP_REFERENCE(interpreter,interpreter)); 
     220 
     221    if (SMOP_RI(capture) == (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { 
     222      SMOP__Object* invocant = capture; 
     223      $frame = q:sm0p { 
     224        $capture; 
     225        $identifier; 
     226        $invocant; 
     227        $invocant.SMOP__ID__REPR_how(); 
     228        SMOP__SLIME__CurrentFrame.copy(1); 
     229        SMOP__SLIME__CurrentFrame.move_responder(2,2); 
     230        SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(2,(4,5,6),(),1)); 
     231        SMOP__NATIVE__bool_true.SMOP__ID__dispatch(); 
     232        $invocant.SMOP__ID__REPR_DESTROY(); 
     233        $interpreter.goto(|$continuation); 
     234      }; 
     235    } else { 
     236      $frame = q:sm0p { 
     237        $capture; 
     238        $identifier; 
     239        $capture.SMOP__ID__invocant(); 
     240        $capture.SMOP__ID__invocant(); 
     241        SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 
     242        SMOP__p6opaque__RI.SMOP__ID__REPR_how(); 
     243        SMOP__SLIME__CurrentFrame.copy(1); 
     244        SMOP__SLIME__CurrentFrame.move_responder(2,2); 
     245        SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(2,(6,7,8),(),1)); 
     246        SMOP__NATIVE__bool_true.SMOP__ID__dispatch(); 
     247        $capture.SMOP__ID__invocant(); 
     248        SMOP__SLIME__CurrentFrame.move_responder(1,3); 
     249        $capture.SMOP__ID__invocant(); 
     250        SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 
     251        SMOP__p6opaque__RI.SMOP__ID__REPR_DESTROY(); 
     252        $interpreter.goto(|$continuation); 
     253      }; 
     254    } 
     255 
     256    SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
     257                  SMOP__ID__goto, 
     258                  frame); 
     259 
    185260  } else { 
    186261    // as we want to support different captures, we'll start to use a 
     
    196271      $identifier; 
    197272      $capture.SMOP__ID__invocant(); 
    198       SMOP__SLIME__CurrentFrame.copy(1); 
     273      $capture.SMOP__ID__invocant(); 
    199274      SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 
    200275      SMOP__p6opaque__RI.SMOP__ID__REPR_how(); 
  • v6/smop/src/smop_s1p_scalar.c

    r20111 r21202  
    2929 
    3030SMOP__Object* SMOP__S1P__Scalar_STORE(SMOP__Object* object, SMOP__Object* val) { 
    31   smop_lowlevel_rdlock(object); 
     31  smop_lowlevel_wrlock(object); 
    3232  SMOP__Object* old = ((SMOP__S1P__Scalar_struct*)object)->cell; 
    3333  ((SMOP__S1P__Scalar_struct*)object)->cell = val; 
     
    5454    SMOP_RELEASE(interpreter,scalar); 
    5555    SMOP_RELEASE(interpreter,capture); 
     56 
    5657  } else if (SMOP__ID__DESTROYALL == identifier) { 
    5758    SMOP__S1P__Scalar_struct* s = (SMOP__S1P__Scalar_struct*)capture; 
     
    6263 
    6364    SMOP_RELEASE(interpreter,cell); 
     65 
    6466  } else { 
    6567    fprintf(stderr,"Unknown identifier in lowlevel method object invocation.\n"); 
    6668    SMOP_RELEASE(interpreter,capture); 
     69     
    6770  } 
    6871  return SMOP__NATIVE__bool_false; 
  • v6/smop/src/smop_slime_frame.c

    r21201 r21202  
    7979        ret = SMOP__NATIVE__bool_true; 
    8080      } else { 
     81        smop_lowlevel_unlock(frame); 
    8182        ret = SMOP__NATIVE__bool_false; 
    8283      } 
     
    200201        ret = SMOP__NATIVE__bool_true; 
    201202      } else { 
     203        smop_lowlevel_unlock(frame); 
    202204        ret = SMOP__NATIVE__bool_false; 
    203205      } 
  • v6/smop/test/12_p6opaque.sm0p

    r21201 r21202  
    44#include <smop_slime.h> 
    55#include <smop_oo.h> 
     6#include <smop_lowlevel.h> 
     7 
     8static SMOP__Object* test_message(SMOP__Object* interpreter, 
     9                                  SMOP__ResponderInterface* responder, 
     10                                  SMOP__Object* identifier, 
     11                                  SMOP__Object* capture) { 
     12  if (identifier == SMOP__ID__dispatch) { 
     13    printf("ok 3 - called dispatch\n"); 
     14    SMOP_RELEASE(interpreter, capture); 
     15  } else if (identifier == SMOP__ID__DESTROYALL) { 
     16    printf("ok 4 - called DESTROYALL\n"); 
     17  } else { 
     18    printf("not ok - unkown method\n"); 
     19    SMOP_RELEASE(interpreter, capture); 
     20  } 
     21  return SMOP__NATIVE__bool_true; 
     22} 
     23 
     24extern SMOP__Object* test_release(SMOP__Object* interpreter,  
     25                                  SMOP__ResponderInterface* responder, 
     26                                  SMOP__Object* obj) { 
     27  printf("-"); 
     28  smop_lowlevel_refcnt_dec(interpreter, responder, obj); 
     29  return obj; 
     30} 
     31 
     32extern SMOP__Object* test_reference(SMOP__Object* interpreter,  
     33                                    SMOP__ResponderInterface* responder, 
     34                                    SMOP__Object* obj) { 
     35  printf("+"); 
     36  smop_lowlevel_refcnt_inc(interpreter, responder, obj); 
     37  return obj; 
     38} 
    639 
    740int main() { 
    841  smop_init(); 
    942 
    10   printf("1..4\n"); 
     43  printf("1..6\n"); 
    1144 
    1245 
     
    1649                                                                         SMOP__INTPTR__InterpreterInstance,NULL,NULL)); 
    1750  SMOP__Object* frame; 
    18   SMOP__Object* how = SMOP__NATIVE__bool_true; 
     51  SMOP__Object* how = smop_lowlevel_alloc(sizeof(SMOP__ResponderInterface)); 
     52  ((SMOP__ResponderInterface*)how)->MESSAGE = &test_message; 
     53  ((SMOP__ResponderInterface*)how)->REFERENCE = &test_reference; 
     54  ((SMOP__ResponderInterface*)how)->RELEASE = &test_release; 
     55  ((SMOP__ResponderInterface*)how)->id = "test metaclass"; 
     56 
    1957  SMOP__Object* p6opaque =  
    2058    SMOP_DISPATCH(SMOP__INTPTR__InterpreterInstance, SMOP__p6opaque__RI, 
     
    2462  $frame = q:sm0p { 
    2563    ; 
    26     $p6opaque.SMOP__ID__new(); 
     64    $p6opaque.SMOP__ID__REPR_how($how); 
     65    $p6opaque.SMOP__ID__STORE(); 
    2766  }; 
    28   //  SMOP__SLIME__CurrentFrame.move_responder(7,2); 
    29   //  SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(9,(),(),1)); 
    30   //  SMOP__p6opaque__RI.SMOP__ID__new(); 
    31   //}; 
    3267 
    3368  if (!frame) printf("not "); 
    3469  printf("ok 1 - frame created.\n"); 
    3570 
    36   SMOP_RELEASE(interpreter,p6opaque); 
    3771  SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
    3872                SMOP__ID__goto, 
     
    4175  printf("ok 2 - goto frame.\n"); 
    4276 
     77  SMOP_RELEASE(interpreter,p6opaque); 
    4378  SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
    4479                SMOP__ID__loop, SMOP__NATIVE__capture_create(interpreter, 
    4580                                                             SMOP_REFERENCE(interpreter,interpreter), 
    4681                                                             NULL, NULL)); 
    47   printf("ok 3 - interpreter loop.\n"); 
     82  printf("ok 5 - interpreter loop.\n"); 
    4883 
    4984 
    5085  SMOP_RELEASE(SMOP__INTPTR__InterpreterInstance,interpreter); 
    5186 
    52   printf("ok 4 - Scalar destroyed should free the p6opaque object also.\n"); 
     87  printf("ok 6 - Scalar destroyed should free the p6opaque object also.\n"); 
    5388 
    5489  smop_destr();