GnuCash
Contact   Instructions
Bug 796858 - TypeError: in method 'qof_query_int32_predicate', argument 2 of type 'gint32' on gnucash.gnucash_core.QueryInt32Predicate
Summary: TypeError: in method 'qof_query_int32_predicate', argument 2 of type 'gint32'...
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Python Bindings (show other bugs)
Version: git-maint
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: core
QA Contact: core
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-17 09:39 EDT by Tom Lofts
Modified: 2018-09-18 13:44 EDT (History)
2 users (show)

See Also:


Attachments
Example Python script reproducing issue (797 bytes, text/x-python)
2018-09-17 09:39 EDT, Tom Lofts
no flags Details
Patch which resolves issue (365 bytes, patch)
2018-09-17 09:40 EDT, Tom Lofts
jralls: rejected+
Details

Description Tom Lofts 2018-09-17 09:39:07 EDT
Created attachment 372974 [details]
Example Python script reproducing issue

Hi All,

When using gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 2) as part of a qof query I recieve a TypeError: in method 'qof_query_int32_predicate', argument 2 of type 'gint32' and a crash as below:

 python3 test.py
Traceback (most recent call last):
  File "test.py", line 25, in <module>
    pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 2)
  File "/usr/lib/python3/dist-packages/gnucash/function_class.py", line 71, in __init__
    *process_list_convert_to_instance(args) )
  File "/usr/lib/python3/dist-packages/gnucash/gnucash_core_c.py", line 2512, in qof_query_int32_predicate
    return _gnucash_core_c.qof_query_int32_predicate(how, val)
TypeError: in method 'qof_query_int32_predicate', argument 2 of type 'gint32'
*** Error in `python3': free(): invalid pointer: 0x00007fe40b63df58 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fe40b2f07e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fe40b2f937a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fe40b2fd53c]
/build/lib/gnucash/libgncmod-engine.so(_ZN13GncDateFormatD1Ev+0x28)[0x7fe409c22876]
/build/lib/gnucash/libgncmod-engine.so(_ZSt8_DestroyI13GncDateFormatEvPT_+0x18)[0x7fe409c43485]
/build/lib/gnucash/libgncmod-engine.so(_ZNSt12_Destroy_auxILb0EE9__destroyIP13GncDateFormatEEvT_S4_+0x2e)[0x7fe409c4201b]
/build/lib/gnucash/libgncmod-engine.so(_ZSt8_DestroyIP13GncDateFormatEvT_S2_+0x23)[0x7fe409c40418]
/build/lib/gnucash/libgncmod-engine.so(_ZSt8_DestroyIP13GncDateFormatS0_EvT_S2_RSaIT0_E+0x27)[0x7fe409c4d198]
/build/lib/gnucash/libgncmod-engine.so(_ZNSt6vectorI13GncDateFormatSaIS0_EED1Ev+0x35)[0x7fe409c4c33d]
/lib/x86_64-linux-gnu/libc.so.6(+0x39ff8)[0x7fe40b2b2ff8]
/lib/x86_64-linux-gnu/libc.so.6(+0x3a045)[0x7fe40b2b3045]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0x7fe40b299837]
python3(_start+0x29)[0x5d6049]
======= Memory map: ========
00400000-007a9000 r-xp 00000000 00:30 106                                /usr/bin/python3.5
009a9000-009ab000 r--p 003a9000 00:30 106                                /usr/bin/python3.5
009ab000-00a42000 rw-p 003ab000 00:30 106                                /usr/bin/python3.5
00a42000-00a73000 rw-p 00000000 00:00 0
029c2000-02d4d000 rw-p 00000000 00:00 0                                  [heap]
[Removed]

After some investigation, it looks as though either as part of the change to Python 3 or some other changes in the code since the 2.x branch some of the code around qof_query_int32_predicate now uses gint32 instead of gint leading to this error which looks like it can be removed by adding this to the int typemap e.g.:

%apply int { gint, gint32 };

I've attached a sample Python 3 script reproducing the issues (with MySQL as a datasource expecting certain credentials) and will upload a patch with the above changes which resolves the issue and will submit a pull request shortly.

Kind regards,

Tom
Comment 1 Tom Lofts 2018-09-17 09:40:48 EDT
Created attachment 372975 [details]
Patch which resolves issue
Comment 2 Tom Lofts 2018-09-17 10:20:52 EDT
I've submitted this patch as pull request #412.

Kind regards,

Tom
Comment 3 John Ralls 2018-09-17 14:11:34 EDT
That's a bit disappointing, the SWIG docs say that %apply isn't necessary for typedeffed aliases.

Anyway, I prefer 
%apply int32_t { gint32 };
%apply uint32_t { guint32 };

While it's generally true these days that gint32 is int, it isn't necessarily so for all systems forever, but gint32 and int32_t should always be the same.

After testing that that worked using your test program I found another Py3 fix required in base_typemaps.i:
@@ -250,8 +251,8 @@ typedef char gchar;
         int size = PyList_Size($input);
         for (i = size-1; i >= 0; i--) {
             PyObject *o = PyList_GetItem($input, i);
-            if (PyString_Check(o)) {
-                $1 = g_slist_prepend($1,PyString_AsString(PyList_GetItem($input, i)));
+            if (PyUnicode_Check(o)) {
+                $1 = g_slist_prepend($1,PyUnicode_AsUTF8(PyList_GetItem($input, i)));
             } else {
                 PyErr_SetString(PyExc_TypeError, "list must contain strings");
                 g_slist_free($1);

without which I got the complaint "list must contain strings" (once I'd actually imported or defined INVOICE_TYPE in the program).

Would you like to update your PR or shall I just commit what I have?
Comment 4 Tom Lofts 2018-09-18 09:08:38 EDT
Hi John,

Please go ahead and commit what you have.

Thanks for your help on getting these Python issues sorted.

Kind regards,

Tom
Comment 5 John Ralls 2018-09-18 13:44:02 EDT
Done. Thanks for your perseverance in tracking down the python problems.

Note You need to log in before you can comment on or make changes to this bug.