Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pypy
pypy
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 582
    • Issues 582
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 12
    • Merge Requests 12
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards

This instance will be upgraded to Heptapod 0.19.0rc2 on 2021-01-18 at 11:00 UTC+1 (a few minutes of downtime)

  • PyPy
  • pypypypy
  • Issues
  • #3300

Closed
Open
Opened Sep 18, 2020 by 4D617278@4D617278

ctypes structure with custom __new__ which takes argument does not support construction by "from_buffer_copy"

This is a case where ctypes lib in CPython and PyPy give different result. I would say this issue is minor.

Code snippet run in PyPy:

/usr/bin/pypy3

Python 3.6.9 (?, Apr 17 2020, 09:36:06)

[PyPy 7.3.1 with GCC 9.3.0]

#!pypy3

>>>> from ctypes import *
>>>> class test(Structure):
....     _fields_ = [('test', c_ubyte)]
....     def __new__(cls, buffer):
....         return cls.from_buffer_copy(buffer)
....     def __init__(self, buffer):
....         pass
....         
>>>> a = test(b'A')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in __new__
  File "/opt/pypy3/lib_pypy/_ctypes/basics.py", line 127, in from_buffer_copy
    result = self._newowninstance_()
  File "/opt/pypy3/lib_pypy/_ctypes/basics.py", line 139, in _newowninstance_
    result = self.__new__(self)
TypeError: __new__() missing 1 required positional argument: 'buffer'

#!python3

>>> from ctypes import *
>>> class test(Structure):
...     _fields_ = [("test", c_ubyte)]
...     def __new__(cls, buffer):
...             return cls.from_buffer_copy(buffer)
...     def __init__(self, buffer):
...             pass
... 
>>> a = test(b'A')
>>>
Edited Sep 18, 2020 by 4D617278
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: pypy/pypy#3300