| 1 | = RFC 7: Use VSILFILE for VSI*L Functions = |
| 2 | |
| 3 | Author: Eric Doenges[[BR]] |
| 4 | Contact: Eric.Doenges@gmx.net[[BR]] |
| 5 | Status: Proposed |
| 6 | |
| 7 | == Purpose == |
| 8 | |
| 9 | To change the API for the VSI*L family of functions to use a new data-type |
| 10 | VSILFILE instead of the current FILE. |
| 11 | |
| 12 | == Background, Rationale == |
| 13 | |
| 14 | Currently, GDAL offers two APIs to abstract file access functions (referred to |
| 15 | as VSI* and VSI*L in this document). Both APIs claim to operate on FILE |
| 16 | pointers; however, the VSI*L functions can only operate on FILE pointers |
| 17 | created by the VSIFOpenL function. This is because VSIFOpenL returns a pointer |
| 18 | to an internal C++ class typecast to a FILE pointer, not an actual FILE pointer. |
| 19 | This makes it impossible for the compiler to warn when the VSI* and VSI*L |
| 20 | functions are inappropriately mixed. |
| 21 | |
| 22 | == Proposed Fix == |
| 23 | |
| 24 | A new opaque data-type VSILFILE shall be declared. All VSI*L functions shall |
| 25 | be changed to use this new type instead of FILE. Additionally, any GDAL code |
| 26 | that uses the VSI*L functions must be changed to use this data-type as well. |
| 27 | |
| 28 | == Compatibility Issues, Transition timeline == |
| 29 | |
| 30 | In order to allow the compiler to detect inappropriate parameters passed to |
| 31 | any of the VSI*L functions, VSILFILE would have to be declared with the help |
| 32 | of an empty forward declaration, i.e. |
| 33 | {{{ |
| 34 | typedef struct VSILFILE VSILFILE |
| 35 | }}} |
| 36 | with the struct VSILFILE itself left undefined. However, this would break |
| 37 | source compatibility for any existing code using the VSI*L API. |
| 38 | |
| 39 | Therefore, VSILFILE* will be declared as a void pointer for now, and the change |
| 40 | to a distinct pointer type deferred to a future release of gdal that is not |
| 41 | constrained with backward compatibility issues. While this will not solve the |
| 42 | primary issue (no warnings/errors from the compiler), looking at the |
| 43 | declarations of the VSI*L functions will at least make it immediately clear |
| 44 | that these functions cannot be expected to work if passed a FILE pointer. |
| 45 | |