From a8706f3eb3a840a9048de54e67eadc2126bf7dac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20K=C3=B6lbl?=
Date: Tue, 28 Jun 2022 17:57:28 +0200
Subject: [PATCH] Move sphinxudf to cpp
C++ allows for reinterpret cast and avoids undefined behaviour because
of type punning. The project aims to provide cpp code anyways and the
ammended code should not change.
---
codeblocks/libsphinx.cbp | 2 +-
doc/sphinx.html | 8 ++++----
doc/sphinx.txt | 8 ++++----
doc/sphinx.xml | 8 ++++----
src/CMakeLists.txt | 2 +-
src/Makefile.am | 2 +-
src/Makefile.in | 2 +-
src/{sphinxudf.c => sphinxudf.cpp} | 4 ++--
win/libsphinx12.vcxproj | 2 +-
win/libsphinx13.vcxproj | 2 +-
10 files changed, 20 insertions(+), 20 deletions(-)
rename src/{sphinxudf.c => sphinxudf.cpp} (99%)
diff --git a/codeblocks/libsphinx.cbp b/codeblocks/libsphinx.cbp
index 2590f6b..eb5e53c 100644
--- a/codeblocks/libsphinx.cbp
+++ b/codeblocks/libsphinx.cbp
@@ -74,7 +74,7 @@
-
+
diff --git a/doc/sphinx.html b/doc/sphinx.html
index b56e445..bb30cdc 100644
--- a/doc/sphinx.html
+++ b/doc/sphinx.html
@@ -3665,12 +3665,12 @@ header file definitions of a few UDF related structures and types. For most
UDFs and plugins, a mere #include "sphinxudf.h", like in the example,
should be completely sufficient, too. However, if you're writing a ranking function and
need to access the ranking signals (factors) data from within the UDF, you will
-also need to compile and link with src/sphinxudf.c (also
+also need to compile and link with src/sphinxudf.cpp (also
available in our source code), because the implementations
of the fuctions that let you access the signal data from within the UDF reside
in that file.
-Both sphinxudf.h header and sphinxudf.c
+Both sphinxudf.h header and sphinxudf.cpp
are standalone. So you can copy around those files only; they do not depend
on any other bits of Sphinx source code.
@@ -3888,8 +3888,8 @@ Just as with UDFs, you want to include src/sphinxudf.hsrc/sphinxudf.c. However, as of 2.2.2-beta all
-the functions implemented in sphinxudf.c are about
+src/sphinxudf.cpp. However, as of 2.2.2-beta all
+the functions implemented in sphinxudf.cpp are about
unpacking the PACKEDFACTORS() blob, and no plugin types are exposed to that
kind of data. So currently, you would never need to link with the C-file,
just the header would be sufficient. (In fact, if you copy over the
diff --git a/doc/sphinx.txt b/doc/sphinx.txt
index ed994f9..b4a2b65 100644
--- a/doc/sphinx.txt
+++ b/doc/sphinx.txt
@@ -4280,11 +4280,11 @@ related structures and types. For most UDFs and plugins, a mere #include
"sphinxudf.h", like in the example, should be completely sufficient, too.
However, if you're writing a ranking function and need to access the
ranking signals (factors) data from within the UDF, you will also need to
-compile and link with src/sphinxudf.c (also available in our source code),
+compile and link with src/sphinxudf.cpp (also available in our source code),
because the implementations of the fuctions that let you access the signal
data from within the UDF reside in that file.
-Both sphinxudf.h header and sphinxudf.c are standalone. So you can copy
+Both sphinxudf.h header and sphinxudf.cpp are standalone. So you can copy
around those files only; they do not depend on any other bits of Sphinx
source code.
@@ -4490,8 +4490,8 @@ and plugin; that is up to you.
Just as with UDFs, you want to include src/sphinxudf.h header file. At the
very least, you will need the SPH_UDF_VERSION constant to implement
a proper version function. Depending on the specific plugin type, you might
-or might not need to link your plugin with src/sphinxudf.c. However, as of
-2.2.2-beta all the functions implemented in sphinxudf.c are about unpacking
+or might not need to link your plugin with src/sphinxudf.cpp. However, as of
+2.2.2-beta all the functions implemented in sphinxudf.cpp are about unpacking
the PACKEDFACTORS() blob, and no plugin types are exposed to that kind of
data. So currently, you would never need to link with the C-file, just the
header would be sufficient. (In fact, if you copy over the UDF version
diff --git a/doc/sphinx.xml b/doc/sphinx.xml
index bdfb125..d7f44b8 100644
--- a/doc/sphinx.xml
+++ b/doc/sphinx.xml
@@ -4094,13 +4094,13 @@ header file definitions of a few UDF related structures and types. For most
UDFs and plugins, a mere #include "sphinxudf.h", like in the example,
should be completely sufficient, too. However, if you're writing a ranking function and
need to access the ranking signals (factors) data from within the UDF, you will
-also need to compile and link with src/sphinxudf.c (also
+also need to compile and link with src/sphinxudf.cpp (also
available in our source code), because the implementations
of the fuctions that let you access the signal data from within the UDF reside
in that file.
-Both sphinxudf.h header and sphinxudf.c
+Both sphinxudf.h header and sphinxudf.cpp
are standalone. So you can copy around those files only; they do not depend
on any other bits of Sphinx source code.
@@ -4336,8 +4336,8 @@ Just as with UDFs, you want to include src/sphinxudf.h
header file. At the very least, you will need the SPH_UDF_VERSION
constant to implement a proper version function. Depending on the specific
plugin type, you might or might not need to link your plugin with
-src/sphinxudf.c. However, as of 2.2.2-beta all
-the functions implemented in sphinxudf.c are about
+src/sphinxudf.cpp. However, as of 2.2.2-beta all
+the functions implemented in sphinxudf.cpp are about
unpacking the PACKEDFACTORS() blob, and no plugin types are exposed to that
kind of data. So currently, you would never need to link with the C-file,
just the header would be sufficient. (In fact, if you copy over the
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 469e47b..1c99e02 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,7 +8,7 @@ set (LIBSPHINX_SRCS sphinx.cpp sphinxexcerpt.cpp
sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp
sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp
sphinxaot.cpp sphinxplugin.cpp
- sphinxudf.c)
+ sphinxudf.cpp)
set (INDEXER_SRCS indexer.cpp)
set (INDEXTOOL_SRCS indextool.cpp)
set (SEARCHD_SRCS searchd.cpp)
diff --git a/src/Makefile.am b/src/Makefile.am
index 048a112..b5f56b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
SRC_SPHINX = sphinx.cpp sphinxexcerpt.cpp sphinxquery.cpp \
sphinxsoundex.cpp sphinxmetaphone.cpp sphinxstemen.cpp sphinxstemru.cpp sphinxstemcz.cpp sphinxstemar.cpp \
sphinxutils.cpp sphinxstd.cpp sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp \
- sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.c sphinxaot.cpp sphinxplugin.cpp
+ sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.cpp sphinxaot.cpp sphinxplugin.cpp
noinst_LIBRARIES = libsphinx.a
libsphinx_a_SOURCES = $(SRC_SPHINX)
diff --git a/src/Makefile.in b/src/Makefile.in
index d6fd90b..84d956c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -222,7 +222,7 @@ top_srcdir = @top_srcdir@
SRC_SPHINX = sphinx.cpp sphinxexcerpt.cpp sphinxquery.cpp \
sphinxsoundex.cpp sphinxmetaphone.cpp sphinxstemen.cpp sphinxstemru.cpp sphinxstemcz.cpp sphinxstemar.cpp \
sphinxutils.cpp sphinxstd.cpp sphinxsort.cpp sphinxexpr.cpp sphinxfilter.cpp \
- sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.c sphinxaot.cpp sphinxplugin.cpp
+ sphinxsearch.cpp sphinxrt.cpp sphinxjson.cpp sphinxudf.cpp sphinxaot.cpp sphinxplugin.cpp
noinst_LIBRARIES = libsphinx.a
libsphinx_a_SOURCES = $(SRC_SPHINX)
diff --git a/src/sphinxudf.c b/src/sphinxudf.cpp
similarity index 99%
rename from src/sphinxudf.c
rename to src/sphinxudf.cpp
index e831910..6c2f838 100644
--- a/src/sphinxudf.c
+++ b/src/sphinxudf.cpp
@@ -302,14 +302,14 @@ int sphinx_get_term_factor_int ( const unsigned int * in, enum sphinx_term_facto
float sphinx_get_field_factor_float ( const unsigned int * in, enum sphinx_field_factor f )
{
int r = sphinx_get_field_factor_int ( in, f );
- return *(float*)&r;
+ return *reinterpret_cast(&r);
}
float sphinx_get_term_factor_float ( const unsigned int * in, enum sphinx_term_factor f )
{
int r = sphinx_get_term_factor_int ( in, f );
- return *(float*)&r;
+ return *reinterpret_cast(&r);
}
//
diff --git a/win/libsphinx12.vcxproj b/win/libsphinx12.vcxproj
index ec54f3e..621b024 100644
--- a/win/libsphinx12.vcxproj
+++ b/win/libsphinx12.vcxproj
@@ -155,7 +155,7 @@
-
+
diff --git a/win/libsphinx13.vcxproj b/win/libsphinx13.vcxproj
index cc2a5d4..0fcbb33 100644
--- a/win/libsphinx13.vcxproj
+++ b/win/libsphinx13.vcxproj
@@ -177,7 +177,7 @@
-
+
--
2.35.1