New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prevent double-precision externals from crashing a single-precision Pd (and vice versa) #300
Conversation
…ize (longs are size 4 on 64-bit Windows rather than 8)
class_new() might not be able to create a new class and thus return NULL. in theory externals should check whether class_new()!=NULL, but probably none do so...
… prints an error otherwise
…orrect variant this also requires a forward declaration of new_anything
maybe an external wants to see both class_new and class_new64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first commit (by @lukexi) is slightly unrelated to double precision, but since double is also a lot about "64bit" I included it :-)
up to date with today's (0.49-0test0) |
I think this can be done better by having 64-bit-float versions of Pd call xxx_setup64(). That way, |
the proposed way does allow single binaries to have both 32 and 64 bit code, as the external might still call it also caters for libraries that do not use the and you also need to cater for hexmangled finally, it requires code-changes for each and every library to support double-precision builds. |
however, there is one drawback in my proposal: an external that is compiled for double-precision (either as "only double-precision" or "single + double-precision") will not be loadable by a legacy Pd. |
pure-data/pure-data#300 has been accepted...
… to load a single-precision external, or vice versa this was somehow stripped from my original PR. this commit is a new (and I hope somewhat simpler attempt) to solve the issue Related: #300
this implements a simple, API-compatible mechanism to prevent double-precision externals from being loaded into a single-precision Pd and vice versa, as proposed on the mailnglist and mentioned in #299
how it works
PD_FLOATTYPE==32
) externals useclass_new()
to register new classesPD_FLOATTYPE==64
) externals useclass_new64()
to register new classesif an external uses the wrong variant of
class_new
(e.g.class_new64()
on a single-precision Pd host) will yield an error message and the class will not be registered (withclass_new
returningNULL
).API compatibility is kept by using a pre-processor define, so externals keep using
class_new
in their code, but it gets magically replaced withclass_new64
, ifPD_FLOATTYPE==64
.ABI (binary) compatibility is retained for single-precision externals (since we still use
class_new()
), but not for double-precision externals.this also adds some NULL-pointer checks to functions with a
t_class*
argument, since practically all externals do not check whetherclass_new
returns NULL.