[fpc-devel] Access Violation withnested DLL'scompiledbyFPC(andsomemore info on bug #4538)

L505 fpc505 at z505.com
Fri Dec 16 12:06:26 CET 2005


> > In this case, it decrements 1 and increments 1, so we will always end up with a
very
> > simple, easy, solvable problem.
> >
> > 1 - 1 = 0
> > 1 - 1 = 0
>
> Nope, since the string was nil, it isn't decremented, so you end up with
> a refcount of 1

The string is 1, not nil
1 - 1 = 0 from your diagram indicates 1 is the starting refcount, not nil.

When I responded to your mail, I didn't just mean if the string was nil, or at 1. I
meant your diagram didn't seem to click in with me when any number was filled in the
blank. i.e. 1, 2, 3, 4, 5 or any number.

>From your diagram, I got this:

String refcount: 2
 Decrement(string)       (1 - 1 = 1)
 string -> 'some string'
 Increment(string)       (1 + 1 = 2)
We are at 2 again. What was the point of doing it at all?

Starting string refcount: 3
 Decrement(string)       (3 - 1 = 2)
 string -> 'some string'
 Increment(string)       (2 + 1 = 3)
We are at 3 again. What was the point of doing it at all?

Starting string refcount: 1
 Decrement(string)       (1 - 1 = 0)
 string -> 'some string'
 Increment(string)       (0 + 1 = 1)
We are at 1 again. What was the point of doing it at all?

I think we are just having issues communicating what is happening.

The way Jonas explained below makes sense to me, as we get something useful out of
the incrementing rather than ending up where we were in the first place. I'm still
running it through my head to really understand it on a deeper level with the DLL
situation, though - since that's what this thread is trying to solve in the end.

> s := t; (-> reference count of ansistring to which s points is
> decreased by 1 and freed if reference count became zero, the one to
> which t points is increased by 1)
> q := t; (-> reference count of ansistring to which q points is
> decreased by 1 and freed if reference count became zero, the one to
> which t points is again increased by 1)

Marc, I think where our communication broke down was that in your diagram it
appeared you were incrementing the same string, rather than a different one.. i.e. in
Jonas' example he explained it with two string variables - one being decremented, and
the other being incremented. Not the same one being incremented and decremented.

The other problem I see with Marc's diagram was that somehow you showed the string
being
decremented before anything even happened. Shouldn't it decrement after something
happens, such as in Jonas' example? i.e. it just looked magical to me, that
decrementing could happen ahead of time.





More information about the fpc-devel mailing list