View Issue Details

IDProjectCategoryView StatusLast Update
0017508ScribusBuild Systempublic2025-05-03 13:51
Reporterlandry Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version1.7.0 
Summary0017508: building on OpenBSD/i386/32-bits fails because "call to 'toPdf' is ambiguous"
Descriptioncf https://github.com/scribusproject/scribus/issues/196

the patch just ensures the right `toPdf` variant exists on OpenBSD:


-#if !defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)
+#if (!defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)) || defined(__OpenBSD__)
Additional Informationcurrently rebuilding with the attached patch, my initial patch dropped the #if and works on amd64 and i386
TagsNo tags attached.
PatchYes

Activities

landry

2025-04-28 06:44

reporter  

patch-scribus_pdfwriter_h (402 bytes)   
fix build on i386

https://github.com/scribusproject/scribus/issues/196

Index: scribus/pdfwriter.h
--- scribus/pdfwriter.h.orig
+++ scribus/pdfwriter.h
@@ -83,7 +83,7 @@ namespace Pdf
 	/**
 	 Cf. PDF32000-2008, 7.3.3
 	 */
-#if !defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)
+#if (!defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)) || defined(__OpenBSD__)
 	QByteArray toPdf(size_t v);
 #endif
 	
patch-scribus_pdfwriter_h (402 bytes)   

ale

2025-04-28 16:03

manager   ~0052482

are you sure that openbsd cannot be 64 bits?

landry

2025-04-29 06:39

reporter   ~0052484

OpenBSD/amd64 is 64 bits, OpenBSD/i386 is 32 bits.

The initial patch i tested/commited to our portstree in https://github.com/openbsd/ports/commit/abce6c2658f35d2049375a3b6543072997b18cdc is just removing completely the #if/#endif, so defining QByteArray toPdf(size_t v) in all cases, that fixed the build on OpenBSD/i386, and still built on OpenBSD/amd64.

and now that i've said that and relooked at my commit, i realize that the same change needs to be applied to scribus/pdfwriter.cpp and scribus/scxmlstreamwriter.h

jghali

2025-05-03 13:51

administrator   ~0052491

@landry, I think I have another solution based on C++ templates which remove the ifdefs for all platform. Could you try the attached patch and see if that works for you ?
17508_building_openbsd_fails.patch (4,813 bytes)   
Index: scribus/pdfwriter.cpp
===================================================================
--- scribus/pdfwriter.cpp	(révision 26852)
+++ scribus/pdfwriter.cpp	(copie de travail)
@@ -304,49 +304,11 @@
 		return result;
 	}
 	
-	QByteArray toPdf(bool v)
-	{
-		return v? "true" : "false";
-	}
-	
-	QByteArray toPdf(int v)
-	{
-		return QByteArray::number(v);
-	}
-	
-	QByteArray toPdf(uint v)
-	{
-		return QByteArray::number(v);
-	}
-	
-	QByteArray toPdf(qlonglong v)
-	{
-		return QByteArray::number(v);
-	}
-	
-	QByteArray toPdf(qulonglong v)
-	{
-		return QByteArray::number(v);
-	}
-
-#if !defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)
-	QByteArray toPdf(size_t v)
-	{
-		return QByteArray::number(v);
-	}
-#endif
-
-	QByteArray toPdf(double v)
-	{
-		return QByteArray::number(v, 'f');
-	}
-	
 	QByteArray toObjRef(PdfId id)
 	{
 		return toPdf(id) + " 0 R";
 	}
 	
