Hello all,
I've got this question that has been nagging me for a few days now.
What are the reasons for us to have co_code as read-only? I've been
trying to get some info about it, but I kept hitting the wall.
Correct me if I'm wrong, but as far as I understand, co_code
represents the compiled bytecode that should be run when, for
instance, a function is called. Wouldn't it be beneficial for
programmers to be able to change the bytecode in runtime? I mean, one
can't, as far as I'm aware, change the bytecode by accident, so if the
programmer would wish to change a function at runtime, he could do so
at his own risk.
If there is a higher reason behind the read-only property of co_code,
I definitely fail to see it, and would like to know what it is. If
not, why aren't we allowed to write into it?
Thanks in advance,
Joćo Neves 4 1164
On Apr 2, 5:00*am, Joćo Neves <seve...@gmail.comwrote:
Hello all,
I've got this question that has been nagging me for a few days now.
What are the reasons for us to have co_code as read-only? I've been
trying to get some info about it, but I kept hitting the wall.
Correct me if I'm wrong, but as far as I understand, co_code
represents the compiled bytecode that should be run when, for
instance, a function is called. Wouldn't it be beneficial for
programmers to be able to change the bytecode in runtime? I mean, one
can't, as far as I'm aware, change the bytecode by accident, so if the
programmer would wish to change a function at runtime, he could do so
at his own risk.
If there is a higher reason behind the read-only property of co_code,
I definitely fail to see it, and would like to know what it is. If
not, why aren't we allowed to write into it?
Thanks in advance,
Joćo Neves
Are Python bytes codes Python byte codes? Do you foresee any machine-
dependent optimizations?
I'm not quite sure I understood your question, sorry.
And you won't. He's one of the resident trolls... Better killfile him
ASAP :)
Diez
On Apr 3, 4:43 am, Scott David Daniels <Scott.Dani...@Acm.Orgwrote:
Nope: If you change the code in-place, the whole stack's references
to where they were running would need to get updated to corresponding
locations in the new code. _That_ is a lot of work.
Ah, there it is. Now I get it, it makes perfect sense.
Looks like I'll have to stick to the usual mechanisms!
Thanks everyone!
---
Joćo Neves
JoĆ£o Neves wrote:
Let me give a very basic example. Say we have these two functions:
I suppose you mean
>>def inc(x): return x + 1
....
>>def dec(x): return x - 1
....
>>inc(1), dec(1)
(2, 0)
Examining the compiled bytecodes for these two functions:
>inc.func_code.co_code
'|\x00\x00d\x01\x00\x17}\x00\x00d\x00\x00S'
>dec.func_code.co_code
'|\x00\x00d\x01\x00\x18}\x00\x00d\x00\x00S'
Now suppose that I wanted to mess with inc, and have it behave like
dec.
>>inc.func_code = dec.func_code inc(1), dec(1)
(0, 0)
There you are, and there wasn't even a slight chance that you combined the
byte code with an incompatible function signature ;)
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matt Feinstein |
last post by:
Hi all--
I'm new to Python, and was somewhat taken aback to discover that the
core language lacks some basic numerical types (e.g., single-precision
float, short integers). I realize that there...
|
by: Alexander Grigoriev |
last post by:
I hope Mr. Stroustrup can give an answer to this question:
What was rationale behind the requirements to use an ampersand and a fully
qualified name of a function, to form a pointer to a member...
|
by: Howard Jess |
last post by:
Given the html at the end of this message, I see how
a DOM NodeList exhibits its "live" behavior; that is,
adding elements to a document can change any NodeList
variables, when there's *no* code...
|
by: Robert Latest |
last post by:
Hello,
I'm new in javascript programming (but am quite literate in HTML, CSS,
and C). It's amazing what one can do with JS and fairly modern browsers.
One thing that struck me as odd was that...
|
by: Christopher Benson-Manica |
last post by:
gets() is universally acknowledged to be broken and useless; however,
it is still part of the standard library. Why? Is there enough
conforming code out there using gets() to justify retaining...
| |
by: Bradford Chamberlain |
last post by:
I've been curious for awhile about why C supports some of its binary
operators in an op= format, but not others. For example, why are &=
and |= supported by C, but not &&= and ||=?
For awhile I...
|
by: Michael B Allen |
last post by:
What is the rationale for snprintf to "return the number of characters
(excluding the trailing '\0') which would have been written to the final
string if enough space had been available"?
This...
|
by: acthom |
last post by:
Hi, all,
Is it possible to find C89 standard rationale or draft version
on the Internet?(NOT the C99 version). Any urls?
Thank you in advance.
--
Best regards,
acthom
|
by: Andreas Huber |
last post by:
Hi there
Spending half an hour searching through the archive I haven't found a
rationale for the following behavior.
using System;
// note the missing Flags attribute
enum Color
{
|
by: Edward Diener |
last post by:
Given
value class X
{
public:
// Not allowed: X():i(100000),s(10000) { }
// Allowed
void InitializeDefaults() { i = 100000; s = 10000; }
private:
int i;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |