From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 13 20:34:22 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 78DF016A40B for ; Fri, 13 Jul 2007 20:34:22 +0000 (UTC) (envelope-from mathieu.prevot@gmail.com) Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.191]) by mx1.freebsd.org (Postfix) with ESMTP id E94E813C494 for ; Fri, 13 Jul 2007 20:34:21 +0000 (UTC) (envelope-from mathieu.prevot@gmail.com) Received: by mu-out-0910.google.com with SMTP id w9so642103mue for ; Fri, 13 Jul 2007 13:34:20 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UASJW9xefEqMS9S9iW6K/RytK0DYUhwrf+P1AtTEnlemTqietwyTFVvO63nIWrF6if4rZA2GCyPUsqwzgus/YgI1RLghFEh1m8f0QzB1gGrm4W4J9Y/Y5BERQn+SM5+JA4UdujkPZv9nHwXLOOQjCbb0cvqjS8/7S/ErwTGKWxA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=lhIDQOya06LJprtqWn6vfgpv/NDyt066xRQ3NkuSECK7J95nGM2EqrXdl/scrpnll3ZLimuXHyMx6L4W5qsxtKjyFhmdSnB340BG17IRzds8BPl91LFBFga4EK2cZzM2lAXqmBPFJoSxSBO2Z6if1Twc0v4NX17bBcd/OiHeVOQ= Received: by 10.82.108.9 with SMTP id g9mr2520988buc.1184358860454; Fri, 13 Jul 2007 13:34:20 -0700 (PDT) Received: by 10.82.117.14 with HTTP; Fri, 13 Jul 2007 13:34:20 -0700 (PDT) Message-ID: <3e473cc60707131334u7cf75dbckd3a2b42b1815fbf8@mail.gmail.com> Date: Fri, 13 Jul 2007 22:34:20 +0200 From: "Mathieu Prevot" To: "Mike Meyer" In-Reply-To: <20070713153502.110b1c99@bhuda.mired.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <3e473cc60707131205s1a2912c3p9895832de54e6b94@mail.gmail.com> <3e473cc60707131212u1e3b4552v2dfc5c10cfe8e533@mail.gmail.com> <20070713153502.110b1c99@bhuda.mired.org> Cc: freebsd-hackers@freebsd.org, Joseph Koshy Subject: Re: python modules X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2007 20:34:22 -0000 2007/7/13, Mike Meyer : > On Fri, 13 Jul 2007 21:12:33 +0200 "Mathieu Prevot" wrote: > > This apparently got redirected without sufficient context, so I'm > guessing. I forgot to cc to hackers. > > 2007/7/13, Mathieu Prevot : > > > I learn that modules loaded with import fall into 4 general categories: > > > - code written in Python (.py) > > > - C or C++ extensions that have been compiled into shared libraries (or DLLs) > > These are *Python extensions* written in C or C++ (among other > things), not arbitrary shared object libraries (or .so's). > > > > - Packages containing collection of modules > > > - Built-in modles writen in C and linked into the Python interpreter > > > Why don't we use directly the libpmc library in C instead of rewritting > > > things in python ? > > Are you writing in Python now and want to use libpmc? Doing that is > one approach. I'm doing this. This approach _seems_ to be the easier way. > > I copied libpmc.so and tryed 'import libpmc'. I have: > > ImportError: dynamic module does not define init function (initlibpmc) > > To be expected. The init function is part of what turns it into a > Python extension library. > > > Are we really far from having a libpmc module ? > > There are at least two other approaches to getting access to libpmc > from Python: > > 1) Write a wrapper library that is a Python extensions and translates > calls. This work is in progress in fact, but I wanted to have ASAP access to pmc(3) with a minimum of (keyboard) effort. I don't care of docstrings. > 2) Use the ctypes python module to access libpmc. ctypes has been > bundled into 2.5, so that would be my preference. Just one less > thing to install. > > This is probably more appropriate in c.l.python, but it's hard to say > without context. I didn't tryed this module, rather (a bit) the ezpyinline module, coupled to `gcc -E /usr/src/lib/libpmc/libpmc.c` (no preprocessing with the module, only compilation). The ezpyinline module work like this: ---- #!/usr/bin/python import ezpyinline #step 1 code = r""" int helloworld() { printf("hello ezpyinline! "); } """ #step 2 ezc = ezpyinline.C(code) #step 3 ezc.helloworld() ---- I'll give ctypes a chance (when I have time :) )... thanks Mathieu