Re: acquire

2000-01-16 Thread Erik Thiele

On Sat, Jan 15, 2000 at 04:40:07AM +0100, Andreas Beck wrote:
  i didn't do the correct code:
 if (ggiResourceMustAcquire(dbs[writeframe]-resource))
if (ggiResourceAcquire(dbs[writeframe]-resource,GGI_ACTYPE_WRITE)!=0)
  instead i did:
 if (ggiResourceMustAcquire(dbs[writeframe]))
if (ggiResourceAcquire(dbs[writeframe],GGI_ACTYPE_WRITE)!=0)
 
  but i do not like that this compiles WITHOUT warnings about
  type mismatchs !
  is everything in ggi a void* ?
 
 This is a valid point. We do that void * stuff on pupose to make sure users
 don't try to dereference stuff they shouldn't (bypassing the encapsulation
 rule and the access layers). However in cases like yours, it's in the way ... 
 Ideas ?

i never contributed to ggi, and do not really know about it's structure.
but if you ask me this question, i just think it is bad style.

in my eyes it is a very bad idea to do something in a void* just to
ensure nobody dereferences it.
i think it is enough to say "you mustn't dereference it, it is internal"
you not need to force users to this via void*

i think better style to write things as they really are.
not casting void* to something else internally, but just always using
the correct type.

- improves debugging (you really see the structure, not a nonsensical void
  pointer)
- the compiler won't compile stupid code anymore (type safety)
- eliminates casts from void* to something else in the internal
  ggi library.

for me the idea with the void* is very bad design.


and there is another point:
if you still want your hiding, you can do the following:

#ifdef __AM_INTERNAL_GGI_CODE #or WANT_REALITY_GGI_FOR_DEBUGGING
typedef struct {
  uint16 resource_id;
  uint8 is_locked;
  uint32 memory_address;
  uint16 page_number;
} ggi_resource_t;
#else
typedef struct {
  uint16 INTERNAL_DONT_USE_ME1;
  uint8 INTERNAL_DONT_USE_ME2;
  uint32 INTERNAL_DONT_USE_ME3;
  uint16 INTERNAL_DONT_USE_ME4;
} ggi_resource_t;
#endif

this way you would unite all the benefits of my idea and yours, i think.
because if a programmer really does  myres-INTERNAL_DONT_USE_ME2=34;
then he should be shot onto the moon anyway.

but that's just my 5 cents ;)

cu
erik


-- 
Name:  Erik Thiele   
Email: [EMAIL PROTECTED]o `QQ'_
IRC:   erikyyy/   __8
WWW:   http://www.erikyyy.de/ '  `



Re: acquire

2000-01-15 Thread Andreas Beck

 i didn't do the correct code:
if (ggiResourceMustAcquire(dbs[writeframe]-resource))
   if (ggiResourceAcquire(dbs[writeframe]-resource,GGI_ACTYPE_WRITE)!=0)
 instead i did:
if (ggiResourceMustAcquire(dbs[writeframe]))
   if (ggiResourceAcquire(dbs[writeframe],GGI_ACTYPE_WRITE)!=0)

 but i do not like that this compiles WITHOUT warnings about
 type mismatchs !
 is everything in ggi a void* ?

This is a valid point. We do that void * stuff on pupose to make sure users
don't try to dereference stuff they shouldn't (bypassing the encapsulation
rule and the access layers). However in cases like yours, it's in the way ... 
Ideas ?

CU, ANdy

-- 
= Andreas Beck|  Email :  [EMAIL PROTECTED] =



Re: acquire

2000-01-14 Thread Erik Thiele

