Skip to content

Commit 7ab4ba0

Browse files
Reduce pre-processing of image.hpp
1 parent d618c1a commit 7ab4ba0

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

src/interface/image.i

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@ UNIQUE_PTR(Exiv2::Image);
6060
%thread Exiv2::ImageFactory::create;
6161
%thread Exiv2::ImageFactory::open;
6262

63-
// ImageFactory can open image from a buffer
64-
// (Signature changed in build_swig.py pre-processing.)
65-
INPUT_BUFFER_RO(const Exiv2::byte* data, long B)
66-
INPUT_BUFFER_RO(const Exiv2::byte* data, size_t B)
63+
// ImageFactory can open image or get type from a buffer
64+
INPUT_BUFFER_RO(const Exiv2::byte* data, long size)
65+
INPUT_BUFFER_RO(const Exiv2::byte* data, size_t size)
6766
// Keep reference to memoryview of buffer until it can be released
67+
%{
68+
#define KEEPREF_VIEW_ImageFactory_open
69+
#define KEEPREF_VIEW_ImageFactory_createIo
70+
%}
6871
%typemap(argout, fragment="private_data")
69-
(const Exiv2::byte* data, long B),
70-
(const Exiv2::byte* data, size_t B) %{
72+
(const Exiv2::byte* data, long size),
73+
(const Exiv2::byte* data, size_t size) %{
74+
#ifdef KEEPREF_VIEW_$symname
7175
private_store_set(resultobj, "using_view", _global_view);
76+
#endif
7277
%}
7378

7479
// Release memory buffer after writeMetadata, as it creates its own copy
7580
%typemap(ret, fragment="private_data") void writeMetadata %{
7681
private_store_del(self, "using_view");
7782
%}
7883

79-
// ImageFactory can get type from a buffer
80-
// (Signature changed in build_swig.py pre-processing.)
81-
INPUT_BUFFER_RO(const Exiv2::byte* data, long A)
82-
INPUT_BUFFER_RO(const Exiv2::byte* data, size_t A)
83-
8484
// Convert path encoding on Windows
8585
WINDOWS_PATH(const std::string& path)
8686

@@ -134,11 +134,11 @@ Create a MemIo subclass of BasicIo using the provided memory.
134134
"
135135
%extend Exiv2::ImageFactory {
136136
static Exiv2::BasicIo::SMART_PTR createIo(
137-
const Exiv2::byte* data, size_t B) {
137+
const Exiv2::byte* data, size_t size) {
138138
#if EXIV2_VERSION_HEX < 0x001c0000
139-
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, B));
139+
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, size));
140140
#else
141-
return std::make_unique<Exiv2::MemIo>(data, B);
141+
return std::make_unique<Exiv2::MemIo>(data, size);
142142
#endif
143143
}
144144
}

src/swig-0_27_7/image_wrap.cxx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,6 +4410,10 @@ namespace Exiv2 {
44104410
#endif // EXV_ENABLE_FILESYSTEM
44114411

44124412

4413+
#define KEEPREF_VIEW_ImageFactory_open
4414+
#define KEEPREF_VIEW_ImageFactory_createIo
4415+
4416+
44134417
static bool enableBMFF(bool enable) {
44144418
// deprecated since 2024-08-01
44154419
PyErr_WarnEx(PyExc_DeprecationWarning,
@@ -5034,9 +5038,9 @@ SWIG_AsVal_size_t (PyObject * obj, size_t *val)
50345038
return res;
50355039
}
50365040

5037-
SWIGINTERN Exiv2::BasicIo::AutoPtr Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *data,size_t B){
5041+
SWIGINTERN Exiv2::BasicIo::AutoPtr Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *data,size_t size){
50385042

5039-
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, B));
5043+
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, size));
50405044

50415045

50425046

