Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'xs/src/xsinit.h')
-rw-r--r--xs/src/xsinit.h51
1 files changed, 37 insertions, 14 deletions
diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h
index 96c4b74d7..c9e363602 100644
--- a/xs/src/xsinit.h
+++ b/xs/src/xsinit.h
@@ -68,7 +68,16 @@ extern "C" {
#undef fputc
#undef fwrite
#undef fclose
+
+ // Breaks compilation with Eigen matrices embedded into Slic3r::Point.
+ #undef malloc
+ #undef realloc
+ #undef free
+ #undef select
#endif /* _MSC_VER */
+#undef Zero
+#undef Packet
+#undef _
}
#endif
@@ -80,13 +89,18 @@ extern "C" {
#include <Polygon.hpp>
#include <Polyline.hpp>
#include <TriangleMesh.hpp>
+#include <slic3r/AppController.hpp>
namespace Slic3r {
template<class T>
struct ClassTraits {
+ // Name of a Perl alias of a C++ class type, owned by Perl, reference counted.
static const char* name;
- static const char* name_ref;
+ // Name of a Perl alias of a C++ class type, owned by the C++ code.
+ // The references shall be enumerated at the end of XS.pm, where the desctructor is undefined with sub DESTROY {},
+ // so Perl will never delete the object instance.
+ static const char* name_ref;
};
// use this for typedefs for which the forward prototype
@@ -99,11 +113,16 @@ struct ClassTraits {
class cname; \
__REGISTER_CLASS(cname, perlname);
+// Return Perl alias to a C++ class name.
template<class T>
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
+// Return Perl alias to a C++ class name, suffixed with ::Ref.
+// Such a C++ class instance will not be destroyed by Perl, the instance destruction is left to the C++ code.
template<class T>
const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; }
+// Mark the Perl SV (Scalar Value) as owning a "blessed" pointer to an object reference.
+// Perl will never release the C++ instance.
template<class T>
SV* perl_to_SV_ref(T &t) {
SV* sv = newSV(0);
@@ -111,6 +130,8 @@ SV* perl_to_SV_ref(T &t) {
return sv;
}
+// Mark the Perl SV (Scalar Value) as owning a "blessed" pointer to an object instance.
+// Perl will own the C++ instance, therefore it will also release it.
template<class T>
SV* perl_to_SV_clone_ref(const T &t) {
SV* sv = newSV(0);
@@ -118,6 +139,8 @@ SV* perl_to_SV_clone_ref(const T &t) {
return sv;
}
+// Reference wrapper to provide a C++ instance to Perl while keeping Perl from destroying the instance.
+// The instance is created temporarily by XS.cpp just to provide Perl with a CLASS name and a object instance pointer.
template <class T>
class Ref {
T* val;
@@ -125,10 +148,15 @@ public:
Ref() : val(NULL) {}
Ref(T* t) : val(t) {}
Ref(const T* t) : val(const_cast<T*>(t)) {}
+ // Called by XS.cpp to convert the referenced object instance to a Perl SV, before it is blessed with the name
+ // returned by CLASS()
operator T*() const { return val; }
+ // Name to bless the Perl SV with. The name ends with a "::Ref" suffix to keep Perl from destroying the object instance.
static const char* CLASS() { return ClassTraits<T>::name_ref; }
};
-
+
+// Wrapper to clone a C++ object instance before passing it to Perl for ownership.
+// This wrapper instance is created temporarily by XS.cpp to provide Perl with a CLASS name and a object instance pointer.
template <class T>
class Clone {
T* val;
@@ -136,7 +164,11 @@ public:
Clone() : val(NULL) {}
Clone(T* t) : val(new T(*t)) {}
Clone(const T& t) : val(new T(t)) {}
+ // Called by XS.cpp to convert the cloned object instance to a Perl SV, before it is blessed with the name
+ // returned by CLASS()
operator T*() const { return val; }
+ // Name to bless the Perl SV with. If there is a destructor registered in the XSP file for this class, then Perl will
+ // call this destructor when the reference counter of this SV drops to zero.
static const char* CLASS() { return ClassTraits<T>::name; }
};
@@ -165,23 +197,14 @@ void from_SV_check(SV* poly_sv, Polyline* THIS);
SV* to_SV_pureperl(const Point* THIS);
void from_SV(SV* point_sv, Point* point);
void from_SV_check(SV* point_sv, Point* point);
-SV* to_SV_pureperl(const Pointf* point);
-bool from_SV(SV* point_sv, Pointf* point);
-bool from_SV_check(SV* point_sv, Pointf* point);
+SV* to_SV_pureperl(const Vec2d* point);
+bool from_SV(SV* point_sv, Vec2d* point);
+bool from_SV_check(SV* point_sv, Vec2d* point);
void from_SV_check(SV* surface_sv, Surface* THIS);
SV* to_SV(TriangleMesh* THIS);
}
-#ifdef SLIC3R_HAS_BROKEN_CROAK
-#undef croak
-#ifdef _MSC_VER
- #define croak(...) confess_at(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
-#else
- #define croak(...) confess_at(__FILE__, __LINE__, __func__, __VA_ARGS__)
-#endif
-#endif
-
// Defined in wxPerlIface.cpp
// Return a pointer to the associated wxWidgets object instance given by classname.
extern void* wxPli_sv_2_object( pTHX_ SV* scalar, const char* classname );