-	
 	QByteArray toLiteralString(const QString& s)
 	{
 		return toLiteralString(toPdfDocEncoding(s));
Index: scribus/pdfwriter.h
===================================================================
--- scribus/pdfwriter.h	(révision 26852)
+++ scribus/pdfwriter.h	(copie de travail)
@@ -9,6 +9,8 @@
 #ifndef Scribus_pdfwriter_h
 #define Scribus_pdfwriter_h
 
+#include <type_traits>
+
 #include <QByteArray>
 #include <QDataStream>
 #include <QFile>
@@ -58,43 +60,33 @@
 	/**
 	 Cf. PDF32000-2008, 7.3.2
 	 */
-	QByteArray toPdf(bool v);
-	
-	/**
-	 Cf. PDF32000-2008, 7.3.3
-	 */
-	QByteArray toPdf(int v);
-	
-	/**
-	 Cf. PDF32000-2008, 7.3.3
-	 */
-	QByteArray toPdf(uint v);
+	template <typename T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>, bool> = true>
+	inline QByteArray toPdf(T v)
+	{
+		return QByteArray::number(v);
+	}
 
 	/**
 	 Cf. PDF32000-2008, 7.3.3
 	 */
-	QByteArray toPdf(qlonglong v);
+	template <typename T, std::enable_if_t< std::is_floating_point_v<T>, bool> = true>
+	inline QByteArray toPdf(T v)
+	{
+		return QByteArray::number(v, 'f');
+	}
 
 	/**
-	 Cf. PDF32000-2008, 7.3.3
+	 Cf. PDF32000-2008, 7.3.2
 	 */
-	QByteArray toPdf(qulonglong v);
+	template <>
+	inline QByteArray toPdf<bool>(bool v)
+	{
+		return v ? "true" : "false";
+	}
 	
 	/**
 	 Cf. PDF32000-2008, 7.3.3
 	 */
-#if !defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)
-	QByteArray toPdf(size_t v);
-#endif
-	
-	/**
-	 Cf. PDF32000-2008, 7.3.3
-	 */
-	QByteArray toPdf(double v);
-	
-	/**
-	 Cf. PDF32000-2008, 7.3.3
-	 */
 	QByteArray toObjRef(PdfId id);
 	
 	/**
Index: scribus/scxmlstreamwriter.h
===================================================================
--- scribus/scxmlstreamwriter.h	(révision 26852)
+++ scribus/scxmlstreamwriter.h	(copie de travail)
@@ -7,12 +7,15 @@
 #ifndef SCXMLSTREAMWRITER_H
 #define SCXMLSTREAMWRITER_H
 
-#include "scribusapi.h"
+#include <type_traits>
 
 #include <QByteArray>
 #include <QString>
 #include <QXmlStreamWriter>
 
+#include "pdfversion.h"
+#include "scribusapi.h"
+
 class SCRIBUS_API ScXmlStreamWriter : public QXmlStreamWriter
 {
 public:
@@ -21,15 +24,14 @@
 	ScXmlStreamWriter(QIODevice* device) : QXmlStreamWriter(device) {}
 	ScXmlStreamWriter(QString*   string) : QXmlStreamWriter(string) {}
 
-	void writeAttribute(const QString & name, const QString & value) { QXmlStreamWriter::writeAttribute(name, value); }
-	void writeAttribute(const QString & name, int value)    { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
-	void writeAttribute(const QString & name, qint64 value)    { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
-	void writeAttribute(const QString & name, uint value)   { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
-	void writeAttribute(const QString & name, quint64 value)   { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
-#if !defined(Q_OS_WIN) && (Q_PROCESSOR_WORDSIZE != 4)
-	void writeAttribute(const QString & name, size_t value)   { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
-#endif
-	void writeAttribute(const QString & name, double value) { QXmlStreamWriter::writeAttribute(name, QString::number(value, 'g', 15)); }
+	void writeAttribute(const QString& name, const QString& value) { QXmlStreamWriter::writeAttribute(name, value); }
+	void writeAttribute(const QString& name, const PDFVersion& value) { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
+
+	template<typename T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>, bool> = true>
+	void writeAttribute(const QString & name, T value)    { QXmlStreamWriter::writeAttribute(name, QString::number(value)); }
+
+	template<typename T, std::enable_if_t< std::is_floating_point_v<T>, bool> = true>
+	void writeAttribute(const QString & name, T value) { QXmlStreamWriter::writeAttribute(name, QString::number(value, 'g', 15)); }
 };
 
 #endif

Issue History

Date Modified Username Field Change
2025-04-28 06:44 landry New Issue
2025-04-28 06:44 landry File Added: patch-scribus_pdfwriter_h
2025-04-28 16:03 ale Note Added: 0052482
2025-04-29 06:39 landry Note Added: 0052484
2025-05-03 13:51 jghali Note Added: 0052491
2025-05-03 13:51 jghali File Added: 17508_building_openbsd_fails.patch