Passing DIB image as const void *

Bug #720782 reported by Dmitry Katsubo on 2011-02-17
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cuneiform for Linux
Undecided
Unassigned

Bug Description

If Cumeiform does not modify the DIB image data internally (and I hope it does not) it is nice to have the API reflecting this:
void * --> const void *
The applied patch demonstrates the fix.
Additional note:
CIMAGE_WriteDIB() treats DIB data as Handle datatype, which is not logical in my view. It should be "const void *" and not "Handle".

Dmitry Katsubo (dma-k) wrote :
Jussi Pakkanen (jpakkane) wrote :

This is a good change, but unfortunately changing constness breaks ABI afaik. Furthermore casting away the constness is very, very bad. A proper fix would change all functions dealing with the DIB so that the compiler can enforce the DIB's immutability.

The reason for the Handles is that Cuneiform was for a very long time a Windows app, and Windows developers have a weird fetish for casting things to and from Handles even when it makes absolutely no sense whatsoever.

Dmitry Katsubo (dma-k) wrote :

So, what would be your recommendation: go deeper into CIMAGE_WriteDIB() and kill Handles as well, or give up this idea?

Jussi Pakkanen (jpakkane) wrote :

Constifying is a very good thing, and something I would very much like to see done.

A question for people who have knowledge in C ABI: is it possible to have something like these:

void func(someStruct *foo)
void func(const someStruct *foo)

in the same dynamic library without clashes?

If yes, then the change can be made without breaking ABI by adding the const function and making the non-const call the const one.

On 22 February 2011 08:27, JussiP <email address hidden> wrote:
> Constifying is a very good thing, and something I would very much like
> to see done.
>
> A question for people who have knowledge in C ABI: is it possible to
> have something like these:
>
> void func(someStruct *foo)
> void func(const someStruct *foo)
>
> in the same dynamic library without clashes?
>

You can't have same function exported twice with different signature in C.
And change from one to another breaks API.

You can version your symbols (provide a symbols file) and add a new
function e.g.

 void func_ng(const someStruct *foo)

marked for the new api version (NB! no soname api/abi bump)

That way old binaries will still work with a new library. And new
software can use the new function.

> If yes, then the change can be made without breaking ABI by adding the
> const function and making the non-const call the const one.
>
> --
> You received this bug notification because you are a member of Cuneiform
> Linux, which is the registrant for Cuneiform for Linux.
> https://bugs.launchpad.net/bugs/720782
>
> Title:
>  Passing DIB image as const void *
>

Jakub Wilk (jwilk) wrote :

As far as I can tell, adding const to a function parameter doesn't break ABI. (Removing const, however, would break it.)

Dimitri John Ledkov 🌈 (xnox) wrote :

On 22 February 2011 20:28, Jakub Wilk <email address hidden> wrote:
> As far as I can tell, adding const to a function parameter doesn't break
> ABI. (Removing const, however, would break it.)
>

True. I've learning something new today about C.

See http://stackoverflow.com/q/5083765/259144 for explanation why
Jakub is right ;-)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers