Skip to content

Replace DATA_PTR and Data_Get_Struct by SWIG_ConvertPtr#86

Merged
larskanis merged 4 commits into1.6from
ConvertPtr
Mar 27, 2026
Merged

Replace DATA_PTR and Data_Get_Struct by SWIG_ConvertPtr#86
larskanis merged 4 commits into1.6from
ConvertPtr

Conversation

@larskanis
Copy link
Copy Markdown
Owner

@larskanis larskanis commented Mar 14, 2026

Mixing ruby functions and SWIG functions to access Ruby/C++ objects is bad practice. It relies on a particular expectation of how SWIG maps C++ objects to Ruby objects.

This commit changes the code to use SWIG functions only and to not use raw Ruby functions to access SWIG mapped objects.

Also change the flag of ConvertPtr to the SWIG provided constant SWIG_POINTER_DISOWN, to make it more clear, that the object will be deleted by the object it was assigned to.

The compiler deprecation warning is re-enabled, since they do no longer appear when built with SWIG with the following patch:
swig/swig#3326

Fix type conversions of Array<FXPoint>, Array<FXRectangle>, Array<FXSegment> and Array<FXArc> to raise an error on type mismatch. This wasn't checked before and could lead to invalid memory access.

Mixing ruby functions and SWIG functions to access Ruby/C++ objects is bad practice.
It relies on a particular expectation of how SWIG maps C++ objects to Ruby objects.

This commit changes the code to use SWIG functions only and to not use raw Ruby functions to access SWIG mapped objects.

Also change the flag of ConvertPtr to the SWIG provided constant SWIG_POINTER_DISOWN, to make it more clear, that the object will be deleted by the object it was assigned to.

The compiler deprecation warning is re-enabled, since they do no longer appear when built with SWIG with the following patch:
  swig/swig#3326

Fix type conversions of Array<FXPoint>, Array<FXRectangle>, Array<FXSegment> and Array<FXArc> to raise an error on type mismatch.
This wasn't checked before and could lead to invalid memory access.
larskanis and others added 3 commits March 21, 2026 22:19
Because SWIG-ownership gets dropped when the Fox object is assigned to some other Fox object.
@larskanis larskanis merged commit ea3c203 into 1.6 Mar 27, 2026
30 checks passed
@larskanis larskanis deleted the ConvertPtr branch March 27, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant