473,856 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the execution path of methods at runtime

Hi All,

Can i change the execution path of methods in my process at runtime?

e.g

a()->b()->c()->d()->e()

Now, i want execution to be altered at runtime as -

a()->b()->myfun1()->myfun2()->myfun3()... ->e()

Can this be done without changing the actual source file, may be by
adding a new module at runtime?

Thanks

--pradeep

May 29 '07 #1
17 2401
In article <11************ *********@q19g2 000prn.googlegr oups.com>,
blufox <25**********@g mail.comwrote:
>Can i change the execution path of methods in my process at runtime?
Not in C, because C does not have methods.

>e.g
>a()->b()->c()->d()->e()
>Now, i want execution to be altered at runtime as -
>a()->b()->myfun1()->myfun2()->myfun3()... ->e()
>Can this be done without changing the actual source file, may be by
adding a new module at runtime?
C does not have modules either. Furthermore, C does not offer any
method of activating new code at runtime.

Some operating systems provide mechanisms for dynamically loadable
objects. In the Windows world, these are usually called 'dll';
in the Unix world, these are usually called 'dso' but the
Unix operating system calls usually begin with dlopen() .
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
May 29 '07 #2
On May 29, 7:43 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1180449520.473 891.53...@q19g2 000prn.googlegr oups.com>,

blufox <2500.prad...@g mail.comwrote:
Can i change the execution path of methods in my process at runtime?

Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.
>
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?

C does not have modules either. Furthermore, C does not offer any
method of activating new code at runtime.

Some operating systems provide mechanisms for dynamically loadable
objects. In the Windows world, these are usually called 'dll';
in the Unix world, these are usually called 'dso' but the
Unix operating system calls usually begin with dlopen() .
Right, and i mean a Linux kernel module here.
Essentially it is C(with loads of GCCism) i guess.

So, is it possible using modules in unix/linux then. i must ask?

Thanks for the reply
--pradeep
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson

May 29 '07 #3
blufox wrote:
Hi All,

Can i change the execution path of methods in my process at runtime?

e.g

a()->b()->c()->d()->e()

Now, i want execution to be altered at runtime as -

a()->b()->myfun1()->myfun2()->myfun3()... ->e()

Can this be done without changing the actual source file, may be by
adding a new module at runtime?

Thanks

--pradeep
Hi

a()->b()->c()->d()->e()

means (in C):

call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...

etc

Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().

If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling

This requires a modification at compile time to a() or to b(), etc.

Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.

But all this looks far too complicated.

WHAT are you trying to do?

Explain that first.

jacob
May 29 '07 #4
On May 29, 8:01 pm, jacob navia <j...@jacob.rem comp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep

Hi

a()->b()->c()->d()->e()

means (in C):

call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...

etc

Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().

If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling

This requires a modification at compile time to a() or to b(), etc.

Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.

But all this looks far too complicated.

WHAT are you trying to do?

Explain that first.
Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .

What I intend to do?

I want to invoke my function without changing the actual source code
at runtime.

Is this somehow possible on a Linux system?

Thanks

--pradeep
>
jacob

May 29 '07 #5
On May 29, 4:07 pm, blufox <2500.prad...@g mail.comwrote:
On May 29, 8:01 pm, jacob navia <j...@jacob.rem comp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep
Hi
a()->b()->c()->d()->e()
means (in C):
call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...
etc
Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().
If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling
This requires a modification at compile time to a() or to b(), etc.
Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.
But all this looks far too complicated.
WHAT are you trying to do?
Explain that first.

Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .

What I intend to do?

I want to invoke my function without changing the actual source code
at runtime.

Is this somehow possible on a Linux system?

Thanks

--pradeep
jacob
It's just about possible using portable C, but only if you design the
source file to make it possible. For instance:

/* whichfunc.c */
extern void c(void);
extern void myfun1(void);
void (*func)()=c; /* =myfun1; */

/* prog.c */
extern void (*func)();

void a(void)
{
b();
}

void b(void)
{
(*func)(); /* the key line */
}

/* ... whatever ... */

Then you can link both files together using whatever implementation-
specific method your implementation provides (if you're on Linux,
you're quite possibly using gcc, in which case you specify both files
on the command line or probably use a makefile if it's a complex
project). Changing func will change the path of execution b takes.

Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.
--
ais523

May 29 '07 #6
blufox <25**********@g mail.comwrites:
On May 29, 7:43 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1180449520.473 891.53...@q19g2 000prn.googlegr oups.com>,

blufox <2500.prad...@g mail.comwrote:
>Can i change the execution path of methods in my process at runtime?

Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.
They are? That's news to me.

In any case, you should ask on a Linux-specific newsgroup.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 29 '07 #7
On May 30, 3:00 am, Keith Thompson <k...@mib.orgwr ote:
blufox <2500.prad...@g mail.comwrites:
On May 29, 7:43 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1180449520.473 891.53...@q19g2 000prn.googlegr oups.com>,
blufox <2500.prad...@g mail.comwrote:
Can i change the execution path of methods in my process at runtime?
Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.

They are? That's news to me.
Yes they are called methods in the kernel AFAIK.
May be i am misunderstandin g it.
>
In any case, you should ask on a Linux-specific newsgroup.
Tried that, didn't get satisfying answers so resorted to clc.
I 'll give another try though.

Thank you
--psr
>
--
Keith Thompson (The_Other_Keit h) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

May 30 '07 #8
On May 29, 8:30 pm, ais523 <ais...@bham.ac .ukwrote:
On May 29, 4:07 pm, blufox <2500.prad...@g mail.comwrote:
On May 29, 8:01 pm, jacob navia <j...@jacob.rem comp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep
Hi
a()->b()->c()->d()->e()
means (in C):
call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...
etc
Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().
If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling
This requires a modification at compile time to a() or to b(), etc.
Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.
But all this looks far too complicated.
WHAT are you trying to do?
Explain that first.
Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .
What I intend to do?
I want to invoke my function without changing the actual source code
at runtime.
Is this somehow possible on a Linux system?
Thanks
--pradeep
jacob

It's just about possible using portable C, but only if you design the
source file to make it possible. For instance:

/* whichfunc.c */
extern void c(void);
extern void myfun1(void);
void (*func)()=c; /* =myfun1; */

/* prog.c */
extern void (*func)();

void a(void)
{
b();

}

void b(void)
{
(*func)(); /* the key line */

}

/* ... whatever ... */

Then you can link both files together using whatever implementation-
specific method your implementation provides (if you're on Linux,
you're quite possibly using gcc, in which case you specify both files
on the command line or probably use a makefile if it's a complex
project). Changing func will change the path of execution b takes.

Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.
This is fruitful.
I ll look into this and see if i can get something concrete from this
hint.

Thanks a ton for the help.

--psr
--
ais523

May 30 '07 #9
blufox wrote:
ais523 <ais...@bham.ac .ukwrote:
.... snip about 100 lines ...
>>
Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.

This is fruitful. I ll look into this and see if i can get something
concrete from this hint.
Please snip irrelevant data from the quoted portion of your
replies. The links below (in my sig) may be helpful.

--
Some useful links on quoting:
<http://www.xs4all.nl/%7ewijnands/nnq/nquote.html>
<http://www.complang.tu wien.ac.at/anton/mail-news-errors.html>
<http://www.netmeister. org/news/learn2quote2.ht ml>
<http://www.star-one.org.uk/computer/format.htm>

--
Posted via a free Usenet account from http://www.teranews.com

May 30 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2218
by: Graham | last post by:
I've found that other thing that returns the assembly executable but I don't need the file tacked on to the path, just need the path. I don't want to always have to write code to trim off the filename either... Also, none of my friends want to try my new programs out because they don't want to put the .NET framework on their pc. I was reading that you guys killed the need for runtime files with this version, so what exactly is the .NET...
16
2134
by: chris | last post by:
im new to javascript but slowly getting better what i want to do is have some text on the screen and when an event happens for example click a button the text would change to what i want. how would i do this ??
4
2452
by: Tony W | last post by:
Hi, I am trying to write a simple application to retrieve data from the Windows registry and insert it into textboxs on a windows form. So far I have one namespace containing two classess. The first class handles the form generation - (this was done using GUI form designer).
4
2291
by: AdamM | last post by:
How can I change an object's type at runtime? For example, here's what I want to do in psedocode: object animal; if (dog) { animal=(dog)animal;
2
4690
by: Bassel Tabbara | last post by:
I wrote the following code: oApp = new Outlook.Application(); oApp = new Outlook.Application(); oNameSpace= oApp.GetNamespace("MAPI"); oNameSpace.Logon(null,null,true,true); //gets defaultfolder for my Outlook Outbox oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox); But it won't work and it is giving me the following error:
2
5613
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the content, not even by changing browser encoding setting to the appropriate one. I implemented SoapExtension (called EncodingExtension) to rewrite the xml to change the encoding="utf-8" to encoding="windows-1252" in BeforeDeserialize SoapMessage...
4
1568
by: Mikael Olofsson | last post by:
Hi! This is in Python 2.3.4 under WinXP. I have a situation where I think changing the behaviour of a namespace would be very nice. The goal is to be able to run a python file from another in a separate namespace in such a way that a NameError is not raised if a non-existing variable is used in the file. The file that I want to run is taken out of context, and some needed variables may be missing that are normally there when used in...
18
1939
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two requests at the same time. The first one stops execution as the second continues. If I place either an alert between the two requests or run the second through a setTimeout of only 1 millisecond, they both work. You can see a working example here:...
22
3104
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is created / destroyed at user request). I can check form != null to prevent incorrect access. But, the form could disappear immediately after the check, before the method is run. Or someone could click 'close' when it's in the middle of an update. ...
0
11052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7930
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7090
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5759
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4172
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3198
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.