Re: [Python-Dev] Modify PyMem_Malloc to use pymalloc for performance

2016-02-07 Thread Stefan Behnel
M.-A. Lemburg schrieb am 04.02.2016 um 13:54:
> On 04.02.2016 13:29, Victor Stinner wrote:
>> But, why not PyObject_Malloc() & PObject_Free() were not used in the
>> first place?
> 
> Good question. I guess developers simply thought of PyObject_Malloc()
> being for PyObjects, not arbitrary memory buffers, most likely
> because pymalloc was advertised as allocator for Python objects,
> not random chunks of memory.

Note that the PyObject_Malloc() functions have never been documented.
(Well, there are references regarding their mere existence in the docs, but
nothing more than that.)

https://docs.python.org/3.6/search.html?q=pyobject_malloc&check_keywords=yes&area=default

And, for example, the "what's new in 2.5" document says:

"""
Python’s API has many different functions for allocating memory that are
grouped into families. For example, PyMem_Malloc(), PyMem_Realloc(), and
PyMem_Free() are one family that allocates raw memory, while
PyObject_Malloc(), PyObject_Realloc(), and PyObject_Free() are another
family that’s supposed to be used for creating Python objects.
"""

I don't think there are many extensions out there in which *object* memory
gets allocated manually, which implicitly puts a pretty clear "don't use"
marker on these functions.

Stefan


___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Google Summer of Code

2016-02-07 Thread Victor Stinner
Hi,

I would like to propose the FAT Python project subject to the  Google
Summer of Code:
https://developers.google.com/open-source/gsoc/

I have a long list of optimization ideas for fatoptimizer:
http://fatoptimizer.readthedocs.org/en/latest/todo.html

The fatoptimizer project is written in pure Python and has a simple design.
I implemented quite simple optimizations which are learnt at school. IMHO
such project fits well for a student.

Does the PSF already plan to apply to the GSoC? Are there other projects?

Victor
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ?

2016-02-07 Thread Randy Eels
Hi everyone,

I've a question about the implementation of the `type` builtin (in Python
3.5).

In Objects/typeobject.c, the `tp_alloc` slot of PyType_Type gets set to 0.
However, I can see (using gdb) that it later gets assigned to
`&PyType_GenericAlloc`. I'd argue that this makes sense because, in
`type_new`, there is a line where that member function gets called without
previously checking whether that member points to something:

```
/* Allocate the type object */
type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots);
```

Yet, I can't seem to understand where and when does the `tp_alloc` slot of
PyType_Type get re-assigned to PyType_GenericAlloc. Does that even happen?
Or am I missing something bigger?

And, just out of further curiosity, why doesn't the aforementioned slot get
initialised to `PyType_GenericAlloc` in the first place?

Thanks a lot.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 0492 __aenter__ & __aexit__

2016-02-07 Thread Daniel Miller
Awesome, I missed that. Thank you Brett.

Am I understanding correctly that if I'd like to avoid `async with await
EXPR` whatever is returned from EXPR must implement `__await__` as a
non-coroutine method? Which then I'd just be able to use `async with ...`?



2016-02-06 16:05 GMT-06:00 Brett Cannon :

>
>
> On Sat, 6 Feb 2016 at 13:50 Daniel Miller 
> wrote:
>
>> Hi Python-Dev Group,
>>
>> I am trying to implement __aenter__ and __aexit__ for the RethinkDB
>>  Python driver. Looking at the PEP I don't see
>> any definitions as to what the expected parameters that __exit__ are
>> supposed to take and couldn't find any other similar implementations. Is
>> there a piece of documentation I should be looking at that I'm missing?
>>
>>
>> https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with
>>
>
> The arguments to __aexit__ are the same as __exit__ in a normal context
> manager. See
> https://docs.python.org/3.5/reference/datamodel.html#object.__aexit__ for
> the official docs for __aexit__.
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 0492 __aenter__ & __aexit__

2016-02-07 Thread Brett Cannon
On Sun, 7 Feb 2016 at 08:17 Daniel Miller  wrote:

> Awesome, I missed that. Thank you Brett.
>

Welcome!


>
> Am I understanding correctly that if I'd like to avoid `async with await
> EXPR` whatever is returned from EXPR must implement `__await__` as a
> non-coroutine method? Which then I'd just be able to use `async with ...`?
>

Assuming I'm following what you're asking properly, __aenter__ needs to
return an awaitable:
https://docs.python.org/3/reference/datamodel.html?#awaitable-objects. That
is either an object that implements __await__() or a coroutine (which is
basically a generator decorated with types.coroutine).


>
>
>
> 2016-02-06 16:05 GMT-06:00 Brett Cannon :
>
>>
>>
>> On Sat, 6 Feb 2016 at 13:50 Daniel Miller 
>> wrote:
>>
>>> Hi Python-Dev Group,
>>>
>>> I am trying to implement __aenter__ and __aexit__ for the RethinkDB
>>>  Python driver. Looking at the PEP I don't see
>>> any definitions as to what the expected parameters that __exit__ are
>>> supposed to take and couldn't find any other similar implementations. Is
>>> there a piece of documentation I should be looking at that I'm missing?
>>>
>>>
>>> https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with
>>>
>>
>> The arguments to __aexit__ are the same as __exit__ in a normal context
>> manager. See
>> https://docs.python.org/3.5/reference/datamodel.html#object.__aexit__ for
>> the official docs for __aexit__.
>>
>
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Google Summer of Code

2016-02-07 Thread Brett Cannon
On Sun, 7 Feb 2016 at 02:14 Victor Stinner  wrote:

> Hi,
>
> I would like to propose the FAT Python project subject to the  Google
> Summer of Code:
> https://developers.google.com/open-source/gsoc/
>
> I have a long list of optimization ideas for fatoptimizer:
> http://fatoptimizer.readthedocs.org/en/latest/todo.html
>
> The fatoptimizer project is written in pure Python and has a simple
> design. I implemented quite simple optimizations which are learnt at
> school. IMHO such project fits well for a student.
>
> Does the PSF already plan to apply to the GSoC? Are there other projects?
>

Terri Oda has already emailed the core-mentorship mailing list looking for
core projects, so the PSF is definitely doing it again and is looking for
core projects.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ?

2016-02-07 Thread Guido van Rossum
I think it's probably line 2649 in typeobject.c, in type_new():

type->tp_alloc = PyType_GenericAlloc;

On Sun, Feb 7, 2016 at 5:58 AM, Randy Eels  wrote:
> Hi everyone,
>
> I've a question about the implementation of the `type` builtin (in Python
> 3.5).
>
> In Objects/typeobject.c, the `tp_alloc` slot of PyType_Type gets set to 0.
> However, I can see (using gdb) that it later gets assigned to
> `&PyType_GenericAlloc`. I'd argue that this makes sense because, in
> `type_new`, there is a line where that member function gets called without
> previously checking whether that member points to something:
>
> ```
> /* Allocate the type object */
> type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots);
> ```
>
> Yet, I can't seem to understand where and when does the `tp_alloc` slot of
> PyType_Type get re-assigned to PyType_GenericAlloc. Does that even happen?
> Or am I missing something bigger?
>
> And, just out of further curiosity, why doesn't the aforementioned slot get
> initialised to `PyType_GenericAlloc` in the first place?
>
> Thanks a lot.
>
> ___
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ?

2016-02-07 Thread eryk sun
On Sun, Feb 7, 2016 at 7:58 AM, Randy Eels  wrote:
>
> Yet, I can't seem to understand where and when does the `tp_alloc` slot of
> PyType_Type get re-assigned to PyType_GenericAlloc. Does that even happen?
> Or am I missing something bigger?

_Py_InitializeEx_Private in Python/pylifecycle.c calls _Py_ReadyTypes
in Objects/object.c. This calls PyType_Ready(&PyType_Type) in
Objects/typeobject.c, which assigns type->tp_base = &PyBaseObject_Type
and then calls inherit_slots. This executes COPYSLOT(tp_alloc), which
assigns PyType_Type.tp_alloc = PyBaseObject_Type.tp_alloc, which is
statically assigned as PyType_GenericAlloc.

Debug trace on Windows:

0:000> bp python35!PyType_Ready
0:000> g
Breakpoint 0 hit
python35!PyType_Ready:
`6502d160 4053pushrbx
0:000> ?? ((PyTypeObject *)@rcx)->tp_name
char * 0x`650e4044
 "object"
0:000> g
Breakpoint 0 hit
python35!PyType_Ready:
`6502d160 4053pushrbx
0:000> ?? ((PyTypeObject *)@rcx)->tp_name
char * 0x`651d8e5c
 "type"
0:000> bp python35!inherit_slots
0:000> g
Breakpoint 1 hit
python35!inherit_slots:
`6502c440 48895c2408  mov qword ptr [rsp+8],rbx
ss:`0028f960={
python35!PyType_Type
(`6527cba0)}

At entry to inherit_slots, PyType_Type.tp_alloc is NULL:

0:000> ?? python35!PyType_Type.tp_alloc
 * 0x`
0:000> pt
python35!inherit_slots+0xd17:
`6502d157 c3  ret

At exit it's set to PyType_GenericAlloc:

0:000> ?? python35!PyType_Type.tp_alloc
 * 0x`65025580
0:000> ln 65025580
(`65025580)   python35!PyType_GenericAlloc   |
(`650256a0)   python35!PyType_GenericNew
Exact matches:
python35!PyType_GenericAlloc (void)
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Google Summer of Code

2016-02-07 Thread Stephen J. Turnbull
As long as it's been brought up here:

Yes, the PSF is applying.  Google has been deliberately stirring
things up in the last couple of years, so no promises, but it is very
likely that we will be approved and core Python will have at least two
slots allocated (although I'm not sure core Python even has a suborg
admin yet, Terri will recruit someone).

Please see the Wiki page at
https://wiki.python.org/moin/SummerOfCode/2016
for more details.

To contact the org admins (for wiki permissions and to join the
mentors' mailing list), use the python.org mailbox gsoc-admins.
core-mentorship is a good place to recruit students as well as to get
advice on mentoring (or mentor-mentoring, if you're a suborg admin
with new mentors).

@Victor: I agree with you that implementing FATPython optimizations is
a good student-level project, and one that is likely to attract
continuing participation.  You should get in touch with the admins[1]
about updating the wiki page at:
https://wiki.python.org/moin/SummerOfCode/2016/python-core.

It's looking kinda lonely at the moment.  Note that we can still add
suborgs and projects after we've been approved (in 2-3 weeks) up to
March 7, but the more projects and the more attractive they are, the
better our chances of being accepted, and the better the students
we'll attract.



Footnotes: 
[1]  I'm an assistant admin, but just recovering from Faculty Hell
Month and a nasty cold, and don't have a handle on my own tools yet.
Somebody else is likely to get to it more quickly. :-(

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com