[issue2799] Remove _PyUnicode_AsString(), rework _PyUnicode_AsStringAndSize(), add PyUnicode_AsChar()

2010-12-07 Thread Julian Andres Klode

Julian Andres Klode  added the comment:

The problem I see here is that there is no public way to simply get a C string 
from a unicode object similar to PyBytes_AsString() for bytes. That's bad 
because we don't want to rewrite the whole code to duplicate strings all the 
time and free every string we get from a MyPyUnicode_AsString() like function.

I used the following, but this clearly has a memory leak:


  static const char *MyPyUnicode_AsString(PyObject *op) {
  PyObject *bytes = PyUnicode_AsEncodedString(op,0,0);
  return bytes ? PyBytes_AS_STRING(bytes) : 0;
  }

I now use the following which has no memory leak, but needs an internal 
function (I would use _PyUnicode_AsString, but I need Python 2.X compatibility 
as well):

  static const char *MyPyUnicode_AsString(PyObject *op) {
  PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);
  return bytes ? PyBytes_AS_STRING(bytes) : 0;
  }

So could something be done about this?

--
nosy: +jak

___
Python tracker 
<http://bugs.python.org/issue2799>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6483] Modules are not deallocated correctly if m_size = -1

2010-04-20 Thread Julian Andres Klode

Julian Andres Klode  added the comment:

This bug still exists in Python 3.1.2.

--

___
Python tracker 
<http://bugs.python.org/issue6483>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6446] import_spam() in extending python can fail without setting the error.

2009-07-09 Thread Julian Andres Klode

New submission from Julian Andres Klode :

The given example function initspam fails if an 

Based on some experience with my own code, I have found out that the
function import_spam() fails when the module is not importable. In this
case, it returns 0, although it should return -1 when an error occurs.

This causes a standalone program to crash if it has a main() function like:

Py_Initialize();
if (import_spam() < 0) {
Py_Finalize();
return 1;
}
Py_Finalize();

The function should return -1, so we can know there is an error and are
able to handle it.

--
assignee: georg.brandl
components: Documentation
messages: 90325
nosy: georg.brandl, jak
severity: normal
status: open
title: import_spam() in extending python can fail without setting the error.
type: crash
versions: Python 2.6

___
Python tracker 
<http://bugs.python.org/issue6446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6483] Modules are not deallocated correctly if m_size = -1

2009-07-14 Thread Julian Andres Klode

New submission from Julian Andres Klode :

The documentation states that m_size should be -1 if no additional
memory is needed. But this causes the objects inside the module to not
be deallocated at all.

The attached module (test) stores an object of a type 'Test', which
prints "Deallocation is happening" in it's tp_dealloc. If m_size in the
TestModule is set to -1, this is never reached. If it is 0, it is reached.

--
components: Interpreter Core
files: test.c
messages: 90514
nosy: jak
severity: normal
status: open
title: Modules are not deallocated correctly if m_size = -1
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file14500/test.c

___
Python tracker 
<http://bugs.python.org/issue6483>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6483] Modules are not deallocated correctly if m_size = -1

2009-07-15 Thread Julian Andres Klode

Julian Andres Klode  added the comment:

I believe this may be related to Python/import.c (l. 592):

   def->m_base.m_copy = PyDict_Copy(dict);

It creates a copy of the module dictionary, but the reference count of
this copy is not decreased when the module object is deallocated, thus
causing the objects contained therein to be not allocated as well.

--

___
Python tracker 
<http://bugs.python.org/issue6483>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com