getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] [getfem-commits] branch master updated: Fix compilation


From: Konstantinos Poulios
Subject: [Getfem-commits] [getfem-commits] branch master updated: Fix compilation warning, allocate memory for strings passed from Python
Date: Tue, 17 Oct 2023 06:00:35 -0400

This is an automated email from the git hooks/post-receive script.

logari81 pushed a commit to branch master
in repository getfem.

The following commit(s) were added to refs/heads/master by this push:
     new 77348c0c Fix compilation warning, allocate memory for strings passed 
from Python
77348c0c is described below

commit 77348c0c3ea9082269da468a668eaa236d6e3d1e
Author: Konstantinos Poulios <logari81@gmail.com>
AuthorDate: Tue Oct 17 12:00:24 2023 +0200

    Fix compilation warning, allocate memory for strings passed from Python
    
      - do not use a pointer to cached utf8 version of python string
      - allocate memory and make a copy of the utf8 string instead
---
 interface/src/python/getfem_python.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/interface/src/python/getfem_python.c 
b/interface/src/python/getfem_python.c
index 38abcfd6..53766e6e 100644
--- a/interface/src/python/getfem_python.c
+++ b/interface/src/python/getfem_python.c
@@ -341,14 +341,14 @@ PyObject_to_gfi_array(gcollect *gc, PyObject *o)
     //printf("String\n");
     /* for strings, the pointer is shared, no copy */
     int L = (int)(strlen(PyUnicode_AsUTF8(o)));
-    char *s = PyUnicode_AsUTF8(o);
-    gc_ref(gc, o, 0);
+    const char *s = PyUnicode_AsUTF8(o);
 
     t->storage.type = GFI_CHAR;
     t->dim.dim_len = 1;
     t->dim.dim_val = &TGFISTORE(char,len);
     TGFISTORE(char,len)=L;
-    TGFISTORE(char,val)=s;
+    if (!(TGFISTORE(char,val)=gc_alloc(gc,L*sizeof(char)))) return NULL;
+    memcpy(TGFISTORE(char,val), s, L);
 #if PY_MAJOR_VERSION < 3
   } else if (PyInt_Check(o) || PyLong_Check(o)) {
 #else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]