Changeset 876

Show
Ignore:
Timestamp:
06/27/07 03:03:57 (2 years ago)
Author:
lilo_booter
Message:

+ use_count clean up and (some) simplification (work in progress)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jahtools/jbatch/jstack.py

    r852 r876  
    9494                if op.input is None: 
    9595                        uri = op.uri 
    96                         if not self.objects.has_key( uri ): 
    97                                 self.objects[ uri ] = [ ] 
    98                         instances = self.objects[ uri ] 
     96                        if self.objects.has_key( uri ): 
     97                                instances = self.objects[ uri ] 
     98                        else: 
     99                                instances = [] 
    99100                        if len( instances ) > 0: 
    100101                                result = instances.pop( ) 
     102                                if result is not None: 
     103                                        result.use_count += 1 
    101104                        elif uri.find( "var:" ) == 0: 
    102105                                result = operands.input_operand( unicode( uri[ 4: ] ), op ) 
     
    107110                        elif uri.find( "filter:" ) == 0: 
    108111                                result = openmedialib.create_filter( str( uri[ 7: ] ) ) 
     112                                if result is not None: 
     113                                        result.use_count = 1 
    109114                        else: 
    110115                                # Special case for images 
     
    117122                                if result is None or result.get_frames( ) == 0: 
    118123                                        result = None 
     124                                else: 
     125                                        result.use_count = 1 
     126 
    119127                        if result is not None: 
    120128                                properties.update_prop( result, "rpn_uri", str( uri ) ) 
    121                                 result.use_count = 0 
    122129                        else: 
    123130                                result = operands.input_operand( unicode( uri ), op ) 
    124                                 result.use_count = 0 
    125131                else: 
    126132                        result = op.input 
     
    128134 
    129135        def deposit( self, input ): 
     136                if input is None or not hasattr( input, "use_count" ): 
     137                        return 
     138                uri = str( properties.retrieve_uri( input ) ) 
    130139                if input is not None and input.use_count == 0: 
    131140                        i = 0 
     
    135144                                i += 1 
    136145                        if input.reuse( ): 
    137                                 uri = properties.retrieve_uri( input ) 
     146                                uri = str( properties.retrieve_uri( input ) ) 
     147                                if not self.objects.has_key( uri ): 
     148                                        self.objects[ uri ] = [ ] 
    138149                                if input not in self.objects[ uri ]: 
    139150                                        properties.update_prop( input, "rpn_uri", str( uri ) ) 
    140151                                        self.objects[ uri ].append( input ) 
    141                 elif input is not None: 
    142                         input.use_count -= 1 
    143152 
    144153        def clear( self, **args ): 
     
    236245                if name.find( "var:" ) == 0: name = name[ 4: ] 
    237246                if name in self.locals[ -1 ].keys( ): 
     247                        if hasattr( self.locals[ -1 ][ name ], "use_count" ): self.locals[ -1 ][ name ].use_count -= 1 
    238248                        self.deposit( self.locals[ -1 ][ name ] ) 
    239249                self.locals[ -1 ][ name ] = value 
     250                if hasattr( value, "use_count" ): value.use_count += 1 
    240251 
    241252        def delete_frame( self ): 
     
    247258                op = self.pop( ) 
    248259                tos = self.pop( ) 
    249                 tos.use_count += 1 
    250260                self.assign_( op.uri, tos ) 
    251261 
     
    253263                op = self.pop( ) 
    254264                tos = self.pop( ) 
    255                 tos.use_count += 2 
     265                tos.use_count += 1 
    256266                self.push_input( tos ) 
    257267                self.assign_( op.uri, tos ) 
     
    418428 
    419429        def push_input( self, input, incref = True, **args ): 
    420                 if incref and hasattr( input, "use_count" ): input.use_count += 1 
     430                if hasattr( input, "use_count" ): input.use_count += 1 
    421431                id = properties.retrieve_uri( input ) 
    422432                self.stack.append( operands.operand( id, input ) ) 
     
    435445                                while slot > 0: 
    436446                                        slot -= 1 
    437                                         if result.fetch_slot( slot ) is not None: 
    438                                                 self.push_input( result.fetch_slot( slot ) ) 
    439                                         result.connect( self.pop( ), slot ) 
     447                                        if result.fetch_slot( slot ) is None: 
     448                                                result.connect( self.pop( ), slot ) 
    440449                                op.assign( result ) 
    441450                                properties.update_prop( result, "rpn_length", result.get_frames( ) ) 
    442451                                properties.update_prop( result, "rpn_props", [] + op.properties ) 
    443452                                result.register( op.callback ) 
     453                                if hasattr( result, "use_count" ): result.use_count -= 1 
    444454                        else: 
    445455                                result = operands.input_operand( op.uri, op )