Author: Wim Lavrijsen <[email protected]> Branch: cppyy-packaging Changeset: r92008:80bd00a75270 Date: 2017-07-31 16:48 -0700 http://bitbucket.org/pypy/pypy/changeset/80bd00a75270/
Log: remove backend code (lives in http://bitbucket/wlav/cppyy-backend and is shared with CPython) and the builtin capi option (never used in production) diff too long, truncating to 2000 out of 3411 lines diff --git a/pypy/module/_cppyy/backend/create_cppyy_package.py b/pypy/module/_cppyy/backend/create_cppyy_package.py deleted file mode 100755 --- a/pypy/module/_cppyy/backend/create_cppyy_package.py +++ /dev/null @@ -1,649 +0,0 @@ -#!/usr/bin/env python -from __future__ import print_function - -import os, sys -import argparse, re, shutil, tarfile, urllib2 - - -DEBUG_TESTBUILD = False - -TARBALL_CACHE_DIR = 'releases' - -ROOT_KEEP = ['build', 'cmake', 'config', 'core', 'etc', 'interpreter', - 'io', 'LICENSE', 'net', 'Makefile', 'CMakeLists.txt', 'math', - 'main'] # main only needed in more recent root b/c of rootcling -ROOT_CORE_KEEP = ['CMakeLists.txt', 'base', 'clib', 'clingutils', 'cont', - 'dictgen', 'foundation', 'lzma', 'macosx', 'meta', - 'metacling', 'metautils', 'rootcling_stage1', 'textinput', - 'thread', 'unix', 'utils', 'winnt', 'zip'] -ROOT_IO_KEEP = ['CMakeLists.txt', 'io', 'rootpcm'] -ROOT_NET_KEEP = ['CMakeLists.txt', 'net'] -ROOT_MATH_KEEP = ['CMakeLists.txt', 'mathcore'] -ROOT_ETC_KEEP = ['Makefile.arch', 'class.rules', 'cmake', 'dictpch', - 'gdb-backtrace.sh', 'gitinfo.txt', 'helgrind-root.supp', - 'hostcert.conf', 'system.plugins-ios', - 'valgrind-root-python.supp', 'valgrind-root.supp', 'vmc'] - -ROOT_EXPLICIT_REMOVE = ['core/base/v7', 'math/mathcore/v7', 'io/io/v7'] - - -ERR_RELEASE_NOT_FOUND = 2 - - -# -## CLI arguments -# -class ReleaseValidation(argparse.Action): - def __call__(self, parser, namespace, value, option_string=None): - if not re.match(r'6\.\d\d\.\d\d', value): - raise argparse.ArgumentTypeError( - "release number should of the form '6.dd.dd'") - setattr(namespace, self.dest, value) - return value - -parser = argparse.ArgumentParser( - description='Build PyPi package for cppyy containing the minimum of ROOT') -parser.add_argument('-r', '--release', type=str, nargs='?', - action=ReleaseValidation, help='ROOT release to use') - -args = parser.parse_args() - - -# -## ROOT source pull and cleansing -# -def clean_directory(directory, keeplist, trim_cmake=True): - removed_entries = [] - for entry in os.listdir(directory): - if entry[0] == '.' or entry in keeplist: - continue - removed_entries.append(entry) - entry = os.path.join(directory, entry) - print('now removing', entry) - if os.path.isdir(entry): - shutil.rmtree(entry) - else: - os.remove(entry) - - if not trim_cmake: - return - - # now take the removed entries out of the CMakeLists.txt - if removed_entries: - inp = os.path.join(directory, 'CMakeLists.txt') - print('trimming', inp) - outp = inp+'.new' - new_cml = open(outp, 'w') - for line in open(inp).readlines(): - if ('add_subdirectory' in line) or\ - ('COMMAND' in line and 'copy' in line) or\ - ('ROOT_ADD_TEST_SUBDIRECTORY' in line) or\ - ('install(DIRECTORY' in line): - for sub in removed_entries: - if sub in line: - line = '#'+line - break - new_cml.write(line) - new_cml.close() - os.rename(outp, inp) - else: - print('reusing existing %s/CMakeLists.txt' % (directory,)) - - -class ReleaseValidation(argparse.Action): - def __call__(self, parser, namespace, value, option_string=None): - if not re.match(r'6\.\d\d\.\d\d', value): - raise argparse.ArgumentTypeError( - "release number should of the form '6.dd.dd'") - setattr(namespace, self.dest, value) - return value - -parser = argparse.ArgumentParser( - description='Build PyPi package for cppyy containing the minimum of ROOT') -parser.add_argument('-r', '--release', type=str, nargs='?', - action=ReleaseValidation, help='ROOT release to use') - -args = parser.parse_args() - -if not os.path.exists(TARBALL_CACHE_DIR): - os.mkdir(TARBALL_CACHE_DIR) - -if args.release: - # use provided release - fn = 'root_v%s.source.tar.gz' % args.release - addr = 'https://root.cern.ch/download/'+fn - if not os.path.exists(os.path.join(TARBALL_CACHE_DIR, fn)): - try: - print('retrieving', fn) - resp = urllib2.urlopen(addr, fn) - out = open(os.path.join(TARBALL_CACHE_DIR, fn), 'wb') - out.write(resp.read()) - out.close() - except urllib2.HTTPError: - print('release %s not found' % args.release) - sys.exit(ERR_RELEASE_NOT_FOUND) - else: - print('reusing', fn, 'from local directory') -else: - print('provide release ... getting latest release is not yet implemented ...') - sys.exit(1) - # get latest and set fn, args.release, etc. - -# construct version for package -args.version = '' -testnext = False -for c in args.release: - if testnext: - testnext = False - if c == '0': - continue - if c == '.': - testnext = True - args.version += c -args.version += '.0' - -fn = os.path.join(TARBALL_CACHE_DIR, fn) -pkgdir = os.path.join('root-'+args.release) -if not os.path.exists(pkgdir): - print('now extracting', args.release) - tf = tarfile.TarFile.gzopen(fn) - tf.extractall() - tf.close() -else: - print('reusing existing directory', pkgdir) - -# remove everything except for the listed set of libraries -os.chdir(pkgdir) - -clean_directory(os.path.curdir, ROOT_KEEP) -clean_directory('core', ROOT_CORE_KEEP) -clean_directory('etc', ROOT_ETC_KEEP, trim_cmake=False) -clean_directory('io', ROOT_IO_KEEP) -clean_directory('math', ROOT_MATH_KEEP) -clean_directory('net', ROOT_NET_KEEP) - - -# trim main (only need rootcling) -print('trimming main') -for entry in os.listdir('main/src'): - if entry != 'rootcling.cxx': - os.remove('main/src/'+entry) -inp = 'main/CMakeLists.txt' -outp = inp+'.new' -new_cml = open(outp, 'w') -for line in open(inp).readlines(): - if ('ROOT_EXECUTABLE' in line or\ - 'SET_TARGET_PROPERTIES' in line) and\ - not 'rootcling' in line: - line = '#'+line - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - - -# remove afterimage and ftgl explicitly -print('trimming externals') -for cmf in ['AfterImage', 'FTGL']: - os.remove('cmake/modules/Find%s.cmake' % (cmf,)) -inp = 'cmake/modules/SearchInstalledSoftware.cmake' -outp = inp+'.new' -now_stripping = False -new_cml = open(outp, 'w') -for line in open(inp).readlines(): - if '#---Check for ftgl if needed' == line[0:28] or\ - '#---Check for AfterImage' == line[0:24]: - now_stripping = True - elif '#---Check' == line[0:9]: - now_stripping = False - if now_stripping: - line = '#'+line - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - -inp = 'cmake/modules/RootBuildOptions.cmake' -outp = inp+'.new' -new_cml = open(outp, 'w') -for line in open(inp).readlines(): - if 'ROOT_BUILD_OPTION(builtin_ftgl' in line or\ - 'ROOT_BUILD_OPTION(builtin_afterimage' in line: - line = '#'+line - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - - -# remove testing and examples -print('trimming testing') -inp = 'CMakeLists.txt' -outp = inp+'.new' -now_stripping = False -new_cml = open(outp, 'w') -for line in open(inp).readlines(): - if '#---Configure Testing using CTest' == line[0:33] or\ - '#---hsimple.root' == line[0:16]: - now_stripping = True - elif '#---Packaging' == line[0:13] or\ - '#---version' == line[0:11]: - now_stripping = False - if now_stripping: - line = '#'+line - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - -print('trimming RootCPack') -inp = 'cmake/modules/RootCPack.cmake' -outp = inp+'.new' -new_cml = open(outp, 'w') -for line in open(inp): - if 'README.txt' in line: - line = '#'+line - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - -# some more explicit removes: -for dir_to_remove in ROOT_EXPLICIT_REMOVE: - try: - shutil.rmtree(dir_to_remove) - except OSError: - pass - -# special fixes -inp = 'core/base/src/TVirtualPad.cxx' -outp = inp+'.new' -new_cml = open(outp, 'w') -for line in open(inp): - if '#include "X3DBuffer.h"' == line[0:22]: - line = """//#include "X3DBuffer.h" -typedef struct _x3d_sizeof_ { - int numPoints; - int numSegs; - int numPolys; -} Size3D; -""" - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - -inp = 'math/mathcore/src/Fitter.cxx' -if os.path.exists(inp): - outp = inp+'.new' - new_cml = open(outp, 'w') - for line in open(inp): - if '#include "TF1.h"' in line: - continue - new_cml.write(line) - new_cml.close() - os.rename(outp, inp) - -# done -os.chdir(os.path.pardir) - -# debugging: run a test build -if DEBUG_TESTBUILD: - print('running a debug test build') - tb = "test_builddir" - if os.path.exists(tb): - shutil.rmtree(tb) - os.mkdir(tb) - os.chdir(tb) - os.system('cmake ../%s -DCMAKE_INSTALL_PREFIX=../install -Dminimal=ON -Dasimage=OFF' % pkgdir) - os.system('make -j 32') - - -# -## package creation -# -countdown = 0 -pidir = 'Package-'+args.release -print('creating package', pidir) -if not os.path.exists(pidir): - os.mkdir(pidir) -os.chdir(pidir); countdown += 1 - -print('creating LICENSE.txt') -with open('LICENSE.txt', 'w') as outp: - outp.write("""There are three main parts: - - LLVM: distributed under University of Illinois/NCSA Open Source License - https://opensource.org/licenses/UoI-NCSA.php - ROOT: distributed under LGPL 2.1 - https://root.cern.ch/license - Cppyy: distributed under LBNL BSD - https://fedoraproject.org/wiki/Licensing/LBNLBSD -""") - -print('creating MANIFEST.in') -with open('MANIFEST.in', 'w') as outp: - outp.write("""# Include the license file -include LICENSE.txt - -# Include the data files -recursive-include src * -""") - -print('creating README.rst') -with open('README.rst', 'w') as outp: - outp.write("""PyPy cling-support -================== - ----- - -Find the documentation here: - http://doc.pypy.org/en/latest/cppyy.html -""") - -print('creating setup.cfg') -with open('setup.cfg', 'w') as outp: - outp.write("""[bdist_wheel] -universal=0 -""") - -print('creating setup.py') -with open('setup.py', 'w') as outp: - outp.write("""import os, sys, subprocess -from setuptools import setup, find_packages -from distutils import log -from distutils.command.build import build as _build -from setuptools.command.install import install as _install -from distutils.sysconfig import get_python_lib -from distutils.errors import DistutilsSetupError -from codecs import open - -here = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() - -builddir = None -def get_builddir(): - global builddir - if builddir is None: - topdir = os.getcwd() - builddir = os.path.join(topdir, 'builddir') - return builddir - -srcdir = None -def get_srcdir(): - global srcdir - if srcdir is None: - topdir = os.getcwd() - srcdir = os.path.join(topdir, 'src', 'backend') - return srcdir - -class my_cmake_build(_build): - def __init__(self, dist, *args, **kwargs): - _build.__init__(self, dist, *args, **kwargs) - # TODO: can't seem to find a better way of getting hold of - # the install_lib parameter during the build phase ... - prefix = '' - try: - prefix = dist.get_command_obj('install').install_lib - except AttributeError: - pass - if not prefix: - prefix = get_python_lib(1, 0) - self.prefix = os.path.join(prefix, 'cppyy_backend') - - def run(self): - # base run - _build.run(self) - - # custom run - log.info('Now building libcppyy_backend.so and dependencies') - builddir = get_builddir() - srcdir = get_srcdir() - if not os.path.exists(builddir): - log.info('Creating build directory %s ...' % builddir) - os.makedirs(builddir) - - os.chdir(builddir) - log.info('Running cmake for cppyy_backend') - if subprocess.call([ - 'cmake', srcdir, '-Dminimal=ON -Dasimage=OFF', - '-DCMAKE_INSTALL_PREFIX='+self.prefix]) != 0: - raise DistutilsSetupError('Failed to configure cppyy_backend') - - nprocs = os.getenv("MAKE_NPROCS") - if nprocs: - try: - ival = int(nprocs) - nprocs = '-j'+nprocs - except ValueError: - log.warn("Integer expected for MAKE_NPROCS, but got %s (ignored)", nprocs) - nprocs = '-j1' - else: - nprocs = '-j1' - log.info('Now building cppyy_backend and dependencies ...') - if subprocess.call(['make', nprocs]) != 0: - raise DistutilsSetupError('Failed to build cppyy_backend') - - log.info('build finished') - -class my_libs_install(_install): - def run(self): - # base install - _install.run(self) - - # custom install - log.info('Now installing libcppyy_backend.so and dependencies') - builddir = get_builddir() - if not os.path.exists(builddir): - raise DistutilsSetupError('Failed to find build dir!') - os.chdir(builddir) - - prefix = self.install_lib - log.info('Now installing in %s ...', prefix) - if subprocess.call(['make', 'install']) != 0: - raise DistutilsSetupError('Failed to install cppyy_backend') - - log.info('install finished') - - def get_outputs(self): - outputs = _install.get_outputs(self) - outputs.append(os.path.join(self.install_lib, 'cppyy_backend')) - return outputs - -setup( - name='PyPy-cppyy-backend', -""") - outp.write(" version='%s', # corresponds to ROOT %s, extra number is for packager\n"\ - % (args.version, args.release)) - outp.write(""" description='Cling support for PyPy', - long_description=long_description, - - url='http://pypy.org', - - # Author details - author='PyPy Developers', - author_email='[email protected]', - - license='LLVM: UoI-NCSA; ROOT: LGPL 2.1; Cppyy: LBNL BSD', - - classifiers=[ - 'Development Status :: 4 - Beta', - - 'Intended Audience :: Developers', - - 'Topic :: Software Development', - 'Topic :: Software Development :: Interpreters', - - #'License :: OSI Approved :: MIT License', - - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Programming Language :: C', - 'Programming Language :: C++', - - 'Natural Language :: English' - ], - - keywords='interpreter development', - - packages=find_packages('src', ['backend']), - include_package_data=True, - - extras_require={ - }, - - cmdclass = { - 'build': my_cmake_build, - 'install': my_libs_install, - }, -) -""") - - -print('creating src ... ROOT part') -if not os.path.exists('src'): - os.mkdir('src') -os.chdir('src'); countdown += 1 -if not os.path.exists('backend'): - src = os.path.join(os.path.pardir, os.path.pardir, pkgdir) - print('now copying', src) - shutil.copytree(src, 'backend') - -print('creating src ... cppyy part') -os.chdir('backend'); countdown += 1 -if not os.path.exists('cppyy'): - os.mkdir('cppyy') - os.chdir('cppyy'); countdown += 1 - - with open('CMakeLists.txt', 'w') as outp: - outp.write("""############################################################################ -# CMakeLists.txt file for building cppyy package -############################################################################ - -ROOT_GLOB_SOURCES(sources ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cxx) -set_source_files_properties(${sources} COMPILE_FLAGS "-fomit-frame-pointer -fvisibility=hidden -DRPY_EXTERN=RPY_EXPORTED -DRPYTHON_LL2CTYPES") - -add_definitions(${CLING_CXXFLAGS}) - -ROOT_LINKER_LIBRARY(cppyy_backend ${sources} - LIBRARIES ${CMAKE_DL_LIBS} - DEPENDENCIES Core Cling RIO Thread) - -add_dependencies(cppyy_backend CLING) -""") - - os.mkdir('src') - os.chdir('src'); countdown += 1 - print('pulling cppyy/clingcwrapper.cxx from pypy') - base = 'https://bitbucket.org/pypy/pypy/raw/default/pypy/module/cppyy/' - for cppyy_file in ['src/callcontext.h', 'include/capi.h', 'src/clingcwrapper.cxx', - 'include/clingcwrapper.h', 'include/cpp_cppyy.h', 'include/cppyy.h']: - resp = urllib2.urlopen(base+cppyy_file) - with open(os.path.basename(cppyy_file), 'w') as outp: - outp.write(resp.read()) - - # fix include - inp = 'capi.h' - outp = inp+'.new' - new_cml = open(outp, 'w') - for line in open(inp).readlines(): - if 'src/precommondefs.h' in line: - line = '#include "precommondefs.h"\n' - new_cml.write(line) - new_cml.close() - os.rename(outp, inp) - - with open('precommondefs.h', 'w') as outp: - outp.write("""/***** Start of precommondefs.h *****/ - -/* This is extracted from pyconfig.h from CPython. It sets the macros - that affect the features we get from system include files. - It must not #include anything. */ - -#ifndef __PYPY_PRECOMMONDEFS_H -#define __PYPY_PRECOMMONDEFS_H - - -/* Define on Darwin to activate all library features */ -#define _DARWIN_C_SOURCE 1 -/* This must be set to 64 on some systems to enable large file support. */ -#define _FILE_OFFSET_BITS 64 -/* Define on Linux to activate all library features */ -#define _GNU_SOURCE 1 -/* This must be defined on some systems to enable large file support. */ -#define _LARGEFILE_SOURCE 1 -/* Define on NetBSD to activate all library features */ -#define _NETBSD_SOURCE 1 -/* Define to activate features from IEEE Stds 1003.1-2001 */ -#ifndef _POSIX_C_SOURCE -# define _POSIX_C_SOURCE 200112L -#endif -/* Define on FreeBSD to activate all library features */ -#define __BSD_VISIBLE 1 -#define __XSI_VISIBLE 700 -/* Windows: winsock/winsock2 mess */ -#define WIN32_LEAN_AND_MEAN -#ifdef _WIN64 - typedef __int64 Signed; - typedef unsigned __int64 Unsigned; -# define SIGNED_MIN LLONG_MIN -#else - typedef long Signed; - typedef unsigned long Unsigned; -# define SIGNED_MIN LONG_MIN -#endif - -#if !defined(RPY_ASSERT) && !defined(RPY_LL_ASSERT) && !defined(NDEBUG) -# define NDEBUG -#endif - - -/* All functions and global variables declared anywhere should use - one of the following attributes: - - RPY_EXPORTED: the symbol is exported out of libpypy-c.so. - - RPY_EXTERN: the symbol is not exported out of libpypy-c.so, but - otherwise works like 'extern' by being available to - other C sources. - - static: as usual, this means the symbol is local to this C file. - - Don't use _RPY_HIDDEN directly. For tests involving building a custom - .so, translator/tool/cbuild.py overrides RPY_EXTERN so that it becomes - equal to RPY_EXPORTED. - - Any function or global variable declared with no attribute at all is - a bug; please report or fix it. -*/ -#ifdef __GNUC__ -# define RPY_EXPORTED extern __attribute__((visibility("default"))) -# define _RPY_HIDDEN __attribute__((visibility("hidden"))) -#else -# define RPY_EXPORTED extern __declspec(dllexport) -# define _RPY_HIDDEN /* nothing */ -#endif -#ifndef RPY_EXTERN -# define RPY_EXTERN extern _RPY_HIDDEN -#endif - - -#endif /* __PYPY_PRECOMMONDEFS_H */ - -/***** End of precommondefs.h *****/ -""") - -# back up to pip package top -for i in range(countdown-1): - os.chdir(os.path.pardir) - -# add cppyy module to cmake -os.chdir('src/backend') -inp = 'CMakeLists.txt' -print('adding cppyy to cmake') -outp = inp+'.new' -new_cml = open(outp, 'w') -for line in open(inp).readlines(): - if 'add_subdirectory' in line and 'net' in line: - line += 'add_subdirectory (cppyy)\n' - new_cml.write(line) -new_cml.close() -os.rename(outp, inp) - -# done! diff --git a/pypy/module/_cppyy/capi/__init__.py b/pypy/module/_cppyy/capi/__init__.py --- a/pypy/module/_cppyy/capi/__init__.py +++ b/pypy/module/_cppyy/capi/__init__.py @@ -1,16 +1,6 @@ from rpython.rtyper.lltypesystem import rffi, lltype -# There are two possible ways of accessing the backend through the reflection -# C-API: built it into pypy-c, or load it dynamically. The latter is preferred -# (and is the default) for use with Reflex. B/c of some builtin pythonizations, -# the former is recommended (for now) with CINT. - -# Note: if builtin_capi is chosen, then inside builtin_capi.py, there is still -# the selection of the desired backend (default is Reflex). - -# choose C-API access method: from pypy.module._cppyy.capi.loadable_capi import * -#from pypy.module._cppyy.capi.builtin_capi import * from pypy.module._cppyy.capi.capi_types import C_OBJECT,\ C_NULL_TYPE, C_NULL_OBJECT diff --git a/pypy/module/_cppyy/capi/builtin_capi.py b/pypy/module/_cppyy/capi/builtin_capi.py deleted file mode 100644 --- a/pypy/module/_cppyy/capi/builtin_capi.py +++ /dev/null @@ -1,590 +0,0 @@ -from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib.rarithmetic import intmask -from rpython.rlib import jit - -import cling_capi as backend - -from pypy.module._cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\ - C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_FUNC_PTR - -identify = backend.identify -pythonize = backend.pythonize -register_pythonizations = backend.register_pythonizations -std_string_name = backend.std_string_name - -ts_reflect = backend.ts_reflect -ts_call = backend.ts_call -ts_memory = backend.ts_memory -ts_helper = backend.ts_helper - -def verify_backend(space): - return True # by definition - -c_load_dictionary = backend.c_load_dictionary - -# name to opaque C++ scope representation ------------------------------------ -_c_num_scopes = rffi.llexternal( - "cppyy_num_scopes", - [C_SCOPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_num_scopes(space, cppscope): - return _c_num_scopes(cppscope.handle) -_c_scope_name = rffi.llexternal( - "cppyy_scope_name", - [C_SCOPE, rffi.INT], rffi.CCHARP, - compilation_info = backend.eci) -def c_scope_name(space, cppscope, iscope): - return charp2str_free(space, _c_scope_name(cppscope.handle, iscope)) - -_c_resolve_name = rffi.llexternal( - "cppyy_resolve_name", - [rffi.CCHARP], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_resolve_name(space, name): - return charp2str_free(space, _c_resolve_name(name)) -_c_get_scope_opaque = rffi.llexternal( - "cppyy_get_scope", - [rffi.CCHARP], C_SCOPE, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_get_scope_opaque(space, name): - return _c_get_scope_opaque(name) -_c_actual_class = rffi.llexternal( - "cppyy_actual_class", - [C_TYPE, C_OBJECT], C_TYPE, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_actual_class(space, cppclass, cppobj): - return _c_actual_class(cppclass.handle, cppobj) - -# memory management ---------------------------------------------------------- -_c_allocate = rffi.llexternal( - "cppyy_allocate", - [C_TYPE], C_OBJECT, - releasegil=ts_memory, - compilation_info=backend.eci) -def c_allocate(space, cppclass): - return _c_allocate(cppclass.handle) -_c_deallocate = rffi.llexternal( - "cppyy_deallocate", - [C_TYPE, C_OBJECT], lltype.Void, - releasegil=ts_memory, - compilation_info=backend.eci) -def c_deallocate(space, cppclass, cppobject): - _c_deallocate(cppclass.handle, cppobject) -_c_destruct = rffi.llexternal( - "cppyy_destruct", - [C_TYPE, C_OBJECT], lltype.Void, - releasegil=ts_call, - compilation_info=backend.eci) -def c_destruct(space, cppclass, cppobject): - _c_destruct(cppclass.handle, cppobject) - -# method/function dispatching ------------------------------------------------ -_c_call_v = rffi.llexternal( - "cppyy_call_v", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], lltype.Void, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_v(space, cppmethod, cppobject, nargs, args): - _c_call_v(cppmethod, cppobject, nargs, args) -_c_call_b = rffi.llexternal( - "cppyy_call_b", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.UCHAR, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_b(space, cppmethod, cppobject, nargs, args): - return _c_call_b(cppmethod, cppobject, nargs, args) -_c_call_c = rffi.llexternal( - "cppyy_call_c", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.CHAR, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_c(space, cppmethod, cppobject, nargs, args): - return _c_call_c(cppmethod, cppobject, nargs, args) -_c_call_h = rffi.llexternal( - "cppyy_call_h", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.SHORT, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_h(space, cppmethod, cppobject, nargs, args): - return _c_call_h(cppmethod, cppobject, nargs, args) -_c_call_i = rffi.llexternal( - "cppyy_call_i", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.INT, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_i(space, cppmethod, cppobject, nargs, args): - return _c_call_i(cppmethod, cppobject, nargs, args) -_c_call_l = rffi.llexternal( - "cppyy_call_l", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONG, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_l(space, cppmethod, cppobject, nargs, args): - return _c_call_l(cppmethod, cppobject, nargs, args) -_c_call_ll = rffi.llexternal( - "cppyy_call_ll", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONGLONG, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_ll(space, cppmethod, cppobject, nargs, args): - return _c_call_ll(cppmethod, cppobject, nargs, args) -_c_call_f = rffi.llexternal( - "cppyy_call_f", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.FLOAT, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_f(space, cppmethod, cppobject, nargs, args): - return _c_call_f(cppmethod, cppobject, nargs, args) -_c_call_d = rffi.llexternal( - "cppyy_call_d", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.DOUBLE, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_d(space, cppmethod, cppobject, nargs, args): - return _c_call_d(cppmethod, cppobject, nargs, args) -_c_call_ld = rffi.llexternal( - "cppyy_call_ld", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONGDOUBLE, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_ld(space, cppmethod, cppobject, nargs, args): - return _c_call_ld(cppmethod, cppobject, nargs, args) - -_c_call_r = rffi.llexternal( - "cppyy_call_r", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.VOIDP, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_r(space, cppmethod, cppobject, nargs, args): - return _c_call_r(cppmethod, cppobject, nargs, args) -_c_call_s = rffi.llexternal( - "cppyy_call_s", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, rffi.SIZE_TP], rffi.CCHARP, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_s(space, cppmethod, cppobject, nargs, args): - length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw') - try: - cstr = _c_call_s(cppmethod, cppobject, nargs, args, length) - cstr_len = intmask(length[0]) - finally: - lltype.free(length, flavor='raw') - return cstr, cstr_len - -_c_constructor = rffi.llexternal( - "cppyy_constructor", - [C_METHOD, C_TYPE, rffi.INT, rffi.VOIDP], C_OBJECT, - releasegil=ts_call, - compilation_info=backend.eci) -def c_constructor(space, cppmethod, cppobject, nargs, args): - return _c_constructor(cppmethod, cppobject, nargs, args) -_c_call_o = rffi.llexternal( - "cppyy_call_o", - [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, C_TYPE], rffi.LONG, - releasegil=ts_call, - compilation_info=backend.eci) -def c_call_o(space, method, cppobj, nargs, args, cppclass): - return _c_call_o(method, cppobj, nargs, args, cppclass.handle) - -_c_get_function_address = rffi.llexternal( - "cppyy_get_function_address", - [C_SCOPE, C_INDEX], C_FUNC_PTR, - releasegil=ts_reflect, - compilation_info=backend.eci, - random_effects_on_gcobjs=False) -def c_get_function_address(space, cppscope, index): - return _c_get_function_address(cppscope.handle, index) - -# handling of function argument buffer --------------------------------------- -_c_allocate_function_args = rffi.llexternal( - "cppyy_allocate_function_args", - [rffi.SIZE_T], rffi.VOIDP, - releasegil=ts_memory, - compilation_info=backend.eci) -def c_allocate_function_args(space, size): - return _c_allocate_function_args(size) -_c_deallocate_function_args = rffi.llexternal( - "cppyy_deallocate_function_args", - [rffi.VOIDP], lltype.Void, - releasegil=ts_memory, - compilation_info=backend.eci) -def c_deallocate_function_args(space, args): - _c_deallocate_function_args(args) -_c_function_arg_sizeof = rffi.llexternal( - "cppyy_function_arg_sizeof", - [], rffi.SIZE_T, - releasegil=ts_memory, - compilation_info=backend.eci, - random_effects_on_gcobjs=False) [email protected] -def c_function_arg_sizeof(space): - return _c_function_arg_sizeof() -_c_function_arg_typeoffset = rffi.llexternal( - "cppyy_function_arg_typeoffset", - [], rffi.SIZE_T, - releasegil=ts_memory, - compilation_info=backend.eci, - random_effects_on_gcobjs=False) [email protected] -def c_function_arg_typeoffset(space): - return _c_function_arg_typeoffset() - -# scope reflection information ----------------------------------------------- -_c_is_namespace = rffi.llexternal( - "cppyy_is_namespace", - [C_SCOPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_namespace(space, scope): - return _c_is_namespace(scope) -_c_is_template = rffi.llexternal( - "cppyy_is_template", - [rffi.CCHARP], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_template(space, name): - return _c_is_template(name) -_c_is_abstract = rffi.llexternal( - "cppyy_is_abstract", - [C_SCOPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_abstract(space, cpptype): - return _c_is_abstract(cpptype) -_c_is_enum = rffi.llexternal( - "cppyy_is_enum", - [rffi.CCHARP], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_enum(space, name): - return _c_is_enum(name) - -# type/class reflection information ------------------------------------------ -_c_final_name = rffi.llexternal( - "cppyy_final_name", - [C_TYPE], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_final_name(space, cpptype): - return charp2str_free(space, _c_final_name(cpptype)) -_c_scoped_final_name = rffi.llexternal( - "cppyy_scoped_final_name", - [C_TYPE], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_scoped_final_name(space, cpptype): - return charp2str_free(space, _c_scoped_final_name(cpptype)) -_c_has_complex_hierarchy = rffi.llexternal( - "cppyy_has_complex_hierarchy", - [C_TYPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_has_complex_hierarchy(space, cpptype): - return _c_has_complex_hierarchy(cpptype) -_c_num_bases = rffi.llexternal( - "cppyy_num_bases", - [C_TYPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_num_bases(space, cppclass): - return _c_num_bases(cppclass.handle) -_c_base_name = rffi.llexternal( - "cppyy_base_name", - [C_TYPE, rffi.INT], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_base_name(space, cppclass, base_index): - return charp2str_free(space, _c_base_name(cppclass.handle, base_index)) -_c_is_subtype = rffi.llexternal( - "cppyy_is_subtype", - [C_TYPE, C_TYPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci, - random_effects_on_gcobjs=False) [email protected] -def c_is_subtype(space, derived, base): - if derived == base: - return 1 - return _c_is_subtype(derived.handle, base.handle) - -_c_base_offset = rffi.llexternal( - "cppyy_base_offset", - [C_TYPE, C_TYPE, C_OBJECT, rffi.INT], rffi.LONG, # actually ptrdiff_t - releasegil=ts_reflect, - compilation_info=backend.eci, - random_effects_on_gcobjs=False) [email protected] -def c_base_offset(space, derived, base, address, direction): - if derived == base: - return 0 - return _c_base_offset(derived.handle, base.handle, address, direction) -def c_base_offset1(space, derived_h, base, address, direction): - return _c_base_offset(derived_h, base.handle, address, direction) - -# method/function reflection information ------------------------------------- -_c_num_methods = rffi.llexternal( - "cppyy_num_methods", - [C_SCOPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_num_methods(space, cppscope): - return _c_num_methods(cppscope.handle) -_c_method_index_at = rffi.llexternal( - "cppyy_method_index_at", - [C_SCOPE, rffi.INT], C_INDEX, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_index_at(space, cppscope, imethod): - return _c_method_index_at(cppscope.handle, imethod) -_c_method_indices_from_name = rffi.llexternal( - "cppyy_method_indices_from_name", - [C_SCOPE, rffi.CCHARP], C_INDEX_ARRAY, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_indices_from_name(space, cppscope, name): - indices = _c_method_indices_from_name(cppscope.handle, name) - if not indices: - return [] - py_indices = [] - i = 0 - index = indices[i] - while index != -1: - i += 1 - py_indices.append(index) - index = indices[i] - c_free(space, rffi.cast(rffi.VOIDP, indices)) # c_free defined below - return py_indices - -_c_method_name = rffi.llexternal( - "cppyy_method_name", - [C_SCOPE, C_INDEX], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_name(space, cppscope, index): - return charp2str_free(space, _c_method_name(cppscope.handle, index)) -_c_method_result_type = rffi.llexternal( - "cppyy_method_result_type", - [C_SCOPE, C_INDEX], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_result_type(space, cppscope, index): - return charp2str_free(space, _c_method_result_type(cppscope.handle, index)) -_c_method_num_args = rffi.llexternal( - "cppyy_method_num_args", - [C_SCOPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_num_args(space, cppscope, index): - return _c_method_num_args(cppscope.handle, index) -_c_method_req_args = rffi.llexternal( - "cppyy_method_req_args", - [C_SCOPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_req_args(space, cppscope, index): - return _c_method_req_args(cppscope.handle, index) -_c_method_arg_type = rffi.llexternal( - "cppyy_method_arg_type", - [C_SCOPE, C_INDEX, rffi.INT], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_arg_type(space, cppscope, index, arg_index): - return charp2str_free(space, _c_method_arg_type(cppscope.handle, index, arg_index)) -_c_method_arg_default = rffi.llexternal( - "cppyy_method_arg_default", - [C_SCOPE, C_INDEX, rffi.INT], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_arg_default(space, cppscope, index, arg_index): - return charp2str_free(space, _c_method_arg_default(cppscope.handle, index, arg_index)) -_c_method_signature = rffi.llexternal( - "cppyy_method_signature", - [C_SCOPE, C_INDEX], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_signature(space, cppscope, index): - return charp2str_free(space, _c_method_signature(cppscope.handle, index)) - -_c_method_is_template = rffi.llexternal( - "cppyy_method_is_template", - [C_SCOPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_method_is_template(space, cppscope, index): - return _c_method_is_template(cppscope.handle, index) -_c_method_num_template_args = rffi.llexternal( - "cppyy_method_num_template_args", - [C_SCOPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -_c_method_template_arg_name = rffi.llexternal( - "cppyy_method_template_arg_name", - [C_SCOPE, C_INDEX, C_INDEX], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_template_args(space, cppscope, index): - nargs = _c_method_num_template_args(cppscope.handle, index) - args = [c_resolve_name(space, - charp2str_free(space, _c_method_template_arg_name(cppscope.handle, index, iarg))) - for iarg in range(nargs)] - return args - -_c_get_method = rffi.llexternal( - "cppyy_get_method", - [C_SCOPE, C_INDEX], C_METHOD, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_get_method(space, cppscope, index): - return _c_get_method(cppscope.handle, index) -_c_get_global_operator = rffi.llexternal( - "cppyy_get_global_operator", - [C_SCOPE, C_SCOPE, C_SCOPE, rffi.CCHARP], WLAVC_INDEX, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_get_global_operator(space, nss, lc, rc, op): - if nss is not None: - return _c_get_global_operator(nss.handle, lc.handle, rc.handle, op) - return rffi.cast(WLAVC_INDEX, -1) - -# method properties ---------------------------------------------------------- -_c_is_constructor = rffi.llexternal( - "cppyy_is_constructor", - [C_TYPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_constructor(space, cppclass, index): - return _c_is_constructor(cppclass.handle, index) -_c_is_staticmethod = rffi.llexternal( - "cppyy_is_staticmethod", - [C_TYPE, C_INDEX], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_staticmethod(space, cppclass, index): - return _c_is_staticmethod(cppclass.handle, index) - -# data member reflection information ----------------------------------------- -_c_num_datamembers = rffi.llexternal( - "cppyy_num_datamembers", - [C_SCOPE], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_num_datamembers(space, cppscope): - return _c_num_datamembers(cppscope.handle) -_c_datamember_name = rffi.llexternal( - "cppyy_datamember_name", - [C_SCOPE, rffi.INT], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_datamember_name(space, cppscope, datamember_index): - return charp2str_free(space, _c_datamember_name(cppscope.handle, datamember_index)) -_c_datamember_type = rffi.llexternal( - "cppyy_datamember_type", - [C_SCOPE, rffi.INT], rffi.CCHARP, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_datamember_type(space, cppscope, datamember_index): - return charp2str_free(space, _c_datamember_type(cppscope.handle, datamember_index)) -_c_datamember_offset = rffi.llexternal( - "cppyy_datamember_offset", - [C_SCOPE, rffi.INT], rffi.LONG, # actually ptrdiff_t - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_datamember_offset(space, cppscope, datamember_index): - return _c_datamember_offset(cppscope.handle, datamember_index) - -_c_datamember_index = rffi.llexternal( - "cppyy_datamember_index", - [C_SCOPE, rffi.CCHARP], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_datamember_index(space, cppscope, name): - return _c_datamember_index(cppscope.handle, name) - -# data member properties ----------------------------------------------------- -_c_is_publicdata = rffi.llexternal( - "cppyy_is_publicdata", - [C_SCOPE, rffi.INT], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_publicdata(space, cppscope, datamember_index): - return _c_is_publicdata(cppscope.handle, datamember_index) -_c_is_staticdata = rffi.llexternal( - "cppyy_is_staticdata", - [C_SCOPE, rffi.INT], rffi.INT, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_is_staticdata(space, cppscope, datamember_index): - return _c_is_staticdata(cppscope.handle, datamember_index) - -# misc helpers --------------------------------------------------------------- -_c_strtoll = rffi.llexternal( - "cppyy_strtoll", - [rffi.CCHARP], rffi.LONGLONG, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_strtoll(space, svalue): - return _c_strtoll(svalue) -_c_strtoull = rffi.llexternal( - "cppyy_strtoull", - [rffi.CCHARP], rffi.ULONGLONG, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_strtoull(space, svalue): - return _c_strtoull(svalue) -_c_free = rffi.llexternal( - "cppyy_free", - [rffi.VOIDP], lltype.Void, - releasegil=ts_memory, - compilation_info=backend.eci) -def c_free(space, voidp): - return _c_free(voidp) - -def charp2str_free(space, charp): - string = rffi.charp2str(charp) - voidp = rffi.cast(rffi.VOIDP, charp) - _c_free(voidp) - return string - -_c_charp2stdstring = rffi.llexternal( - "cppyy_charp2stdstring", - [rffi.CCHARP, rffi.SIZE_T], C_OBJECT, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_charp2stdstring(space, pystr, sz): - with rffi.scoped_view_charp(pystr) as cstr: - cppstr = _c_charp2stdstring(cstr, sz) - return cppstr -_c_stdstring2stdstring = rffi.llexternal( - "cppyy_stdstring2stdstring", - [C_OBJECT], C_OBJECT, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_stdstring2stdstring(space, cppobject): - return _c_stdstring2stdstring(cppobject) - -_c_stdvector_valuetype = rffi.llexternal( - "cppyy_stdvector_valuetype", - [rffi.CCHARP], rffi.CCHARP, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_stdvector_valuetype(space, pystr): - cstr = rffi.str2charp(pystr) - result = _c_stdvector_valuetype(cstr) - rffi.free_charp(cstr) - if result: - return charp2str_free(space, result) - return "" -_c_stdvector_valuesize = rffi.llexternal( - "cppyy_stdvector_valuesize", - [rffi.CCHARP], rffi.SIZE_T, - releasegil=ts_helper, - compilation_info=backend.eci) -def c_stdvector_valuesize(space, pystr): - cstr = rffi.str2charp(pystr) - result = _c_stdvector_valuesize(cstr) - rffi.free_charp(cstr) - return result diff --git a/pypy/module/_cppyy/capi/cling_capi.py b/pypy/module/_cppyy/capi/cling_capi.py deleted file mode 100644 --- a/pypy/module/_cppyy/capi/cling_capi.py +++ /dev/null @@ -1,196 +0,0 @@ -import py, os - -from pypy.objspace.std.iterobject import W_AbstractSeqIterObject - -from pypy.interpreter.error import OperationError -from pypy.interpreter.gateway import interp2app - -from rpython.translator.tool.cbuild import ExternalCompilationInfo -from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib.rarithmetic import intmask -from rpython.rlib import jit, libffi, rdynload - -from pypy.module._rawffi.array import W_ArrayInstance -from pypy.module._cppyy.capi.capi_types import C_OBJECT - -__all__ = ['identify', 'std_string_name', 'eci', 'c_load_dictionary'] - -pkgpath = py.path.local(__file__).dirpath().join(os.pardir) -srcpath = pkgpath.join("src") -incpath = pkgpath.join("include") - -import commands -(config_stat, incdir) = commands.getstatusoutput("root-config --incdir") - -if os.environ.get("ROOTSYS"): - if config_stat != 0: # presumably Reflex-only - rootincpath = [os.path.join(os.environ["ROOTSYS"], "interpreter/cling/include"), - os.path.join(os.environ["ROOTSYS"], "interpreter/llvm/inst/include"), - os.path.join(os.environ["ROOTSYS"], "include"),] - rootlibpath = [os.path.join(os.environ["ROOTSYS"], "lib64"), os.path.join(os.environ["ROOTSYS"], "lib")] - else: - rootincpath = [incdir] - rootlibpath = commands.getoutput("root-config --libdir").split() -else: - if config_stat == 0: - rootincpath = [incdir] - rootlibpath = commands.getoutput("root-config --libdir").split() - else: - rootincpath = [] - rootlibpath = [] - -def identify(): - return 'Cling' - -ts_reflect = False -ts_call = 'auto' -ts_memory = 'auto' -ts_helper = 'auto' - -std_string_name = 'std::basic_string<char>' - -# force loading (and exposure) of libCore symbols -with rffi.scoped_str2charp('libCore.so') as ll_libname: - _coredll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | rdynload.RTLD_NOW) - -# require local translator path to pickup common defs -from rpython.translator import cdir -translator_c_dir = py.path.local(cdir) - -eci = ExternalCompilationInfo( - separate_module_files=[srcpath.join("clingcwrapper.cxx")], - include_dirs=[incpath, translator_c_dir] + rootincpath, - includes=["clingcwrapper.h"], - library_dirs=rootlibpath, - libraries=["Cling"], - compile_extra=["-fno-strict-aliasing", "-std=c++11"], - use_cpp_linker=True, -) - -_c_load_dictionary = rffi.llexternal( - "cppyy_load_dictionary", - [rffi.CCHARP], rdynload.DLLHANDLE, - releasegil=False, - compilation_info=eci) - -def c_load_dictionary(name): - pch = _c_load_dictionary(name) - return pch - -_c_stdstring2charp = rffi.llexternal( - "cppyy_stdstring2charp", - [C_OBJECT, rffi.SIZE_TP], rffi.CCHARP, - releasegil=ts_helper, - compilation_info=eci) -def c_stdstring2charp(space, cppstr): - sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw') - try: - cstr = _c_stdstring2charp(cppstr, sz) - cstr_len = intmask(sz[0]) - finally: - lltype.free(sz, flavor='raw') - return rffi.charpsize2str(cstr, cstr_len) - -# TODO: factor these out ... -# pythonizations - -# -# std::string behavior -def stdstring_c_str(space, w_self): - """Return a python string taking into account \0""" - - from pypy.module._cppyy import interp_cppyy - cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, can_be_None=False) - return space.wrap(c_stdstring2charp(space, cppstr._rawobject)) - -# -# std::vector behavior -class W_STLVectorIter(W_AbstractSeqIterObject): - _immutable_fields_ = ['overload', 'len']#'data', 'converter', 'len', 'stride', 'vector'] - - def __init__(self, space, w_vector): - W_AbstractSeqIterObject.__init__(self, w_vector) - # TODO: this should live in rpythonize.py or something so that the - # imports can move to the top w/o getting circles - from pypy.module._cppyy import interp_cppyy - assert isinstance(w_vector, interp_cppyy.W_CPPInstance) - vector = space.interp_w(interp_cppyy.W_CPPInstance, w_vector) - self.overload = vector.cppclass.get_overload("__getitem__") - - from pypy.module._cppyy import capi - v_type = capi.c_stdvector_valuetype(space, vector.cppclass.name) - v_size = capi.c_stdvector_valuesize(space, vector.cppclass.name) - - if not v_type or not v_size: - raise NotImplementedError # fallback on getitem - - w_arr = vector.cppclass.get_overload("data").call(w_vector, []) - arr = space.interp_w(W_ArrayInstance, w_arr, can_be_None=True) - if not arr: - raise OperationError(space.w_StopIteration, space.w_None) - - self.data = rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space))) - - from pypy.module._cppyy import converter - self.converter = converter.get_converter(space, v_type, '') - self.len = space.uint_w(vector.cppclass.get_overload("size").call(w_vector, [])) - self.stride = v_size - - def descr_next(self, space): - if self.w_seq is None: - raise OperationError(space.w_StopIteration, space.w_None) - if self.len <= self.index: - self.w_seq = None - raise OperationError(space.w_StopIteration, space.w_None) - try: - from pypy.module._cppyy import capi # TODO: refector - offset = capi.direct_ptradd(rffi.cast(C_OBJECT, self.data), self.index*self.stride) - w_item = self.converter.from_memory(space, space.w_None, space.w_None, offset) - except OperationError as e: - self.w_seq = None - if not e.match(space, space.w_IndexError): - raise - raise OperationError(space.w_StopIteration, space.w_None) - self.index += 1 - return w_item - -def stdvector_iter(space, w_self): - return W_STLVectorIter(space, w_self) - -# setup pythonizations for later use at run-time -_pythonizations = {} -def register_pythonizations(space): - "NOT_RPYTHON" - - allfuncs = [ - - ### std::string - stdstring_c_str, - - ### std::vector - stdvector_iter, - - ] - - for f in allfuncs: - _pythonizations[f.__name__] = space.wrap(interp2app(f)) - -def _method_alias(space, w_pycppclass, m1, m2): - space.setattr(w_pycppclass, space.wrap(m1), - space.getattr(w_pycppclass, space.wrap(m2))) - -def pythonize(space, name, w_pycppclass): - if name == "string": - space.setattr(w_pycppclass, space.wrap("c_str"), _pythonizations["stdstring_c_str"]) - _method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str") - _method_alias(space, w_pycppclass, "__str__", "c_str") - - if "vector" in name[:11]: # len('std::vector') == 11 - from pypy.module._cppyy import capi - v_type = capi.c_stdvector_valuetype(space, name) - if v_type: - space.setattr(w_pycppclass, space.wrap("value_type"), space.wrap(v_type)) - v_size = capi.c_stdvector_valuesize(space, name) - if v_size: - space.setattr(w_pycppclass, space.wrap("value_size"), space.wrap(v_size)) - space.setattr(w_pycppclass, space.wrap("__iter__"), _pythonizations["stdvector_iter"]) diff --git a/pypy/module/_cppyy/include/clingcwrapper.h b/pypy/module/_cppyy/include/clingcwrapper.h deleted file mode 100644 --- a/pypy/module/_cppyy/include/clingcwrapper.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef CPPYY_CLINGCWRAPPER -#define CPPYY_CLINGCWRAPPER - -#include "capi.h" - -#ifdef __cplusplus -extern "C" { -#endif // ifdef __cplusplus - - /* misc helpers */ - void* cppyy_load_dictionary(const char* lib_name); - -#ifdef __cplusplus -} -#endif // ifdef __cplusplus - -// TODO: pick up from llvm-config --cxxflags -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#ifndef __STDC_CONSTANT_MACROS -#define __STDC_CONSTANT_MACROS -#endif - -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif - -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS -#endif - -// Wrapper callback: except this to become available from Cling directly -typedef void (*CPPYY_Cling_Wrapper_t)(void*, int, void**, void*); - -#endif // ifndef CPPYY_CLINGCWRAPPER diff --git a/pypy/module/_cppyy/include/cpp_cppyy.h b/pypy/module/_cppyy/include/cpp_cppyy.h deleted file mode 100644 --- a/pypy/module/_cppyy/include/cpp_cppyy.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef PYROOT_CPPYY_H -#define PYROOT_CPPYY_H - -// Standard -#include <string> -#include <vector> -#include <stddef.h> - -// ROOT types -typedef long Long_t; -typedef unsigned long ULong_t; -typedef long long Long64_t; -typedef unsigned long long ULong64_t; -typedef float Float_t; -typedef double Double_t; -typedef long double LongDouble_t; -typedef bool Bool_t; -typedef char Char_t; -typedef unsigned char UChar_t; -typedef short Short_t; -typedef unsigned short UShort_t; -typedef int Int_t; -typedef unsigned int UInt_t; - -namespace Cppyy { - typedef ptrdiff_t TCppScope_t; - typedef TCppScope_t TCppType_t; - typedef void* TCppObject_t; - typedef ptrdiff_t TCppMethod_t; - - typedef Long_t TCppIndex_t; - typedef void* TCppFuncAddr_t; - -// name to opaque C++ scope representation ----------------------------------- - TCppIndex_t GetNumScopes( TCppScope_t parent ); - std::string GetScopeName( TCppScope_t parent, TCppIndex_t iscope ); - std::string ResolveName( const std::string& cppitem_name ); - TCppScope_t GetScope( const std::string& scope_name ); - TCppType_t GetActualClass( TCppType_t klass, TCppObject_t obj ); - size_t SizeOf( TCppType_t klass ); - - Bool_t IsBuiltin( const std::string& type_name ); - Bool_t IsComplete( const std::string& type_name ); - - extern TCppScope_t gGlobalScope; // for fast access - -// memory management --------------------------------------------------------- - TCppObject_t Allocate( TCppType_t type ); - void Deallocate( TCppType_t type, TCppObject_t instance ); - TCppObject_t Construct( TCppType_t type ); - void Destruct( TCppType_t type, TCppObject_t instance ); - -// method/function dispatching ----------------------------------------------- - void CallV( TCppMethod_t method, TCppObject_t self, void* args ); - UChar_t CallB( TCppMethod_t method, TCppObject_t self, void* args ); - Char_t CallC( TCppMethod_t method, TCppObject_t self, void* args ); - Short_t CallH( TCppMethod_t method, TCppObject_t self, void* args ); - Int_t CallI( TCppMethod_t method, TCppObject_t self, void* args ); - Long_t CallL( TCppMethod_t method, TCppObject_t self, void* args ); - Long64_t CallLL( TCppMethod_t method, TCppObject_t self, void* args ); - Float_t CallF( TCppMethod_t method, TCppObject_t self, void* args ); - Double_t CallD( TCppMethod_t method, TCppObject_t self, void* args ); - LongDouble_t CallLD( TCppMethod_t method, TCppObject_t self, void* args ); - void* CallR( TCppMethod_t method, TCppObject_t self, void* args ); - Char_t* CallS( TCppMethod_t method, TCppObject_t self, void* args, size_t* length ); - TCppObject_t CallConstructor( TCppMethod_t method, TCppType_t type, void* args ); - void CallDestructor( TCppType_t type, TCppObject_t self ); - TCppObject_t CallO( TCppMethod_t method, TCppObject_t self, void* args, TCppType_t result_type ); - - TCppFuncAddr_t GetFunctionAddress( TCppScope_t scope, TCppIndex_t imeth ); - -// handling of function argument buffer -------------------------------------- - void* AllocateFunctionArgs( size_t nargs ); - void DeallocateFunctionArgs( void* args ); - size_t GetFunctionArgSizeof(); - size_t GetFunctionArgTypeoffset(); - -// scope reflection information ---------------------------------------------- - Bool_t IsNamespace( TCppScope_t scope ); - Bool_t IsTemplate( const std::string& template_name ); - Bool_t IsAbstract( TCppType_t type ); - Bool_t IsEnum( const std::string& type_name ); - -// class reflection information ---------------------------------------------- - std::string GetFinalName( TCppType_t type ); - std::string GetScopedFinalName( TCppType_t type ); - Bool_t HasComplexHierarchy( TCppType_t type ); - TCppIndex_t GetNumBases( TCppType_t type ); - std::string GetBaseName( TCppType_t type, TCppIndex_t ibase ); - Bool_t IsSubtype( TCppType_t derived, TCppType_t base ); - void AddSmartPtrType( const std::string& ); - Bool_t IsSmartPtr( const std::string& ); - -// calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0 - ptrdiff_t GetBaseOffset( - TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror = false ); - -// method/function reflection information ------------------------------------ - TCppIndex_t GetNumMethods( TCppScope_t scope ); - TCppIndex_t GetMethodIndexAt( TCppScope_t scope, TCppIndex_t imeth ); - std::vector< TCppMethod_t > GetMethodsFromName( TCppScope_t scope, const std::string& name ); - - TCppMethod_t GetMethod( TCppScope_t scope, TCppIndex_t imeth ); - - std::string GetMethodName( TCppMethod_t ); - std::string GetMethodResultType( TCppMethod_t ); - TCppIndex_t GetMethodNumArgs( TCppMethod_t ); - TCppIndex_t GetMethodReqArgs( TCppMethod_t ); - std::string GetMethodArgName( TCppMethod_t, int iarg ); - std::string GetMethodArgType( TCppMethod_t, int iarg ); - std::string GetMethodArgDefault( TCppMethod_t, int iarg ); - std::string GetMethodSignature( TCppScope_t scope, TCppIndex_t imeth ); - Bool_t IsConstMethod( TCppMethod_t ); - - Bool_t IsMethodTemplate( TCppMethod_t ); - TCppIndex_t GetMethodNumTemplateArgs( TCppScope_t scope, TCppIndex_t imeth ); - std::string GetMethodTemplateArgName( TCppScope_t scope, TCppIndex_t imeth, TCppIndex_t iarg ); - - TCppIndex_t GetGlobalOperator( - TCppType_t scope, TCppType_t lc, TCppScope_t rc, const std::string& op ); - -// method properties --------------------------------------------------------- - Bool_t IsConstructor( TCppMethod_t method ); - Bool_t IsPublicMethod( TCppMethod_t method ); - Bool_t IsStaticMethod( TCppMethod_t method ); - -// data member reflection information ---------------------------------------- - TCppIndex_t GetNumDatamembers( TCppScope_t scope ); - std::string GetDatamemberName( TCppScope_t scope, TCppIndex_t idata ); - std::string GetDatamemberType( TCppScope_t scope, TCppIndex_t idata ); - ptrdiff_t GetDatamemberOffset( TCppScope_t scope, TCppIndex_t idata ); - TCppIndex_t GetDatamemberIndex( TCppScope_t scope, const std::string& name ); - -// data member properties ---------------------------------------------------- - Bool_t IsPublicData( TCppScope_t scope, TCppIndex_t idata ); - Bool_t IsStaticData( TCppScope_t scope, TCppIndex_t idata ); - Bool_t IsConstData( TCppScope_t scope, TCppIndex_t idata ); - Bool_t IsEnumData( TCppScope_t scope, TCppIndex_t idata ); - Int_t GetDimensionSize( TCppScope_t scope, TCppIndex_t idata, int dimension ); - -} // namespace Cppyy - -#endif // ifndef PYROOT_CPPYY_H diff --git a/pypy/module/_cppyy/include/cppyy.h b/pypy/module/_cppyy/include/cppyy.h deleted file mode 100644 --- a/pypy/module/_cppyy/include/cppyy.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CPPYY_CPPYY -#define CPPYY_CPPYY - -#include "cpp_cppyy.h" - -#ifdef __cplusplus -struct CPPYY_G__DUMMY_FOR_CINT7 { -#else -typedef struct -#endif - void* fTypeName; - unsigned int fModifiers; -#ifdef __cplusplus -}; -#else -} CPPYY_G__DUMMY_FOR_CINT7; -#endif - -#ifdef __cplusplus -struct CPPYY_G__p2p { -#else -typedef struct { -#endif - long i; - int reftype; -#ifdef __cplusplus -}; -#else -} CPPYY_G__p2p; -#endif - - -#ifdef __cplusplus -struct CPPYY_G__value { -#else -typedef struct { -#endif - union { - double d; - long i; /* used to be int */ - struct CPPYY_G__p2p reftype; - char ch; - short sh; - int in; - float fl; - unsigned char uch; - unsigned short ush; - unsigned int uin; - unsigned long ulo; - long long ll; - unsigned long long ull; - long double ld; - } obj; - long ref; - int type; - int tagnum; - int typenum; - char isconst; - struct CPPYY_G__DUMMY_FOR_CINT7 dummyForCint7; -#ifdef __cplusplus -}; -#else -} CPPYY_G__value; -#endif - -#endif // CPPYY_CPPYY diff --git a/pypy/module/_cppyy/src/callcontext.h b/pypy/module/_cppyy/src/callcontext.h deleted file mode 100644 --- a/pypy/module/_cppyy/src/callcontext.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef PYROOT_TCALLCONTEXT_H -#define PYROOT_TCALLCONTEXT_H - -// Standard -#include <vector> - -//Bindings -#include "cpp_cppyy.h" - -//ROOT -#include "Rtypes.h" - -namespace PyROOT { - -// general place holder for function parameters - struct TParameter { - union Value { - Bool_t fBool; - Short_t fShort; - UShort_t fUShort; - Int_t fInt; - UInt_t fUInt; - Long_t fLong; - ULong_t fULong; - Long64_t fLongLong; - ULong64_t fULongLong; - Float_t fFloat; - Double_t fDouble; - LongDouble_t fLongDouble; - void* fVoidp; - } fValue; - void* fRef; - char fTypeCode; - }; - -// extra call information - struct TCallContext { - TCallContext( std::vector< TParameter >::size_type sz = 0 ) : fArgs( sz ), fFlags( 0 ) {} - - enum ECallFlags { - kNone = 0, - kIsSorted = 1, // if method overload priority determined - kIsCreator = 2, // if method creates python-owned objects - kIsConstructor = 4, // if method is a C++ constructor - kUseHeuristics = 8, // if method applies heuristics memory policy - kUseStrict = 16, // if method applies strict memory policy - kManageSmartPtr = 32, // if executor should manage smart pointers - kReleaseGIL = 64, // if method should release the GIL - kFast = 128, // if method should NOT handle signals - kSafe = 256 // if method should return on signals - }; - - // memory handling - static ECallFlags sMemoryPolicy; - static Bool_t SetMemoryPolicy( ECallFlags e ); - - // signal safety - static ECallFlags sSignalPolicy; - static Bool_t SetSignalPolicy( ECallFlags e ); - - // payload - std::vector< TParameter > fArgs; - UInt_t fFlags; - }; - - inline Bool_t IsSorted( UInt_t flags ) { - return flags & TCallContext::kIsSorted; - } - - inline Bool_t IsCreator( UInt_t flags ) { - return flags & TCallContext::kIsCreator; - } - - inline Bool_t IsConstructor( UInt_t flags ) { - return flags & TCallContext::kIsConstructor; - } - - inline Bool_t ManagesSmartPtr( TCallContext* ctxt ) { - return ctxt->fFlags & TCallContext::kManageSmartPtr; - } - - inline Bool_t ReleasesGIL( UInt_t flags ) { - return flags & TCallContext::kReleaseGIL; - } - - inline Bool_t ReleasesGIL( TCallContext* ctxt ) { - return ctxt ? (ctxt->fFlags & TCallContext::kReleaseGIL) : kFALSE; - } - - inline Bool_t UseStrictOwnership( TCallContext* ctxt ) { - if ( ctxt && (ctxt->fFlags & TCallContext::kUseStrict) ) - return kTRUE; - if ( ctxt && (ctxt->fFlags & TCallContext::kUseHeuristics) ) - return kFALSE; - - return TCallContext::sMemoryPolicy == TCallContext::kUseStrict; - } - -} // namespace PyROOT - -#endif // !PYROOT_TCALLCONTEXT_H diff --git a/pypy/module/_cppyy/src/clingcwrapper.cxx b/pypy/module/_cppyy/src/clingcwrapper.cxx deleted file mode 100644 --- a/pypy/module/_cppyy/src/clingcwrapper.cxx +++ /dev/null @@ -1,1569 +0,0 @@ -// Bindings -#include "capi.h" -#include "cpp_cppyy.h" -#include "callcontext.h" - -// ROOT -#include "TBaseClass.h" -#include "TClass.h" -#include "TClassRef.h" -#include "TClassTable.h" -#include "TClassEdit.h" -#include "TCollection.h" -#include "TDataMember.h" -#include "TDataType.h" -#include "TError.h" -#include "TFunction.h" -#include "TGlobal.h" -#include "TInterpreter.h" -#include "TList.h" -#include "TMethod.h" -#include "TMethodArg.h" -#include "TROOT.h" -#include "TSystem.h" - -// Standard -#include <assert.h> -#include <algorithm> // for std::count -#include <dlfcn.h> -#include <map> -#include <set> -#include <sstream> -#include <stdlib.h> // for getenv - -// temp -#include <iostream> -typedef PyROOT::TParameter TParameter; -// --temp - - -// small number that allows use of stack for argument passing -const int SMALL_ARGS_N = 8; - -// data for life time management --------------------------------------------- -typedef std::vector< TClassRef > ClassRefs_t; -static ClassRefs_t g_classrefs( 1 ); -static const ClassRefs_t::size_type GLOBAL_HANDLE = 1; - -typedef std::map< std::string, ClassRefs_t::size_type > Name2ClassRefIndex_t; -static Name2ClassRefIndex_t g_name2classrefidx; - -typedef std::map< Cppyy::TCppMethod_t, CallFunc_t* > Method2CallFunc_t; -static Method2CallFunc_t g_method2callfunc; - -typedef std::vector< TGlobal* > GlobalVars_t; -static GlobalVars_t g_globalvars; - -// data ---------------------------------------------------------------------- -Cppyy::TCppScope_t Cppyy::gGlobalScope = GLOBAL_HANDLE; - -// smart pointer types -static std::set< std::string > gSmartPtrTypes = - { "auto_ptr", "shared_ptr", "weak_ptr", "unique_ptr" }; - -// configuration -static bool gEnableFastPath = true; - - -// global initialization ----------------------------------------------------- -namespace { - -class ApplicationStarter { -public: - ApplicationStarter() { - // setup dummy holders for global and std namespaces - assert( g_classrefs.size() == GLOBAL_HANDLE ); - g_name2classrefidx[ "" ] = GLOBAL_HANDLE; - g_classrefs.push_back(TClassRef("")); - // aliases for std (setup already in pythonify) - g_name2classrefidx[ "std" ] = GLOBAL_HANDLE+1; - g_name2classrefidx[ "::std" ] = GLOBAL_HANDLE+1; - g_classrefs.push_back(TClassRef("std")); - // add a dummy global to refer to as null at index 0 - g_globalvars.push_back( nullptr ); - // disable fast path if requested - if (getenv("CPPYY_DISABLE_FASTPATH")) gEnableFastPath = false; - } - - ~ApplicationStarter() { - for ( auto ifunc : g_method2callfunc ) - gInterpreter->CallFunc_Delete( ifunc.second ); - } -} _applicationStarter; - -} // unnamed namespace - -// local helpers ------------------------------------------------------------- -static inline -TClassRef& type_from_handle( Cppyy::TCppScope_t scope ) -{ - assert( (ClassRefs_t::size_type) scope < g_classrefs.size() ); - return g_classrefs[ (ClassRefs_t::size_type)scope ]; -} - -// type_from_handle to go here -static inline -TFunction* type_get_method( Cppyy::TCppType_t klass, Cppyy::TCppIndex_t idx ) -{ - TClassRef& cr = type_from_handle( klass ); - if ( cr.GetClass() ) - return (TFunction*)cr->GetListOfMethods()->At( idx ); - assert( klass == (Cppyy::TCppType_t)GLOBAL_HANDLE ); - return (TFunction*)idx; -} - -static inline -Cppyy::TCppScope_t declaring_scope( Cppyy::TCppMethod_t method ) -{ - TMethod* m = dynamic_cast<TMethod*>( (TFunction*)method ); - if ( m ) return Cppyy::GetScope( m->GetClass()->GetName() ); - return (Cppyy::TCppScope_t)GLOBAL_HANDLE; -} - -static inline -char* cppstring_to_cstring( const std::string& cppstr ) { - char* cstr = (char*)malloc( cppstr.size() + 1 ); - memcpy( cstr, cppstr.c_str(), cppstr.size() + 1 ); - return cstr; -} - - -// name to opaque C++ scope representation ----------------------------------- -Cppyy::TCppIndex_t Cppyy::GetNumScopes( TCppScope_t scope ) -{ - TClassRef& cr = type_from_handle( scope ); - if ( cr.GetClass() ) { - // this is expensive, but this function is only ever called for __dir__ - // TODO: rewrite __dir__ on the C++ side for a single loop - std::string s = GetFinalName( scope ); s += "::"; - gClassTable->Init(); - const int N = gClassTable->Classes(); - int total = 0; - for ( int i = 0; i < N; ++i ) { - if ( strncmp( gClassTable->Next(), s.c_str(), s.size() ) == 0 ) - total += 1; - } - return total; - } - assert( scope == (TCppScope_t)GLOBAL_HANDLE ); - return gClassTable->Classes(); -} - -std::string Cppyy::GetScopeName( TCppScope_t parent, TCppIndex_t iscope ) -{ -// Retrieve the scope name of the scope indexed with iscope in parent. - TClassRef& cr = type_from_handle( parent ); - if ( cr.GetClass() ) { - // this is expensive (quadratic in number of classes), but only ever called for __dir__ - // TODO: rewrite __dir__ on the C++ side for a single loop _______________________________________________ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
