[pypy-svn] r28719 - in pypy/dist/pypy: module/readline module/readline/test rpython/rctypes/tool
arigo at codespeak.net
arigo at codespeak.net
Mon Jun 12 18:45:54 CEST 2006
Author: arigo
Date: Mon Jun 12 18:45:52 2006
New Revision: 28719
Modified:
pypy/dist/pypy/module/readline/__init__.py
pypy/dist/pypy/module/readline/c_readline.py
pypy/dist/pypy/module/readline/interp_readline.py
pypy/dist/pypy/module/readline/test/test_readline.py
pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
Log:
Added a basic Library class in ctypes_platform, and made
pypy.module.readline importable.
Modified: pypy/dist/pypy/module/readline/__init__.py
==============================================================================
--- pypy/dist/pypy/module/readline/__init__.py (original)
+++ pypy/dist/pypy/module/readline/__init__.py Mon Jun 12 18:45:52 2006
@@ -1,21 +1,22 @@
# this is a sketch of how one might one day be able to define a pretty simple
# ctypes-using module, suitable for feeding to the ext-compiler
-import py; py.test.skip("in-progress")
-from pypy.interpreter.ctypesmodule import CTypesModule
+from pypy.interpreter.mixedmodule import MixedModule
# XXX raw_input needs to check for space.readline_func and use
# it if its there
-class Module(CTypesModule):
+class Module(MixedModule):
"""Importing this module enables command line editing using GNU readline."""
# the above line is the doc string of the translated module
def init(self, space):
from pypy.module.readline import c_readline
c_readline.setup_readline(space, self)
- space.readline_func = self.dict_w['readline']
interpleveldefs = {
'readline' : 'interp_readline.readline',
}
+
+ appleveldefs = {
+ }
Modified: pypy/dist/pypy/module/readline/c_readline.py
==============================================================================
--- pypy/dist/pypy/module/readline/c_readline.py (original)
+++ pypy/dist/pypy/module/readline/c_readline.py Mon Jun 12 18:45:52 2006
@@ -1,6 +1,5 @@
-from pypy.module.readline import Module
from ctypes import *
-from pypy.rpython.rctypes.tool.ctypes_platform import Library
+from pypy.rpython.rctypes.tool.ctypes_platform import configure, Library
#------------------------------------------------------------
# configuration for binding to external readline library
@@ -10,21 +9,29 @@
_header_ = """#include <readline/readline.h>"""
readline = Library('readline')
-
-
-cconfig = Module.cconfig(CConfig)
+cconfig = configure(CConfig)
+libreadline = cconfig['readline']
-libreadline = cconfig.readline
# get a binding to c library functions and define their args and return types
# char *readline(char *)
-c_readline = libreadline.get_func('readline', [c_char_p], c_char_p)
+c_readline = libreadline.readline
+c_readline.argtypes = [c_char_p]
+c_readline.restype = c_char_p
+
# void rl_initiliaze(void)
-c_rl_initialize = libreadline.get_func('rl_initiliaze', [], None)
+c_rl_initialize = libreadline.rl_initialize
+c_rl_initialize.argtypes = []
+c_rl_initialize.restype = None
+
#------------------------------------------------------------
# special initialization of readline
-def setup_readline(space):
+def setup_readline(space, w_module):
# XXX ...
c_rl_initialize()
+ space.readline_func = readline_func
+
+def readline_func(s):
+ return c_readline(s)
Modified: pypy/dist/pypy/module/readline/interp_readline.py
==============================================================================
--- pypy/dist/pypy/module/readline/interp_readline.py (original)
+++ pypy/dist/pypy/module/readline/interp_readline.py Mon Jun 12 18:45:52 2006
@@ -1,7 +1,6 @@
# this is a sketch of how one might one day be able to define a pretty simple
# ctypes-using module, suitable for feeding to the ext-compiler
-from pypy.interpreter.ctypesmodule import CTypesModule
from pypy.interpreter.baseobjspace import ObjSpace
from pypy.module.readline import c_readline
@@ -9,9 +8,9 @@
#------------------------------------------------------------
# exported API (see interpleveldefs in __init__.py)
#
-def readline(space, w_prompt):
- prompt = space.str_w(w_prompt)
+def readline(space, prompt):
return space.wrap(c_readline.c_readline(prompt))
+readline.unwrap_spec = [ObjSpace, str]
def setcompleter(space, w_callback):
"""Set or remove the completer function.
Modified: pypy/dist/pypy/module/readline/test/test_readline.py
==============================================================================
--- pypy/dist/pypy/module/readline/test/test_readline.py (original)
+++ pypy/dist/pypy/module/readline/test/test_readline.py Mon Jun 12 18:45:52 2006
@@ -1,10 +1,13 @@
+from pypy.conftest import gettestobjspace
-#def setup_mod(mod):
-# mod.space = StdObjSpace(usemodules=['readline'])
-# mod.space = CPyObjSpace(usemodules=['readline'])
+class AppTestReadline:
-def app_test_basic_import():
- import readline
- readline.set_completer
- # test more
+ def setup_class(cls):
+ space = gettestobjspace(usemodules=('readline',))
+ cls.space = space
+
+ def test_basic_import(self):
+ import readline
+ readline.readline
+ # test more
Modified: pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py (original)
+++ pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py Mon Jun 12 18:45:52 2006
@@ -297,6 +297,24 @@
def build_result(self, info, config_result):
return bool(info['defined'])
+
+class Library(CConfigEntry):
+ """The loaded CTypes library object.
+ """
+ def __init__(self, name):
+ self.name = name
+
+ def prepare_code(self):
+ # XXX should check that we can link against the lib
+ return []
+
+ def build_result(self, info, config_result):
+ from pypy.rpython.rctypes.tool import util
+ path = util.find_library(self.name)
+ mylib = ctypes.cdll.LoadLibrary(path)
+ mylib._header_ = config_result.CConfig._header_
+ return mylib
+
# ____________________________________________________________
#
# internal helpers
More information about the Pypy-commit
mailing list