On Thu, Jan 13, 2000 at 11:09:56PM +0100, Christian Reiniger wrote:
 Marcus Sundberg wrote:
 
  const ggi_directbuffer *dbuf;
  
  /* Acquire DirectBuffer before we use it. */
  if (ggiResourceAcquire(dbuf-resource, GGI_ACTYPE_WRITE) != 0) {
  fail("Error acquiring DirectBuffer\n");
  }
  
  
  this cannot work. if ggi_directbuffer is const, and
  ggiResourceAcquire wants a non-const ggi_resource_t my compiler
  kicks me.
 
 What compiler is that? Sounds like a broken compiler to me.
 dbuf-resource is a pointer, and the fact that dbuf is a const *
 shouldn't affect the type of dbuf-resource afaik.
 
 dbuf is a pointer to a const ggi_directbuffer, i.e. it is not allowed to
 modify the contents of the object *it points to*. That means it's illegal
 to change the value of dbuf-resource

ok. it was all my fault. i sum up my results:

i did check if there were directbuffers.
the reason why it segfaulted is instead this:

i didn't do the correct code:
   if (ggiResourceMustAcquire(dbs[writeframe]-resource))
  if (ggiResourceAcquire(dbs[writeframe]-resource,GGI_ACTYPE_WRITE)!=0)
instead i did:
   if (ggiResourceMustAcquire(dbs[writeframe]))
  if (ggiResourceAcquire(dbs[writeframe],GGI_ACTYPE_WRITE)!=0)

this was the reason the const thing didn't work.
ggi is const correct in this case. it was my fault.

but i do not like that this compiles WITHOUT warnings about
type mismatchs !
is everything in ggi a void* ?


cu
erik

-- 
Name:  Erik Thiele   
Email: [EMAIL PROTECTED]o `QQ'_
IRC:   erikyyy/   __8
WWW:   http://www.erikyyy.de/ '  `



Re: acquire

2000-01-13 Thread Marcus Sundberg

Erik Thiele [EMAIL PROTECTED] writes:

 ggiResourceMustAcquire is simply a macro that returns true if the
   resource must be explicitly acquired and released, or false if not.
   However, it is still safe to call
 ggiResourceAcquire or ggiResourceRelease even in the latter case --
   it would be a no-op.
 
 are you sure about this ?
 in my case -resource ==0
 
 (using 16bit Xserver with palemu target and GT_8BIT mode)
 
 i do resource acquire of my dbuf and it segfaults...

That's because you don't _have_ a dbuf. The palemu target doesn't
support DirectBuffers...
You probably forgot to check your return codes somewhere.

 const ggi_directbuffer *dbuf;
 
 /* Acquire DirectBuffer before we use it. */
 if (ggiResourceAcquire(dbuf-resource, GGI_ACTYPE_WRITE) != 0) {
 fail("Error acquiring DirectBuffer\n");
 }
 
 
 this cannot work. if ggi_directbuffer is const, and
 ggiResourceAcquire wants a non-const ggi_resource_t my compiler
 kicks me.

What compiler is that? Sounds like a broken compiler to me.
dbuf-resource is a pointer, and the fact that dbuf is a const *
shouldn't affect the type of dbuf-resource afaik.

//Marcus
-- 
---+
Marcus Sundberg| http://www.stacken.kth.se/~mackan
 Royal Institute of Technology |   Phone: +46 707 295404
   Stockholm, Sweden   |   E-Mail: [EMAIL PROTECTED]



Re: acquire

2000-01-13 Thread Christian Reiniger

Marcus Sundberg wrote:

 const ggi_directbuffer *dbuf;
 
 /* Acquire DirectBuffer before we use it. */
 if (ggiResourceAcquire(dbuf-resource, GGI_ACTYPE_WRITE) != 0) {
 fail("Error acquiring DirectBuffer\n");
 }
 
 
 this cannot work. if ggi_directbuffer is const, and
 ggiResourceAcquire wants a non-const ggi_resource_t my compiler
 kicks me.

What compiler is that? Sounds like a broken compiler to me.
dbuf-resource is a pointer, and the fact that dbuf is a const *
shouldn't affect the type of dbuf-resource afaik.

dbuf is a pointer to a const ggi_directbuffer, i.e. it is not allowed to
modify the contents of the object *it points to*. That means it's illegal
to change the value of dbuf-resource


Christian
-- 

Drive A: not responding...Formatting C: instead