@@ -6566,7 +6570,9 @@ SWIGINTERN PyObject *_wrap_ImageFactory_open__SWIG_1(PyObject *self, Py_ssize_t
65666570
resultobj = SWIG_NewPointerObj((&result)->release(), SWIGTYPE_p_Exiv2__Image, SWIG_POINTER_OWN | 0 );
65676571

65686572

6573+
#ifdef KEEPREF_VIEW_ImageFactory_open
65696574
private_store_set(resultobj, "using_view", _global_view);
6575+
#endif
65706576

65716577

65726578
Py_XDECREF(_global_view);
@@ -6835,6 +6841,11 @@ SWIGINTERN PyObject *_wrap_ImageFactory_getType__SWIG_1(PyObject *self, Py_ssize
68356841
SWIG_fail;
68366842
}
68376843

6844+
#ifdef KEEPREF_VIEW_ImageFactory_getType
6845+
private_store_set(resultobj, "using_view", _global_view);
6846+
#endif
6847+
6848+
68386849
Py_XDECREF(_global_view);
68396850

68406851
return resultobj;
@@ -7071,7 +7082,9 @@ SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_1(PyObject *self, Py_ssiz
70717082
resultobj = SWIG_NewPointerObj((&result)->release(), SWIGTYPE_p_Exiv2__BasicIo, SWIG_POINTER_OWN | 0 );
70727083

70737084

7085+
#ifdef KEEPREF_VIEW_ImageFactory_createIo
70747086
private_store_set(resultobj, "using_view", _global_view);
7087+
#endif
70757088

70767089

70777090
Py_XDECREF(_global_view);
@@ -7915,6 +7928,7 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__ImageFactory_methods[] = {
79157928
":type data: :py:term:`bytes-like object`\n"
79167929
":param data: Pointer to a data buffer containing an image. The contents\n"
79177930
" of the memory are tested to determine the image type.\n"
7931+
":type size: int\n"
79187932
":param size: Number of bytes pointed to by *data*.\n"
79197933
":rtype: :py:class:`Image`\n"
79207934
":return: An auto-pointer that owns an Image instance whose type\n"
@@ -7966,6 +7980,7 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__ImageFactory_methods[] = {
79667980
":type data: :py:term:`bytes-like object`\n"
79677981
":param data: Pointer to a data buffer containing an image. The contents\n"
79687982
" of the memory are tested to determine the image type.\n"
7983+
":type size: int\n"
79697984
":param size: Number of bytes pointed to by *data*.\n"
79707985
":rtype: :py:class:`ImageType`\n"
79717986
":return: %Image type or Image::none if the type is not recognized.\n"

src/swig-0_28_5/image_wrap.cxx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,6 +4410,10 @@ namespace Exiv2 {
44104410
#endif // EXV_ENABLE_FILESYSTEM
44114411

44124412

4413+
#define KEEPREF_VIEW_ImageFactory_open
4414+
#define KEEPREF_VIEW_ImageFactory_createIo
4415+
4416+
44134417
static bool enableBMFF(bool enable) {
44144418
// deprecated since 2024-08-01
44154419
PyErr_WarnEx(PyExc_DeprecationWarning,
@@ -5034,11 +5038,11 @@ SWIG_AsVal_size_t (PyObject * obj, size_t *val)
50345038
return res;
50355039
}
50365040

5037-
SWIGINTERN Exiv2::BasicIo::UniquePtr Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *data,size_t B){
5041+
SWIGINTERN Exiv2::BasicIo::UniquePtr Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *data,size_t size){
50385042

50395043

50405044

5041-
return std::make_unique<Exiv2::MemIo>(data, B);
5045+
return std::make_unique<Exiv2::MemIo>(data, size);
50425046

50435047
}
50445048
#ifdef __cplusplus
@@ -6566,7 +6570,9 @@ SWIGINTERN PyObject *_wrap_ImageFactory_open__SWIG_1(PyObject *self, Py_ssize_t
65666570
resultobj = SWIG_NewPointerObj((&result)->release(), SWIGTYPE_p_Exiv2__Image, SWIG_POINTER_OWN | 0 );
65676571

65686572

6573+
#ifdef KEEPREF_VIEW_ImageFactory_open
65696574
private_store_set(resultobj, "using_view", _global_view);
6575+
#endif
65706576

65716577

65726578
Py_XDECREF(_global_view);
@@ -6839,6 +6845,11 @@ SWIGINTERN PyObject *_wrap_ImageFactory_getType__SWIG_1(PyObject *self, Py_ssize
68396845
SWIG_fail;
68406846
}
68416847

6848+
#ifdef KEEPREF_VIEW_ImageFactory_getType
6849+
private_store_set(resultobj, "using_view", _global_view);
6850+
#endif
6851+
6852+
68426853
Py_XDECREF(_global_view);
68436854

68446855
return resultobj;
@@ -7075,7 +7086,9 @@ SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_1(PyObject *self, Py_ssiz
70757086
resultobj = SWIG_NewPointerObj((&result)->release(), SWIGTYPE_p_Exiv2__BasicIo, SWIG_POINTER_OWN | 0 );
70767087

70777088

7089+
#ifdef KEEPREF_VIEW_ImageFactory_createIo
70787090
private_store_set(resultobj, "using_view", _global_view);
7091+
#endif
70797092

70807093

70817094
Py_XDECREF(_global_view);
@@ -7932,6 +7945,7 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__ImageFactory_methods[] = {
79327945
":type data: :py:term:`bytes-like object`\n"
79337946
":param data: Pointer to a data buffer containing an image. The contents\n"
79347947
" of the memory are tested to determine the image type.\n"
7948+
":type size: int\n"
79357949
":param size: Number of bytes pointed to by *data*.\n"
79367950
":rtype: :py:class:`Image`\n"
79377951
":return: An auto-pointer that owns an Image instance whose type\n"
@@ -7983,6 +7997,7 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__ImageFactory_methods[] = {
79837997
":type data: :py:term:`bytes-like object`\n"
79847998
":param data: Pointer to a data buffer containing an image. The contents\n"
79857999
" of the memory are tested to determine the image type.\n"
8000+
":type size: int\n"
79868001
":param size: Number of bytes pointed to by *data*.\n"
79878002
":rtype: :py:class:`ImageType`\n"
79888003
":return: %Image type or Image::none if the type is not recognized.\n"

utils/build_swig.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,7 @@ def main():
102102
os.path.join(output_dir, mod_name))
103103
# pre-process include files to a temporary directory
104104
subst = {
105-
'image.hpp': [('getType(const byte* data, size_t size',
106-
'getType(const byte* data, size_t A'),
107-
('getType(const byte* data, long size',
108-
'getType(const byte* data, long A'),
109-
('open(const byte* data, size_t size',
110-
'open(const byte* data, size_t B'),
111-
('open(const byte* data, long size',
112-
'open(const byte* data, long B'),
113-
('/*! @brief', '/*!\n @brief')],
105+
'image.hpp': [('/*! @brief', '/*!\n @brief')],
114106
'metadatum.hpp': [('toString(size_t n)', 'toString(size_t i)'),
115107
('toString(long n)', 'toString(long i)')],
116108
'preview.hpp': [('_{};', '_;')],

0 commit comments

Comments
 (0)