Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Last yeer I kudn't spel Engineer. Now I are won.


devel / comp.lang.python / Re: Embedding Python

SubjectAuthor
* Re: Embedding PythonFaraaz Mohammed
`- Re: Embedding PythonChris Angelico

1
Re: Embedding Python

<04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13526&group=comp.lang.python#13526

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:622a:1045:: with SMTP id f5mr23639676qte.392.1622633775607;
Wed, 02 Jun 2021 04:36:15 -0700 (PDT)
X-Received: by 2002:a05:620a:a4c:: with SMTP id j12mr26380375qka.33.1622633775344;
Wed, 02 Jun 2021 04:36:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Wed, 2 Jun 2021 04:36:15 -0700 (PDT)
In-Reply-To: <mailman.1024.1214928620.1044.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2409:4072:214:27f3:904f:bc26:1e0b:1bf5;
posting-account=UikV6QoAAABFYtieXOhHTMjnG5dc25LB
NNTP-Posting-Host: 2409:4072:214:27f3:904f:bc26:1e0b:1bf5
References: <mailman.1013.1214905216.1044.python-list@python.org>
<cuqak.10448$xZ.9476@nlpi070.nbdc.sbc.com> <mailman.1024.1214928620.1044.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com>
Subject: Re: Embedding Python
From: fara...@gmail.com (Faraaz Mohammed)
Injection-Date: Wed, 02 Jun 2021 11:36:15 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Faraaz Mohammed - Wed, 2 Jun 2021 11:36 UTC

On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote:
> Carsten Haese wrote:
> > python_code is a C string containing the raw bytes from your pyc file.
> > Casting that to a PyObject pointer will not magically transform it into
> > a Python code object.
> <scratching my head> well yeah, I kind of didn't think that through..
> A pyc file contains the following:
> >
> > 1) An 8 byte header containing a magic number.
> > 2) A "marshal" serialization of the code object.
> >
> > So, in order to transform those contents into a code object, you need to
> > skip the 8 byte header and an unmarshal the rest. Basically, replace the
> > line above with something like this:
> >
> > codeobj = PyMarshal_ReadObjectFromString(python_code+8, size-8);
> > mainobj = PyImport_ExecCodeModule("multiply", codeobj);
> >
> > where codeobj is of type (PyObject *).
> >
> > Once that works, add magic number checking and exception handling to taste.
> Thanks. That's exactly what I was looking for.

I tried exactly the same thing. but I am still hitting segmentation fault at PyImport_ExecCodeModule(). python version is 2.7.17

Re: Embedding Python

<mailman.504.1622657341.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13533&group=comp.lang.python#13533

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Embedding Python
Date: Thu, 3 Jun 2021 04:08:47 +1000
Lines: 33
Message-ID: <mailman.504.1622657341.3087.python-list@python.org>
References: <mailman.1013.1214905216.1044.python-list@python.org>
<cuqak.10448$xZ.9476@nlpi070.nbdc.sbc.com>
<mailman.1024.1214928620.1044.python-list@python.org>
<04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com>
<CAPTjJmp22AQMNrTD__izFuu+o0cf5FvP6=6GeaoQ9Li59iXmPw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de exL9BtpD7YuS8+L3Moj8EwiLkp0IPNpieDHia/ELZenw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=fvHtivDr;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'this:': 0.03;
'containing': 0.05; 'string': 0.05; 'hitting': 0.07; 'thing.':
0.07; 'byte': 0.09; 'fault': 0.09; 'segmentation': 0.09;
'subject:Python': 0.12; '2008': 0.16; 'chrisa': 0.16; 'for.':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'object,': 0.16; 'over,': 0.16; 'wrote:': 0.16; 'python': 0.16;
'thu,': 0.20; 'version': 0.22; 'exception': 0.23; "what's": 0.23;
"i'd": 0.23; 'to:addr:python-list': 0.23; 'header': 0.24; 'code':
0.24; 'skip:p 30': 0.26; 'tried': 0.26; 'jun': 0.27; "didn't":
0.29; 'replying': 0.29; 'think': 0.31; 'but': 0.31; 'raw': 0.32;
'to:name:python': 0.32; 'transform': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'using': 0.33; 'received:209.85.166':
0.33; 'header:In-Reply-To:1': 0.33; 'same': 0.34;
'received:google.com': 0.34; 'contains': 0.35; 'handling': 0.35;
'from:addr:gmail.com': 0.35; 'recommend': 0.37; "that's": 0.37;
'thanks.': 0.37; 'received:209.85': 0.38; 'file': 0.38; 'those':
0.38; 'something': 0.38; 'received:209': 0.38; 'going': 0.38;
'lot': 0.62; 'time.': 0.63; 'once': 0.64; 'your': 0.64; 'above':
0.65; 'july': 0.66; 'well': 0.66; 'years': 0.67; 'order': 0.68;
'exactly': 0.69; 'number.': 0.69; '2021': 0.84; 'casting': 0.84;
'figuring': 0.84; 'pointer': 0.84; 'magic': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=GFukvy6SGT2EX6QMqZ5u9nulQiVwzmwBAy0Kk9+Zbts=;
b=fvHtivDr29p/uzGXjnJ/FtZ342ysmzPM4GJ4Q2XpGvWFCC11IVIK4vH++teKsD+013
+ZME/uiqzOaUIff2lKPUS7gpa2ZVMS85LOBy/cUI5wyknfkWROlDgbFo2Ggx2EWw7/9x
MhcLL3mXhFHuLjXsdXe7APcL/SrwuxR4PHqUlcJD8F57ty9yaEfnqHf/nFHgrDfJoE6O
0qtnwKPkZZm81DKXrweRoqnwMgWDZR/pLuqzmuM9rDiT7UVniTU+VhSe5bpLoCq2NYvh
IVsMs8b61ZjWI59yp+boUQgVWnMs5F7WUGz1X8XMp2bu7d1LdDVd7YwkpDKb492wLt/T
aJow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=GFukvy6SGT2EX6QMqZ5u9nulQiVwzmwBAy0Kk9+Zbts=;
b=H+GH6Mx7ZLq57XE/7y/4ArjfrjDVWnhskM8Q84lmCjNKWiuwV+w8h8c2dCXWG6OMHn
22U98F8QceE1iBsWlo3vGW9fQF6oUqlv2Fsl1qBTV06PBzZ/nxY2Eva0CXVaAGM9ue3X
2NtRKoZNN94Q9woMTlnGcDPp6YoNv2kr1MbQEOWE2SDzNDpLsI66+7XGpEGmqNWrTqpG
BA+3ECFSrq8JXLrtrZtyqVI8UYKCrcUevuffquvUcHjhPOvvdxfnrnIFxLNXWksP8d5U
kygfDsH0W63p7Wlxn3CZK7wkCtq64+M7akYHHf6ShUeNbQt7kG/c4eb31tgyG+LI+kfH
vVkA==
X-Gm-Message-State: AOAM5306b6obAYaSCA7RgfnxZ9EhtpL8erC9fbwZpvvwW6rq0gXpbQcA
dRQc04I84/88dZlMnqSC2a+j10JrhfD9s0Yb7jYYm8pQ
X-Google-Smtp-Source: ABdhPJzgkJvXoQhWYM4bWvYzrbtKOSRp5j52TCqfiBgdXdIVezmmfXUzdL4QR43eoUYVbDPvMpnvwPV0YglRZUPBl0g=
X-Received: by 2002:a92:c689:: with SMTP id o9mr19234900ilg.297.1622657338446;
Wed, 02 Jun 2021 11:08:58 -0700 (PDT)
In-Reply-To: <04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmp22AQMNrTD__izFuu+o0cf5FvP6=6GeaoQ9Li59iXmPw@mail.gmail.com>
X-Mailman-Original-References: <mailman.1013.1214905216.1044.python-list@python.org>
<cuqak.10448$xZ.9476@nlpi070.nbdc.sbc.com>
<mailman.1024.1214928620.1044.python-list@python.org>
<04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com>
 by: Chris Angelico - Wed, 2 Jun 2021 18:08 UTC

On Thu, Jun 3, 2021 at 4:05 AM Faraaz Mohammed <faraazc@gmail.com> wrote:
>
> On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote:
> > Carsten Haese wrote:
> > > python_code is a C string containing the raw bytes from your pyc file.
> > > Casting that to a PyObject pointer will not magically transform it into
> > > a Python code object.
> > <scratching my head> well yeah, I kind of didn't think that through..
> > A pyc file contains the following:
> > >
> > > 1) An 8 byte header containing a magic number.
> > > 2) A "marshal" serialization of the code object.
> > >
> > > So, in order to transform those contents into a code object, you need to
> > > skip the 8 byte header and an unmarshal the rest. Basically, replace the
> > > line above with something like this:
> > >
> > > codeobj = PyMarshal_ReadObjectFromString(python_code+8, size-8);
> > > mainobj = PyImport_ExecCodeModule("multiply", codeobj);
> > >
> > > where codeobj is of type (PyObject *).
> > >
> > > Once that works, add magic number checking and exception handling to taste.
> > Thanks. That's exactly what I was looking for.
>
>
> I tried exactly the same thing. but I am still hitting segmentation fault at PyImport_ExecCodeModule(). python version is 2.7.17

You're replying to something from *thirteen years ago*. A lot has
changed in that time. I'd recommend starting over, figuring out what's
going on, and preferably, using Python 3.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor